Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpMethod


        return res;
    }
   
    protected static HttpResponse delete(String url, String user, String password) throws IOException {
        HttpClient httpClient = new HttpClient();
        HttpMethod method = new DeleteMethod(url);
        addAuthHeader(method, user, password);
       
        String contentType = "application/xml; charset=utf-8";
        method.setRequestHeader("Content-type", contentType);
       
        int status = httpClient.executeMethod(method);
        InputStream responseBody = method.getResponseBodyAsStream();
       
        HttpResponse res = new HttpResponse(status, responseBody);
        return res;
    }
View Full Code Here


  @NotNull
  public HttpMethod executeSelfSignedCertificateAwareRequest(@NotNull HttpClient client,
                                                             @NotNull String uri,
                                                             @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
    throws IOException {
    HttpMethod method = methodCreator.convert(uri);
    try {
      client.executeMethod(method);
      return method;
    }
    catch (IOException e) {
      HttpMethod m = handleCertificateExceptionAndRetry(e, method.getURI().getHost(), client, method.getURI(), methodCreator);
      if (m == null) {
        throw e;
      }
      return m;
    }
View Full Code Here

      hc.setHost(host, 443, easyHttps);
      String relativeUri = new URI(uri.getPathQuery(), false).getURI();
      // it is important to use relative URI here, otherwise our custom protocol won't work.
      // we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
      // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
      HttpMethod method = methodCreator.convert(relativeUri);
      client.executeMethod(hc, method);
      return method;
    }
    throw e;
  }
View Full Code Here

    /**
     * @throws RuleOracleUnavailableException
     * @see RuleDao#getRuleTree(String)
     */
    public RuleSet getRuleTree(String surt) throws RuleOracleUnavailableException {
        HttpMethod method = new GetMethod(oracleUrl + "/rules/tree/" + surt);
        RuleSet rules;

        try {
            http.executeMethod(method);
            String response = method.getResponseBodyAsString();
            System.out.println(response);
            rules = (RuleSet) xstream.fromXML(method.getResponseBodyAsStream());
        } catch (IOException e) {
            throw new RuleOracleUnavailableException(e);
        }
        method.releaseConnection();
        return rules;
    }
View Full Code Here

        return http;
    }

    public RobotRules getRulesForUrl(String url, String userAgent) throws IOException, RobotsUnavailableException {
        String robotsUrl = robotsUrlForUrl(url);
        HttpMethod method = new GetMethod(robotsUrl);
        method.addRequestHeader("User-Agent", userAgent);
        try {
            int code = http.executeMethod(method);
            // TODO: Constant 200
            if (code != 200) {
                throw new RobotsUnavailableException(robotsUrl);
            }
        } catch (HttpException e) {
            e.printStackTrace();
            throw new RobotsUnavailableException(robotsUrl);
        } catch (UnknownHostException e) {
            LOGGER.info("Unknown host for URL " + robotsUrl);
            throw new RobotsUnavailableException(robotsUrl);
        } catch (ConnectTimeoutException e) {
            LOGGER.info("Connection Timeout for URL " + robotsUrl);
            throw new RobotsUnavailableException(robotsUrl);
        } catch (NoRouteToHostException e) {
            LOGGER.info("No route to host for URL " + robotsUrl);
            throw new RobotsUnavailableException(robotsUrl);
        } catch (ConnectException e) {
            LOGGER.info("ConnectException URL " + robotsUrl);
            throw new RobotsUnavailableException(robotsUrl);
        }
        RobotRules rules = new RobotRules();
        rules.parse(method.getResponseBodyAsStream());
        return rules;
    }
View Full Code Here

            sb.append(e.getKey() + "=" + e.getValue()[0]);
          }
          methodString = sb.toString();
        }
        HttpClient httpclient = new HttpClient();
        HttpMethod method = new GetMethod(methodString);

        int sc = httpclient.executeMethod(method);
        response.setStatus(sc);
        response.setContentType("text/html");
        InputStream is = method.getResponseBodyAsStream();
        int len = 0;
        int bufferSize = 4096;
        byte[] buf = new byte[bufferSize];
        while ((len = is.read(buf)) >= 0) {
          response.getOutputStream().write(buf, 0, len);
View Full Code Here

   }

   public void undeploy(String name) throws IOException
   {
      String deployUrl = getManagerUrl("undeploy", "path=/" + getContextName(name));
      HttpMethod get = new GetMethod(deployUrl);
      try
      {
         int status = client.executeMethod(get);
         if (status != HttpURLConnection.HTTP_OK)
         {
            throw new IllegalStateException(new String(get.getResponseBody()));
         }
      }
      finally
      {
         get.releaseConnection();
         ManagersImpl.cleanUp();
      }
   }
View Full Code Here

    public void process(Exchange exchange) throws Exception {
        if (((HttpEndpoint)getEndpoint()).isBridgeEndpoint()) {
            exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
        }
        HttpMethod method = createMethod(exchange);
        Message in = exchange.getIn();
        HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy();

        // propagate headers as HTTP headers
        for (Map.Entry<String, Object> entry : in.getHeaders().entrySet()) {
            String headerValue = in.getHeader(entry.getKey(), String.class);
            if (strategy != null && !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) {
                method.addRequestHeader(entry.getKey(), headerValue);
            }
        }

        // lets store the result in the output message.
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Executing http " + method.getName() + " method: " + method.getURI().toString());
            }
            int responseCode = executeMethod(method);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Http responseCode: " + responseCode);
            }

            if (!throwException) {
                // if we do not use failed exception then populate response for all response codes
                populateResponse(exchange, method, in, strategy, responseCode);
            } else {
                if (responseCode >= 100 && responseCode < 300) {
                    // only populate response for OK response
                    populateResponse(exchange, method, in, strategy, responseCode);
                } else {
                    // operation failed so populate exception to throw
                    throw populateHttpOperationFailedException(exchange, method, responseCode);
                }
            }
        } finally {
            method.releaseConnection();
        }
    }
View Full Code Here

        String url = HttpProducerHelper.createURL(exchange, getEndpoint());

        RequestEntity requestEntity = createRequestEntity(exchange);
        HttpMethods methodToUse = HttpProducerHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
        HttpMethod method = methodToUse.createMethod(url);

        // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
        String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
        if (queryString == null) {
            queryString = getEndpoint().getHttpUri().getRawQuery();           
        }
        if (queryString != null) {
            // need to make sure the queryString is URI safe
            method.setQueryString(queryString);
        }

        if (methodToUse.isEntityEnclosing()) {
            ((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
            if (requestEntity != null && requestEntity.getContentType() == null) {
View Full Code Here

                        httpClient.setTimeout(enviarMensagemWebCtrl
                                .getParametrosGerais()
                                .getTempoAcessoBaseFuncionarios().intValue());
                    }
                   
                    HttpMethod method = new GetMethod(this.getOrgao(request)
                    .getConfiguracoes().getUrlBaseFuncionarios()
                    + "?matricula=" + matriculaAcionadorFuncionario);
                   
                    method.setDoAuthentication(true);
                   
                    try {
                        // Execute the method.
                        int statusCode = httpClient.executeMethod(method);
                       
                        if (statusCode != HttpStatus.SC_OK) {
                           
                            resultadoBuscaFunc = "A busca pelos seus dados cadastrais na sua instituição não retornou nenhuma informação.";

                        } else {
                           
                            InputStream in = method.getResponseBodyAsStream();
                           
                            DocumentBuilderFactory dFactory = DocumentBuilderFactory
                                    .newInstance();
                            DocumentBuilder dBuilder = dFactory
                                    .newDocumentBuilder();
                            Document doc = dBuilder.parse(in);
                           
                            NodeList nodes = doc
                                    .getElementsByTagName("Funcionario");
                           
                            if (nodes.getLength() != 0) {
                                Node no = nodes.item(0);
                                NamedNodeMap nnm = no.getAttributes();
                               
                                if (nnm.getNamedItem("nome") != null) {
                                    try {
                                        _form.setNomeAcionadorFuncionario(nnm
                                                .getNamedItem("nome")
                                                .getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (nnm.getNamedItem("cpf") != null) {
                                    try {
                                        _form.setCpfAcionadorFuncionario(nnm
                                                .getNamedItem("cpf")
                                                .getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (nnm.getNamedItem("setor") != null) {
                                    try {
                                        _form.setSetorAcionadorFuncionario(nnm
                                                .getNamedItem("setor")
                                                .getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                                if (nnm.getNamedItem("idade") != null) {
                                    try {
                                        _form
                                                .setFaixaEtaria(new Integer(
                                                enviarMensagemWebCtrl
                                                .getFaixaEtaria(
                                                nnm
                                                .getNamedItem(
                                                "idade")
                                                .getNodeValue())
                                                .getId()
                                                .intValue()));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                                if (nnm.getNamedItem("sexo") != null) {
                                    try {
                                        _form.setSexo(nnm.getNamedItem("sexo")
                                        .getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                                if (nnm.getNamedItem("escolaridade") != null) {
                                    try {
                                        _form
                                                .setEscolaridade(new Integer(
                                                enviarMensagemWebCtrl
                                                .getEscolaridade(
                                                nnm
                                                .getNamedItem(
                                                "escolaridade")
                                                .getNodeValue())
                                                .getId()
                                                .intValue()));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                                if (nnm.getNamedItem("pais") != null) {
                                    try {
                                        _form
                                                .setPais(new Integer(
                                                enviarMensagemWebCtrl
                                                .getPais(
                                                nnm
                                                .getNamedItem(
                                                "pais")
                                                .getNodeValue())
                                                .getId()
                                                .intValue()));
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                                if (_form.getPais().intValue() == 1) {
                                    if (nnm.getNamedItem("localResidencia") != null) {
                                        try {
                                            _form
                                                    .setUf(new Integer(
                                                    enviarMensagemWebCtrl
                                                    .getUF(
                                                    nnm
                                                    .getNamedItem(
                                                    "localResidencia")
                                                    .getNodeValue())
                                                    .getId()
                                                    .intValue()));
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                                if (nnm.getNamedItem("email") != null) {
                                    try {
                                        _form.setEmail(nnm
                                                .getNamedItem("email")
                                                .getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                if (nnm.getNamedItem("telefone") != null) {
                                    try {
                                        _form.setTelefone(nnm.getNamedItem(
                                                "telefone").getNodeValue());
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                               
                            }
                           
                            resultadoBuscaFunc = "Os seus dados cadastrais foram preenchidos conforme dados informados pela sua instituição.";
                        }
                    } catch (Exception e) {
                        if (Constants.DEBUG)
                            e.printStackTrace(System.out);
                    } finally {
                        method.releaseConnection();
                    }
                    request.setAttribute("flagPesquisaFuncionario", "true");
                }
            }
           
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpMethod

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.