session.save not saving Binary data set to jcr:data propery of .xml file | Community
Skip to main content
karthik2907
September 20, 2017

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

  • September 20, 2017
  • 2 replies
  • 2161 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

smacdonald2008
Level 10
September 20, 2017

What is the size of the content you are attempting to save?

smacdonald2008
Level 10
September 20, 2017

Also -- see this thread - it is applicable: Is there a limitation to the size of JCR Property value?

joerghoh
Adobe Employee
Adobe Employee
September 20, 2017

Can strip down your code to a minimalistic example and post it here to demonstrate the problem?

Jörg

smacdonald2008
Level 10
September 21, 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.

karthik2907
September 21, 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!!