public abstract class WebServiceClient
extends java.lang.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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ENVELOPE_PREFIX
Holds standard SOAP envelope prefix.
|
static java.lang.String |
ENVELOPE_URI
Holds standard SOAP envelope namespace.
|
Constructor and Description |
---|
WebServiceClient()
Default constructor (address not set).
|
Modifier and Type | Method and Description |
---|---|
void |
invoke()
Invokes the web service.
|
protected void |
readResponse(XMLObjectReader in)
Reads the web service response (SOAP body).
|
WebServiceClient |
setAddress(java.lang.String address)
Sets the address of this web service.
|
protected abstract void |
writeRequest(XMLObjectWriter out)
Writes the web service request (SOAP body).
|
public static final java.lang.String ENVELOPE_PREFIX
public static final java.lang.String ENVELOPE_URI
public WebServiceClient()
public WebServiceClient setAddress(java.lang.String address)
address
- the service full address.public void invoke() throws java.io.IOException, XMLStreamException
java.io.IOException
XMLStreamException
protected abstract void writeRequest(XMLObjectWriter out) throws XMLStreamException
out
- the XML object writer.XMLStreamException
protected void readResponse(XMLObjectReader in) throws XMLStreamException
System.out
.in
- the XML object reader.XMLStreamException
Copyright © 2005 - 2007 Javolution.