List of usage examples for org.apache.commons.httpclient HttpConnection isOpen
boolean isOpen
To view the source code for org.apache.commons.httpclient HttpConnection isOpen.
Click Source Link
From source file:com.carrotsearch.util.httpclient.SingleHttpConnectionManager.java
/** */ @Override/* w w w . j a v a 2 s. c o m*/ public void releaseConnection(HttpConnection conn) { // copied from superclass because it wasn't made available to subclasses final InputStream lastResponse = conn.getLastResponseInputStream(); if (lastResponse != null) { conn.setLastResponseInputStream(null); try { lastResponse.close(); } catch (final IOException ioe) { // ignore. } } if (conn.isOpen()) { conn.close(); } }
From source file:com.cyberway.issue.httpclient.ThreadLocalHttpConnectionManager.java
/** * @see HttpConnectionManager#getConnectionWithTimeout(HostConfiguration, long) * //w w w .j a va2s.c o m * @since 3.0 */ public HttpConnection getConnectionWithTimeout(final HostConfiguration hostConfiguration, final long timeout) { final ConnectionInfo ci = getConnectionInfo(); HttpConnection httpConnection = ci.conn; // make sure the host and proxy are correct for this connection // close it and set the values if they are not if (httpConnection == null || !finishLastResponse(httpConnection) || !hostConfiguration.hostEquals(httpConnection) || !hostConfiguration.proxyEquals(httpConnection)) { if (httpConnection != null && httpConnection.isOpen()) { closer.closeConnection(httpConnection); } httpConnection = new HttpConnection(hostConfiguration); httpConnection.setHttpConnectionManager(this); httpConnection.getParams().setDefaults(this.params); ci.conn = httpConnection; httpConnection.setHost(hostConfiguration.getHost()); httpConnection.setPort(hostConfiguration.getPort()); httpConnection.setProtocol(hostConfiguration.getProtocol()); httpConnection.setLocalAddress(hostConfiguration.getLocalAddress()); httpConnection.setProxyHost(hostConfiguration.getProxyHost()); httpConnection.setProxyPort(hostConfiguration.getProxyPort()); } // remove the connection from the timeout handler ci.idleStartTime = Long.MAX_VALUE; return httpConnection; }
From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java
/** * Issues back channel logout request to session participant. * * @param sloContext/*w w w. ja va 2s.co m*/ * @param serviceLogoutInfo * @throws ProfileException */ private void initiateBackChannelLogout(SingleLogoutContext sloContext, LogoutInformation serviceLogoutInfo) throws ProfileException { if (!serviceLogoutInfo.isLoggedIn()) { log.info("Logout status for entity is '{}', not attempting logout", serviceLogoutInfo.getLogoutStatus().toString()); return; } String spEntityID = serviceLogoutInfo.getEntityID(); Endpoint endpoint = getEndpointForBinding(spEntityID, SAMLConstants.SAML2_SOAP11_BINDING_URI); if (endpoint == null) { log.info("No SAML2 LogoutRequest SOAP endpoint found for entity '{}'", spEntityID); serviceLogoutInfo.setLogoutUnsupported(); return; } serviceLogoutInfo.setLogoutAttempted(); LogoutRequestContext requestCtx = createLogoutRequestContext(sloContext, serviceLogoutInfo, endpoint); if (requestCtx == null) { log.info("Cannot create LogoutRequest Context for entity '{}'", spEntityID); serviceLogoutInfo.setLogoutFailed(); return; } HttpConnection httpConn = null; try { //prepare http message exchange for soap log.debug("Preparing HTTP transport for SOAP request"); httpConn = createHttpConnection(serviceLogoutInfo, endpoint); if (httpConn == null) { log.warn("Unable to acquire usable http connection from the pool"); serviceLogoutInfo.setLogoutFailed(); return; } log.debug("Opening HTTP connection to '{}'", endpoint.getLocation()); httpConn.open(); if (!httpConn.isOpen()) { log.warn("HTTP connection could not be opened"); serviceLogoutInfo.setLogoutFailed(); return; } log.debug("Preparing transports and encoders/decoders"); prepareSOAPTransport(requestCtx, httpConn, endpoint); SAMLMessageEncoder encoder = new HTTPSOAP11Encoder(); SAMLMessageDecoder decoder = new HTTPSOAP11Decoder(getParserPool()); //encode and sign saml request encoder.encode(requestCtx); //TODO: audit log is still missing log.info("Issuing back-channel logout request to SP '{}'", spEntityID); //execute SOAP/HTTP call log.debug("Executing HTTP POST"); if (!requestCtx.execute(httpConn)) { log.warn("Logout execution failed on SP '{}', HTTP status is '{}'", spEntityID, requestCtx.getHttpStatus()); serviceLogoutInfo.setLogoutFailed(); return; } //decode saml response decoder.decode(requestCtx); LogoutResponse spResponse = requestCtx.getInboundSAMLMessage(); StatusCode statusCode = spResponse.getStatus().getStatusCode(); if (statusCode.getValue().equals(StatusCode.SUCCESS_URI)) { log.info("Logout was successful on SP '{}'.", spEntityID); serviceLogoutInfo.setLogoutSucceeded(); } else { log.warn("Logout failed on SP '{}', logout status code is '{}'.", spEntityID, statusCode.getValue()); StatusCode secondaryCode = statusCode.getStatusCode(); if (secondaryCode != null) { log.warn("Additional status code: '{}'", secondaryCode.getValue()); } serviceLogoutInfo.setLogoutFailed(); } } catch (SocketTimeoutException e) { //socket connect or read timeout log.info("Socket timeout while sending SOAP request to SP '{}'", serviceLogoutInfo.getEntityID()); serviceLogoutInfo.setLogoutFailed(); } catch (IOException e) { //other networking error log.info("IOException caught while sending SOAP request", e); serviceLogoutInfo.setLogoutFailed(); } catch (Throwable t) { //unexpected log.error("Unexpected exception caught while sending SAML Logout request", t); serviceLogoutInfo.setLogoutFailed(); } finally { // requestCtx.releaseConnection(); if (httpConn != null && httpConn.isOpen()) { log.debug("Closing HTTP connection"); try { httpConn.close(); } catch (Throwable t) { log.warn("Caught exception while closing HTTP Connection", t); } } } }
From source file:org.globus.axis.transport.commons.CommonsHttpConnectionManager.java
public void releaseConnection(HttpConnection conn) { // we only maintain list of opened connections // so ignore the connections that are closed if (conn.isOpen()) { ExtendedHttpConnection extendedHostConfiguration = (ExtendedHttpConnection) conn; HostConfiguration hostConfiguration = extendedHostConfiguration.getHostConfiguration(); ConnectionPool pool = getConnectionPool(hostConfiguration); if (pool != null) { pool.releaseConnection(conn); }// w w w . j a v a2 s . c o m } else { if (logger.isDebugEnabled()) { logger.debug("not releasing closed connection: " + conn); } } }
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testConnectionReuseWithoutParams() throws Exception { CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null); HostConfiguration h1 = new HostConfiguration(); h1.setHost(address, server1.getLocalPort()); HttpConnection c1 = manager.getConnection(h1); // new connection assertTrue(!c1.isOpen()); c1.open();/* ww w .ja va2s .c o m*/ c1.releaseConnection(); HostConfiguration h2 = new HostConfiguration(); h2.setHost(address, server1.getLocalPort()); HttpConnection c2 = manager.getConnection(h2); // connection should have been released // so c2 is c1 assertTrue(h2.equals(h1)); assertTrue(c2 == c1); assertTrue(c2.isOpen()); HttpConnection c3 = manager.getConnection(h2); // connection c2 was not released so new connection // c2 != c3 assertTrue(!c3.isOpen()); assertTrue(c3 != c2); assertTrue(c3 != c1); c2.releaseConnection(); c3.releaseConnection(); Server server2 = new Server(); // it's a new port HostConfiguration h4 = new HostConfiguration(); h4.setHost(address, server2.getLocalPort()); HttpConnection c4 = manager.getConnection(h4); assertTrue(!c4.isOpen()); assertTrue(c4 != c1); assertTrue(c4 != c2); assertTrue(c4 != c3); server2.close(); }
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testConnectionReuseWithParams() throws Exception { CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(PARAMS); HostConfiguration h1 = new HostConfiguration(); h1.setHost(address, server1.getLocalPort()); h1.getParams().setParameter("A", "foo"); h1.getParams().setParameter("B", "bar"); h1.getParams().setParameter("C", "fff"); HttpConnection c1 = manager.getConnection(h1); assertTrue(!c1.isOpen()); c1.open();//from w w w . j a va 2s . c o m c1.releaseConnection(); HostConfiguration h2 = new HostConfiguration(); h2.setHost(address, server1.getLocalPort()); h2.getParams().setParameter("A", "foo"); h2.getParams().setParameter("B", "bar"); // still should be reused since C is not checked param h2.getParams().setParameter("C", "ggg"); HttpConnection c2 = manager.getConnection(h2); // connection should have been released // so c2 is c1 assertTrue(h2.equals(h1)); assertTrue(c2.isOpen()); assertTrue(c2 == c1); HttpConnection c3 = manager.getConnection(h2); // new connection becuase it wasn't released assertTrue(c3 != c1); assertTrue(c3 != c2); assertTrue(!c3.isOpen()); c2.releaseConnection(); c3.releaseConnection(); // this one does not have params HostConfiguration h4 = new HostConfiguration(); h4.setHost(address, server1.getLocalPort()); HttpConnection c4 = manager.getConnection(h4); // new connection assertTrue(c4 != c1); assertTrue(c4 != c2); assertTrue(c4 != c3); assertTrue(!c4.isOpen()); c4.open(); c4.releaseConnection(); // this one only has B parameter HostConfiguration h5 = new HostConfiguration(); h5.setHost(address, server1.getLocalPort()); h5.getParams().setParameter("B", "bar"); HttpConnection c5 = manager.getConnection(h5); // also a new connection assertTrue(c5 != c1); assertTrue(c5 != c2); assertTrue(c5 != c3); assertTrue(c5 != c4); assertTrue(!c5.isOpen()); c5.open(); c5.releaseConnection(); // this one only has different B parameter HostConfiguration h6 = new HostConfiguration(); h6.setHost(address, server1.getLocalPort()); h6.getParams().setParameter("A", "fooo"); h6.getParams().setParameter("B", "bar"); HttpConnection c6 = manager.getConnection(h6); assertTrue(c6 != c1); assertTrue(c6 != c2); assertTrue(c6 != c3); assertTrue(c6 != c4); assertTrue(c6 != c5); assertTrue(!c6.isOpen()); c6.open(); c6.releaseConnection(); }
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testIdleConnectionSweeper() throws Exception { CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null); manager.setConnectionIdleTime(1000 * 2); HostConfiguration h1 = new HostConfiguration(); h1.setHost(address, server1.getLocalPort()); HttpConnection c1 = manager.getConnection(h1); // new connection assertTrue(!c1.isOpen()); c1.open();/* w ww . java 2s.com*/ Thread.sleep(1000); c1.releaseConnection(); assertTrue(c1 == manager.getConnection(h1)); assertTrue(c1.isOpen()); c1.releaseConnection(); Thread.sleep(1000 * 4); HttpConnection c2 = manager.getConnection(h1); assertTrue(c1 != c2); }
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testMultipleConnectionRelease() throws Exception { CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null); HostConfiguration h1 = new HostConfiguration(); h1.setHost(address, server1.getLocalPort()); HttpConnection c1 = manager.getConnection(h1); assertTrue(!c1.isOpen()); c1.open();/* w w w . j a v a 2 s. co m*/ c1.releaseConnection(); c1.releaseConnection(); HttpConnection c2 = manager.getConnection(h1); assertTrue(c1 == c2); HttpConnection c3 = manager.getConnection(h1); assertTrue(c3 != c2); }