Examples of PostMethod


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

         if (k.getName().equalsIgnoreCase("JSESSIONID"))
            sessionID = k.getValue();
      }
      getLog().debug("Saw JSESSIONID=" + sessionID);
      // Submit the login form
      PostMethod formPost = new PostMethod(baseURLNoAuth + "custom-principal/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth + "custom-principal/login.jsp");
      formPost.addParameter("j_username", this.username);
      formPost.addParameter("j_password", new String(password));
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(), formPost, state);
      String loginResult = formPost.getResponseBodyAsString();
      if( loginResult.indexOf("Encountered a login error") > 0 )
         fail("Login Failed");

      String response = formPost.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the index.jsp
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod war1Index = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
            war1Index, state);
      response = war1Index.getStatusText();
View Full Code Here

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

            sessionID = k.getValue();
      }
      log.debug("Saw JSESSIONID="+sessionID);

      // Submit the login form
      PostMethod formPost = new PostMethod(baseURL0_ + securityCheckUrl_);
      formPost.addRequestHeader("Referer", baseURL0_ + loginFormUrl_);
      formPost.addParameter("j_username", "admin");
      formPost.addParameter("j_password", "admin");
      int responseCode = client.executeMethod(formPost.getHostConfiguration(),
         formPost, state);
      String response = formPost.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
         responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the index.html page
View Full Code Here

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

         fail("get of " + url + " redirected to login page");
   }

   public static void executeFormLogin(HttpClient httpConn, String warURL) throws IOException, HttpException
   {     
      PostMethod formPost = new PostMethod(warURL + "j_security_check");
      formPost.addRequestHeader("Referer", warURL + "login.html");
      formPost.addParameter("j_username", "jduke");
      formPost.addParameter("j_password", "theduke");
      int responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
         formPost, httpConn.getState());
      assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
         responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the index.html page
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod warIndex = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(warIndex.getHostConfiguration(),
         warIndex, httpConn.getState());
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
View Full Code Here

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

      {
         return new GetMethod(url);
      }
      else if ("POST".equals(restVerb))
      {
         return new PostMethod(url);
      }
      else if ("DELETE".equals(restVerb))
      {
         return new DeleteMethod(url);
      }
      else
      {
         final String verb = restVerb;
         return new PostMethod(url)
         {
            @Override
            public String getName()
            {
               return verb;
View Full Code Here

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

         throw new RuntimeException("You cannot send both form parameters and an entity body");

      if (!request.getFormParameters().isEmpty())
      {
         commitHeaders(request, httpMethod);
         PostMethod post = (PostMethod) httpMethod;

         for (Map.Entry<String, List<String>> formParam : request.getFormParameters().entrySet())
         {
            List<String> values = formParam.getValue();
            for (String value : values)
            {
               post.addParameter(formParam.getKey(), value);
            }
         }
      }
      else if (request.getBody() != null)
      {
         if (!(httpMethod instanceof EntityEnclosingMethod))
            throw new RuntimeException("A GET request cannot have a body.");
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         request.writeRequestBody(request.getHeadersAsObjects(), baos);
         commitHeaders(request, httpMethod);
         ClientRequestEntity requestEntity = new ClientRequestEntity(request.getBodyContentType().toString(), baos.toByteArray());
         EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
         post.setRequestEntity(requestEntity);
      }
      else
      {
         commitHeaders(request, httpMethod);
      }
View Full Code Here

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

   @Test
   public void testAsynch() throws Exception
   {
      HttpClient client = new HttpClient();
      {
         PostMethod method = new PostMethod("http://localhost:9095/resource?asynch=true");
         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

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

    }
   
    public void sendMessage(String callbackURI, String messageSenderId, String message) {
        HttpClient client = new HttpClient();
        try {
            PostMethod method = new PostMethod(getPushMessageURL(callbackURI, messageSenderId));
            method.setRequestEntity(new StringRequestEntity(message, "text/plain", "UTF-8"));
            int status = client.executeMethod(method);
            if (HttpResponseCodes.SC_OK != status) {
               throw new RuntimeException("Message can not be delivered to subscribers");
            }
        } catch (Exception ex)
View Full Code Here

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

   }
  
   public String getSharedSecret(String consumerKey) throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(ConsumerRegistrationURL);
      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

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

    }

    @Test
    public void testPost() throws Exception {

        PostMethod post = new PostMethod(TEST_URI);

        MyObject o1 = YamlResource.createMyObject();

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

        post.setRequestEntity(new StringRequestEntity(s1, "text/x-yaml", "utf-8"));

        client.executeMethod(post);

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

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

        Assert.assertEquals(s1, post.getResponseBodyAsString());

    }
View Full Code Here

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

    }

    @Test
    public void testBadPost() throws Exception {

        PostMethod post = new PostMethod(TEST_URI);

        post.setRequestEntity(new StringRequestEntity("---! bad", "text/x-yaml", "utf-8"));

        client.executeMethod(post);

        Assert.assertEquals(500, post.getStatusCode());

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.