The Shortest Path To Exposing and Consuming Web Services in Java
The Shortest Path To Exposing and Consuming Web Services in Java
– As quickly as possible
● WSDL/SOAP based:
● Apache Axis
● Servlet-based
Exposing Web Services
with Apache Axis
● Set up basic Axis webapp
<target name="java2wsdl">
<axis-java2wsdl
classname="com.chariotsolutions.wsinjava.axis.SampleService"
namespace="axis.wsinjava.chariotsolutions.com"
location="http://localhost:8080/axisSample/services/SampleService"
output="axisSample.wsdl">
<classpath path="bin"/>
</axis-java2wsdl>
</target>
Generating the WSDD
Deployment Descriptor
● Use the wsdl2java ANT task:
<axis-wsdl2java
output="gen/java"
verbose="true"
url="gen/wsdl/axisSample.wsdl"
serverside="true"/>
● Document Style:
public void method(PurchaseOrder po);
● Wrapped Style:
public void purchaseOrder(String item, int quantity, String desc)
Axis Message Type
● DOM Elements or SOAPBodyElements:
– public Element [] method(Element [] bodies);
– public SOAPBodyElement [] method
(SOAPBodyElement [] bodies);
● SOAPEnvelopeObject
– public void method(SOAPEnvelope req,
SOAPEnvelope resp);
Intro to JBossWS
● JBossWS is JBoss's implementation of web
services
● Brief History:
– JBoss.NET: earier implementation JBoss 3.x
– Replaced by JBossWS in JBoss 4.x
<servlet>
<servlet-name>JBossSample</servlet-name>
<servlet-class>
com.chariotsolutions...JBossWSSampleJSEEndpoint
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JBossSample</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Create webservices.xml
<webservice-description>
<webservice-description-name>
JbossSampleService
</webservice-description-name>
<wsdl-file>
WEB-INF/wsdl/JBossWSSampleService.wsdl
</wsdl-file>
<jaxrpc-mapping-file>
WEB-INF/jaxrpc-mapping.xml
</jaxrpc-mapping-file>
<port-component>
<wsdl-port>JBossWSSamplePort</wsdl-port>
<service-endpoint-interface>
com.chariotsolutions.wsinjava.jbossws.JBossWSSample
</service-endpoint-interface>
<service-impl-bean>
<servlet-link>JBossSample</servlet-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>
Intro to Codehaus XFire
● Relative newcomer, announced Aug 2004
<axis-wsdl2java
output="gen/java"
verbose="true"
url="http://localhost:8080/xFireSample/services/XFireSample?wsdl"
serverside="false"/>
Axis Client for Axis Server
● Just works:
● XFire:
– http://xfire.codehaus.org/User's+Guide
● JBoss
– http://www.jboss.org/wiki/Wiki.jsp?page=JBossWS
Download Slides and Code
● Slides and Code can be downloaded from:
www.chariotsolutions.com
● Further questions: