This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes [javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175]" Watch "[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175]" New topic
Author

[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175]

gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
Hello

I am trying to run a RPC web service. I had the service working fine until a problem showed up. Now it won't work at all. I even tried it on a different machine.

javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175]
Message: An invalid XML character (Unicode: 0x14) was found in the element content of the document.]
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unkno
wn Source)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unkn

The web service publisher window is where this error shows up. I don't know what process is trying to parse an XML document that is running into this problem. I wish that it gave you some indication about what it was trying to parse. As best I can tell its not an XML file on a drive.

Anybody have any ideas about what process is trying to parse an XML stream and where the stream comes from?

I appreciate your help. Cheers
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
OK, I figured this one out. The web service publisher parses the character stream that it receives when you make a service call.

PatientQuery query = service.getPort(PatientQuery.class);
query.patientQuery(myString); // myString will be parsed

It gets upset if you include low ranged unicode values, say less than 20. These produce an XML parsing exception.

Here's why I ran into this problem. I was sending encrypted strings! Sure enough, the encrypted strings included low range unicode values.

OK so now I have to figure out how to encrypt a string without using low ranged unicode values. I have no idea how to do that.

Anybody have any ideas on the that one?

gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
One more thing. I was using JAX RPC. It is my understanding that Document web services consider payloads as XML fragments. So I guess I can understand why Document web services would indeed have a problem with special characters. So what can you do for "encryption" with web services? I guess Base64 might work. Not the most secure but it might be your only choice.

I would think that remote procedure calls wouldn't be subject to special character problems but apparently they are.
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
OK, now I'm not so sure that my theory is correct. The char 0x14 is causing an XMLStreamException but only some of the time.


This works

String encryptedValue = new BASE64Encoder().encode(valueToEncrypt.getBytes()); // encryptedValue contains some 0x14 characters
QName qname = new QName("http://webservice.patientquery.sapient.com/", "PatientQueryImplService");
Service service = Service.create(url, qname);
PatientQuery query = service.getPort(PatientQuery.class);
String results = query.patientQuery(encryptedQuery);


This fails (XMLStreamException thrown by the Publisher)

String encryptedValue = new BASE64Encoder().encode(valueToEncrypt.getBytes()); // encrypted value contains some 0x14 chars, did not cause a problem in the previous example
// encryptedValue contains some 0x14 characters
QName qname = new QName("http://webservice.patientquery.sapient.com/", "PatientQueryImplService");
Service service = Service.create(url, qname);
PatientQuery query = service.getPort(PatientQuery.class);
encryptedValue = encryptedValue + (char)0x14; // append a 0x14 char
String results = query.patientQuery(encryptedQuery);


This is driving me crazy. I can't figure out why the inclusion of the 0x14 character is OK in some instances and causes failures in other instances.

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

I suspect the reason it fails in your second example is because the character 0x14 is not encoded. This is not a character supported by XML so must be escaped or encoded.
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24

>>>> I suspect the reason it fails in your second example is because the character 0x14 is not encoded. This is not a character supported by XML so must be escaped or encoded.

I read that encoded or escaping the 0x14 character is not going to work. It's still not going to like it.

My problem has evolved to an even stranger level. When I Base64 encode a String and send it to the web service there are no problems. There is no 0x14 character within the String. When I use AES to encrypt a String it fails when it is sent to the web service due to a 0x14 character in the stream. The thing is I check every character in the problem String before it is sent and I don't find any 0x14 characters. I don't know how the problem character is getting into the stream.

javax.xml.ws.WebServiceException: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,49]
Message: An invalid XML character (Unicode: 0x14) was found in the element conte
nt of the document.]
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unkno
wn Source)
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

I read that encoded or escaping the 0x14 character is not going to work. It's still not going to like it.


Do you have a link for this? How else do you explain the difference between your first two examples?
gilbert engle
Greenhorn

Joined: Jun 03, 2009
Posts: 24
thanks for your input

// here's where I saw the note saying that there is now way to escape 0x14
http://stackoverflow.com/questions/1165966/xml-serialization-of-an-object-containing-invalid-chars


OK, I really messed up my earlier source code example. Let me try again.


String encryptedValue = new BASE64Encoder().encode(valueToEncrypt.getBytes());

Sending this string does not cause a problem and it does not contain any 0x14 characters.



String something = "medium length XML string, plain vanilla characters";
Key secretKey = generateKey(something.getBytes());
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, secretKey);
System.out.println("doFinal");
byte[] encValue = c.doFinal(valueToEncrypt.getBytes());
String encryptedValue = new BASE64Encoder().encode(encValue);

This encryptedValue String causes an XMLStreamException. Before I send the String I examine every character and I do not find any 0x14 characters. Somehow a 0x14 character is getting added to the stream. Here's the error message


[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,57]
Message: An invalid XML character (Unicode: 0x14) was found in the element content of the document.]

The thing is I have no way of figuring out [row,col]:[7,57]. There are no newLine characters in the stream to account for 7 rows.

Do you have any idea how to use [row,col]:[7,57] to find the actual character? Thanks very much.
 
 
subject: [javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,175]
 
Similar Threads
Parsing an xml response from a url using STAX
web service - send java List
Axis2 ParseError
Exception when invoking a Web Service using dispatch
SSL in JAVA