Highlighted

session.save not saving Binary data set to jcr:data propery of .xml file

karthik2907

20-09-2017

I tried creating a sitemap.XML file which contains the data of all the active pages as shown in What is the best API to use to create files in the JCR programatically?

Though we can see that the XML file gets created, it's not in the saved state, we have to click "save all" again to save. Any programmatically made changes are not getting reflected as session.save() is not creating the file in saved state

I have used session.save ,session.refresh(true) and also resolver.commit(), which didn't solve my problem.

When I tried applying a smaller value to jcr:data, its getting created in the saved state.
Is there any limit on the size of binary we apply as a value to the property jcr: data to create a file in the saved state.

Replies

Highlighted
Highlighted

smacdonald2008

20-09-2017

ALso what type of node are you trying to modify - please post a pic of the nodes and CRXDE props corresponding to the node.

Highlighted

karthik2907

21-09-2017

First i'm creating an xml file using Document api. which is not in prettify format so i'm using Transformer api to prettify it and then converting it to input stream

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

DOMSource source = new DOMSource(doc);//doc contains the xml data

StreamResult streamResult = new StreamResult(outputStream);

TransformerFactory transformerFactory = TransformerFactory

.newInstance();

Transformer transformer = transformerFactory.newTransformer();

transformer.setOutputProperty(OutputKeys.INDENT, "yes");

transformer.setOutputProperty(OutputKeys.STANDALONE, "no");

transformer.setOutputProperty(

"{http://xml.apache.org/xslt}indent-amount", "2");

transformer.transform(source, streamResult);

InputStream is = new ByteArrayInputStream(

outputStream.toByteArray());

after this step, i'm creating the node sitemap.xml as shown below

mySession = resolver.adaptTo(Session.class);

Binary binary = mySession.getValueFactory().createBinary(is);

Node myNewNode = mySession.getNode(page.getPath());// path example: /content/adobe/en

Node xmlNode = myNewNode.addNode(SITEMAP_XML, "nt:file");

xmlNode.addMixin("mix:referenceable");

Node contentNode = xmlNode.addNode("jcr:content", "nt:resource");

contentNode.setProperty("jcr:data", binary);

contentNode.setProperty("jcr:mimeType", "application/xml");

Calendar lastModified = Calendar.getInstance();

lastModified.setTimeInMillis(lastModified.getTimeInMillis());

contentNode.setProperty("jcr:lastModified", lastModified);

mySession.save();

mySession.refresh(true);

you can see in the image that the created document is not in saved state.I have to manually save it after creation.
please help me here!!

Capture.PNG

Highlighted

Jörg_Hoh

Employee

21-09-2017

Can you try to replace your custom code with this utility function "JcrUtil.putFile()"? It should pretty much the thing you want to do.

JcrUtils (Apache Jackrabbit 2.12.7 API)

Regarding your screenshot: When you run your code, it is using a JCR session, which is different from the session you use in the CRX DE Lite Frontend. So executing the code will not save any session in the CRX DE Lite!

Jörg

Highlighted

karthik2907

22-09-2017

The problem is because of formatting the xml. I tried removing the below code


transformer.setOutputProperty(OutputKeys.INDENT, "yes");

transformer.setOutputProperty(OutputKeys.STANDALONE, "no");

transformer.setOutputProperty(

"{http://xml.apache.org/xslt}indent-amount", "2");


which formats the xml. Now the file is getting created in saved state.

Still confused that why those 3 lines are causing the issue.

Highlighted

Jörg_Hoh

Employee

22-09-2017

I guess, it's caused by the curly brackets.

Can you reduce your example to a minimal one and post it on the Apache Oak mailing list? The people there can probably help you.

Jörg