Skip to main content

How to marshal into javax.xml.transform.Source

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
lulseged
Offline
Joined: 2008-03-19

Hi

I am using JAXWS and JAXB to build my web service application. I am struggling to get it work.

When unmarshaling from a file, javax.xml.transform.Source can be created from an input stream. It works fine.

But I have problem marshaling back to source. I can marshal it to System.out but want to reply to a client in form of javax.xml.transform.Source.

StringWriter writer = new StringWriter();

getMarshaller().marshal(o, writer);

Source source = new StreamSource(writer.toString());

Then I get:
java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> . . . .

I have to return Source as I am implementing Provider

public class TestService implements Provider
{
public Source invoke(Source source)
{

}
}

Any idea?

BR
Lulseged