Red Hat Application Server: JOnAS User Guide | ||
---|---|---|
Prev | Chapter 36. Web Service Interoperability between JOnAS and BEA WebLogic | Next |
Refer to Chapter 34 How to use Axis in JOnAS, which describes how to develop and deploy web services on JOnAS.
To create a web service based on an EJB, first create a stateless EJB. Then, create a web application (.war) or an application (.ear) with this EJB that will define a URL with access to the Web Service.
This section describes the deployment descriptor of the web service. To deploy a web service based on an EJB, specify the various elements in the WSDD. This WSDD enables the web service to be mapped on an EJB, by specifying the different EJB classes used.
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <!-- AXIS deployment file for HelloBeanService --> <service name="WebServiceName" provider="java:EJB"> <!-- JNDI name specified in jonas-EJB.xml --> <parameter name="beanJndiName" value="EJB_JNDI_Name"/> <!-- use of remote interfaces to access the EJB is allowed, but this example uses local interfaces --> <parameter name="homeInterfaceName" value="EJB_Home"/> <parameter name="remoteInterfaceName" value="EJB_Interface"/> <!-- JNDI properties: it may be necessary to modify hostname and port number, protocol name could be changed in accordance with the ORB used --> <!-- for a RMI ORB --> <parameter name="jndiURL" value="rmi://<url>:<port>"/> <parameter name="jndiContextClass" value="com.sun.jndi.rmi.registry.RegistryContextFactory"/> <!-- Specify here allowed methods for Web Service access (* for all) --> <parameter name="allowedMethods" value="*"/> </service> </deployment> |
The various tags allow mapping of the web service on different java classes. If a web service uses a complex type, this complex type must be mapped with a java class. To do this, two tags can be used:
<beanMapping qName="ns:local" xmlns:ns="someNameSpace" languageSpecificType="java:my.class"/> |
This maps the QName [someNameSpace]:[local] with the class my.class.
<typeMapping qname="ns:local" wmlns:ns="someNamespace" languageSpecificType="java:my.class" serializer="my.java.Serializer" deserializer="my.java.DeserializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> |
where QName [someNameSpace]:[local] is mapped with my.class. The serializer used is the class my.java.Serializer and the deserializer used is my.java.DeserializerFactory.
First, deploy the web application or the application containing the EJB. Then, deploy the web service using the Axis client tool:
jclient org.apache.axis.client.AdminClient -hjonasServerHostname -p9000 deploy.wsdd |
The web service WSDL is accessible from the url:
http://host:port/url-servlet/webservicename?wsdl. |
This EJB provides access to the web service deployed on JOnAS from the WebLogic Server.
To access the web service, generate the client class using the Ant task clientgen. For example:
<clientgen wsdl="<wsdl_url>" packageName="my.package" clientJar="client.jar" generatePublicFields="True" keep generated="True"/> |
This command creates four classes:
Service implementation
Java interface
Stub class
Service interface to the corresponding web service.
The tool can also generate the Java classes corresponding to future complex types of web services.
Then, call the web service in the EJB proxy code using the generated classes. For example:
try { WSNAME_Impl tsl=new WSNAME_Impl(); // access web service impl EJB_endpoint tsp = tsl.getEJB_endpoint(); // access WS endpoint interface ComplexType tr=tsp.method(param); } catch (Exception e) { e.printStackTrace(System.err); }; |