Package org.apache.commons.httpclient.methods

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


       HttpMethod theMethod = null;
       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) {
View Full Code Here


   */
  private static Channel fetchChannelViaHTTP(String url)
    throws HttpException, IOException, SAXException
  {
    Digester parser = new XMLDigester();
    GetMethod get = new GetMethod(url);
    //get.setRequestHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; zh-cn) Opera 8.52");
        try {
          http_client.executeMethod(get);
          if(get.getStatusCode()==HttpServletResponse.SC_OK){
            Charset cs = null;
            Header header_cs = getResponseHeader(get,"Content-Type");
            if(header_cs==null){
              cs = Charset.forName(get.getResponseCharSet());
            }
            else{
              String content_type = header_cs.getValue().toLowerCase();
              try {
            Object[] values = content_type_parser.parse(content_type);
            cs = Charset.forName((String)values[1]);
          } catch (ParseException e) {
            URL o_url = new URL(url);
            String host = o_url.getHost();
            Iterator hosts = charsets.keySet().iterator();
            while(hosts.hasNext()){
              String t_host = (String)hosts.next();
              if(host.toLowerCase().endsWith(t_host)){
                cs = Charset.forName((String)charsets.get(t_host));
                break;
              }
            }
            if(cs==null)
              cs = default_charset;
           
          }
            }           
           
            BufferedReader rd = new BufferedReader(new InputStreamReader(
            get.getResponseBodyAsStream(), cs));
           
            char[] cbuf = new char[1];
            int read_idx = 1;
            do{
              rd.mark(read_idx++);
              if(rd.read(cbuf)==-1)
                break;
              if(cbuf[0]!='<')
                continue;
              rd.reset();
              break;
            }while(true);
            return (Channel)parser.parse(rd);
          }
          else{
            log.error("Fetch RSS from " + url + " failed, code="+get.getStatusCode());
          }
        }finally{
          get.releaseConnection();
        }
      return null;
  }
View Full Code Here

    private String retrieveTagHelp() {
        if (_connectionErrors < MAX_CONNECTION_ERRORS) {
                StringBuffer information = new StringBuffer()
                try {
                    // build online help url
                    GetMethod getMethod = new GetMethod(retrieveTagInfoURL(_tagname, _versionCompliance));
                    int returnCode = _httpClient.executeMethod(getMethod);
                    if (returnCode == HttpsURLConnection.HTTP_OK) {
                        information.append(getMethod.getResponseBodyAsString());
                    }
                } catch (Exception e) {
                    Plugin.getDefault().logError("Unable to retrieve online help data.", e);
                    _connectionErrors ++;
                }
View Full Code Here

    private String retrieveAttributeHelp() {
        if (_connectionErrors < MAX_CONNECTION_ERRORS) {
                StringBuffer information = new StringBuffer();
                try {
                    // build online help url
                    GetMethod getMethod = null;
                    if (_attribute != null) {
                        getMethod = new GetMethod(retrieveAttributeInfoURL(_tagname, _attribute, _value, _versionCompliance));                     
                    }
                   
                    if (getMethod != null) {
                        int returnCode = _httpClient.executeMethod(getMethod);
                        if (returnCode == HttpsURLConnection.HTTP_OK) {
                            information.append(getMethod.getResponseBodyAsString());
                        }
                    }
                } catch (Exception e) {
                    Plugin.getDefault().logError("Unable to retrieve online help data.", e);
                    _connectionErrors++;
View Full Code Here

  }
 
   public TemporaryFile downloadWGA(IProgressMonitor monitor, String url) throws IllegalStateException, IOException, URISyntaxException {
        monitor.setTaskName("Downloading OpenWGA from '" + url + "'");                    
        HttpClient client = new DefaultHttpClient((IProxyService)_proxyServiceTracker.getService(), new URI(url));
        GetMethod get = new GetMethod(url);
    int result = client.executeMethod(get);
    if (result == HttpURLConnection.HTTP_OK) {
      long size = get.getResponseContentLength();               
            TemporaryFile temp = new TemporaryFile("wga.war", new ProgressMonitorInputStream(monitor, "Downloading OpenWGA ", size, get.getResponseBodyAsStream()), getStateLocation().toFile());
      return temp;
    } else {
            throw new IOException("Download of OpenWGA failed. Server returned '" + result + "'.");
    }
   
View Full Code Here

    Object args = parameters != null ? parameters
        .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));
View Full Code Here

  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)
      throw exception;
  }
View Full Code Here

            org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
            httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
           
            for (int j = 0; j< 1000; j++) {
             
              GetMethod getMeth = new GetMethod("http://localhost:" + server.getLocalPort() + "/");
              httpClient.executeMethod(getMeth);
             
              Assert.assertEquals(200, getMeth.getStatusCode());
              Assert.assertEquals("OK", getMeth.getResponseBodyAsString());
             
              getMeth.releaseConnection();
            }

           
          } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

          try {
            org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
            httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
            for (int j = 0; j< 1000; j++) {
             
              GetMethod getMeth = new GetMethod("http://localhost:" + server.getLocalPort() + "/");
              httpClient.executeMethod(getMeth);
             
              Assert.assertEquals(200, getMeth.getStatusCode());
              Assert.assertEquals("OK", getMeth.getResponseBodyAsString());
             
              getMeth.releaseConnection();
            }

           
          } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

     * <p>The returned stream does not have to be buffered.
     */
    protected InputStream doGetInputStream()
        throws Exception
    {
        final GetMethod getMethod = new GetMethod();
        setupMethod(getMethod);
        final int status = fileSystem.getClient().executeMethod(getMethod);
        if (status != HttpURLConnection.HTTP_OK)
        {
            throw new FileSystemException("vfs.provider.http/get.error", getName());
View Full Code Here

TOP

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

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.