MemberzPlus
Ross Group Inc   Client Portal  |  (800) 652-4985  |  Contact   



JBoss6 TCP Port Configuration

I've spent the last week or so attempting to get MemberzPlus running on JBoss 6.1.0. We currently run all of our clubs on version 4.2.3, but new web service standards and other obsolete features are making it difficult to continue with that incarnation of JBoss. I looked at JBoss 7, but it is so completely different than any prior version that I punted and decided to tackle JBoss 6 first.

Once I figured out how to get encryption working (see previous blog), the next hurdle was to figure out how to get it running on the correct port. Within our development environment, we use a standard of '8'+club code for the web port. So, for instance, if the club's code is 240 we run their instance on port 8240.

Under JBoss 4.2.3, the port configurations were specified in one massive XML file with a complete section for each set of ports you want to use. For instance, the port settings for club 240 occupy about 400 lines of the 2000+ line file. The file is located under C:\jboss-4.2.3.GA\conf, outside the "server" structure. This is its one and only advantage; a single location controls all the ports for all the running instances.

In JBoss 6.1.0, the configuration is much more sensibly located in the server structure. In my local development environment, it's located at C:\jboss-6.1.0.Final\server\mzp4\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml. Within that XML, instead of having a full complete set of port specifications for each configuration, there is one set of default values, then "mbean" entries used to specify a numerical offset from the default.

First we need to decide what to call our derivation of the ports, I'll call mine "Ports240Bindings" to continue with the club 240 theme.

<!-- The binding sets -->
<parameter>
  <set>
   <inject bean="PortsDefaultBindings"/>
   <inject bean="Ports01Bindings"/>
   <inject bean="Ports02Bindings"/>
   <inject bean="Ports03Bindings"/>
   <inject bean="Ports240Bindings"/>
  </set>
</parameter>

Next we have to define the "Ports240Bindings" mbean. The standard entries provided by the folks at JBoss use a strict offset methodology. In other words, every port binding is some offset from the default value. The "ports-02" entry, for instance, bumps all ports up by 200:

  <!-- The ports-02 bindings add 200 to each port value -->
  <bean name="Ports02Bindings"
    class="org.jboss.services.binding.impl.ServiceBindingSet">
   <constructor>
    <!-- The name of the set -->
    <parameter>ports-02</parameter>
    <!-- Default host name -->
    <parameter>${jboss.bind.address}</parameter>
    <!-- The port offset -->
    <parameter>200</parameter>
    <!-- Set of bindings to which the "offset by X"
     approach can't be applied -->
    <parameter><null/></parameter>
   </constructor>
  </bean>

Now, you would think that to get from 8080 to 8240, all you would need to do would be to set 160 and you're done, right? Well, yes, that does work. Mostly. But let's say you are running multiple servers and one has an offset of 160 (Club 240) and one has an offset of -73 (Club 007 - 8007). It is possible that some port somewhere + 160 could collide with some other port somewhere - 73. Then you're stuck. There is a solution. You can use standard offsets, which are always a multiple of 100, then explicitly set the web port. This way, you'll never collide on ports, but you're still able to run the application on the port you want.

 <!-- The ports-240 bindings add 400 to each port value, set http to 8240 -->
 <bean name="Ports240Bindings"
  class="org.jboss.services.binding.impl.ServiceBindingSet">
  <constructor>
    <!-- The name of the set -->
    <parameter>ports-240</parameter>
    <!-- Default host name -->
    <parameter>${jboss.bind.address}</parameter>
    <!-- The port offset -->
    <parameter>400</parameter>
    <!-- Set of bindings to which the "offset by X"
      approach can't be applied -->
    <parameter>
     <set>
      <bean class="org.jboss.services.binding.ServiceBindingMetadata">
       <property name="serviceName">jboss.web:service=WebServer</property>
       <property name="bindingName">HttpConnector</property>
       <property name="port">8240>/property>
       <property name="description">JBoss Web HTTP connector socket</property>
       <property name="fixedPort">true</property>
      </bean>
     </set>
    </parameter>
  </constructor>
 </bean>

You may want to bookmark this page, it took me FOREVER to find the proper format of that last constructor parameter to fix the HTTP port at 8240. Even the JBoss docs just say you can do it, they don't show you exactly how.

And finally, add the following to your java JVM arguments (typically the JAVA_OPTS environment variable):

-Djboss.service.binding.set=ports-240

Alan Moor
VP of Technology

Mr. Moor joined the team in 1996 as an experienced developer in Oracle, PL/SQL, and PowerBuilder. He has been a team lead and project manager of many high visibility projects including lead on the roll-out of our membership management software MemberzPlus to a membership organization over five million members. Mr. Moor is an Air Force Veteran with 8 years of service and served on the board of the Turner Syndrome Society. Mr. Moor has over 25 years experience in software development in a variety of technical disciplines including Oracle and Java.