wrting a soap response to file

J

jude.ulibarri

Hello:

I'm using AXIS to create a SOAP Envelope. I can successfully send
this request to the web service and get a response back. But now, I
want to write the response to file. How is this done? I have tried
several different java.io classes but none have worked.

Jude
 
M

Mike Schilling

Hello:

I'm using AXIS to create a SOAP Envelope. I can successfully send
this request to the web service and get a response back. But now, I
want to write the response to file. How is this done?

What form do you have the response in? If it's XML, you can use a
java.xml.transform.Transformer to turn it into a byte stream and write
those bytes to a file. (Use a StreamResult constructed from a File or
a FileOutputStream.)
 
J

jude.ulibarri

What form do you have the response in?  If it's XML, you can use a
java.xml.transform.Transformer to turn it into a byte stream and write
those bytes to a file.  (Use a StreamResult constructed from a File or
a FileOutputStream.)

The response is in an AXIS SOAPEnvelope object. Let me look at any
other return values that an axis.client.Call will return. I'll also
try the Transformer class
 
J

jude.ulibarri

The response is in an AXIS SOAPEnvelope object.  Let me look at any
other return values that an axis.client.Call will return.  I'll also
try the Transformer class

The Transformer constructor takes an XML source and a result. Well,
it doesn't recognize the SOAPEnvelope as an XML source. I'm also
getting the error that Transformer is abstract and can't be
instantiated. Sweet.... This just gets better all the time.
 
J

jude.ulibarri

The Transformer constructor takes an XML source and a result.  Well,
it doesn't recognize the SOAPEnvelope as an XML source.  I'm also
getting the error that Transformer is abstract and can't be
instantiated.  Sweet.... This just gets better all the time.

Call returns a SOAPEnvelope (response = call.invoke(request)). I'm
searching through the AXIS java doc for something that will stream the
Envelope to a file. No luck yet.
 
M

Mike Schilling

The Transformer constructor takes an XML source and a result. Well,
it doesn't recognize the SOAPEnvelope as an XML source.

SOAPEnvelope extends org.w3c.dom.Node, so this should work fine.

It goes something like (I'm not going to compile this, so watch out
for typos)

import java.xml.transform.*;
import java.xml.transform.dom.*;
import java.xml.transform.stream.*;

Transformer transformer =
TransformerFactory.newInstance().newTransformer();
transformer.transform(
new DOMSource(envelope),
new StreamResult(new File(fileName)));
 
J

jude.ulibarri

SOAPEnvelope extends org.w3c.dom.Node, so this should work fine.

It goes something like (I'm not going to compile this, so watch out
for typos)

    import java.xml.transform.*;
    import java.xml.transform.dom.*;
    import java.xml.transform.stream.*;

    Transformer transformer =
TransformerFactory.newInstance().newTransformer();
    transformer.transform(
        new DOMSource(envelope),
        new StreamResult(new File(fileName)));

You ROCK!!

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

Transformer transformer =
TransformerFactory.newInstance().newTransformer();

transformer.transform(new DOMSource(response), new StreamResult(new
File("response.xml")))

I only do JAVA on the side now. Been years since I've done anything
meaningful with it.

Thank you for all the help!!
 
M

Mike Schilling

You ROCK!!

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

Transformer transformer =
TransformerFactory.newInstance().newTransformer();

transformer.transform(new DOMSource(response), new StreamResult(new
File("response.xml")))

I only do JAVA on the side now. Been years since I've done anything
meaningful with it.

Thank you for all the help!!

Happy to have been of service.
 
A

Arne Vajhøj

I'm using AXIS to create a SOAP Envelope. I can successfully send
this request to the web service and get a response back. But now, I
want to write the response to file. How is this done? I have tried
several different java.io classes but none have worked.

I like org.apache.xml.serialize.XMLSerializer for that. Good
options for controlling output.

Code snippet:

OutputFormat fmt = new OutputFormat();
fmt.setIndenting(true);
XMLSerializer ser = new XMLSerializer(somestream, fmt);
ser.serialize(somedoc);

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top