List of usage examples for org.apache.commons.httpclient HostConfiguration HostConfiguration
public HostConfiguration()
From source file:edu.tsinghua.lumaqq.test.CustomHeadUploader.java
/** * //from ww w . j av a 2 s . c o m * * @param filename */ public void upload(String filename, QQUser user) { HttpClient client = new HttpClient(); HostConfiguration conf = new HostConfiguration(); conf.setHost(QQ.QQ_SERVER_UPLOAD_CUSTOM_HEAD); client.setHostConfiguration(conf); PostMethod method = new PostMethod("/cgi-bin/cface/upload"); method.addRequestHeader("Accept", "*/*"); method.addRequestHeader("Pragma", "no-cache"); StringPart uid = new StringPart("clientuin", String.valueOf(user.getQQ())); uid.setContentType(null); uid.setTransferEncoding(null); //StringPart clientkey = new StringPart("clientkey", "0D649E66B0C1DBBDB522CE9C846754EF6AFA10BBF1A48A532DF6369BBCEF6EE7"); //StringPart clientkey = new StringPart("clientkey", "3285284145CC19EC0FFB3B25E4F6817FF3818B0E72F1C4E017D9238053BA2040"); StringPart clientkey = new StringPart("clientkey", "2FEEBE858DAEDFE6352870E32E5297ABBFC8C87125F198A5232FA7ADA9EADE67"); //StringPart clientkey = new StringPart("clientkey", "8FD643A7913C785AB612F126C6CD68A253F459B90EBCFD9375053C159418AF16"); // StringPart clientkey = new StringPart("clientkey", Util.convertByteToHexStringWithoutSpace(user.getClientKey())); clientkey.setContentType(null); clientkey.setTransferEncoding(null); //StringPart sign = new StringPart("sign", "2D139466226299A73F8BCDA7EE9AB157E8D9DA0BB38B6F4942A1658A00BD4C1FEE415838810E5AEF40B90E2AA384A875"); //StringPart sign = new StringPart("sign", "50F479417088F26EFC75B9BCCF945F35346188BB9ADD3BDF82098C9881DA086E3B28D56726D6CB2331909B62459E1E62"); //StringPart sign = new StringPart("sign", "31A69198C19A7C4BFB60DCE352FE2CC92C9D27E7C7FEADE1CBAAFD988906981ECC0DD1782CBAE88A2B716F84F9E285AA"); StringPart sign = new StringPart("sign", "68FFB636DE63D164D4072D7581213C77EC7B425DDFEB155428768E1E409935AA688AC88910A74C5D2D94D5EF2A3D1764"); sign.setContentType(null); sign.setTransferEncoding(null); FilePart file; try { file = new FilePart("customfacefile", filename, new File(filename)); } catch (FileNotFoundException e) { return; } Part[] parts = new Part[] { uid, clientkey, sign, file }; MultipartRequestEntity entity = new MultipartRequestEntity(parts, method.getParams()); method.setRequestEntity(entity); try { client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { Header header = method.getResponseHeader("CFace-Msg"); System.out.println(header.getValue()); header = method.getResponseHeader("CFace-RetCode"); System.out.println(header.getValue()); } } catch (HttpException e) { return; } catch (IOException e) { return; } finally { method.releaseConnection(); } }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClientTest.java
@BeforeMethod public void setUp() throws Exception { httpClient = mock(org.apache.commons.httpclient.HttpClient.class); when(httpClient.getHostConfiguration()).thenReturn(new HostConfiguration()); }
From source file:com.datos.vfs.provider.http.HttpClientFactory.java
/** * Creates a new connection to the server. * @param builder The HttpFileSystemConfigBuilder. * @param scheme The protocol.//ww w.j a v a 2 s. c o m * @param hostname The hostname. * @param port The port number. * @param username The username. * @param password The password * @param fileSystemOptions The file system options. * @return a new HttpClient connection. * @throws FileSystemException if an error occurs. * @since 2.0 */ public static HttpClient createConnection(final HttpFileSystemConfigBuilder builder, final String scheme, final String hostname, final int port, final String username, final String password, final FileSystemOptions fileSystemOptions) throws FileSystemException { HttpClient client; try { final HttpConnectionManager mgr = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams connectionMgrParams = mgr.getParams(); client = new HttpClient(mgr); final HostConfiguration config = new HostConfiguration(); config.setHost(hostname, port, scheme); if (fileSystemOptions != null) { final String proxyHost = builder.getProxyHost(fileSystemOptions); final int proxyPort = builder.getProxyPort(fileSystemOptions); if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { config.setProxy(proxyHost, proxyPort); } final UserAuthenticator proxyAuth = builder.getProxyAuthenticator(fileSystemOptions); if (proxyAuth != null) { final UserAuthenticationData authData = UserAuthenticatorUtils.authenticate(proxyAuth, new UserAuthenticationData.Type[] { UserAuthenticationData.USERNAME, UserAuthenticationData.PASSWORD }); if (authData != null) { final UsernamePasswordCredentials proxyCreds = new UsernamePasswordCredentials( UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, null)), UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, null))); final AuthScope scope = new AuthScope(proxyHost, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, proxyCreds); } if (builder.isPreemptiveAuth(fileSystemOptions)) { final HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setAuthenticationPreemptive(true); client.setParams(httpClientParams); } } final Cookie[] cookies = builder.getCookies(fileSystemOptions); if (cookies != null) { client.getState().addCookies(cookies); } } /** * ConnectionManager set methods must be called after the host & port and proxy host & port * are set in the HostConfiguration. They are all used as part of the key when HttpConnectionManagerParams * tries to locate the host configuration. */ connectionMgrParams.setMaxConnectionsPerHost(config, builder.getMaxConnectionsPerHost(fileSystemOptions)); connectionMgrParams.setMaxTotalConnections(builder.getMaxTotalConnections(fileSystemOptions)); connectionMgrParams.setConnectionTimeout(builder.getConnectionTimeout(fileSystemOptions)); connectionMgrParams.setSoTimeout(builder.getSoTimeout(fileSystemOptions)); client.setHostConfiguration(config); if (username != null) { final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); final AuthScope scope = new AuthScope(hostname, AuthScope.ANY_PORT); client.getState().setCredentials(scope, creds); } } catch (final Exception exc) { throw new FileSystemException("vfs.provider.http/connect.error", exc, hostname); } return client; }
From source file:de.kp.ames.webdav.WebDAVClient.java
/** * Constructor// ww w. j a v a 2 s . c o m * * @param alias * @param keypass * @param uri */ public WebDAVClient(String alias, String keypass, String uri) { /* * Register request uri */ this.uri = uri; /* * Setup HttpClient */ HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(uri); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); int maxHostConnections = 200; params.setMaxConnectionsPerHost(hostConfig, maxHostConnections); connectionManager.setParams(params); client = new HttpClient(connectionManager); client.setHostConfiguration(hostConfig); Credentials creds = new UsernamePasswordCredentials(alias, keypass); client.getState().setCredentials(AuthScope.ANY, creds); }
From source file:colt.nicity.performance.agent.LatentHttpPump.java
private org.apache.commons.httpclient.HttpClient createApacheClient(String host, int port, int maxConnections, int socketTimeoutInMillis) { HttpConnectionManager connectionManager = createConnectionManager(maxConnections); org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient( connectionManager);// www. jav a2s . c o m client.getParams().setParameter(HttpMethodParams.COOKIE_POLICY, CookiePolicy.RFC_2109); client.getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); client.getParams().setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, true); client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); client.getParams().setParameter(HttpConnectionParams.SO_TIMEOUT, socketTimeoutInMillis > 0 ? socketTimeoutInMillis : 0); HostConfiguration hostConfiguration = new HostConfiguration(); configureSsl(hostConfiguration, host, port); configureProxy(hostConfiguration); client.setHostConfiguration(hostConfiguration); return client; }
From source file:edu.usc.corral.api.Client.java
public Client(String host, int port) { Protocol httpg = new Protocol("httpg", new SocketFactory(), 9443); HostConfiguration hc = new HostConfiguration(); hc.setHost(host, port, httpg);/*from w ww. j a v a 2s . c o m*/ connmgr = new SimpleHttpConnectionManager(); httpclient = new HttpClient(); httpclient.setHostConfiguration(hc); httpclient.setHttpConnectionManager(connmgr); }
From source file:com.lazerycode.ebselen.customhandlers.FileDownloader.java
/** * Mimic the WebDriver host configuration * * @param hostURL/*from w w w . j a v a 2s . co m*/ * @return */ private HostConfiguration mimicHostConfiguration(String hostURL, int hostPort) { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(hostURL, hostPort); return hostConfig; }
From source file:cn.leancloud.diamond.client.processor.ServerAddressProcessor.java
private void initHttpClient() { HostConfiguration hostConfiguration = new HostConfiguration(); SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); connectionManager.closeIdleConnections(5000L); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); connectionManager.setParams(params); configHttpClient = new HttpClient(connectionManager); configHttpClient.setHostConfiguration(hostConfiguration); }
From source file:dk.netarkivet.viewerproxy.ViewerProxyTester.java
@Before public void setUp() throws Exception { rs.setUp();/*ww w . ja va2 s. c om*/ JMSConnectionMockupMQ.useJMSConnectionMockupMQ(); ChannelsTesterHelper.resetChannels(); Settings.set(CommonSettings.REMOTE_FILE_CLASS, "dk.netarkivet.common.distribute.TestRemoteFile"); TestFileUtils.copyDirectoryNonCVS(TestInfo.ORIGINALS_DIR, TestInfo.WORKING_DIR); TestFileUtils.copyDirectoryNonCVS(TestInfo.ORIGINALS_DIR, TestInfo.ARCHIVE_DIR); Settings.set(CommonSettings.CACHE_DIR, new File(TestInfo.WORKING_DIR, "cachedir").getAbsolutePath()); // Set up an HTTP client that can send commands to our proxy; int httpPort = Integer.parseInt(Settings.get(CommonSettings.HTTP_PORT_NUMBER)); httpClient = new HttpClient(); HostConfiguration hc = new HostConfiguration(); String hostName = "localhost"; hc.setProxy(hostName, httpPort); httpClient.setHostConfiguration(hc); }
From source file:com.urswolfer.intellij.plugin.gerrit.rest.SslSupport.java
@Nullable private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host, @NotNull HttpClient client, @NotNull URI uri, @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator) throws IOException { if (!isCertificateException(e)) { throw e;//from ww w . j a v a 2 s .com } if (isTrusted(host)) { // creating a special configuration that allows connections to non-trusted HTTPS hosts // see the javadoc to EasySSLProtocolSocketFactory for details Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443); HostConfiguration hc = new HostConfiguration(); hc.setHost(host, 443, easyHttps); String relativeUri = new URI(uri.getPathQuery(), false).getURI(); // it is important to use relative URI here, otherwise our custom protocol won't work. // we have to recreate the method, because HttpMethod#setUri won't overwrite the host, // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated. HttpMethod method = methodCreator.convert(relativeUri); client.executeMethod(hc, method); return method; } throw e; }