|
J avolution v5.4 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.xml.ws.WebServiceClient
public abstract class WebServiceClient
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.
Field Summary | |
---|---|
static java.lang.String |
ENVELOPE_PREFIX
Holds standard SOAP envelope prefix. |
static java.lang.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(java.lang.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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ENVELOPE_PREFIX
public static final java.lang.String ENVELOPE_URI
Constructor Detail |
---|
public WebServiceClient()
Method Detail |
---|
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
|
J avolution v5.4 (J2SE 1.6+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |