JBossWs Deployment Descriptor
Once the code is ready and compiled. You have modify the web.xml file located in WEB-INF folder.
Modify the web.xml file like below. (web.xml)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TestWS</display-name>
<servlet>
<servlet-name>TestWs</servlet-name>
<servlet-class>com.test.dhanago.TestWs</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TestWs</servlet-name>
<url-pattern>/TestWs</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Deploying the JBoss web service application
Once this is done, its time to build and deploy the application in JBoss Application server.
Once every thing is compiled with out any errors. And if you have enabled the Auto build functionality of the Eclipse IDE, You have already done with building the application. If the auto build functionality of eclipse is not enabled, then right click on the project and build the project using build option.
Go to Servers window and right click on the JBoss server listed over there and select Run.
Wait for server to start. Once it starts, right click on the server listing. You can find a option called "Add and Remove Project". Click on the option. You will get a wizard where you can select your projects to move to right and configure with server. Once you moved your project. Click on finish.
Once it is done, you can find that the project is again build and moved to server default deployment folder automatically.
Console will display you like below.
Buildfile: D:\ec2\eclipse\plugins\org.eclipse.jst.server.generic.jboss_1.5.102.v20070608\buildfiles\jboss323.xml
deploy.j2ee.web:
[jar] Building jar: D:\validation\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\Tws.war
[move] Moving 1 file to D:\MyBoss\jboss-4.0.5.GA_ws121\server\default\deploy
BUILD SUCCESSFUL
Total time: 10 seconds
The dynamic web application i created is with the name "Tws". So the build has created Tws.war and moved it to the default deploy folder of the JBoss server.
To make sure web service is started once it is deployed in the JBoss console you can find the log like below.
13:57:52,306 INFO [ServiceEndpointManager] WebService started: http://<machine name>:8080/Tws/TestWs
To view the WSDL follow the link http://<machine name>:8080/Tws/TestWs?wsdl
To see the list of webservices deployed in your JBoss Application server follow the link http://localhost:8080/jbossws. This browser console will have link to see your deployed webservices and their WSDL files.
JBossWs Browser Console.
Clicking on View a list of deployed services will list you the deployed web services. In our case we will get the following screen where we can see the registered service endpoints.
Here in this screen you can see the ServiceEndpointAddress link which will take you to the WSDL file.
You can also find the WSDL file in the following path:
<jboss_path>\server\default\data\wsdl\<project_name>.war\<filename>.wsdl
You can generate the client stubs using this file and access the web service. Creating the client stubs to access the web service is out of scope of this article.
The WSDL file generated using JBossWs is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="TestWsService" targetNamespace="http://dhanago.test.com/" xmlns:tns="http://dhanago.test.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xs:schema targetNamespace="http://dhanago.test.com/" version="1.0" xmlns:tns="http://dhanago.test.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="greet" type="tns:greet"/>
<xs:element name="greetResponse" type="tns:greetResponse"/>
<xs:complexType name="greet">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="greetResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>
<message name="TestWs_greet">
<part name="greet" element="tns:greet"/>
</message>
<message name="TestWs_greetResponse">
<part name="greetResponse" element="tns:greetResponse"/>
</message>
<portType name="TestWs">
<operation name="greet" parameterOrder="greet">
<input message="tns:TestWs_greet"/>
<output message="tns:TestWs_greetResponse"/>
</operation>
</portType>
<binding name="TestWsBinding" type="tns:TestWs">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="greet">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="TestWsService">
<port name="TestWsPort" binding="tns:TestWsBinding">
<soap:address location="http://EC3-NOR-124251:8080/Tws/TestWs"/>
</port>
</service>
</definitions>
Conclusion:
This article is just a quick start to start with for developers who want to quickly proceed with JBoss web services. It is up to the developers interest to leverage on this and proceed further. This is not the only procedure to expose a web service in JBoss. There might be lot of ways to do that and this is one of the way. So don't stop here and continue Exploring.
|