Change Notes item #848220, was opened at 2003-11-24 11:27
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=381174&aid=848220&group_id=22866
Category: None
Group: v4.0
Status: Open
Priority: 5
Submitted By: thomas diesler (tdiesler)
Assigned to: Nobody/Anonymous (nobody)
Summary: J2EE1.4 compatible webservices HOWTO - client model
Initial Comment:
J2EE1.4 compatible webservices HOWTO - client model
=========================================
This tracker describes how to implement J2EE1.4
compatible webservice clients in JBoss4.x.
The basic notion is, that the client can lookup a Service
Interface (javax.xml.rpc.Service) as defined by the the
JAX-RPC specification from its JNDI environment context
(ENC) and invoke the methods of the webservice like a
local method call.
A client can be any of the following: J2EE application
client, EJB component, web component, or another
webservice. (see Scott's tracker on J2EE application
clients)
Packaging
=======
The client deployment should contains the following files:
#1 Service Endpoint Interface (SEI) class
#2 Web services client deployment descriptor
(webservicesclient.xml)
#3 WSDL file
#4 JAX-RPC mapping file
#1 Service Endpoint Interface
-----------------------------
Is the public interface of the webservice's business
methods
public interface HelloWs extends Remote {
public String sayHello(String input) throws
RemoteException;
}
#2 webservicesclient.xml
------------------------
Is webservice client deployment descriptor, it lives in
META-INF for application and EJB clients and in WEB-INF
for web component clients.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webservicesclient PUBLIC
"-//IBM Corporation, Inc.//DTD J2EE Web services
client 1.0//EN"
"http://www.ibm.
com/webservices/dtd/j2ee_web_services_client_1_0.
dtd">
<webservicesclient>
<service-ref>
<service-ref-name>service/HelloWsService</service-ref-
name>
<service-interface>javax.xml.rpc.
Service</service-interface>
<wsdl-file>META-INF/HelloClient.wsdl</wsdl-file>
<jaxrpc-mapping-file>META-INF/HelloMapping.
xml</jaxrpc-mapping-file>
<port-component-ref>
<service-endpoint-interface>org.jboss.test.
webservice.ws4eesimple.
HelloWs</service-endpoint-interface>
</port-component-ref>
</service-ref>
</webservicesclient>
As you can see, it names the webservice, the SEI, the
WSDL and JAX-RPC maping files.
The webservice interface (javax.xml.rpc.Service) is
boound into the client's ENC under the name given in the
<service-ref-name>.
#3 WSDL file
------------
Is in the standard WSDL format. Axis comes with a tool
Java2WSDL that can help you generate this file.
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
targetNamespace="http://test.jboss.
org/ws4eesimple"
xmlns:intf="http://test.jboss.org/ws4eesimple"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.
org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.
org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="sayHelloResponse">
<wsdl:part name="return" type="SOAP-ENC:
string"/>
</wsdl:message>
<wsdl:message name="sayHelloRequest">
<wsdl:part name="in0" type="SOAP-ENC:string"/>
</wsdl:message>
<wsdl:portType name="HelloWs">
<wsdl:operation name="sayHello"
parameterOrder="in0">
<wsdl:input message="intf:sayHelloRequest"/>
<wsdl:output message="intf:
sayHelloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding
name="HelloPortComponentSoapBinding" type="intf:
HelloWs">
<wsdlsoap:binding style="rpc" transport="http:
//schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<wsdlsoap:operation soapAction=""/>
<wsdl:input>
<wsdlsoap:body encodingStyle="http:
//schemas.xmlsoap.org/soap/encoding/"
namespace="http://test.jboss.org/ws4eesimple"
use="encoded"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body encodingStyle="http:
//schemas.xmlsoap.org/soap/encoding/"
namespace="http://test.jboss.org/ws4eesimple"
use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWsService">
<wsdl:port binding="intf:
HelloPortComponentSoapBinding"
name="HelloPortComponent">
<wsdlsoap:address location="http://localhost:
8080/jboss-net/services/HelloPortComponentEJB"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
One point to notice is, that the port address (in our case
http://localhost:
8080/jboss-net/services/HelloPortComponentEJB) can
point to any available webservice not just one hosted by
JBoss.NET. The webservice must be available at call time,
not necessarily at deploy time.
#4 JAX-RPC mapping file
-----------------------
Describes the Java mapping to a known WSDL document.
It contains the mapping between package names and
XML namespaces, WSDL root types and Java artifacts,
and the set of mappings for services.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE java-wsdl-mapping PUBLIC
"-//IBM Corporation, Inc.//DTD J2EE JAX-RPC mapping
1.0//EN"
"http://www.ibm.
com/webservices/dtd/j2ee_jaxrpc_mapping_1_0.dtd">
<java-wsdl-mapping>
<package-mapping>
<package-type>org.jboss.test.webservice.
ws4eesimple</package-type>
<namespaceURI>http://test.jboss.
org/ws4eesimple</namespaceURI>
</package-mapping>
</java-wsdl-mapping>
Webservice access
=================
Below you see a stateless session bean accessing a
webservice. First is the lookup from the bean ENC. Then
it obtains the service endpoint interface from the Service
object. The webservice runtime is required to provide
access to the webservice either through a generated
stub, a dynamic proxy, or through dynamic port access
(DII).
In our case we get a dynamic proxy generated by the
Axis client runtime.
public class HelloClientBean implements SessionBean
{
public String sayHello(String input) throws
RemoteException
{
try
{
InitialContext iniCtx = new InitialContext();
Context envCtx = (Context)iniCtx.lookup("java:
comp/env");
javax.xml.rpc.Service svc = (javax.xml.rpc.
Service)envCtx.lookup("service/HelloWsService");
HelloWs sei = (HelloWs)svc.getPort(HelloWs.
class);
String output = sei.sayHello(input);
return output;
}
catch (Exception e)
{
return e.toString();
}
}
// EJB life cycle methods
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}
}
Thats it, have fun.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=381174&aid=848220&group_id=22866
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development