HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Beyond SOAP: Optimized Web Services by Howard D'Souza
WSJ Vol 03 Issue 1 - pg.24

	


Listing 1:  Abstract service definition'

<!-- Input and output messages -->
   <wsdl:message name="getQuoteResponse">
      <wsdl:part name="getQuoteReturn" type="xsd:double"/>
   </wsdl:message>
   <wsdl:message name="getQuoteRequest">
      <wsdl:part name="symbol" type="xsd:string"/>
   </wsdl:message>

<!-- portType for the StockQuote service -->
   <wsdl:portType name="StockQuote">
      <wsdl:operation name="getQuote" parameterOrder="symbol">
         <wsdl:input name="getQuoteRequest" message="impl:getQuoteRequest"/>
         <wsdl:output name="getQuoteResponse" message="impl:getQuoteResponse"/>
      </wsdl:operation>
   </wsdl:portType>

Listing 2:  Factory interface class

package quote;

public interface StockQuoteService extends javax.xml.rpc.Service 
{
    public java.lang.String getStockQuoteAddress();
    public quote.StockQuote getStockQuote() 
throws javax.xml.rpc.ServiceException;
    public quote.StockQuote getStockQuote(java.net.URL portAddress) 
throws javax.xml.rpc.ServiceException;
}

Listing 3: Overloaded version of getStockQuote method
   
    EJBAddressInfo ejbInfo = new EJBAddressInfo();

    // set the values of the EJB location in ejbInfo ...

    StockQuoteServiceLocator locator = new StockQuoteServiceLocator(ejbInfo);
    StockQuote quote = locator.getStockQuote();
    double price = quote.getQuote("CYSV");

Listing 4: EJB location information added to port section

  <wsdl:service name="StockQuoteService">
<!-- SOAP Port -->
    <wsdl:port name="StockQuoteSOAPPort" binding="impl:StockQuoteSoapBinding">
         <wsdlsoap:address location=
		 "http://localhost:8080/axis/services/StockQuote"/>
    </wsdl:port>

<!-- EJB Port -->
    <wsdl:port name="StockQuoteEJBPort" binding="impl:StockQuoteEJBBinding">
     <ejb:port>
      <address location="jnp://localhost:1099">
        <property name="jndi-name">ejb/MyStockQuote></property>
        <property name="initial-ctx-factory">   
            org.jnp.interfaces.NamingContextFactory</property>
        <property name="home-interface"> ejbquote.StockQuoteHome</property>
        <property name="remote-interface">ejbquote.StockQuote</property>
      </address>
     </ejb:port>
    </wsdl:port>
  </wsdl:service>

Listing 5:  InvocationHandler interface

public class EJBHandler implements java.lang.reflect.InvocationHandler
{
    // ...
    private File wsdlFile = null;
    private Object ejbStub = null;

    public EJBHandler(File wsdlFile)
    {
        /* 
         Parse the WSDL file, extract the EJB destination info.
         Retrieve the EJB's home interface. From it, retrieve 
         the remote interface, and assign it to ejbStub.
         Be sure to use PortableRemoteObject.narrow() to get 
		 the correct home and remote interface types ...
        */
    }

    // Called when any method is invoked on the target interface
    public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable
    {
        Method instanceMethod = ejbStub.getClass().getMethod(method.getName(),
            method.getParameterTypes());
        return instanceMethod.invoke(ejbStub, args);    
    }
}

Listing 6:  Dynamic proxy implementation of StockQuote

public class StockQuoteServiceLocator 
{
  File wsdlFile; // Initialized in the constructor
  //...
    public StockQuote getStockQuote()
    {
        // If the preferred port is EJB Instantiate
        // an EJBHandler proxy and pass it the WSDL file
        return java.lang.reflect.Proxy.newProxyInstance( 
            StockQuote.class.getClassLoader(),
            new Class[]{quote.StockQuote.class},
            new EJBHandler(wsdlFile));
    }
}