List of usage examples for org.apache.commons.httpclient.params HttpConnectionParams HttpConnectionParams
HttpConnectionParams
From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java
@Test(expected = java.io.IOException.class) public void shouldFailCreatingSocketForUnknownHost() throws Exception { // Given// www . j ava 2s .co m String unknownHost = "localhorst"; InetAddress localAddress = InetAddress.getLoopbackAddress(); int localPort = 28080; HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(60000); // When socketFactory.createSocket(unknownHost, 18080, localAddress, localPort, params); // Then = IOException }
From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java
@Test public void shouldCreateSocketWithGivenLocalAddressAndPort() throws Exception { // Given/*w w w . ja va2s.co m*/ InetAddress localAddress = InetAddress.getLoopbackAddress(); int localPort = 28080; // When Socket sslSocket = socketFactory.createSocket("localhost", 18080, localAddress, localPort, new HttpConnectionParams()); // Then assertThat(sslSocket.getLocalAddress(), is(equalTo(localAddress))); assertThat(sslSocket.getLocalPort(), is(equalTo(localPort))); }
From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java
@Test(expected = SocketTimeoutException.class) @Ignore // TODO Won't work unless we figure out a way to slow down connect process artificially public void shouldFailCreatingSocketWithInstantTimeout() throws Exception { // Given/*from w w w. j a v a 2s. c o m*/ HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(1); // When socketFactory.createSocket("localhost", 18080, InetAddress.getLoopbackAddress(), 38080, params); // Then = SocketTimeoutException }
From source file:com.sittinglittleduck.DirBuster.EasySSLProtocolSocketFactoryUnitTest.java
@Test public void shouldSucceedCreatingSocketWithReasonableTimeout() throws Exception { // Given/* w ww . ja va2 s .c o m*/ HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(1000); // When Socket sslSocket = socketFactory.createSocket("localhost", 18080, InetAddress.getLoopbackAddress(), 48080, params); // Then assertThat(sslSocket, is(notNullValue())); }
From source file:domderrien.wrapper.UrlFetch.UrlFetchHttpConnection.java
@Override public HttpConnectionParams getParams() { return new HttpConnectionParams(); }
From source file:de.ingrid.mdek.quartz.jobs.URLValidatorJob.java
@Override protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS); JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap(); Map<String, URLState> urlMap = (Map<String, URLState>) mergedJobDataMap.get(URL_MAP); List<URLValidator> validatorTasks = new ArrayList<URLValidator>(urlMap.size()); Map<String, URLState> capabilitiesMap = (Map<String, URLState>) mergedJobDataMap.get(CAP_URL_MAP); List<CapabilitiesValidator> capabilitiesValidatorTasks = new ArrayList<CapabilitiesValidator>( capabilitiesMap.size());/*from w w w. jav a 2 s . co m*/ HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setConnectionManagerTimeout(0); httpClientParams.setSoTimeout(SOCKET_TIMEOUT); HttpConnectionParams httpParams = new HttpConnectionParams(); httpParams.setConnectionTimeout(CONNECTION_TIMEOUT); httpClientParams.setDefaults(httpParams); HttpClient httpClient = new HttpClient(httpClientParams, new MultiThreadedHttpConnectionManager()); if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyPort") != null) { httpClient.getHostConfiguration().setProxy(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort"))); } for (URLState urlState : urlMap.values()) { validatorTasks.add(new URLValidator(httpClient, urlState)); } for (URLState urlState : capabilitiesMap.values()) { capabilitiesValidatorTasks.add(new CapabilitiesValidator(httpClient, urlState)); } log.debug("Starting url validation..."); long startTime = System.currentTimeMillis(); List<Future<URLState>> resultFutureList = new ArrayList<Future<URLState>>(); for (URLValidator validator : validatorTasks) { resultFutureList.add(executorService.submit(validator)); } for (CapabilitiesValidator validator : capabilitiesValidatorTasks) { resultFutureList.add(executorService.submit(validator)); } for (Future<URLState> future : resultFutureList) { try { if (!cancelJob) { future.get(); } else { log.debug("forcing shutdown of executor service..."); executorService.shutdownNow(); break; } } catch (Exception ex) { log.debug("Exception while fetching result from future.", ex); } } long endTime = System.currentTimeMillis(); log.debug("URL Validation took " + (endTime - startTime) + " ms."); executorService.shutdown(); // Only store if job was not cancelled if (!cancelJob) { Map<String, List<URLObjectReference>> map = new HashMap<String, List<URLObjectReference>>(); map.put(MdekKeys.URL_RESULT, (List<URLObjectReference>) mergedJobDataMap.get(URL_OBJECT_REFERENCES)); map.put(MdekKeys.CAP_RESULT, (List<URLObjectReference>) mergedJobDataMap.get(CAPABILITIES_REFERENCES)); jobExecutionContext.setResult(map); } }
From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java
/** * Creates Http connection.//from w w w. ja va 2 s . c om * * @param serviceLogoutInfo * @param endpoint * @return * @throws URIException * @throws GeneralSecurityException * @throws IOException */ private HttpConnection createHttpConnection(LogoutInformation serviceLogoutInfo, Endpoint endpoint) throws URIException, GeneralSecurityException, IOException { HttpClientBuilder httpClientBuilder = new HttpClientBuilder(); httpClientBuilder.setContentCharSet("UTF-8"); SecureProtocolSocketFactory sf = new EasySSLProtocolSocketFactory(); httpClientBuilder.setHttpsProtocolSocketFactory(sf); //build http connection HttpClient httpClient = httpClientBuilder.buildClient(); HostConfiguration hostConfig = new HostConfiguration(); URI location = new URI(endpoint.getLocation()); hostConfig.setHost(location); LogoutRequestConfiguration config = (LogoutRequestConfiguration) getProfileConfiguration( serviceLogoutInfo.getEntityID(), getProfileId()); if (log.isDebugEnabled()) { log.debug("Creating new HTTP connection with the following timeouts:"); log.debug("Maximum waiting time for the connection pool is {}", config.getBackChannelConnectionPoolTimeout()); log.debug("Timeout for connection establishment is {}", config.getBackChannelConnectionTimeout()); log.debug("Timeout for soap response is {}", config.getBackChannelResponseTimeout()); } HttpConnection httpConn = null; try { httpConn = httpClient.getHttpConnectionManager().getConnectionWithTimeout(hostConfig, config.getBackChannelConnectionPoolTimeout()); } catch (ConnectionPoolTimeoutException e) { return null; } HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(config.getBackChannelConnectionTimeout()); params.setSoTimeout(config.getBackChannelResponseTimeout()); httpConn.setParams(params); return httpConn; }
From source file:opendap.dap.http.EasySSLProtocolSocketFactory.java
/** * @see SecureProtocolSocketFactory#createSocket(java.lang.String, int, java.net.InetAddress, int) *//*from w w w . ja v a 2s . c o m*/ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { return createSocket(host, port, clientHost, clientPort, new HttpConnectionParams()); }
From source file:org.eclipse.mylyn.commons.tests.net.SslProtocolSocketFactoryTest.java
public void testTrustAllSslProtocolSocketFactory() throws Exception { SecureProtocolSocketFactory factory = new PollingSslProtocolSocketFactory(); Socket s;//from ww w . jav a 2 s . c o m s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort()); assertNotNull(s); assertTrue(s.isConnected()); s.close(); InetAddress anyHost = new Socket().getLocalAddress(); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0); assertNotNull(s); assertTrue(s.isConnected()); s.close(); HttpConnectionParams params = new HttpConnectionParams(); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0, params); assertNotNull(s); assertTrue(s.isConnected()); s.close(); params.setConnectionTimeout(1000); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0, params); assertNotNull(s); assertTrue(s.isConnected()); s.close(); }
From source file:org.openo.nfvo.vnfmadapter.service.csm.connect.SslAnonymousSocketTest.java
@Test(expected = Exception.class) public void createSocketTestException2() throws IOException, ConnectTimeoutException { String host = "localhost"; int port = 29912; InetAddress localAddress = null; int localPort = 4859; HttpConnectionParams params = new HttpConnectionParams(); SslAnonymousSocket sslsocket = new SslAnonymousSocket(); Socket socket = sslsocket.createSocket(host, port, localAddress, localPort, params); }