Examples of PostMethod


Examples of com.dotcms.repackage.org.apache.commons.httpclient.methods.PostMethod

     * @throws UpdateException
     * @throws IOException
     */
    private File searchForVersion ( Map<String, String> map ) throws UpdateException, IOException {

        PostMethod method = doGet( url, map );
        int ret = method.getStatusCode();
        if ( ret == 200 ) {
            // Get the version of the jar.
            try {
                newMinor = method.getResponseHeader( "Minor-Version" ).getValue();
                if ( newMinor.trim().length() > 0 ) {
                    String[] minorArr = newMinor.split( "_" );
                    if ( minorArr.length > 1 ) {
                        logger.info( Messages.getString( "UpdateAgent.text.latest.version" ) + minorArr[0] + " / " + minorArr[1] );
                    } else {
                        logger.info( Messages.getString( "UpdateAgent.text.latest.version" ) + minorArr[0] );
                    }
                    newVersion = minorArr[0];
                    logger.info( " " );
                } else {
                    throw new Exception();
                }
            } catch ( Exception e ) {
                logger.debug( Messages.getString( "UpdateAgent.error.no.minor.version" ), e );
                throw new UpdateException( Messages.getString( "UpdateAgent.error.no.minor.version" ), UpdateException.ERROR );
            }

            String fileName = "update_" + newVersion + ".zip";
            File updateFile = new File( getDistributionPath() + File.separator + FOLDER_HOME_UPDATER + File.separator + "updates" + File.separator + fileName );
            if ( updateFile.exists() ) {
                //check md5 of file
                String MD5 = null;
                boolean hasMD5 = false;
                if ( method.getResponseHeader( "Content-MD5" ) != null && !method.getResponseHeader( "Content-MD5" ).equals( "" ) && !method.getResponseHeader( "Content-MD5" ).equals( "null" ) ) {
                    MD5 = method.getResponseHeader( "Content-MD5" ).getValue();
                    if ( !MD5.equals( "" ) ) {
                        hasMD5 = true;
                    }
                }
                if ( hasMD5 ) {
                    String dlMD5 = UpdateUtil.getMD5( updateFile );
                    logger.debug( Messages.getString( "UpdateAgent.debug.server.md5" ) + MD5 );
                    logger.debug( Messages.getString( "UpdateAgent.debug.file.md5" ) + dlMD5 );

                    if ( MD5 == null || MD5.length() == 0 || !dlMD5.equals( MD5 ) ) {
                        logger.fatal( Messages.getString( "UpdateAgent.error.md5.failed" ) );
                        throw new UpdateException( Messages.getString( "UpdateAgent.error.file.exists" ) + fileName, UpdateException.ERROR );
                    }
                } else {
                    // file verified, let's use it
                    logger.info( updateFile.getName() + ": " + Messages.getString( "UpdateAgent.text.md5.verified" ) );
                }

            } else {
                //Create the updates directory
                if ( !updateFile.getParentFile().exists() ) {
                    updateFile.getParentFile().mkdirs();
                }
                // Download the update content, the update servlet will provide an url for the update file
                String downloadUrl = method.getResponseHeader( "Download-Link" ).getValue();
                download( downloadUrl, updateFile, method );
            }

            return updateFile;

View Full Code Here

Examples of com.maverick.http.PostMethod

        return value == null || value.length() == 0;
    }

    private static void runStep(HttpClient client, HttpTestEntryStep step) throws Exception {
        String url = "/" + step.getUrl();
        HttpMethod get = step.isPost() ? new PostMethod(url) : new GetMethod(url);
        for (Map.Entry<String, String> entry : step.getParameters().entrySet()) {
            get.setParameter(entry.getKey(), entry.getValue());
        }

        HttpResponse response = client.execute(get);
View Full Code Here

Examples of com.sola.instagram.io.PostMethod

      postArgs.put("scope", getScope());
    }
    postArgs.put("code", code);

   
      JSONObject response = (new PostMethod() .setPostParameters(postArgs)
      .setMethodURI(UriFactory.Auth.GET_ACCESS_TOKEN) ).call().getJSON();
    
    try {
      setAccessToken(new
          AccessToken(response.getString("access_token")));
View Full Code Here

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

    java.net.URL u=new java.net.URL(url);
    String soapAction="";
    String request=new String(b);
       
    HttpClient httpClient = new HttpClient();
        PostMethod httpPostMethod = new PostMethod(u.toExternalForm());
        httpPostMethod.setRequestHeader("SOAPAction", "\"" + soapAction + "\"");
        httpPostMethod.setRequestHeader("Content-Type", "text/xml");
        httpPostMethod.setRequestEntity(new StringRequestEntity(request));
        httpClient.executeMethod(httpPostMethod);
        String result=httpPostMethod.getResponseBodyAsString();
   
    return(result);
  }
View Full Code Here

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

       StringBuffer sb = new StringBuffer();

       if ("GET".equalsIgnoreCase(method)) {
           theMethod = new GetMethod(urlpath);
       } else if ("POST".equalsIgnoreCase(method)) {
           theMethod = new PostMethod(urlpath);
       }

       if (username != null && password != null) {

           try {
               httpclient.executeMethod(theMethod);
           } catch (IOException e) {
               e.printStackTrace();
           } finally {
               theMethod.releaseConnection();
           }
         PostMethod authMethod = new PostMethod(authentication_url);
         NameValuePair[] data = {new NameValuePair("j_username", username), new NameValuePair("j_password", password)};
         authMethod.setRequestBody(data);
           try {
               httpclient.executeMethod(authMethod);
           } catch (IOException e) {
               e.printStackTrace();
           } finally {
               authMethod.releaseConnection();
           }
       }

       try {
         httpclient.executeMethod(theMethod);
View Full Code Here

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

        .get(ModelMap.RPC_ARGS_KEY) : null;

    if (methodType.equalsIgnoreCase("get")) {
      method = new GetMethod(url);
    } else if (methodType.equalsIgnoreCase("post")) {
      PostMethod postMethod = new PostMethod(url);
      if (args != null) {
        byte[] output = constructArgs(method, args);
        postMethod.setRequestEntity(new ByteArrayRequestEntity(output));
      }
      method = postMethod;
    } else if (methodType.equalsIgnoreCase("put")) {
      method = new PutMethod(url);
      if (args != null) {
View Full Code Here

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

  public synchronized  void login(HttpClient httpClient,
      String securityHost, String loginUrl,String userName,String password) throws Exception {
    Exception exception = null;

    GetMethod authget = null;
    PostMethod authpost = null;
    GetMethod redirect = null;
    try {
      httpClient.getParams().setCookiePolicy(
          CookiePolicy.BROWSER_COMPATIBILITY);

      authget = new GetMethod(securityHost + loginUrl);

      httpClient.executeMethod(authget);
      int statuscode = authget.getStatusCode();

      authpost = new PostMethod(securityHost + "/j_security_check");
      NameValuePair j_username = new NameValuePair("j_username", userName);
      NameValuePair j_password = new NameValuePair("j_password", password);
      authpost.setRequestBody(new NameValuePair[] { j_username, j_password });

      httpClient.executeMethod(authpost);
      statuscode = authpost.getStatusCode();
      if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY)
          || (statuscode == HttpStatus.SC_MOVED_PERMANENTLY)
          || (statuscode == HttpStatus.SC_SEE_OTHER)
          || (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
        Header header = authpost.getResponseHeader("location");
        if (header != null) {
          String newuri = header.getValue();
          if ((newuri == null) || (newuri.equals(""))) {
            newuri = "/";
          }
          redirect = new GetMethod(newuri);

          httpClient.executeMethod(redirect);
          redirect.releaseConnection();
        }
      } else {
        exception = new LoginErrorException("用户名或者密码错误");
      }
    } catch (Exception e) {
      exception = e;
    } finally {
      if (authget != null)
        authget.releaseConnection();
      if (authpost != null)
        authpost.releaseConnection();
      if (redirect != null)
        redirect.releaseConnection();
    }

    if (exception != null)
View Full Code Here

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


        HttpClient httpClient = new 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.apache.commons.httpclient.methods.PostMethod

   * @see net.sf.xbus.technical.ObjectSender#execute(java.lang.String,
   *      java.lang.Object)
   */
  public Object execute(String function, Object callData) throws XException
  {
    PostMethod method = initialize(function, null);

    InputStream inStream = (InputStream) callData;
    method.setRequestEntity(new InputStreamRequestEntity(inStream));
    sendMessage(method);

    try
    {
      inStream.close();
View Full Code Here

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

   *
   * @return <code>null</code>
   */
  public String execute(String function, String callData) throws XException
  {
    PostMethod method = initialize(function, null);

    if (callData == null)
      callData = "";

    method.setRequestEntity(new StringRequestEntity(callData));
    // method.setRequestContentLength(callData.length());
    // method.setRequestBody(callData);

    return sendMessage(method);
  }
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.