List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:de.wikilab.android.friendica01.TwAjax.java
private void setHttpClientProxy(DefaultHttpClient httpclient) { if (myProxyIp == null) return;/* w w w .j a v a2 s . c o m*/ httpclient.getCredentialsProvider().setCredentials(new AuthScope(myProxyIp, myProxyPort), new UsernamePasswordCredentials(myProxyUsername, myProxyPassword)); HttpHost proxy = new HttpHost(myProxyIp, myProxyPort); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }
From source file:com.marklogic.client.tutorial.util.Bootstrapper.java
/** * Programmatic invocation.//from w w w . j av a 2 s . c om * @param configServer the configuration server for creating the REST server * @param restServer the specification of the REST server */ public void makeServer(ConfigServer configServer, RESTServer restServer) throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError { DefaultHttpClient client = new DefaultHttpClient(); String host = configServer.getHost(); int configPort = configServer.getPort(); Authentication authType = configServer.getAuthType(); if (authType != null) { List<String> prefList = new ArrayList<String>(); if (authType == Authentication.BASIC) prefList.add(AuthPolicy.BASIC); else if (authType == Authentication.DIGEST) prefList.add(AuthPolicy.DIGEST); else throw new IllegalArgumentException("Unknown authentication type: " + authType.name()); client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, prefList); String configUser = configServer.getUser(); String configPassword = configServer.getPassword(); client.getCredentialsProvider().setCredentials(new AuthScope(host, configPort), new UsernamePasswordCredentials(configUser, configPassword)); } BasicHttpContext context = new BasicHttpContext(); StringEntity content = new StringEntity(restServer.toXMLString()); content.setContentType("application/xml"); HttpPost poster = new HttpPost("http://" + host + ":" + configPort + "/v1/rest-apis"); poster.setEntity(content); HttpResponse response = client.execute(poster, context); //poster.releaseConnection(); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); String statusPhrase = status.getReasonPhrase(); client.getConnectionManager().shutdown(); if (statusCode >= 300) { throw new RuntimeException("Failed to create REST server: " + statusCode + " " + statusPhrase + "\n" + "Please check the server log for detail"); } }
From source file:com.akop.bach.parser.LiveParser.java
@Override protected DefaultHttpClient createHttpClient(Context context) { mLastRedirectedUrl = null;/* w ww . j a v a 2 s. c om*/ DefaultHttpClient client = new DefaultHttpClient(); client.setRedirectHandler(new DefaultRedirectHandler() { @Override public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException { URI uri = super.getLocationURI(response, context); if (uri != null) mLastRedirectedUrl = uri.toString(); return uri; } }); client.getCookieSpecs().register("lenient", new CookieSpecFactory() { public CookieSpec newInstance(HttpParams params) { return new LenientCookieSpec(); } }); HttpClientParams.setCookiePolicy(client.getParams(), "lenient"); return client; }
From source file:com.cloudant.client.org.lightcouch.CouchDbClientAndroid.java
/** * @return {@link DefaultHttpClient} instance. *//*ww w . ja v a 2s. c o m*/ @Override HttpClient createHttpClient(CouchDbProperties props) { DefaultHttpClient httpclient = null; try { final SchemeRegistry schemeRegistry = createRegistry(props); // Http params final HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, props.getSocketTimeout()); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, props.getConnectionTimeout()); final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(params, schemeRegistry); httpclient = new DefaultHttpClient(ccm, params); if (props.getProxyHost() != null) { HttpHost proxy = new HttpHost(props.getProxyHost(), props.getProxyPort()); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } // basic authentication if (props.getUsername() != null && props.getPassword() != null) { httpclient.getCredentialsProvider().setCredentials(new AuthScope(props.getHost(), props.getPort()), new UsernamePasswordCredentials(props.getUsername(), props.getPassword())); props.clearPassword(); } registerInterceptors(httpclient); } catch (Exception e) { throw new IllegalStateException("Error Creating HTTP client. ", e); } return httpclient; }
From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java
private void initProxy(final DefaultHttpClient httpClient, final CallerConfig config) throws IllegalArgumentException { final String proxyUrl = config.getProxy(); final String[] hostAndPort = proxyUrl.split(":"); if (hostAndPort.length != 2) { throw new IllegalArgumentException("Unable to parse proxy url. Supported format is 'hostname:port''"); }//w w w. j a v a 2 s. c om final String host = hostAndPort[0]; int port; try { port = Integer.parseInt(hostAndPort[1]); } catch (final NumberFormatException e) { throw new IllegalArgumentException( "Unable to parse proxy url because port is Not a Number. Supported format is 'hostname:port''", e); } final HttpHost proxy = new HttpHost(host, port); LOG.info("Use proxy '{}:{}'", proxy.getHostName(), proxy.getPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }
From source file:com.marklogic.client.example.util.Bootstrapper.java
/** * Programmatic invocation./*from ww w . j a v a 2 s . com*/ * @param configServer the configuration server for creating the REST server * @param restServer the specification of the REST server */ public void makeServer(ConfigServer configServer, RESTServer restServer) throws ClientProtocolException, IOException, FactoryConfigurationError { DefaultHttpClient client = new DefaultHttpClient(); String host = configServer.getHost(); int configPort = configServer.getPort(); // TODO: SSL Authentication authType = configServer.getAuthType(); if (authType != null) { List<String> prefList = new ArrayList<String>(); if (authType == Authentication.BASIC) prefList.add(AuthPolicy.BASIC); else if (authType == Authentication.DIGEST) prefList.add(AuthPolicy.DIGEST); else throw new IllegalArgumentException("Unknown authentication type: " + authType.name()); client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, prefList); String configUser = configServer.getUser(); String configPassword = configServer.getPassword(); client.getCredentialsProvider().setCredentials(new AuthScope(host, configPort), new UsernamePasswordCredentials(configUser, configPassword)); } BasicHttpContext context = new BasicHttpContext(); StringEntity content; try { content = new StringEntity(restServer.toXMLString()); } catch (XMLStreamException e) { throw new IOException("Could not create payload to bootstrap server."); } content.setContentType("application/xml"); HttpPost poster = new HttpPost("http://" + host + ":" + configPort + "/v1/rest-apis"); poster.setEntity(content); HttpResponse response = client.execute(poster, context); //poster.releaseConnection(); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); String statusPhrase = status.getReasonPhrase(); client.getConnectionManager().shutdown(); if (statusCode >= 300) { throw new RuntimeException("Failed to create REST server: " + statusCode + " " + statusPhrase + "\n" + "Please check the server log for detail"); } }
From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java
private static List<String> connectAndReadFromURL(URL url) { List<String> data = null; DefaultHttpClient httpClient = null; TrustStrategy easyStrategy = new TrustStrategy() { @Override//w w w. j av a 2 s . c o m public boolean isTrusted(X509Certificate[] certificate, String authType) throws CertificateException { return true; } }; try { SSLSocketFactory sslsf = new SSLSocketFactory(easyStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme = new Scheme("https", 443, sslsf); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(httpsScheme); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); ClientConnectionManager ccm = new ThreadSafeClientConnManager(schemeRegistry); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 50000); HttpConnectionParams.setSoTimeout(httpParams, new Integer(12000)); httpClient = new DefaultHttpClient(ccm, httpParams); httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(schemeRegistry, ProxySelector.getDefault())); // // Additions by lrt for tcia - // // attempt to reduce errors going through a Coyote Point // Equalizer load balance switch httpClient.getParams().setParameter("http.socket.timeout", new Integer(12000)); httpClient.getParams().setParameter("http.socket.receivebuffer", new Integer(16384)); httpClient.getParams().setParameter("http.tcp.nodelay", true); httpClient.getParams().setParameter("http.connection.stalecheck", false); // // end lrt additions HttpPost httpPostMethod = new HttpPost(url.toString()); List<BasicNameValuePair> postParams = new ArrayList<BasicNameValuePair>(); postParams.add(new BasicNameValuePair(osParam, os)); UrlEncodedFormEntity query = new UrlEncodedFormEntity(postParams); httpPostMethod.setEntity(query); HttpResponse response = httpClient.execute(httpPostMethod); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode == HttpStatus.SC_OK) { InputStream inputStream = response.getEntity().getContent(); data = IOUtils.readLines(inputStream); } else { JOptionPane.showMessageDialog(null, "Incorrect response from server: " + responseCode); } } catch (java.net.ConnectException e) { String note = "Connection error 1 while connecting to " + url.toString() + ":\n" + getProxyInfo(); //+ checkListeningPort("127.0.0.1", 8888); printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 1: " + e.getMessage()); e.printStackTrace(); } catch (MalformedURLException e) { String note = "Connection error 2 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 2: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { String note = "Connection error 3 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 3: " + e.getMessage()); e.printStackTrace(); } catch (KeyManagementException e) { String note = "Connection error 4 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 4: " + e.getMessage()); e.printStackTrace(); } catch (NoSuchAlgorithmException e) { String note = "Connection error 5 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 5: " + e.getMessage()); e.printStackTrace(); } catch (KeyStoreException e) { String note = "Connection error 6 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 6: " + e.getMessage()); e.printStackTrace(); } catch (UnrecoverableKeyException e) { String note = "Connection error 7 while connecting to " + url.toString() + ":\n"; printStackTraceToDialog(note, e); //JOptionPane.showMessageDialog(null, "Connection error 7: " + e.getMessage()); e.printStackTrace(); } finally { if (httpClient != null) { httpClient.getConnectionManager().shutdown(); } } return data; }