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!
Modifier and Type | Field and Description |
---|---|
static String |
ENVELOPE_PREFIX
Holds standard SOAP envelope prefix.
|
static 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(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 String ENVELOPE_PREFIX
public static final String ENVELOPE_URI
public WebServiceClient()
public WebServiceClient setAddress(String address)
address
- the service full address.public void invoke() throws IOException, XMLStreamException
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-2013 Javolution. All Rights Reserved.