Examples of PostMethod


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

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

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

  @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

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


        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

Examples of org.lilystudio.httpclient.PostMethod

      url = "http" + url.substring(4);
    } else {
      isGet = true;
      addParameter(relay, url, encoding);
    }
    IMethod httpMethod = isGet ? new GetMethod(url) : new PostMethod(url);
    // 设置客户端特殊的信息
    httpMethod.setRequestHeader("If-None-Match", request
        .getHeader("If-None-Match"));
    httpMethod.setRequestHeader("If-Modified-Since", request
        .getHeader("If-Modified-Since"));
    // 取出服务器端可能用到的Cookie信息
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
      StringBuilder s = new StringBuilder(64);
      for (Cookie cookie : cookies) {
        String name = cookie.getName();
        if (!name.equals("JSESSIONID")) {
          s.append(name).append('=').append(cookie.getValue()).append(';');
        }
      }
      UserInformation info = relay.getUserInformation(false);
      if (info != null) {
        Object o = info.getProperty(SESSION_COOKIE_KEY);
        if (o != null) {
          s.append(o);
        }
      }
      int len = s.length();
      if (len > 0) {
        s.setLength(len - 1);
      }
      httpMethod.setRequestHeader("Cookie", s.toString());
    }
    HttpClient httpClient = new HttpClient();
    httpClient.setAutoDecode(true);
    try {
      if (param != null) {
        if (!isGet) {
          PostMethod method = (PostMethod) httpMethod;
          int size = param.size();
          for (int i = 0; i < size; i++) {
            Parameter item = param.get(i);
            Object value = item.getValue(relay);
            method.addRequestBody(item.name, value != null ? URLDecoder.decode(
                value.toString(), encoding) : "");
          }
        }
      }
      while (true) {
View Full Code Here

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

            } else {
                hostBuffer.append(mssUrl);
                fullURL = mssUrl;
            }

            PostMethod method = new PostMethod(fullURL);


            // Add the xml to the POST request
            method.setRequestBody(message);

            // set request headers
            if (characterEncoding != null) {
                method.addRequestHeader("Content-Type", "text/xml; charset=" +
                        characterEncoding);
                method.addRequestHeader("Accept-Charset",
                        characterEncoding);
            } else {
                method.addRequestHeader("Content-Type", "text/xml");
            }

            try {
                int statusCode = httpHelper.executeRequest(method,
                                                           fullURL);

                // If the status code is -1 then ran out of retries to
                // connect to the servlet so the xml cannot be processed
                if (statusCode == -1) {
                    final String messageKey =
                            "message-store-connection-failure-for-id-url";
                    LOGGER.error(messageKey);
                    throw new MessageException(
                            LOCALIZER.format(messageKey));
                }

                // Ensure there was a successful send
                if (statusCode != HttpURLConnection.HTTP_OK) {
                    final String messageKey =
                            "message-store-connection-failure-http-error-of";
                    final Object messageParam = new Integer(statusCode);
                    LOGGER.error(messageKey, messageParam);
                    throw new MessageException(
                            LOCALIZER.format(messageKey, messageParam));
                }

                // Read the response header
                Header idHeader = method.getResponseHeader(
                        MessageStoreServlet.MESSAGE_RESPONSE_HEADER_NAME);

                // Check for a null value which indicates that the header was
                // not set for some reason
                if (idHeader == null) {
                    final String messageKey =
                            "message-id-missing-url-construction-failed";
                    LOGGER.error(messageKey);
                    throw new MessageException(
                            LOCALIZER.format(messageKey));
                }

                id = idHeader.getValue();

                // And finally construct the URL to return, encoding the ? and
                // = as this is required by the NowSMS gateway BUT the whole
                // URL cannot be encoded as the / should not be encoded!
                // Rest of URL to return was created above
                hostBuffer.append("%3fpageid%3d");
                hostBuffer.append(id);
                returnURL = new URL(hostBuffer.toString());
            } catch (MalformedURLException mue) {
                final String messageKey = "message-url-invalid-for";
                final Object messageParam = SERVLET_PARTIAL_URL + "%3fid%3d" +
                        id;
                LOGGER.error(messageKey, messageParam);
                throw new MessageException(
                        LOCALIZER.format(messageKey, messageParam), mue);
            } catch (IOException ioe) {
                final String messageKey = "message-store-transport-error";
                LOGGER.error(messageKey);
                throw new MessageException(
                        LOCALIZER.format(messageKey), ioe);
            } finally {
                // Release the connection.
                method.releaseConnection();
            }
        }

        // Return the URL of the message
        return returnURL;
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.