You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by javamonkey79 <ja...@gmail.com> on 2014/01/10 19:50:55 UTC

CXF encoding embedded XML

I have a SOAP service which one of the methods accepts a String as a
parameter. However, the expectation is that this String is XML.

When I call this service, CXF encodes the XML for me by default, like so:

&lt;ORM_O01>&lt;MSH>

Even though when I called it, I called it like so:

<ORM_O01><MSH>

Is there a way to turn this off? I would like CXF to just send what I've
specified and not an encoded version.

I am using CXF 2.7.8 and JDK 1.7.



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-encoding-embedded-XML-tp5738466.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF encoding embedded XML

Posted by javamonkey79 <ja...@gmail.com>.
I'm pretty sure this is not the best way to do it, but it worked for me:

public class MyClass extends AbstractPhaseInterceptor< Message > {
	public MyClass () {
		super( Phase.PRE_STREAM );
		addAfter( AttachmentOutInterceptor.class.getName() );
	}

	@Override
	public void handleMessage( final Message message ) throws Fault {
		message.put( "disable.outputstream.optimization", Boolean.TRUE );
		final SimpleNsStreamWriter writer =
(SimpleNsStreamWriter)StaxUtils.createXMLStreamWriter( message.getContent(
OutputStream.class ) );
		message.setContent( XMLStreamWriter.class, new DelegatingXMLStreamWriter(
writer ) {
			@Override
			public void writeCharacters( final String text ) throws
XMLStreamException {
				System.out.println( "text -> " + text );
				writer.writeRaw( text );
			}
		} );
	}



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-encoding-embedded-XML-tp5738466p5738469.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF encoding embedded XML

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
The correct way of handling this is by using an xs:any for this value in 
the schema, rather than an xs:string type. If it's typed as a string and 
you're using it to pass XML you're going to have problems on every 
platform that handles XML correctly.

   - Dennis

Dennis M. Sosnoski
Java Web Services Consulting <http://www.sosnoski.com/consult.html>
CXF and Web Services Security Training 
<http://www.sosnoski.com/training.html>
Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>

On 01/11/2014 07:50 AM, javamonkey79 wrote:
> I have a SOAP service which one of the methods accepts a String as a
> parameter. However, the expectation is that this String is XML.
>
> When I call this service, CXF encodes the XML for me by default, like so:
>
> &lt;ORM_O01>&lt;MSH>
>
> Even though when I called it, I called it like so:
>
> <ORM_O01><MSH>
>
> Is there a way to turn this off? I would like CXF to just send what I've
> specified and not an encoded version.
>
> I am using CXF 2.7.8 and JDK 1.7.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-encoding-embedded-XML-tp5738466.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>