Hello
We're trying to do Webdav Search by Jackrabbit searchMethod against our
Jackrabbit server, but always get error 405 Method Not Allowed and there's none
error logged in Jackrabbit log.
Then I'm trying to do Search against the Jackrabbit default server, but same
error is given. Could you please give some suggestion?
Code:
import java.io.IOException;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.jackrabbit.webdav.client.methods.SearchMethod;
public class SearchJackRabbit {
public static void main(String[] args) throws IOException {
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost("localhost", 9997);
HttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new
HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig,
maxHostConnections);
connectionManager.setParams(params);
HttpClient client = new HttpClient(connectionManager);
Credentials creds = new UsernamePasswordCredentials("admin",
"admin");
client.getState().setCredentials(AuthScope.ANY, creds);
client.setHostConfiguration(hostConfig);
String query = "<D:searchrequest xmlns:D =\"DAV:\">" +
" <D:sql>" +
" SELECT *" +
" </D:sql>" +
"</D:searchrequest>";
SearchMethod searchMethod = new
SearchMethod("/jackrabbit-webapp_default/repository/default",query,"sql");
client.executeMethod(searchMethod);
byte[] resp = searchMethod.getResponseBody();
System.out.println("response: " + resp);
int statuscode = searchMethod.getStatusCode();
System.out.println("statusCode " + statuscode);
String statustext = searchMethod.getStatusText();
System.out.println("text " + statustext);
}
}
Run result:
response: [...@c44b88
statusCode 405
text Method Not Allowed
Best regards
Shen