Tags

, , , , ,

One day I was reported by our customer that they had a problem in triggering a web service (the customer did not tell me the problem is in triggering web service. But I know the root cause is the web service)

After investigating the logs, I found “An invalid XML character (Unicode: 0xb) was found in the element content” error. As I know not all ASCii chars are allowed in XML message. What does 0xb mean? I checked ASCii and I found it is a tab. Oh my god how to catch a tab in a SOAP message?

Below are the steps I followed:

1. Uncomment this entry in the jboss-log4j.xml file:

<!– Enable JBossWS message tracing

| <category name=”org.jboss.ws.core.MessageTrace”>

| <priority value=”TRACE”/>

| </category>

| –>

This will print the content of the incoming SOAP message in the server.log.

2. I created a standalone Java program and put the SOAP message as a String parameter.

The program looks like:

class Main {
public String stripNonValidXMLCharacters() {

StringBuffer in=new StringBuffer(THE_CONTENT_OF_SOAP);

StringBuffer out = new StringBuffer(); // Used to hold the output.
char current; // Used to reference the current character.

if (in == null || (“”.equals(in)))
return “Empty”; // vacancy test.
for (int i = 0; i < in.length(); i++) {
current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught
// here; it should not happen.
if ((current == 0x9) || (current == 0xA) || (current == 0xD)
|| ((current >= 0x20) && (current <= 0xD7FF))
|| ((current >= 0xE000) && (current <= 0xFFFD))
|| ((current >= 0x10000) && (current <= 0x10FFFF))){
out.append(current);
}else{
System.out.println(“I got you!”);
break;
}
}
return out.toString();
}

public static void main(String[] args) {
Main m = new Main();
System.out.println(m.stripNonValidXMLCharacters());
}
}

The output of the above program told me there is a small tab in the <comments> field.

3. I removed the tab in the comments and trigger the web service through soapUI. Everything goes smoothly.

===

Summary,

This post tells you how to locate an invalid XML char in a SOAP message based on my previous working experience.

Advertisements