JAXWSJBoss

How to create JAX-WS Web services and clients on JBoss 4.0.4


The JBoss Application Server (AS) 4.0.3 introduces the EJB 3.0 programming model, so it's now possible to create and consume JAX-WS web services on JBoss. Netbeans 5.5 don't support JAX-WS web services on JBoss 4. This tutorial will show you hovewer, how to create and deploy it using some workarounds and then how create web service client and consume it. If you want more information about EJB3 and JAX-WS support on JBoss,you can find it here.

Software Needed for the Scenario:


Before you begin, you need to install the following software on your computer:

  • NetBeans IDE 5.5 (development build) download.
  • Java Standard Development Kit (JDK) version 5.0 download. Don't use JDK 1.6 for server or IDE - JBoss doesn't support this yet!
  • JBoss Application Server version 4.0.4 (install it as custom installation and select "ejb3" Install type) download.




Contents





Creating web service and client in Web module



Netbeans 5.5 supports only JAX-RPC web services on JBoss. JAX-WS isn't supported,although there is the way,how to do it-with JBoss 4.0.4 . JBoss 4.0.4 has implemented only EJB3 support.By default we can't create JavaEE 5 Web module on JBoss.Hovewer, if we create web module for example on Tomcat, we could then change server in Properties|Run and it will work.

Creating web service in Web module


  • Choose File > New Project (Ctrl-Shift-N). Select Web Module from the Web category. Name the project WSWebModule.
  • Select JBoss Application Server 4 from the combo box and uncheck Set Source Level to 1.4 checkbox.
  • Go to Properties > Libraries and click Add Library....
  • Select JAX-WS library, click Add Library and back in Libraries view uncheck Package.
  • Right-click the WSWebModule node and choose New > Java Class.
  • Write JBossWebWS into Class Name.
  • Type org.me.wss in Package, and click Finish.
  • Go to editor, where JBossWebWS.java should be opened and write upon the public class JBossWebWS annotation @WebService
  • open web.xml, delete listener passage and change <servlet-class> tag value to org.me.JBossWebWS.

In the Projects window you'll see new Web Service node,however it will be empty.

Image:webws_JAXWSJBoss.png


There's also alternate way through Bundled Tomcat :

  • Choose File > New Project (Ctrl-Shift-N). Select Web Module from the Web category. Name the project WSWebModule.
  • Select Bundled Tomcat(5.5.17) from the combo box and uncheck Set Source Level to 1.4 checkbox.
  • Right-click the WSWebModule node and choose New > Web Service.
  • Write JBossWebWS into Web Service Name.
  • Type org.me.wss in Package, and click Finish.


Image:service_JAXWSJBoss.png

  • Right-click the WSWebModule node and choose Properties.
  • Select Run and change Server from Bundled Tomcat to JBoss Application Server 4.
  • Select Libraries and uncheck JAX-WS 2.0 checkbox . Click OK.





Deploying web service on JBoss


Now we have created web service but we're not ready to deploy it. Web service is created empty by default,but in order to deploy it,we must create at least one operation inside the service.

  • Go to editor, JBossWebWS.java should be opened there.
  • Right-click inside service body and select Web Service | Add Operation
  • In next window change "operation" with "greet" ,click on Add, write s into Name and click OK in both windows.
  • Now the operation should look like this :
/**
     * Web service operation
     */
    @WebMethod
    public String greet(@WebParam(name = "s") String s) {
        // TODO implement operation 
        return null;
    }


  • Change the code this way :


 /**
     * Web service operation
     */
    @WebMethod
    public String greet(@WebParam(name = "s") String s) {
        return "Hello " + s;
    }


  • We must also modify service endpoint according to JSR-181 specification,because otherwise it couldn't be accessed from outside.
Go to Projects tab, open Configuration Files node and select web.xml. Double-click on it and it'll open in editor.
Click on XML in command bar.


You'll see the code:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
        <servlet-name>JBossWebWS</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>JBossWebWS</servlet-name>
        <url-pattern>/JBossWebWS</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
	<welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>JBossWebWS</servlet-name>
        <servlet-class>org.me.wss.JBossWebWS</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>JBossWebWS</servlet-name>
        <url-pattern>/JBossWebWS</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
	<welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>


  • Click File and Save all.


Now it's OK, so right click on Web module and select Deploy Project. Service will be deployed on server. If you Right-click on web service's node in Projects tab, you'll see, that there's not Test Web Service option.We can still display in web browser wsdl code of service or even the tester, like we know from Bundled Tomcat. Right-click on web service's node and select Properties.In next window select service's URL address, as displayed here and copy it(Ctrl+C):

Image:url_JAXWSJBoss.png

Go to web browser and Paste(Ctrl+V) URl into address field.If you now press Enter, WSDL code of our web service will be displayed.



Creating web service client in web module


  • Choose File > New Project (Ctrl-Shift-N). Select Web Module from the Web category. Name the project WSCWebModule.
  • Select JBoss Application Server 4 from the combo box and uncheck Set Source Level to 1.4 checkbox

Click Finish.

  • Choose File > New File (Ctrl-N). Select Web Service Client from the Web Service category and click Next.

Let selected default Project and click on button Browse to the right.
Click on WSWebModule ,select JBossWebWS and click OK.}} Type org.me.wsc in Package, and click Finish.

  • The Projects window displays the new web service client under Web Service References node:

Image:wsclient_JAXWSJBoss.png




Creating web service and client in EJB module


Netbeans 5.5 supports only JAX-RPC web services on JBoss. JAX-WS isn't supported,although there is the way,how to do it-with JBoss 4.0.4 . JBoss 4.0.4 has implemented EJB3 support, hovewer, so we can work also with JAXWS.

Creating web service in EJB module


  • Choose File > New Project (Ctrl-Shift-N). Select EJB Module from the Enterprise category. Name the project WSEJBModule.
  • Select JBoss Application Server 4 from the combo box.Click Finish.
  • Right-click the WSEJBModule node and choose New > Web Service.
  • Write JBossEJBWS into Web Service Name.
  • Type org.me.ejbwss in Package, and click Finish.

The Projects window displays the new web service under Web Services node:

Image:ejbws_JAXWSJBoss.png



Deploying web service on JBoss


We have created web service but we're not ready to deploy it. Web service is created empty by default,but in order to deploy it,we must create at least one operation inside the service.

  • Go to editor, JBossEJBWS.java should be opened there.
  • Right-click inside service body and select Web Service | Add Operation
  • In next window change "operation" with "greet" ,click on Add, write s into Name and click OK in both windows.
  • Now the operation should look like this :
/**
     * Web service operation
     */
    @WebMethod
    public String greet(@WebParam(name = "s") String s) {
        // TODO implement operation 
        return null;
    }


  • Change the code this way :


 /**
     * Web service operation
     */
    @WebMethod
    public String greet(@WebParam(name = "s") String s) {
        return "Hello " + s;
    }


We're ready to deploy it. Right click on EJB module and select Deploy Project. Service will be deployed on server. If you Right-click on web service's node in Projects tab, you'll see, that there's disabled Test Web Service option. We can still display in web browser wsdl code of service but not the tester, like we know from Bundled Tomcat or glassfish.Right-click on web service's node and select Properties.In next window select service's URL address, as displayed here and copy it(Ctrl+C):

Image:ejbservice_JAXWSJBoss.png

Go to web browser and Paste(Ctrl+V) URl into address field.Hovewer, there's bug in the URL we just pasted.We must change it from http://localhost:8080/JBossEJBWS?wsdl to http://localhost:8080/WSEJBModule/JBossEJBWS?wsdl.Now press Enter and wsdl code of deployed service will be displayed in your web browser.

Image:wsdlejb2_JAXWSJBoss.png



Creating web service client in EJB module



  • Choose File > New Project (Ctrl-Shift-N). Select EJB Module from the Enterprise category. Name the project WSCEJBModule.
  • Select JBoss Application Server 4 from the combo box and uncheck Set Source Level to 1.4 checkbox.
  • Project folder can't have spaces in path,othervise client creation fails.Change project folder,if neccessary.Click Finish.
  • Choose File >New File (Ctrl-N). Select Web Service Client from the Web Service category and click Next.

Select WSDL URL and enter "http://localhost:8080/WSEJBModule/JBossEJBWS?wsdl".
Click on button Browseto the right.
Click on WSEJBModule ,select JBossEJBWS and click OK.
Type org.me.ejbwsc in Package, and click Finish.

  • The Projects window displays the new web service client under Web Service References node:


Image:wseclient_JAXWSJBoss.png



Consuming web service


  • Go to Projects tab and double click on WSCWebModule > index.jsp file.
  • Select commented area in page's body,starting with
<%-- This example uses JSTL, uncomment the taglib directive above.

Right-click and select Web Service Client Resources | Call Web Service Operation.
Click on WSWebModule ,select JBossWebWS | greet and click OK.

  • Code will look like this :
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

    <h1>JSP Page</h1>
    
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
        <!-- Let's welcome the user ${param.name} -->
        Hello ${param.name}!
    </c:if>
    --%>
    
    <%-- start web service invocation --%><hr/>
    <%
    try {
	org.me.wsc.JBossWebWSService service = new org.me.wsc.JBossWebWSService();
	org.me.wsc.JBossWebWS port = service.getJBossWebWSPort();
	 // TODO initialize WS operation arguments here
	java.lang.String s = "";
	// TODO process result here
	java.lang.String result = port.greet(s);
	out.println("Result = "+result);
    } catch (Exception ex) {
	// TODO handle custom exceptions here
    }
    %>
    <%-- end web service invocation --%><hr/>
    </body>
</html>
  • Change string 'java.lang.String s = "";' to 'java.lang.String s = "your_name";'.
  • Right-click the WSCWebModule node and choose Properties.
  • Select Run and change Server from Bundled Tomcat to JBoss Application Server 4.Click OK.
  • Right click into Projects tab on WSWebModule node and select Run Project

Reference

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo