JBoss Community

Creating a JSR 181 Web Service using JBT/JBDS Tooling

modified by Administrator Administrator in JBoss Tools - View the full document

This document is meant to provide some simple, straightforward steps to illustrate how to create a JSR 181 web service that you can then mediate in the ESB.

 

  1. In the JBT/JBDS tooling, open the JBoss AS Perspective.
  2. In the Package Explorer view, right-click and select New->Dynamic Web Project or use the File menu and select File->New->Dynamic Web Project.

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1832/409-449/step3.jpg

  3. Type "MyWebServiceProject" as the Project name.
  4. If the Target Runtime is set correctly, just click Finish. Otherwise, specify an appropriate Target Runtime.
  5. The "Open Associated Perspective?" dialog will appear if you are in the JBoss AS perspective. You can switch to the Java EE perspective if you want, but for now we'll stay in the Java AS perspective for these steps, so click "No."

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1833/450-164/step5.jpg

  6. Now we want to create our web service java class in our project. In the "src" folder of your new project, right-click and select New->Class.
  7. Give the class an appropriate package, such as "org.jboss.lab" and the name "MyWebService". Then click Finish.

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1834/450-326/step7.jpg

  8. The code for the class is pretty simple:

     

    package org.jboss.lab;

     

    import javax.jws.WebMethod;

    import javax.jws.WebService;


    @WebService()

    public class MyWebService() {

         @WebMethod()

         public String sayHello ( String name ) {

              return "Hello " + name + "!";

         }

    }

     

  9. Save your class and go to the "WebContent/WEB-INF" folder in your project. Double-click on web.xml.
  10. In the navigator on the left of the Web XML Editor, find and select Servlets.

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1835/450-326/step10.jpg

  11. Click "Add..." in the Servlets section and in the dialog that appears, give it the name "MyWebServiceServlet" and give it the fully-qualified class name for our web service class - org.jboss.lab.MyWebService. Click Finish.

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1836/449-371/step11.jpg

  12. Now click "Add..." in the Servlet Mappings section. In that dialog, give it the name "MyWebServiceServlet" and the URL-pattern "/MyWebService".

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1837/449-371/step12.jpg

  13. Make sure everything is saved (go to the File menu and select Save All if it's enabled) and now we'll deploy our web service to the server.
  14. In the Servers view or JBoss Server View (deprecated in JBT 3.1/JBDS 3), right-click on your runtime server and select "Add and Remove Projects..."

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1838/449-491/step14.jpg

  15. In the dialog that appears, select your web service project and click "Add>" to move it to the "Configured Projects" list. Then click Finish.
  16. If everything goes well, we should see in the console that our web service was deployed and a WSDL was created in the file system.
  17. To verify that it deployed properly, open your web browser and direct it to URL - http://localhost:8080/jbossws/services. (You may need to log in.) Once it comes up, you can see all the web services deployed on the server. Look for your web service "MyWebService" in the list.

    http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1839/450-573/step17.jpg

  18. Now you can use a separate tool such as soapUI to try invoking your web service or the Web Services Explorer from WTP.
  19. To use the Web Services Explorer...

Comment by going to Community

Create a new document in JBoss Tools at Community