javolution.xml.ws
Class WebServiceClient

Object
  extended by WebServiceClient

public abstract class WebServiceClient
extends Object

This class provides a simple web service client capable of leveraging Javolution XML marshalling/unmarshalling.

Sub-classes may work from WSDL files, XMLFormat or directly with the XML streams (StAX). For example:

     private static class HelloWorld extends WebServiceClient  {
         protected void writeRequest(XMLObjectWriter out) throws XMLStreamException {
             XMLStreamWriter xml = out.getStreamWriter();
             xml.writeDefaultNamespace("http://www.openuri.org/");
             xml.writeEmptyElement("helloWorld"); // Operation name.
         }
         protected void readResponse(XMLObjectReader in) throws XMLStreamException {
             XMLStreamReader xml = in.getStreamReader();
             xml.require(START_ELEMENT, "http://www.openuri.org/", "string");
             xml.next(); // Move to character content.
             System.out.println(xml.getText());
         }
     }
     WebServiceClient ws = new HelloWorld().setAddress("http://acme.com:80/HelloWorld.jws");
     ws.invoke();
     
      > Hello World!
     

Note: At this moment, this class is supported only on the J2SE platform. Soon, it will also be supported on mobile devices through the CLDC/MIDP Generic Connection framework.

Version:
5.2, September 16, 2007
Author:
Jean-Marie Dautelle

Field Summary
static String ENVELOPE_PREFIX
          Holds standard SOAP envelope prefix.
static String ENVELOPE_URI
          Holds standard SOAP envelope namespace.
 
Constructor Summary
WebServiceClient()
          Default constructor (address not set).
 
Method Summary
 void invoke()
          Invokes the web service.
protected  void readResponse(XMLObjectReader in)
          Reads the web service response (SOAP body).
 WebServiceClient setAddress(String address)
          Sets the address of this web service.
protected abstract  void writeRequest(XMLObjectWriter out)
          Writes the web service request (SOAP body).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENVELOPE_PREFIX

public static final String ENVELOPE_PREFIX
Holds standard SOAP envelope prefix.

See Also:
Constant Field Values

ENVELOPE_URI

public static final String ENVELOPE_URI
Holds standard SOAP envelope namespace.

See Also:
Constant Field Values
Constructor Detail

WebServiceClient

public WebServiceClient()
Default constructor (address not set).

Method Detail

setAddress

public WebServiceClient setAddress(String address)
Sets the address of this web service.

Parameters:
address - the service full address.

invoke

public void invoke()
            throws IOException,
                   XMLStreamException
Invokes the web service.

Throws:
IOException
XMLStreamException

writeRequest

protected abstract void writeRequest(XMLObjectWriter out)
                              throws XMLStreamException
Writes the web service request (SOAP body).

Parameters:
out - the XML object writer.
Throws:
XMLStreamException

readResponse

protected void readResponse(XMLObjectReader in)
                     throws XMLStreamException
Reads the web service response (SOAP body). The default implementation writes the body XML events to System.out.

Parameters:
in - the XML object reader.
Throws:
XMLStreamException


Copyright © 2005-2012 Javolution. All Rights Reserved.