Change Notes item #848291, was opened at 2003-11-24 14:03
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=848291&group_id=22866

Category: None
Group: None
Status: Open
Priority: 5
Submitted By: thomas diesler (tdiesler)
Assigned to: Nobody/Anonymous (nobody)
Summary: J2EE1.4 compatible webservices HOWTO - server model

Initial Comment:

This tracker describes how to implement J2EE1.4 
compatible webservices in JBoss4.x. I will focus on the 
'pure' JSR109 implementation for stateless session beans 
and web components. See the reference at the end for 
more about the specs and recomended reading.

The basic notion is, that a stateless session bean, or web 
component can make all or part of its public interface 
available as a webservice. Hence that server component 
can then be accessed (interoperability constraints given) 
by any webservice client.

Packaging
=======

The server deployment should contain the following files:

   #1 Service Endpoint Interface (SEI) class

   #2 Web services deployment descriptor (webservices.
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 webservices.xml
------------------

Is the webservice deployment descriptor, it lives in 
META-INF for EJB and in WEB-INF for web components.

  <?xml version="1.0" encoding="UTF-8"?>

  <!DOCTYPE webservices PUBLIC
    "-//IBM Corporation, Inc.//DTD J2EE Web services 1.
0//EN"
    "http://www.ibm.
com/webservices/dtd/j2ee_web_services_1_0.dtd">

  <webservices>
      <webservice-description>
           
<webservice-description-name>HelloWs</webservice-des
cription-name>
           <wsdl-file>META-INF/Hello.wsdl</wsdl-file>
           <jaxrpc-mapping-file>META-INF/HelloMapping.
xml</jaxrpc-mapping-file>
           <port-component>
               
<port-component-name>HelloPortComponentEJB</port-co
mponent-name>
               <wsdl-port>
                   <namespaceURI>http://test.jboss.
org/ws4eesimple</namespaceURI>
                   <localpart>HelloPortComponent</localpart>
               </wsdl-port>
               <service-endpoint-interface>org.jboss.test.
webservice.ws4eesimple.
HelloWs</service-endpoint-interface>
               <service-impl-bean>
                   <ejb-link>HelloEjb</ejb-link>
               </service-impl-bean>
           </port-component>
      </webservice-description>
  </webservices>

This example names the webservice port component, the 
SEI, the WSDL and JAX-RPC maping files.
The port component name specifies the webservice name 
in JBoss.NET, ie http://localhost:
8080/jboss-net/services/HelloPortComponentEJB
The <ejb-link> element corresponds to a <ejb-name> in 
ejb-jar.xml. 

To make a web component available, use: 

    <service-impl-bean>
        <servlet-link>HelloJavaBean</servlet-link>
    </service-impl-bean>

Then, the <servlet-link> element corresponds to a 
<servlet-name> in web.xml. However please note, that 
the service implementation bean, 
you would specify in <servlet-class> does not necessarily 
have to be a javax.servlet.Servlet.   

#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:
//dummyhost/dummypath"/>
         </wsdl:port>
      </wsdl:service>

   </wsdl:definitions>
   
One point to notice is, that the port address can be set 
to dummy values, which will be corrected by the axis 
JBoss.NET server implementation at access time.
The sucessfully deployed service's WSDL can accessed 
at: http://localhost:
8080/jboss-net/services/HelloPortComponentEJB?wsdl

#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 test that accesses the stateless session 
bean webservice:

   public void helpTestSayHello() throws Exception
   {
      Service service = new org.apache.axis.client.
Service();
      Call call = (Call) service.createCall();
      call.setTargetEndpointAddress("http://localhost:
8080/jboss-net/services/HelloPortComponentEJB");
      call.setOperationName("sayHello");

      String retstr = (String) call.invoke(new Object[]
{"Hello"});
      assertEquals("'Hello' to you too!", retstr);
   }

Thats it, have fun.

References
==========

JSR109 spec
http://jcp.
org/aboutJava/communityprocess/final/jsr109/index.html

Build interoperable Web services with JSR-109
http://www-106.ibm.
com/developerworks/library/ws-jsrart/


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=381174&aid=848291&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

Reply via email to