Package com.dotcms.repackage.org.apache.commons.httpclient.methods

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


            if ( allowTestingBuilds ) {
                map.put( "allowTestingBuilds", "true" );
            }
            //Talking with the update servlet....
            PostMethod method = doGet( url, map );

            //Download the update file
            int ret = download( updateFile, method );
            if ( ret == 200 ) {
                return updateFile;
View Full Code Here

                // Authenticate with proxy
                client.getState().setProxyCredentials( null, null, new UsernamePasswordCredentials( proxyUser, proxyPass ) );
            }
        }

        PostMethod method = new PostMethod( fileUrl );
        Object[] keys = pars.keySet().toArray();
        NameValuePair[] data = new NameValuePair[keys.length];
        for ( int i = 0; i < keys.length; i++ ) {
            String key = (String) keys[i];
            NameValuePair pair = new NameValuePair( key, pars.get( key ) );
            data[i] = pair;
        }

        method.setRequestBody( data );
        client.executeMethod( method );

        return method;
    }
View Full Code Here

      }).when(req).setAttribute(Mockito.eq("requestCode"),Mockito.any(String.class));

      LicenseUtil.processForm(req);
     
      HttpClient client=new HttpClient();
      PostMethod post=new PostMethod("https://my.dotcms.com/app/licenseRequest3");
      post.setRequestBody(new NameValuePair[] { new NameValuePair("code", reqcode.toString()) });
      client.executeMethod(post);
     
      if(post.getStatusCode()==200){
        license = post.getResponseBodyAsString();
        HttpServletRequest req2=Mockito.mock(HttpServletRequest.class);
        Mockito.when(req2.getParameter("iwantTo")).thenReturn("paste_license");
        Mockito.when(req2.getParameter("license_text")).thenReturn(license);
        LicenseUtil.processForm(req2);
      }
View Full Code Here

            pars.put( "license", LicenseUtil.getSerial() );
        }

        HttpClient client = new HttpClient();

        PostMethod method = new PostMethod( fileUrl );
        Object[] keys = (Object[]) pars.keySet().toArray();
        NameValuePair[] data = new NameValuePair[keys.length];
        for ( int i = 0; i < keys.length; i++ ) {
            String key = (String) keys[i];
            NameValuePair pair = new NameValuePair( key, pars.get( key ) );
            data[i] = pair;
        }

        method.setRequestBody( data );
        String ret = null;

        try {
            client.executeMethod( method );
            int retCode = method.getStatusCode();
            if ( retCode == 204 ) {
                Logger.info( UpdateUtil.class, "No new updates found" );
            } else {
                if ( retCode == 200 ) {
                    String newMinor = method.getResponseHeader( "Minor-Version" )
                            .getValue();
                    String newPrettyName = null;
                    if ( method.getResponseHeader( "Pretty-Name" ) != null ) {
                        newPrettyName = method.getResponseHeader( "Pretty-Name" )
                                .getValue();
                    }

                    if ( newPrettyName == null ) {
                        Logger.info( UpdateUtil.class, "New Version: "
                                + newMinor );
                        ret = newMinor;
                    } else {
                        Logger.info( UpdateUtil.class, "New Version: "
                                + newPrettyName + "/" + newMinor );
                        ret = newPrettyName;
                    }

                } else {
                    throw new DotDataException( "Unknown return code: " + method.getStatusCode() + " (" + method.getStatusText() + ")" );
                }
            }
        } catch ( HttpException e ) {
            Logger.error( UpdateUtil.class, "HttpException: " + e.getMessage(),
                    e );
View Full Code Here

        client.setState(state);
      }

      if (post) {
        method = new PostMethod(location);
      }
      else {
        method = new GetMethod(location);
      }
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.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.