have you tried to use the same technique as doMkCol()
does:
parentResource.addMember(resource, getInputContext(request, null));
Question
I am working with a jackrabbit server where we faced a problem on running multiple Repositories in a cluster. The problem is that the Folder structure path for a file insertion happens sometimes on the 1st repo and the insertion of the file on the 2nd(before both the servers get synced up). The solution i designed for this is to change the Jackrabbit source code and CREATE A FOLDER PATH FOR A FILE IF THE FOLDER PATH DOSENT EXIST instead of just throwing back a 409 CONFLICT error Following is the change in AbstractWebDavServlet in JackRabbit web-Dav
protected void doPut(WebdavRequest request, WebdavResponse response,
DavResource resource) throws IOException, DavException {
DavResource parentResource = resource.getCollection();
if (parentResource == null || !parentResource.exists()) {
if(!parentResource.exists()) {
try {
createFolder((Session)request.getSession(), parentResource.getLocator().getPrefix(),parentResource.getLocator().getHref(true));
}catch(Exception e) {
throw new IOException();
}
}
// parent does not exist
response.sendError(DavServletResponse.SC_CONFLICT);
return;
}
int status;
// test if resource already exists
if (resource.exists()) {
status = DavServletResponse.SC_NO_CONTENT;
} else {
status = DavServletResponse.SC_CREATED;
}
parentResource.addMember(resource, getInputContext(request, request.getInputStream()));
response.setStatus(status);
}
private String[] getFolders(String desUrl) throws Exception {
if (null == desUrl || desUrl.length() == 0)
return null;
String[] folder = desUrl.split("/");
String[] folders = new String[folder.length];
for (int i = 0; i < folder.length; i++) {
if (i == 0)
folders[i] = folder[i];
else
folders[i] = folders[i - 1] + "/" + folder[i];
}
return folders;
}
public void createFolder(Session session123,String prefix,String href) throws Exception {
String[] folders = /*this.getFolders(href.substring(prefix.length(),href.length()))*/href.substring(prefix.length()+1,href.length()-1).split("/");
if (null != folders) {
String davFolder = "";
int length = folders.length;
//Session session123 = ((JcrDavSession)session).getRepositorySession();
Node rootNode=session123.getRootNode();
for (int i = 0; i < length; i++) {
if(!rootNode.hasNode(folders[i]))
IOUtil.mkDirs(rootNode, folders[i], NodeType.NT_UNSTRUCTURED);
else
rootNode.getNode(folders[i]);
}
}
}
..
Now im in a nightmare situation trying to figure out a way to get the session.The above method for getting the jcr session dosent work.
PLEASE PLEASE HELP
No correct solution
OTHER TIPS
have you tried to use the same technique as doMkCol()
does:
parentResource.addMember(resource, getInputContext(request, null));