cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in webservice of 1.1.2?

cburghardt
Champ in-the-making
Champ in-the-making
I try to create a new content node of type pdf with the following code:

NamedValue[] props = new NamedValue[] {new NamedValue("{http://www.alfresco.org/model/content/1.0}name", name)};
CMLCreate create = new CMLCreate(name, parentReference, "{http://www.alfresco.org/model/content/1.0}content", props);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = repositoryService.update(cml);
Reference newContentNode = result[0].getDestination();
ContentFormat format = new ContentFormat("application/pdf", "UTF-8");
byte[] bytes = IOUtils.toByteArray(new FileInputStream("test.pdf"));
contentService.write(newContentNode, "{http://www.alfresco.org/model/content/1.0}content", bytes, format);

The result is a pdf file that contains the correct number of pages but no text. If I upload this file via Webclient everything is ok. Text nodes (like in the webservice example) also work. The size of the created node is too big so I guess there is some encoding problem.
3 REPLIES 3

cburghardt
Champ in-the-making
Champ in-the-making
This is definitely a bug and not limited to pdf files (of course) but can be reproduced with all binary content - at least here.
The content is transferred like this at the moment:
Client uses ContentService and writes byte[]. The byte[] is transformed to a string in ContentWebService:205. AbstractContentWriter creates a byte[] from that string (yuck!) with the specified encoding.
One minor problem can be found in ContentWebService:
writer.putContent(new String(content));
You should use the encoding that is specified by the ContentFormat as the ContentWriter does the same.
But I still do not know where the problem is - perhaps Axis destroys my data. The default encoding of my platform is UTF-8 so this shouldn't be a problem.

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

I've created a Jira bug for this so you track its progress.

http://www.alfresco.org/jira/browse/AR-328

Thanks,
Roy

rwetherall
Confirmed Champ
Confirmed Champ
HI ,

This has been fixed now.

Thanks,
Roy