Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpConnection$WrappedInputStream


    res.setSampleLabel(urlStr);
    res.sampleStart(); // Count the retries as well in the time

        try
        {
            HttpConnection connection = setupConnection(url, method, res);
             
            if (method.equals(POST))
            {
                sendPostData(httpMethod);
            }
View Full Code Here


        }
       
        Iterator connectionIter = connectionToAdded.keySet().iterator();
       
        while (connectionIter.hasNext()) {
            HttpConnection conn = (HttpConnection) connectionIter.next();
            Long connectionTime = (Long) connectionToAdded.get(conn);
            if (connectionTime.longValue() <= idleTimeout) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Closing connection, connection time: "  + connectionTime);
                }
                connectionIter.remove();
                conn.close();
            }
        }
    }
View Full Code Here

  }

  public XScriptObject invoke()
    throws ProcessingException
  {
    HttpConnection conn = null;

    try {
      if (action == null || action.equals(""))
        action = "\"\"";

      String host = url.getHost();
      int port = url.getPort();

      if (System.getProperty("http.proxyHost") != null) {
        String proxyHost = System.getProperty("http.proxyHost");
        int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
        conn = new HttpConnection(proxyHost, proxyPort, host, port);
      }
      else {
        conn = new HttpConnection(host, port);
      }

      PostMethod method = new PostMethod(url.getFile()) {
          protected String generateRequestBody(HashMap params)
          {
            try {
              StringBuffer bodyBuffer
                = new StringBuffer(super.generateRequestBody(params));

              // Write the SOAP request
              InputSource saxInputStream = xscriptObject.getInputSource();
              InputStream is = saxInputStream.getByteStream();
              InputStreamReader isr = new InputStreamReader(is);

              char[] buffer = new char[1024];
              int len;
              while ((len = isr.read(buffer)) > 0)
                bodyBuffer.append(buffer, 0, len);
              isr.close();
              is.close();
              return bodyBuffer.toString();
            }
            catch (Exception ex) {
              return null;
            }
          }
        };

        method.setRequestHeader(
                new Header("Content-type", "text/xml; charset=\"utf-8\""));
        method.setRequestHeader(new Header("SOAPAction", action));
        method.setUseDisk(false);

        method.execute(new HttpState(), conn);

        String ret = method.getResponseBodyAsString();
        int startOfXML = ret.indexOf("<?xml");
        if(startOfXML == -1) { // No xml?!
            throw new ProcessingException("Invalid response - no xml");
        }

        return new XScriptObjectInlineXML(
            xscriptManager,
            ret.substring(startOfXML));
    }
    catch (Exception ex) {
      throw new ProcessingException("Error invoking remote service: " + ex,
                                    ex);
    }
    finally {
      try {
        if (conn != null)
          conn.close();
      }
      catch (Exception ex) {
      }
    }
  }
View Full Code Here

        }
       
        Iterator connectionIter = connectionToAdded.keySet().iterator();
       
        while (connectionIter.hasNext()) {
            HttpConnection conn = (HttpConnection) connectionIter.next();
            Long connectionTime = (Long) connectionToAdded.get(conn);
            if (connectionTime.longValue() <= idleTimeout) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Closing connection, connection time: "  + connectionTime);
                }
                connectionIter.remove();
                conn.close();
            }
        }
    }
View Full Code Here

        this.xscriptObject = xscriptObject;
    }

    public XScriptObject invoke() throws ProcessingException
    {
        HttpConnection conn = null;

        try {
            if (this.action == null || this.action.length() == 0) {
                this.action = "\"\"";
            }

            String host = this.url.getHost();
            int port = this.url.getPort();
            Protocol protocol = Protocol.getProtocol(this.url.getProtocol());

            if (System.getProperty("http.proxyHost") != null) {
                String proxyHost = System.getProperty("http.proxyHost");
                int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
                conn = new HttpConnection(proxyHost, proxyPort, host, null, port, protocol);
            } else {
                conn = new HttpConnection(host, port, protocol);
            }

            PostMethod method = new PostMethod(this.url.getFile());
            String request;

            try {
                // Write the SOAP request body
                if (this.xscriptObject instanceof XScriptObjectInlineXML) {
                    // Skip overhead
                    request = ((XScriptObjectInlineXML)this.xscriptObject).getContent();
                } else {
                    StringBuffer bodyBuffer = new StringBuffer();
                    InputSource saxSource = this.xscriptObject.getInputSource();

                    Reader r = null;
                    // Byte stream or character stream?
                    if (saxSource.getByteStream() != null) {
                        r = new InputStreamReader(saxSource.getByteStream());
                    } else {
                        r = saxSource.getCharacterStream();
                    }

                    try {
                        char[] buffer = new char[1024];
                        int len;
                        while ((len = r.read(buffer)) > 0) {
                            bodyBuffer.append(buffer, 0, len);
                        }
                    } finally {
                        if (r != null) {
                            r.close();
                        }
                    }

                    request = bodyBuffer.toString();
                }

            } catch (Exception ex) {
                throw new ProcessingException("Error assembling request", ex);
            }

            method.setRequestHeader(
                    new Header("Content-type", "text/xml; charset=\"utf-8\""));
            method.setRequestHeader(new Header("SOAPAction", this.action));
            method.setRequestBody(request);

            if (this.authorization != null && !this.authorization.equals("")) {
               method.setRequestHeader(
                       new Header("Authorization",
                                  "Basic " + SourceUtil.encodeBASE64(this.authorization)));
            }

            method.execute(new HttpState(), conn);

            String ret = method.getResponseBodyAsString();
            return new XScriptObjectInlineXML(this.xscriptManager, ret);
        } catch (ProcessingException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new ProcessingException("Error invoking remote service: " + ex, ex);
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception ex) {
            }
        }
    }
View Full Code Here

            StringBuffer otherHeaders = new StringBuffer();
            URL targetURL =
                    new URL(msgContext.getStrProp(MessageContext.TRANS_URL));
            String host = targetURL.getHost();
            int port = targetURL.getPort();
            HttpConnection conn = null;
            HttpState state = new HttpState();

            // create socket based on the url protocol type
            if (targetURL.getProtocol().equalsIgnoreCase("https")) {
                conn = getSecureConnection(state, host, port);
View Full Code Here

        boolean hostInNonProxyList =
                isHostInNonProxyList(host, tcp.getNonProxyHosts());

        if (tcp.getProxyHost().length() == 0 || hostInNonProxyList) {
            return new HttpConnection(host, port, true);
        } else {

            // Default proxy port is 80, even for https
            int tunnelPort = ((tcp.getProxyPort().length() != 0)
                              ? Integer.parseInt(tcp.getProxyPort())
                              : 80);

            if (tunnelPort < 0)
                tunnelPort = 80;
               
            if (tcp.getProxyUser().length() != 0) {
                Credentials proxyCred =
                        new UsernamePasswordCredentials(tcp.getProxyUser(),
                                                        tcp.getProxyPassword());

                state.setProxyCredentials(null, proxyCred);
            }

            return new HttpConnection(tcp.getProxyHost(), tunnelPort, host, port, true);
        }
    }
View Full Code Here

            port = 80;
        }
        if (tcp.getProxyHost().length() == 0 ||
            tcp.getProxyPort().length() == 0 ||
            hostInNonProxyList) {
            return new HttpConnection(host, port);
        } else {
            if (tcp.getProxyUser().length() != 0) {
                Credentials proxyCred =
                        new UsernamePasswordCredentials(tcp.getProxyUser(),
                                                        tcp.getProxyPassword());

                state.setProxyCredentials(null, proxyCred);
            }
            return new HttpConnection(tcp.getProxyHost(),
                                      new Integer(tcp.getProxyPort()).intValue(), host,
                                      port);
        }
    }
View Full Code Here

    // Javadoc inherited.
    public HttpConnection getConnection(
            HostConfiguration hostConfiguration, long l) {

        HttpConnection connection = new HttpConnection(hostConfiguration);
        connection.setHttpConnectionManager(this);
        return connection;
    }
View Full Code Here

        }

        // Get the connection from the manager, it is the responsibility
        // of the caller to release this connection by calling
        // HttpMethod#releaseConnection.
        HttpConnection connection = manager.getConnection(configuration);
        prepareConnection(connection);

        TimingOutTask task = null;
        int statusCode;
        URI uri = null;
        try {
            // Get the URI now so that it can be used to report errors if
            // necessary.
            uri = new URI(connection.getProtocol().getScheme(), null,
                    configuration.getHost(), connection.getPort(),
                    method.getPath(), method.getQueryString(), null);

            if (roundTripTimeout != Period.INDEFINITELY) {
                task = createTimingOutTask(connection);
                TIMER.schedule(new RunnableTimerTask(task),
                        roundTripTimeout.inMillis());
            }


            // Normally HttpClient takes care or opening collection
            // but since we use our own HttpClient we need to do
            // it manually
            if (!connection.isOpen()) {
                connection.open();
            }
            statusCode = method.execute(httpState, connection);
           
        } catch (Exception e) {
            if (task != null && task.timedOut()) {
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpConnection$WrappedInputStream

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.