February 18, 2010

Getting Started with JBoss Web Serivce using JAX-WS on JBoss 5.1 using Maven, OpenEJB and eviware soapUI

The easiest way to get started with writing Web Service is using Java API for XML Web Service, JAX-WS. The downside with this is that the creation of the WSDL file is automatic, and that is not the preferred way of writing cross platform independent web service. If that is your design goal, you should handwrite the WSDL, i.e. contract first. But if you know that the only clients are going to be Java client, than automatically generating the WSDL could be fine.

A good practice when writing all kind of code, is to make the code testable and also make it testable outside the container. To achieve that I will use OpenEJB, if have never heard or used OpenEJB and you are writing EJB 3.0 applications, it is definitely worth the time to check it out.

Lets start with writing a standard Stateless EJB.





src/main/resources/META-INF/ejb-jar.xml


src/main/resources/META-INF/jboss.xml


pom.xml


Now lets test our EJB with OpenEJB. The first thing we need to do, is to add the OpenEJB dependency to our pom.xml



Then we write our JUnit test case.



After verifying that our Stateless Session Bean is working, we now continue to deploy it to the JBoss container.



We start our JBoss container and checks that the EJB is successfully deployed.

Now lets add Web Service support to our EJB.





Now lets write our JUnit test case, to test our web service outside the JBoss container.



Before running the testcase we need to update our pom.xml with a concrete web service implementation.



After running the testcase from withing Eclipse, we can now be confident that we our is executing as expected. Now lets deploy our EJB to the JBoss container.



If you have stopped the JBoss, then restarted and verify that everything is looking healthy in the server log. Verify that the web service is working by firing up a web browser and go to http://localhost:8080/jbossws-example/HelloServiceBean?wsdl, to verify that you see the wsdl file.

Instead of writing a web service client, we are going to use a good test tool for testing web service – eviware soapUI. Start the soapUI and then select new project.

 

  

 

5 comments:

Alexander said...
This comment has been removed by the author.
Alexander said...

i found it's not a quite useful to test with saopui against the jboss. much more interesting is to write integration test which will start openjb, deploy artifacts and test with soapui-maven-plugin. it's possible with jetty in case of non ejb webservices, but with exposed ejbs plain jetty is useless. any ideas on that?

Magnus K Karlsson said...

I think the best practise is to use OpenEJB for module test, that are automatically runned when doing maven install.
These module test are also the platform for test driven development.

When it comes to integration test I think these should be run on your production environment platform. And if that is JBoss, yes, these integration test should be run on JBoss.
To achieve this, use maven-soapui-plugin and to start JBoss, use cargo-maven2-plugin.

Anonymous said...

pom.xml is not a valid XML. (seems like a lot of open/close tags have differce cAsE)

Risto said...

I need to learn more about JAX WS. Are some code blocks or images missing from the blog?


Lets start with writing a standard Stateless EJB.





src/main/resources/META-INF/ejb-jar.xml


src/main/resources/META-INF/jboss.xml


pom.xml