Package org.apache.commons.httpclient

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


        throws IOException, SAXException, ProcessingException {
            RequestForwardingHttpMethod method =
                new RequestForwardingHttpMethod(request, destination);
            
            // Build the forwarded connection   
            HttpConnection conn = new HttpConnection(destination.getHost(), destination.getPort());           
            HttpState state = new HttpState();
            state.setCredentials(null, destination.getHost(),
                new UsernamePasswordCredentials(destination.getUser(), destination.getPassword()));
            method.setPath(path);
           
            // Execute the method
            method.execute(state, conn);
           
            // Send the output to the client: set the status code...
            response.setStatus(method.getStatusCode());
 
            // ... retrieve the headers from the origin server and pass them on
            Header[] methodHeaders = method.getResponseHeaders();
            for (int i = 0; i < methodHeaders.length; i++) {
                // there is more than one DAV header
                if (methodHeaders[i].getName().equals("DAV")) {
                    response.addHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
                } else if (methodHeaders[i].getName().equals("Content-Length")) {
                    // drop the original Content-Length header. Don't ask me why but there
                    // it's always one byte off
                } else {
                    response.setHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
                }   
            }
           
            // no HTTP keepalives here...
            response.setHeader("Connection", "close");

            // Parse the XML, if any
            if (method.getResponseHeader("Content-Type").getValue().startsWith("text/xml")) {     
                InputStream stream = method.getResponseBodyAsStream();             
                parser.parse(new InputSource(stream), this.contentHandler, this.lexicalHandler);
            } else {
                // Just send a dummy XML
                this.contentHandler.startDocument();
                this.contentHandler.startElement("", "no-xml-content", "no-xml-content", new AttributesImpl());
                this.contentHandler.endElement("", "no-xml-content", "no-xml-content");
                this.contentHandler.endDocument();
            }
           
            // again, no keepalive here.
            conn.close();
  
    }
View Full Code Here


            HttpURL url = new HttpURL(this.targetUrl);
            HttpState state = new HttpState();
            state.setCredentials(null, new UsernamePasswordCredentials(
                    url.getUser(),
                    url.getPassword()));                      
            HttpConnection conn = new HttpConnection(url.getHost(), url.getPort());
            WebdavResource resource = new WebdavResource(new HttpURL(this.targetUrl));
            if(!resource.exists()) {
                throw new SAXException("The WebDAV resource don't exist");
            }
            optionsMethod.execute(state, conn);
View Full Code Here

            this.generateDebugOutput();
            return;
        }

        /* Call up the remote HTTP server */
        HttpConnection connection = new HttpConnection(this.method.getHostConfiguration());
        HttpState state = new HttpState();
        this.method.setFollowRedirects(true);
        int status = this.method.execute(state, connection);
        if (status == 404) {
            throw new ResourceNotFoundException("Unable to access \"" + this.method.getURI()
                    + "\" (HTTP 404 Error)");
        } else if ((status < 200) || (status > 299)) {
            throw new IOException("Unable to access HTTP resource at \""
                    + this.method.getURI().toString() + "\" (status=" + status + ")");
        }
        InputStream response = this.method.getResponseBodyAsStream();

        /* Let's try to set up our InputSource from the response output stream and to parse it */
        SAXParser parser = null;
        try {
            InputSource inputSource = new InputSource(response);
            parser = (SAXParser) this.manager.lookup(SAXParser.ROLE);
            parser.parse(inputSource, super.xmlConsumer);
        } catch (ServiceException ex) {
            throw new ProcessingException("Unable to get parser", ex);
        } finally {
            this.manager.release(parser);
            this.method.releaseConnection();
            connection.close();
        }
    }
View Full Code Here

        Reference ref = ( Reference )referenceIter.next();
        ConnectionSource source = ( ConnectionSource )REFERENCE_TO_CONNECTION_SOURCE.get( ref );
        if( source.connectionPool == connectionPool )
        {
          referenceIter.remove();
          HttpConnection connection = ( HttpConnection )ref.get();
          if( connection != null )
          {
            connectionsToClose.add( connection );
          }
        }
      }
    }

    // close and release the connections outside of the synchronized block to
    // avoid holding the lock for too long
    for( Iterator i = connectionsToClose.iterator(); i.hasNext(); )
    {
      HttpConnection connection = ( HttpConnection )i.next();
      connection.close();
      // remove the reference to the connection manager. this ensures
      // that the we don't accidentally end up here again
      connection.setHttpConnectionManager( null );
      connection.releaseConnection();
    }
  }
View Full Code Here

    if( LOG.isDebugEnabled() )
    {
      LOG.debug( "HttpConnectionManager.getConnection:  config = " + hostConfiguration + ", timeout = " + timeout );
    }

    final HttpConnection conn = doGetConnection( hostConfiguration, timeout );
    conn.getParams().setParameter( SoapUIHostConfiguration.SOAPUI_SSL_CONFIG,
        hostConfiguration.getParams().getParameter( SoapUIHostConfiguration.SOAPUI_SSL_CONFIG ) );

    // wrap the connection in an adapter so we can ensure it is used
    // only once
    return new HttpConnectionAdapter( conn );
View Full Code Here

  private HttpConnection doGetConnection( HostConfiguration hostConfiguration, long timeout )
      throws ConnectionPoolTimeoutException
  {

    HttpConnection connection = null;

    int maxHostConnections = this.params.getMaxConnectionsPerHost( hostConfiguration );
    int maxTotalConnections = this.params.getMaxTotalConnections();

    synchronized( connectionPool )
View Full Code Here

    {
      // close all free connections
      Iterator<?> iter = freeConnections.iterator();
      while( iter.hasNext() )
      {
        HttpConnection conn = ( HttpConnection )iter.next();
        iter.remove();
        conn.close();
      }

      // close all connections that have been checked out
      shutdownCheckedOutConnections( this );
View Full Code Here

      Iterator iter = freeConnections.iterator();

      while( iter.hasNext() )
      {
        HttpConnection conn = ( HttpConnection )iter.next();
        if( !conn.isOpen() )
        {
          iter.remove();
          deleteConnection( conn );
        }
      }
View Full Code Here

     * Close and delete an old, unused connection to make room for a new one.
     */
    public synchronized void deleteLeastUsedConnection()
    {

      HttpConnection connection = ( HttpConnection )freeConnections.removeFirst();

      if( connection != null )
      {
        deleteConnection( connection );
      }
View Full Code Here

    public void releaseConnection()
    {
      if( !isLocked() && hasConnection() )
      {
        HttpConnection wrappedConnection = this.wrappedConnection;
        this.wrappedConnection = null;
        wrappedConnection.releaseConnection();
      }
      else
      {
        // do nothing
      }
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.