Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.GetMethod


         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(Response.Status.ACCEPTED.getStatusCode(), status);
         String jobUrl1 = method.getResponseHeader(HttpHeaders.LOCATION).getValue();

         GetMethod get = new GetMethod(jobUrl1);
         status = client.executeMethod(get);
         Assert.assertEquals(Response.Status.ACCEPTED.getStatusCode(), status);

         Thread.sleep(1500);
         status = client.executeMethod(get);
         Assert.assertEquals(Response.Status.OK.getStatusCode(), status);
         Assert.assertEquals(get.getResponseBodyAsString(), "content");

         method.releaseConnection();
      }
   }
View Full Code Here


   public void testNoDefaultsResource() throws Exception
   {
      HttpClient client = new HttpClient();

      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/basic");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/ejb-integration-war/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/queryParam");
         NameValuePair[] params = {new NameValuePair("param", "hello world")};
         method.setQueryString(params);
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("hello world", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/uriParam/1234");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("1234", method.getResponseBodyAsString());
         method.releaseConnection();
      }
   }
View Full Code Here

   public void testLocatingResource() throws Exception
   {
      HttpClient client = new HttpClient();

      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/locating/basic");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("basic", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         PutMethod method = new PutMethod("http://localhost:8080/ejb-integration-war/locating/basic");
         method.setRequestEntity(new StringRequestEntity("basic", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(204, status);
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/locating/queryParam");
         NameValuePair[] params = {new NameValuePair("param", "hello world")};
         method.setQueryString(params);
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("hello world", method.getResponseBodyAsString());
         method.releaseConnection();
      }
      {
         GetMethod method = new GetMethod("http://localhost:8080/ejb-integration-war/locating/uriParam/1234");
         int status = client.executeMethod(method);
         Assert.assertEquals(HttpResponseCodes.SC_OK, status);
         Assert.assertEquals("1234", method.getResponseBodyAsString());
         method.releaseConnection();
      }
   }
View Full Code Here

   }

   private void accessWithoutToken(String uri) throws Exception
   {
       HttpClient client = new HttpClient();
       GetMethod method = new GetMethod(uri + "/resource1");
       int status = client.executeMethod(method);
       if (400 != status) {
           throw new RuntimeException("Consumer has not been authorized yet but already can access the resource");
       }
   }
View Full Code Here

  
   public Token getRequestToken(String consumerKey, String consumerSecret,
                                String callbackURI, String scope, String permission) throws Exception
   {
      HttpClient client = new HttpClient();
      GetMethod method = new GetMethod(
              getRequestURL(consumerKey, consumerSecret, callbackURI, scope, permission));
      int status = client.executeMethod(method);
      if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Request token can not be obtained");
      }
      // check that we got all tokens
      Map<String, String> response = getResponse(method);
      if (response.size() != 3
          || !response.containsKey(OAuth.OAUTH_TOKEN)
          || !(response.get(OAuth.OAUTH_TOKEN).length() > 0)
          || !response.containsKey(OAuth.OAUTH_TOKEN_SECRET)
          || !(response.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)
          || !response.containsKey(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM)
          || !response.get(OAuthUtils.OAUTH_CALLBACK_CONFIRMED_PARAM).equals("true")) {
          throw new RuntimeException("Wrong request token details");
      }

      method.releaseConnection();
     
      return new Token(response.get(OAuth.OAUTH_TOKEN), response.get(OAuth.OAUTH_TOKEN_SECRET));
   }
View Full Code Here

   public Token getAccessToken(String consumerKey, String consumerSecret,
           Token requestToken) throws Exception
   {
      HttpClient client = new HttpClient();
      GetMethod method = new GetMethod(getAccessURL(consumerKey, consumerSecret,
                 requestToken.getToken(), requestToken.getSecret(), requestToken.getVerifier()));
      int status = client.executeMethod(method);
      if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Request token can not be obtained");
      }
      // check that we got all tokens
      Map<String, String> response = getResponse(method);
      if (response.size() != 2
          || !response.containsKey(OAuth.OAUTH_TOKEN)
          || !(response.get(OAuth.OAUTH_TOKEN).length() > 0)
          || !response.containsKey(OAuth.OAUTH_TOKEN_SECRET)
          || !(response.get(OAuth.OAUTH_TOKEN_SECRET).length() > 0)) {
          throw new RuntimeException("Wrong access token details");
      }
     
      method.releaseConnection();
      return new Token(response.get(OAuth.OAUTH_TOKEN), response.get(OAuth.OAUTH_TOKEN_SECRET));
   }
View Full Code Here

  
  public String accessEndUserResource(Token accessToken) throws Exception
  {
      HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(getEndUserURL("/resource1", DEFAULT_CONSUMER_ID, consumerSecret, accessToken.getToken(), accessToken.getSecret()));
      try {
          int status = client.executeMethod(method);
          if (200 != status) {
              throw new RuntimeException("Unexpected status");
          }
          return method.getResponseBodyAsString();
      } finally {
          method.releaseConnection();
      }
   }
View Full Code Here

   }
 
  public void tryAccessEndUserAdminResource(Token accessToken) throws Exception
    {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(getEndUserURL("/resource2", DEFAULT_CONSUMER_ID, consumerSecret, accessToken.getToken(), accessToken.getSecret()));
        try {
            int status = client.executeMethod(method);
            if (401 != status) {
                throw new RuntimeException("Unexpected status");
            }
        } finally {
            method.releaseConnection();
        }
   } 
View Full Code Here

            String returnToUrl = httpReq.getRequestURL().toString();
            authReq = manager.authenticate(discovered, returnToUrl);
           
            String destinationUrl = authReq.getDestinationUrl(true);
            HttpClient client = new HttpClient();
            GetMethod request = new GetMethod(destinationUrl);
            client.executeMethod(request);
            String body = request.getResponseBodyAsString();
            String[] paramValues = body.split("\n");
            Map<String, String> paramsMap = new HashMap<String, String>();
            for (String paramValue : paramValues) {
                String theRealValue = paramValue.trim();
                if (theRealValue.isEmpty()) {
View Full Code Here

    }

    @Test
    public void testGet() throws Exception {

        GetMethod get = new GetMethod(TEST_URI);

        MyObject o1 = YamlResource.createMyObject();

        String s1 = new Yaml().dump(o1);

        client.executeMethod(get);

        Assert.assertEquals(200, get.getStatusCode());

        Assert.assertEquals("text/x-yaml", get.getResponseHeader("Content-Type").getValue());

        String s = get.getResponseBodyAsString();

        Assert.assertEquals(s1, s);

    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.GetMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.