Examples of HttpConnection


Examples of org.apache.commons.httpclient.HttpConnection

        }
       
        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

Examples of org.apache.commons.httpclient.HttpConnection

        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

Examples of org.apache.commons.httpclient.HttpConnection

            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

Examples of org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection

        synchronized(bound) {
            if (!httpServer.started) {
                bound.wait(5000);
            }
        }
        HttpConnection connection = HttpConnectionManager.getDefault().getConnection(new URI("http://127.0.0.1:" + httpServer.port()), 1000);
        HttpConnectionManager.getDefault().returnConnectionToPool(connection);
        assertEquals(initialFreeConnections + 1, HttpConnectionManager.getDefault().numFreeConnections());
        HttpURLConnection c = (HttpURLConnection)
            new URL("http://127.0.0.1:" + httpServer.port()).openConnection();
        c.setDoOutput(true);
View Full Code Here

Examples of org.apache.harmony.rmi.transport.proxy.HttpConnection

            }
        }
        Socket s = ep.createSocket();

        if (s instanceof HttpOutboundSocket) {
            conn = new HttpConnection(s, ep);
        } else {
            conn = new TcpConnection(s, ep);
        }

        synchronized (connsTable) {
View Full Code Here

Examples of org.apache.http.HttpConnection

        // based on testChunkedContent which is known to return true
        // the difference is in the mock connection passed here
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);

        HttpConnection mockonn = new MockConnection(false, false);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, mockonn);
        assertFalse("closed connection should not be kept alive",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

Examples of org.apache.http.HttpConnection

        // based on testChunkedContent which is known to return true
        // the difference is in the mock connection passed here
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);

        HttpConnection mockonn = new MockConnection(true, true);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, mockonn);
        assertTrue("stale connection should not be detected",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here

Examples of org.apache.http.HttpConnection

        }
        if (!request.containsHeader(HTTP.TARGET_HOST)) {
            HttpHost targethost = (HttpHost) context
                .getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (targethost == null) {
                HttpConnection conn = (HttpConnection) context
                    .getAttribute(ExecutionContext.HTTP_CONNECTION);
                if (conn instanceof HttpInetConnection) {
                    // Populate the context with a default HTTP host based on the
                    // inet address of the target host
                    InetAddress address = ((HttpInetConnection) conn).getRemoteAddress();
View Full Code Here

Examples of org.apache.http.HttpConnection

        if (context == null) {
            throw new IllegalArgumentException
                ("HTTP context may not be null.");
        }
       
        HttpConnection conn = (HttpConnection)
            context.getAttribute(ExecutionContext.HTTP_CONNECTION);

        if (conn != null && !conn.isOpen())
            return false;
        // do NOT check for stale connection, that is an expensive operation

        // Check for a self-terminating entity. If the end of the entity will
        // be indicated by closing the connection, there is no keep-alive.
View Full Code Here

Examples of org.apache.http.HttpConnection

        // based on testChunkedContent which is known to return true
        // the difference is in the mock connection passed here
        HttpResponse response =
            createResponse(HttpVersion.HTTP_1_1, 200, "OK", true, -1);

        HttpConnection mockonn = new MockConnection(false, false);
        context.setAttribute(HttpExecutionContext.HTTP_CONNECTION, mockonn);
        assertFalse("closed connection should not be kept alive",
                    reuseStrategy.keepAlive(response, context));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.