How to change JBoss 5.1 default port

In order to run JBoss 5.1 with a different port from the default one (8080), an easy but efficient solution is to execute run.sh or run.bat with adding the following instruction on the command line:

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

To better understand what’s going on, just open file

{JBOSS_DIR}\{PROFILE}/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml

then look at the following lines:

As you can guess, ports-01 it nothing but a bean with mapped values:

where on the default port will be added the X offset of 100, and the listening HTTP port will result on a 8180 value.

PLEASE NOTICE

If you receiving some JNDI error (something like ‘can’t listen to 1099 port), you’ll probabily have an already deployed application that listen to this port;
remember to configure the application properties in the same way as above (i.e. the JNDI port will be the 1099)

Create JMS Topic with JBoss 5.1 GA and Java 6

Send message with JMS and JBoss 5.1 GA

This example will show how to produce an async JMS message after a success update operation.

The source code is based on the previous article on how to set up a restful webapp that uses ejb3 and jpa technology.

So the minimum requirements for this example are:

  • Java J2ee 6.0
  • JPA 1
  • EJB 3.x
  • JBoss 5.1 GA
  • Jersey 2.6

Topic configuration on JBoss

Under {JBOSS_HOME}/server/default/deploy directory, create a “topic” folder and add a file named MyTopic-service.xml, then write in the following content:

Notice it is also possible to put the content above on the already existent file destination-service.xml.

Send message topic from JBoss

Take the sample-ejb project of the previous article and edit the classes as described below:

PersonLocal.java and PersonRemote.java

PersonBean.java

PersonBean EJB now expose the create and update method.

Execute the following command from the Windows prompt:

 

Expose Restful methods for create and update

Take the sample-web project of the previous article and edit the classes as described below:

PersonService.java

 

Execute the following command from the Windows prompt:

Create a simple app client for subscribe to Topic

Create a simple app project archetype by executing the maven command

Edit pom.xml in this way:

Under src/main/resources, place a file named jndi.properties with the following content:

 

Edit App.java

Run the app, it will wait for a message.

From a restclient like Postman or RestClient , set the request body in this way:

Set Content-Type on request headers with value “application/json

On the address bar, type the following with PUT method

put_request_data

 

From the app client console, a log message should display something like this

Create a Java Restful Web Application (Jersey, EJB3, JPA, JBoss 5.1, JDK 6) from ZERO with Maven

Create a web application with JBoss 5.1 and JDK 6

In this post we’ll see how to set up a complete life-cyle webapp within JBoss 5.1 on JDK 6.

Please notice this example is no-IDE dependant, therefore the procedure below is created with maven and manual editing.

The requirements / specs for this example are:

  • JDK 6
  • JBoss 5.1 GA
  • JPA (1.0)
  • EJB 3.x
  • Jersey 2.6
  • MySql

You can download the full example here

MySQL Database

Download full Database definition and script

Basically, create a database called JPADB  and two tables definied as below:

Person

Cities

Make sure you execute the following scripts:

JBoss configuration

To make MySql work on JBoss environment, copy mysql-connector-java-5.1.18.jar under {JBOSS_HOME}/server/default/lib.

Then, create a file called mysql-ds.xml under {JBOSS_HOME}/server/default/deploy with this content:

Optionally:

If you want to enable remote debugging with JBoss, edit run.conf or run.bat.conf (depending on your sistem) and under the line “Sample JPDA settings for remote socket debugging“, type in the following line:

Please notice:

Setting localhost instead of yourhostname can result in access error on mysql db.

Create EJB module

From the command line, type in the following command:

This will create an ejb project compatible with Java6.

Edit pom.xml and edit the following line

By enabling the generation of the client, all the modules using the ejb can include the ejb-client on its classpath

 

Then, create a file called persistence.xml with the following content:

 

Create City.java

and Person.java

Create PersonBeanLocal.java as the following:

The PersonRemote.java interface

The PersonBean.java implementation

Your ejb module is now completed. Build and deploy it under {JBOSS_HOME}/server/default/deploy directory with the following command under project directory:

Windows example

The last line will install the ejb-client.jar under maven local repository in order to be included in the webapp classpath.

Create web module

First off, create a web module with the jersey archetype

Edit pom.xml so the result will be the following:

According to Jersey Documentation, last Jersey compatible with JDK 6 is version 2.6.

Notice that with the line

the war package will not include the ejb-client libraries, otherwise the binding to the ejb interfaces will fail.

Under src directory, create a file named jndi.properties with the following:

Now it’s time to create the model returned from our future rest service; we’ll use JAXB specs in order to return an  xml response, if requested.

Create CityResult.java

Create PersonResult.java

Finally, create PersonService.java

That’s all.

Deploy web module with the following command from project root directory:

Windows command example

You can better test PersonService from a rest client browser like postman or restclient:

Type in the following on the address bar:

http://localhost:8084/sample-web/webapi/person/id/1

restclient

Set Accept: application/xml on the request header will return an xml response instead.