jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xiaojie Shen <Xiaojie.S...@cybercomgroup.com>
Subject Jackrabbit SearchMethod - status code 207 but null response
Date Wed, 23 Jun 2010 13:26:23 GMT
Hello

Running SearchMethod against the Jackrabbit standalone server, I get successful state code
but nothing in response body. Can anybody give some suggestion or a successful query example?

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;
import org.apache.jackrabbit.webdav.client.methods.OptionsMethod;

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 url = "http://localhost:9997/jackrabbit-webapp_default/server/default";
                  OptionsMethod optionsMehod = new OptionsMethod(url);
                  client.executeMethod(optionsMehod);
                  boolean b = optionsMehod.isAllowed("SEARCH");
                  if(b==true)
                    System.out.println("search method is allowed");
                  else
                    System.out.println("search method is not allowed");

                  String query = "//sv:node[@sv:name='jcr:root']";
                  //query = "<xpath>//element(*, rep:root)</xpath>";

                  String uri = "/jackrabbit-webapp_default/server/default";
                  SearchMethod searchMethod = new SearchMethod(uri, query, "xpath");
                  client.executeMethod(searchMethod);

                  if (searchMethod.succeeded()){
                        String resp = searchMethod.getResponseBodyAsString();
                        long length = searchMethod.getResponseContentLength();
                        System.out.println("response: " + resp +
                                " length: " + safeLongToInt(length));
                  }

                  int statuscode = searchMethod.getStatusCode();
                  System.out.println("statusCode " + statuscode);
                  String statustext = searchMethod.getStatusText();
                  System.out.println("text " + statustext);
      }

      public static int safeLongToInt(long l) {
          int i = (int)l;
          if ((long)i != l) {
              throw new IllegalArgumentException(l + " cannot be cast to int without changing
its value.");
          }
          return i;
      }
}

Run result:
search method is allowed
response: null length: 165
statusCode 207
text Multi-Status

Mime
View raw message