Getting below Exception::
WARN main [DavDocumentBuilderFactory.createFactory] - Secure XML processing is not supported
java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
at org.apache.jackrabbit.webdav.xml.DavDocumentBuilderFactory.createFactory(DavDocumentBuilderFactory.java:50)
at org.apache.jackrabbit.webdav.xml.DavDocumentBuilderFactory.<init>(DavDocumentBuilderFactory.java:39)
at org.apache.jackrabbit.webdav.xml.DomUtil.<clinit>(DomUtil.java:60)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:203)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:72)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:61)
at com.spero.poc.WebDavClient.listOfFilesFromWebDav(WebDavClient.java:108)
at com.spero.poc.WebDavClient.main(WebDavClient.java:92)
Exception in thread "main" java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.getXmlStandalone()Z
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:377)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:131)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:684)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:728)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:343)
at org.apache.jackrabbit.webdav.xml.DomUtil.transformDocument(DomUtil.java:805)
at org.apache.jackrabbit.webdav.client.methods.XmlRequestEntity.<init>(XmlRequestEntity.java:43)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:193)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:205)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:72)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:61)
at com.spero.poc.WebDavClient.listOfFilesFromWebDav(WebDavClient.java:109)
at com.spero.poc.WebDavClient.main(WebDavClient.java:92)
Here is my code::
package com.spero.poc;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.client.methods.DavMethod;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
public class WebDavClient {
static HttpClient client = null;
public static void main(String[] args) {
// String uri = "https://www.webdavserver.com/Userab71566/Library/Content.txt";
String uri = "https://www.webdavserver.com/Userab71566/Library/";
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost("https://www.webdavserver.com");
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
params.setConnectionTimeout(60000);
connectionManager.setParams(params);
HttpClientParams cParams = new HttpClientParams();
cParams.setSoTimeout(60000);
// Create the HttpClient object and eventually pass the Credentials if required:
client = new HttpClient(cParams,connectionManager);
client.setHostConfiguration(hostConfig);
// Credentials creds = new UsernamePasswordCredentials("userId", "pw");
// client.getState().setCredentials(AuthScope.ANY, creds);
try {
WebDavClient test = new WebDavClient();
test.listOfFilesFromWebDav(uri);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
client = null;
}
if(client == null)
System.out.println("Client is in null state");
}
private List<String> listOfFilesFromWebDav(String folderUrl) {
try {
PropFindMethod pFind = new PropFindMethod(folderUrl, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
pFind.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
client.executeMethod(pFind);
List<String> files = new ArrayList<>();
MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
for (MultiStatusResponse response : responses) {
if (response.getHref().endsWith(".txt")) {
System.out.println("Data::"+response.getHref());
}
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DavException e) {
e.printStackTrace();
}
return null;
}
}
Thanks for the suggestion, I have gone through the logs and find out the mismatched class and jars. I have added the below system settings to my code and the Jar.
We have to resort to System.setProperty(...) calls from your code, eg:
//this would enforce the DOM implementation to be Xerces
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
//this would enforce the SAX implementation to be Xerces
System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");
//this would enforce the XSLT implementation to be Xalan
System.setProperty("javax.xml.transform.TransformerFactory","org.apache.xalan.processor.TransformerFactoryImpl");
The respective JRE implementation classes are:
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl