Package org.apache.commons.httpclient

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


        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


        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

    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, port, protocol);
    if (httpConn != null && hc.hostEquals(httpConn)) {
      // Same details, no need to reset
    } else {
      httpConn = new HttpConnection(hc);
      // TODO check these
      httpConn.setProxyHost(System.getProperty("http.proxyHost"));
      httpConn.setProxyPort(Integer.parseInt(System.getProperty("http.proxyPort", "80")));
    }
View Full Code Here

    }
    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

        {
          //Same details, no need to reset
        }
        else
        {
          httpConn = new HttpConnection(hc);
          //TODO check these
            httpConn.setProxyHost(System.getProperty("http.proxyHost"));
            httpConn.setProxyPort( Integer.parseInt(System.getProperty("http.proxyPort","80")));
        }
View Full Code Here

    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

            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

        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(null, "no-xml-content", "no-xml-content", new AttributesImpl());
                this.contentHandler.endElement(null, "no-xml-content", "no-xml-content");
                this.contentHandler.endDocument();
            }
           
            // again, no keepalive here.
            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

        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$WrappedOutputStream

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.