Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Clean up your wire protocol with SOAP, Part 4

Dynamic proxies make Apache SOAP client development easy

  • Print
  • Feedback

Page 3 of 4

The remainder of invoke() is fairly straightforward. The Call object parameters (if any) are set; the custom SOAP mapping registry (if one is required) is set; the call is made; and the call results return to the client as shown below:

if( params.size() != 0 )
             call.setParams(params);
if( smr != null )
             call.setSOAPMappingRegistry(smr);
// Invoke the call.
Response resp = call.invoke(serverURL, "");         
if( !resp.generatedFault() )
{
             Parameter ret = resp.getReturnValue();
             return(ret.getValue());
}
else
{
             Fault fault = resp.getFault();
             throw new 
SOAPException(fault.getFaultCode(),fault.getFaultString());
}


The HelloWorld service

Below you will find the complete implementation of the HelloWorld service. Does this code look familiar?

package hello;
public class HelloServer 
{
    public String sayHelloTo(String name)
    {
             System.out.println("sayHelloTo(String name)");
             return "Hello " + name + ", How are you doing?";       
    }
    public String sayHelloTo(Name theName)
    {
             System.out.println("sayHelloTo(Name theName)");
             return "Hello " + theName.getName() + ", How are you 
doing?";       
    }
}


Recall that Name is a simple JavaBean as shown below:

package hello;
public class Name
{
    private String name;
    public String getName()
    {
             return name;
    }
    public void setName(String name)
    {
             this.name = name;
    }
}


This is exactly the same service code that we created in Part 2. The only additional work that the service creator has to complete is to create the Java interfaces. Deploying the service is also exactly the same as the deployment presented in Part 2, so I will not go through it again. The similarities don't end there. The way you compile and run the client program is no different from Part 2's approach. Why so many similarities? Because the SOAP proxy we created is an example of a nonintrusive framework that does not modify or interfere with the inner workings of any Apache SOAP components -- client or server side.

Some implementation notes

The SOAP proxy described in this article (and available for download from Resources) supports the following parameter types:

  1. The following Java primitives and their objectified forms:

                 boolean, Boolean,
                 double, Double,
                 float, Float,
                 long, Long,
                 int, Integer,
                 short, Short,
                 byte, Byte
    
    Note: The server side always receives the primitive.
  2. Any JavaBean.

    Note:

    • The JavaBean must not contain other JavaBeans.
    • The JavaBean must not contain vectors or arrays that contain any parameter other than strings or those listed in 1 above.
  3. The following classes:

                 String, Vector
    


    Note:

    • A vector might contain all parameters in 1, 2, and strings (with an exception noted below).
    • The server side receives a vector as an array of objects.


  4. Arrays of all parameters in 1, 2, and strings (with the exception noted above).


That's all, folks

In this four-part series, I have not only introduced you to the basics of SOAP, but also to an excellent implementation of the SOAP 1.1 standard: Apache SOAP. In this article, I presented a framework based on the dynamic proxy classes that greatly simplifies the life of client-side developers who use Apache SOAP.

  • Print
  • Feedback

Resources
  • Sign up for the JavaWorld This Week free weekly email newsletter to find out what's new on JavaWorld: http://www.idg.net/jw-subscribe