Package org.apache.commons.httpclient

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


        PropFindMethod propfindMethod = new PropFindMethod(url, 0);
        propfindMethod.setDepth(1);
        propfindMethod.setDoAuthentication(true);
        HttpState httpState = new HttpState();
        httpState.setCredentials(null, host, credentials);
        int state = propfindMethod.execute(httpState, new HttpConnection(host, port, protocol));
        if ( state != HttpStatus.SC_MULTI_STATUS ) {
            throw new IOException("Received status code "+state+" when doing PROPFIND on URI="+url);
        }
        List children = new ArrayList();
        for ( Enumeration propertyEnumeration = propfindMethod.getAllResponseURLs(); propertyEnumeration.hasMoreElements(); ) {
View Full Code Here


        String url = domain+"/";
        SearchMethod searchMethod = new SearchMethod(url, query);
        searchMethod.setDoAuthentication(true);
        HttpState httpState = new HttpState();
        httpState.setCredentials(null, host, credentials);
        int state = searchMethod.execute(httpState, new HttpConnection(host, port, protocol));
        if ( state != HttpStatus.SC_MULTI_STATUS ) {
            throw new IOException("Received status code "+state+" when doing SEARCH with query="+query);
        }
        List values = new ArrayList();
        for ( Enumeration e = searchMethod.getAllResponseURLs(); e.hasMoreElements(); ) {
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

        }
       
        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);
        return new XScriptObjectInlineXML(xscriptManager,
                                          method.getResponseBodyAsString());
    }
    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

            client.endSession();
        }
       
*/       
        
        HttpConnection connection = getConnection();
        if ( connection == null ) {
            throw new JellyException(
                "No HTTP connection available. "
                + "This tag should have a 'uri' attribute or be nested inside "
                + "a <http:connection> tag"
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 (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());
            String request;

            try {
                // Write the SOAP request body
                if (xscriptObject instanceof XScriptObjectInlineXML) {
                    // Skip overhead
                    request = ((XScriptObjectInlineXML) xscriptObject).getContent();
                } else {
                    StringBuffer bodyBuffer = new StringBuffer();
                    InputSource saxSource = 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", action));
            method.setRequestBody(request);

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

            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

        get.setDoAuthentication(true);

        try
        {
            scheme = HttpAuthenticator.selectAuthScheme(headers);
            HttpConnection conn = client.getHttpConnectionManager().getConnection(get.getHostConfiguration());
            boolean authenticated = HttpAuthenticator.authenticate(scheme, get, conn, client.getState());
            if (!authenticated)
            {
                throw new Exception("Failed to create authentication headers to HTTP Connection");
            }
View Full Code Here

        get.setDoAuthentication(true);

        try
        {
            scheme = HttpAuthenticator.selectAuthScheme(headers);
            HttpConnection conn = client.getHttpConnectionManager().getConnection(get.getHostConfiguration());
            boolean authenticated = HttpAuthenticator.authenticate(scheme, get, conn, client.getState());
            if (!authenticated)
            {
                throw new Exception("Failed to create authentication headers to HTTP Connection");
            }
View Full Code Here

TOP

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

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.