Skip to main content

Accessing the content of the payload

1 reply [Last post]
ypomonh
Offline
Joined: 2009-02-23

I have client that access a service using:

Dispatch sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));

which I can print as a string:

private static String sourceToXMLString(Source result) {

String xmlResult = null;
try {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
//transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
OutputStream out = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult();
streamResult.setOutputStream(out);
transformer.transform(result, streamResult);
xmlResult = streamResult.getOutputStream().toString();
} catch (TransformerException e) {
e.printStackTrace();
}
return xmlResult;
}

What is the easiest way to access the XML content of the response, eg. print a certain node? Every tutorial I see just prints the whole thing.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Glen Mazza

I think there's a DOMResult you can use instead of a StreamResult.

You can also use JAX-WS Handlers:
http://www.jroller.com/gmazza/entry/adding_jax_ws_handlers_to

HTH,
Glen

metro-3 wrote:
>
> I have client that access a service using:
>
> Dispatch sourceDispatch = null;
> sourceDispatch = service.createDispatch(portQName,
> Source.class, Service.Mode.PAYLOAD);
> Source result = sourceDispatch.invoke(new StreamSource(new
> StringReader(req)));
>
> which I can print as a string:
>
> private static String sourceToXMLString(Source result) {
>
> String xmlResult = null;
> try {
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer();
> transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
> "yes");
> transformer.setOutputProperty(OutputKeys.METHOD, "xml");
> //transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
> OutputStream out = new ByteArrayOutputStream();
> StreamResult streamResult = new StreamResult();
> streamResult.setOutputStream(out);
> transformer.transform(result, streamResult);
> xmlResult = streamResult.getOutputStream().toString();
> } catch (TransformerException e) {
> e.printStackTrace();
> }
> return xmlResult;
> }
>
> What is the easiest way to access the XML content of the response, eg.
> [b]print a certain node[/b]? Every tutorial I see just prints the whole
> thing.
> [Message sent by forum member 'ypomonh' (ypomonh)]
>
> http://forums.java.net/jive/thread.jspa?messageID=333375
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
> For additional commands, e-mail: users-help@metro.dev.java.net
>
>
>

--
View this message in context: http://www.nabble.com/Accessing-the-content-of-the-payload-tp22165187p22...
Sent from the Metro - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net