For some reasons it gives me this
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/logging/LogFactory
        at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:65)
        at RestTest2.getClient(RestTest2.java:16)
        at RestTest2.main(RestTest2.java:27)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.logging.LogFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 3 more
Code:
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.xwiki.rest.model.jaxb.ObjectFactory;
import org.xwiki.rest.model.jaxb.Page;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.NameValuePair;
public class RestTest2 {
         static HttpClient getClient(String host, int port, String username, String
password) {
              HttpClient httpClient = new HttpClient();
              httpClient.getParams().setAuthenticationPreemptive(true);
              httpClient.getState().setCredentials(
                 new AuthScope(host, port, AuthScope.ANY_REALM),
                 new UsernamePasswordCredentials(username, password)
              );
              return httpClient;
           }
           public static void main(String[] args) throws IOException {
             // Get request example
          HttpClient httpClient = getClient("xwiki.aircr.ru", 8080,
"Tobi",
        "gaben1337");
          GetMethod getMethod = new
GetMethod("http://xwiki.aircr.ru/xwiki/bin/view/Main/");
          getMethod.addRequestHeader("Accept", "application/json");
              getMethod.setDoAuthentication( true );
          String getURL = "http://xwiki.aircr.ru/xwiki/bin/view/Main/";
              try {
                  int status = httpClient.executeMethod(getMethod);
                 System.out.println(getMethod.getResponseBodyAsString());
               } catch (Exception e) {
             //...
          } finally {
                  // release any connection resources used by the method
          getMethod.releaseConnection();
               }
          // Put request example
          String putURL = "http://xwiki.aircr.ru/xwiki/bin/view/Main/";
          PutMethod putMethod = new PutMethod(putURL);
            putMethod.addRequestHeader("Accept", "application/json");
            putMethod.setDoAuthentication( true );
            try {
               int status = httpClient.executeMethod(putMethod);
          System.out.println(putMethod.getResponseBodyAsString());
            } catch (Exception e) {
               // ...
          } finally {
               // release any connection resources used by the method
          putMethod.releaseConnection();
            }
          }
}
--
View this message in context:
http://xwiki.475771.n2.nabble.com/xWiki-RESTful-HTTP-Connection-tp7599026p7…
Sent from the XWiki- Users mailing list archive at 
Nabble.com.