AnsweredAssumed Answered

JAVA webscript, transforming content and writing to it

Question asked by sihnu on Apr 9, 2015
Latest reply on Sep 29, 2015 by raghav.bhardwaj

using Java I'm trying to implement a web script where I write to a content of an existing node and change the mimetype of the node. I've already implemented a web scrip where I send Base64 as a string, create a new node, write to the content of the node and store the node to Alfresco repository. So now I'm trying to implement update version of the web script. However, I get an error of channel being open after transformation (changing mimetype) when trying to write to the content of the node. Here is the exact error message:

org.springframework.extensions.webscripts.WebScriptException: 03090001 Wrapped Exception (with status template): 03090028 A channel has already been opened

Here is how I do the transformation:

options = new TransformationOptions(nodeRef, ContentModel.PROP_CONTENT, nodeRef, ContentModel.PROP_CONTENT);
this.contentService.transform(reader, writer, options);

Here I try to close the channel (just trial with errors…):


And here I try to write to the content:

ByteBuffer bf = ByteBuffer.wrap(Base64.decodeBase64(data.getBytes()));
FileChannel fileChannel = writer.getFileChannel(true);

I've tried it other way around as well. First writing then transformation but the I'll get the same error when trying to do the transformation. So what is the proper way of implementing writing & transformation? I guess I'm just missing something simple here which is ruining my implementation but I just can't figure it out by myself. Any help would be greatly appreciated. I've already got so much help from here. I wish I could help ppl here as well. I'm going to try at some point.

Thanks in advance.