views:

2154

answers:

3

I'm using Java for accessing Alfresco content server via it's web service API for importing some content into it. Content should have some NamedValue properties set to UTF-8(cyrillic) string. I keep getting the Sax parser exception:

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x1b) was found in the element content of the document.

The code looks something like this:

NamedValue[] namedValueProperties = new NamedValue[2];

namedValueProperties[0] = Utils.createNamedValue(Constants.PROP_NAME, name );
namedValueProperties[1] = Utils.createNamedValue("{my.custom.model}myProperty", cyrillicString);

CMLCreate create = new CMLCreate("1", parentReference, null, null, null, documentType, namedValueProperties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] results = null;

try {
   results = WebServiceFactory.getRepositoryService().update(cml);
} catch (...)
    Here comes the "org.xml.sax.SAXParseException"
}

Does anyone know how to solve this problem?

A: 

The easiest way to get around it is I think to escape cyrillicString, for instance with escapeXml from Jakarta Commons, or by converting the whole string to XML entities if it's not enough. But in the long run, Alfresco should be fixed, so opening a ticket may be a good choice too.

Damien B
A: 

It's a little hard to tell whether or not this is a bug with Alfresco, without seeing the data you're trying to persist. Which version of Alfresco are you using? I found this bug in Alfresco's issue tracking system. Specifically, this is with 2.1 community, and it seems to suggest there are problems with encoding other than UTF-8, so it may or may not be related to your problem.

One thing you could do to debug this problem is to write a little test using Alfresco's embedded Java (server-side) API, attempting to persist the same data, and see if you still get an error (it would probably not be SAXParseException if you do). If you don't get an error, you know that there is probably a bug in Alfresco's web service API (which unfortunately isn't nearly as well supported as their embedded Java or REST APIs), and you may want to add a comment on the bug report I mentioned earlier, or file your own. If you do still get an error with the embedded API, then it could still either be your code or theirs that's the problem.

Hope that was at least a little helpful!

Julie
+1  A: 

The problem was that alfresco-web-service-client.jar library I used was from 2.9B distribution(I am hitting 2.9B community content server), and dependency libs bcprov-jdk15-136.jar and xmlsec-1.4.0.jar were not adequate(remained old from 2.1 dist). I should have used bcprov-jdk15-137.jar and xmlsec-1.4.1.jar which are deployed along with 2.9B distribution.

Aleksandar Marinkovic