views:

1029

answers:

4

Hello,

I've developped a web service and deployed it with Axis. All is running very well but I've a problem when I consume the service using a String containing a non printable character (such as ETX, FS,..). I have the following error:

exception: java.lang.IllegalArgumentException: The char '0x1c' after '....' is not a valid XML character.

Have you any ideas please?

edit :

I have to send a frame to my server using web service. My frame has a strict form( containing some non printable character as separator)

class Automate {void checkFrame(String frame){// checking the frame}}

wsdl file

<?xml version="1.0" encoding="UTF-8"?>

  <wsdl:part element="impl:checkFrameResponse" name="parameters"/>

  <wsdl:part element="impl:checkFrame" name="parameters"/>

  <wsdl:operation name="checkFrame">

     <wsdl:input message="impl:checkFrameRequest" name="checkFrameRequest"/>

     <wsdl:output message="impl:checkFrameResponse" name="checkFrameResponse"/>

  </wsdl:operation>

  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&gt;

  <wsdl:operation name="checkFrame">

     <wsdlsoap:operation soapAction=""/>

     <wsdl:input name="checkFrameRequest">

        <wsdlsoap:body use="literal"/>

     </wsdl:input>

     <wsdl:output name="checkFrameResponse">

        <wsdlsoap:body use="literal"/>

     </wsdl:output>

  </wsdl:operation>

  <wsdl:port binding="impl:AutomateSoapBinding" name="Automate">

     <wsdlsoap:address location="http://localhost:8080/Gateway/services/Automate"/&gt;

  </wsdl:port>

+1  A: 

This is a natural problem with SOAP, unfortunately - it uses XML for text, and those characters can't be represented in XML (even with entities).

Can you escape the non-printable characters somehow? You'll need to find some way of not representing them as straight text, unfortunately.

Jon Skeet
I can't escape those characters I need them for a further processing.so how can I proceed?
You're going to *have* to escape them somehow. But if you escape them at the calling side you can unescape them at the receiving side and thus still use the data. I wasn't suggesting *dropping* the 'bad' characters.
Jon Skeet
To be more clear. I'm developing a gateway that will receive a frame from a terminal which has a strict form so I can't touch to it.My web service must be able to receive it as well as it's to forward it again to the server!!I'm now creating a client web service just for tests in local host!!
The purpose of this web service is to transmit data, and you're in control of both sides, right? So escape the data just before you transmit it, and unescape it as soon as you receive it. You still get all the data. If you're *not* in control of both sides, you've basically got no options: you *cannot* include those characters in valid XML. It's simply invalid XML.
Jon Skeet
If you're developing the web service, who's developing the client? And can't you ask them to do the escaping?
Jon Skeet
Ok ! But I'm not in control of both sides!! My application is a complement to an existent system. If possible I'll see if possible to escape the characters or to send a base24 data !!thanks for your time :))
A: 

It sounds like you have text that can't possibly be represented in XML. You will have to escape these characters, but to be honest I suspect you should "escape" the entire string. Base64 encoding the string might work, but you could also look at MTOM or some other mechanism of passing binary data across web services.

If you own both sides of this system (the clients and the webservice) then it shouldn't be too difficult to add the encode/decode steps and base64 encoding should be enough.

Martin Peck
unfortunately no!! I'm just developing the web service!! And normally I'd receive a string from the terminal!!!
So, you're defining the contract and the messaging semantics if you own the service. This allows you to either say "send me valid XML" or say "encode your text", doesn't it?
Martin Peck
The only situation where that wouldn't be the case is where you're implementing a well known service contract and the client is unable to be altered.
Martin Peck
Something like that!!I have already a system running and I have to add a middleware between the terminal and the server.
A: 

As you form the XML you're going to tuck inside the SOAP XML envelope, you need to make sure you don't have any unescaped characters in your attribute values and in any text nodes you have in your elements. That is:

<your_elt your_attr="Don&apos;t put unescaped chars here, eg, apostrophe">
    <foo>
        Be sure to escape stuff here too, like: 2 &lt; 100
        A greek lambda is escaped like this: &#955;
    </foo>
</your_elt>

I assume you're doing this in Java, so you should look into libraries that do this for you automatically. Apache has StringEscapeUtils, for instance.

Your control characters would need to be escaped by XML numeric character references. Hopefully StringEscapeUtils handles that for you.

Hope this helps.

Jim Ferrans
I think this's what I'm looking for!!!I'll try it !Thanks :))
A: 

use CDATA for data that is not part of the xml structure (i.e content), if i understand correctly and youre just routing messages this is what you should do.