Package org.apache.commons.httpclient.methods

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


   }
  
   public String registerMessagingService(String consumerKey) throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(ConsumerRegistrationURL);
      method.addRequestHeader(new Header("Authorization", "OpenId " + SubscriberOpenIdIdentifier));
      method.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
      int status = client.executeMethod(method);
      if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Registration failed");
      }
      // check that we got all tokens
      Map<String, String> response = OAuth.newMap(OAuth.decodeForm(method.getResponseBodyAsString()));
      String secret = response.get("xoauth_consumer_secret");
      if (secret == null) {
          throw new RuntimeException("No secret available");
      }
      return secret;
View Full Code Here


  
  
   public void registerMessagingServiceScopes(String consumerKey, String scope) throws Exception
   {
       HttpClient client = new HttpClient();
       PostMethod method = new PostMethod(ConsumerScopesRegistrationURL);
       method.addRequestHeader(new Header("Authorization", "OpenId " + SubscriberOpenIdIdentifier));
       method.addParameter(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
       method.addParameter("xoauth_scope", scope);
       method.addParameter("xoauth_permission", "sendMessages");
       int status = client.executeMethod(method);
       if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Scopes can not be registered");
       }
   }
View Full Code Here

   // Question : what about refresh tokens ?
   public void registerMessagingServiceCallback(String consumerKey, String consumerSecret, String callback)
       throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(MessagingServiceCallbackRegistrationURL);
      method.addRequestHeader(new Header("Authorization", "OpenId " + SubscriberOpenIdIdentifier));
      method.addParameter("consumer_id", consumerKey);
      method.addParameter("consumer_secret", consumerSecret);
      method.addParameter("callback_uri", callback);
      int status = client.executeMethod(method);
      if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Callback Registration failed");
      }
   }
View Full Code Here

  
   public void produceMessages()
      throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(MessagingServiceMessagesURL);
      method.addRequestHeader(new Header("Authorization", "OpenId " + SubscriberOpenIdIdentifier));
      method.setRequestEntity(new StringRequestEntity("Hello !", "text/plain", "UTF-8"));
      int status = client.executeMethod(method);
      if (HttpResponseCodes.SC_OK != status) {
          throw new RuntimeException("Messages can not be sent");
      }
   }
View Full Code Here

  
   public void registerTrustedOpenIdRealms()
       throws Exception
    {
       HttpClient client = new HttpClient();
       PostMethod method = new PostMethod(OpenIdTrustedRealmsURL);
       Base64 base64 = new Base64();
       String base64Credentials = new String(base64.encode("admin:admin".getBytes()));
       method.addRequestHeader(new Header("Authorization", "Basic " + base64Credentials));
       method.addParameter("xopenid.realm", OpenIdTrustedRealm);
       int status = client.executeMethod(method);
       if (HttpResponseCodes.SC_OK != status) {
           throw new RuntimeException("OpenId realms can not be registered");
       }
      
View Full Code Here

      List<Part> partsList = new ArrayList<Part>();
      partsList.add(new StringPart("part1", "This is Value 1"));
      partsList.add(new StringPart("part2", "This is Value 2"));
      partsList.add(new FilePart("data.txt", LocateTestData.getTestData("data.txt")));
      Part[] parts = partsList.toArray(new Part[partsList.size()]);
      PostMethod method = new PostMethod(TEST_URI);
      RequestEntity entity = new MultipartRequestEntity(parts, method.getParams());
      method.setRequestEntity(entity);
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);

      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type").getValue();
      System.out.println(contentType);
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 3);
      method.releaseConnection();

   }
View Full Code Here

    server.start();
   
   
   
    org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
    PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/");
    meth.setRequestBody("test123456");

    httpClient.executeMethod(meth);
   
    String body = meth.getResponseBodyAsString();
    Assert.assertEquals("Hello", body);
 
    meth.releaseConnection();
    server.close();
  }
View Full Code Here

    * @param path the request path
    * @return a PostMethod object
    */
   public static PostMethod createPostMethod(String path)
   {
      return new PostMethod(generateURL(path));
   }
View Full Code Here

  @Test
  public void testApacheClient() throws Exception {

    org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
   
    PostMethod postMethod = new PostMethod(url);
    postMethod.addParameter(new org.apache.commons.httpclient.NameValuePair("file", new String(HttpUtils.encodeBase64(data), "US-ASCII")));

    httpClient.executeMethod(postMethod);
     
      Assert.assertEquals(200, postMethod.getStatusCode());
      Assert.assertTrue(QAUtil.isEquals(file, postMethod.getResponseBody()));
     
      postMethod.releaseConnection();
  }     
View Full Code Here


        org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
        httpClient.getParams().setParameter("http.protocol.expect-continue", true);

        PostMethod meth = new PostMethod("http://localhost:" + server.getLocalPort() + "/test");
        meth.setRequestBody("OK");

        httpClient.executeMethod(meth);
       
        Assert.assertEquals(200, meth.getStatusCode());
        Assert.assertEquals("OK", meth.getResponseBodyAsString());
       
        meth.releaseConnection();
       
        server.close();
    }
View Full Code Here

TOP

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

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.