[jboss-user] [JBoss Tools] - Creating a JSR 181 Web Service using JBT/JBDS Tooling

Administrator Administrator do-not-reply at jboss.com
Mon Jan 24 09:35:28 EST 2011

Administrator Administrator [http://community.jboss.org/people/admin] modified the document:

"Creating a JSR 181 Web Service using JBT/JBDS Tooling"

To view the document, visit: http://community.jboss.org/docs/DOC-14663

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/showImage/102-14663-7-1832/step3.jpg  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/showImage/102-14663-7-1833/step5.jpg  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/showImage/102-14663-7-1834/step7.jpg  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;

public class MyWebService() {
     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/showImage/102-14663-7-1835/step10.jpg  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/showImage/102-14663-7-1836/step11.jpg  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/showImage/102-14663-7-1837/step12.jpg  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/showImage/102-14663-7-1838/step14.jpg  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 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/showImage/102-14663-7-1839/step17.jpg  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...
  * Make sure you are in the J2EE perspective, in the menubar, select "Run -> Launch the Web Services Explorer"
 http://community.jboss.org/servlet/JiveServlet/showImage/102-14663-7-1840/step19a.jpg  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1840/450-439/step19a.jpg 
* The Web Services Explorer opens. There is a small toolbar in the upper right corner of the window. Click the "WSDL Page" button.
 http://community.jboss.org/servlet/JiveServlet/showImage/102-14663-7-1841/step19b.jpg  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1841/142-30/step19b.jpg 
* When the WSDL Page opens, you will see a tree on the left with "WSDL Main" at the root. When you select the "WSDL Main" item in the tree, you will see a panel with "Open WSDL" to the right. Here you can provide a WSDL URL or WSDL file location. When you are finished, click on the 'Go' button.
* Now on the left, you will get a web service tree under the "WSDL Main" root. When you drill in and select your web service operation, you will see "Invoke a WSDL Operation." In the Body section, you'll see a list of arguments where you can provide values. Click Add to provide a value, input the value, and click the "Go" button when you are complete. (If your web service operation needs to input many arguments, you can click the 'Source' menu on the right-top of the right. Then you can give a soap message to the web service.)
 http://community.jboss.org/servlet/JiveServlet/showImage/102-14663-7-1842/step19c.jpg  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-14663-7-1842/450-436/step19c.jpg 
* In the "Status" pane, you will see the reply message from the web service.

Comment by going to Community

Create a new document in JBoss Tools at Community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110124/28354ac5/attachment.html 

More information about the jboss-user mailing list