3

My application is connecting to a web service rpc/encoded. Im using Axis 1.4. When the webservice sends a response, it sends an invalid character then an exception:

http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: 
  An invalid XML character (Unicode: 0x3) was found in the element content of the document.

The xml encoding is "ISO-8859-1". I think that is the problem.

My question is: Is there any configuration that i can make in my application to accept this invalid character ?

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Aurélio Antonio
  • 166
  • 1
  • 3
  • 13
  • Without more details on the web service and how you're calling it and parsing the results it's hard to tell. The problem may be at the server. – Jim Garrison Oct 02 '12 at 22:24
  • 2
    The XML 1.0 spec forbids control characters such as U+0003 regardless of the character encoding, you can't even escape them using ``. If the service is complaining that _you_ sent _it_ an invalid character then you'll have to fix your client, if the client is complaining about a character it received in the response then you'll have to take it up with the service owner. – Ian Roberts Oct 02 '12 at 23:07
  • As a quick'n'dirty solution you can write a proxy that will remove illegal characters from response. – Konstantin V. Salikhov Oct 03 '12 at 07:19
  • Thank's for help. I threw the problem to the web service owner. Btw @KonstantinV.Salikhov your solution worked fine. – Aurélio Antonio Oct 03 '12 at 17:02
  • The web service owner told that i need to change my application to acept "ISO-8859-1", they can do nothing about it. I still waiting some help. – Aurélio Antonio Oct 05 '12 at 14:46
  • @JimGarrison the parse are made by Axis after xml deserialization. I cant see the code. I need to set the encoding as "ISO-8859-1" in somewhere that i dont know. – Aurélio Antonio Oct 05 '12 at 14:53

2 Answers2

2

"My application is connecting to a web service rpc/encoded."

That's the catch. The service is "rpc/encoded" which is non-WS-I-compliant. The developers decided after some heated discussion sometime in the past not to 'fix' this error.

ingyhere
  • 11,818
  • 3
  • 38
  • 52
2

I solved the problem putting a method inside org.apache.axis.handlers.LogHandler to search and destroy illegal characters before parse the the content inside xml response ahead.

To create your own LogHandler

The method to search and destroy illegal characters

Inside logMessages method of your new LogHandler put the following: private void logMessages(MessageContext msgContext) throws AxisFault { ... msgContext.setResponseMessage(new Message( stripNonValidXMLCharacters(((Message) msgContext .getResponseMessage()).getSOAPPartAsString()))); ... }

Aurélio Antonio
  • 166
  • 1
  • 3
  • 13
  • There is a way somewhere with Axis 1.4 to auto-generate the stubs to deal with "rpc/encoded". Then you wouldn't have to intercept responses. However, I read that it does not work with CXF, and you are permanently bound to Axis 1.x. See http://stackoverflow.com/questions/412772/java-rpc-encoded-wsdls-are-not-supported-in-jaxws-2-0 . – ingyhere Oct 11 '12 at 21:00