List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:edu.harvard.liblab.ecru.SolrClient.java
/** * Creates a new HttpClient. If keyStorePath and/or trustStorePath are set, a secure client will * be created by reading in the keyStore and/or trustStore. In addition, system keys will also be * included (i.e. those specified in the JRE). * /*from www.ja va2s .c o m*/ * Most of the code below is "borrowed" from edu.harvard.hul.ois.drs2.callservice.ServiceClient * * @return an HttpClient ready to roll! */ protected HttpClient createHttpClient() throws SolrClientException { // turn on SSL logging, according to Log4j settings DefaultHttpClient httpClient = new DefaultHttpClient(); // set parameters httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, true); return httpClient; }
From source file:org.fabrician.maven.plugins.GridlibUploadMojo.java
public void execute() throws MojoExecutionException { String username = brokerUsername; String password = brokerPassword; if (serverId != null && !"".equals(serverId)) { // TODO: implement server_id throw new MojoExecutionException("serverId is not yet supported"); } else if (brokerUsername == null || "".equals(brokerUsername) || brokerPassword == null || "".equals(brokerPassword)) { throw new MojoExecutionException("serverId or brokerUsername and brokerPassword must be set"); }/*from ww w . ja va2 s . c om*/ DirectoryScanner ds = new DirectoryScanner(); ds.setIncludes(mIncludes); ds.setExcludes(mExcludes); ds.setBasedir("."); ds.setCaseSensitive(true); ds.scan(); String[] files = ds.getIncludedFiles(); if (files == null) { getLog().info("No files found to upload"); } else { getLog().info("Found " + files.length + " file to upload"); for (String file : files) { File gridlibFilename = new File(file); getLog().info("Uploading " + gridlibFilename + " to " + brokerUrl); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); Credentials cred = new UsernamePasswordCredentials(username, password); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, cred); try { MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("gridlibOverwrite", new StringBody(String.valueOf(gridlibOverwrite), Charset.forName("UTF-8"))); entity.addPart("gridlibArchive", new FileBody(gridlibFilename)); HttpPost method = new HttpPost(brokerUrl); method.setEntity(entity); HttpResponse response = httpclient.execute(method); StatusLine status = response.getStatusLine(); int code = status.getStatusCode(); if (code >= 400 && code <= 500) { throw new MojoExecutionException( "Failed to upload " + gridlibFilename + " to " + brokerUrl + ": " + code); } } catch (Exception e) { throw new MojoExecutionException(e.getMessage()); } } } }
From source file:net.bither.image.http.BaseHttpResponse.java
private DefaultHttpClient getThreadSafeHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); ClientConnectionManager mgr = httpClient.getConnectionManager(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HttpSetting.HTTP_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, HttpSetting.HTTP_SO_TIMEOUT); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);/* w w w. j av a 2 s . c o m*/ return httpClient; }
From source file:com.vrs.qrw100s.NetworkReader.java
@Override public void run() { Thread.currentThread().setName("Network Reader"); HttpResponse res;/*from w ww .j a va 2s . com*/ DefaultHttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000); Log.d(TAG, "1. Sending http request"); try { res = httpclient.execute(new HttpGet(URI.create(myURL))); Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode()); if (res.getStatusLine().getStatusCode() == 401) { return; } DataInputStream bis = new DataInputStream(res.getEntity().getContent()); ByteArrayOutputStream jpgOut = new ByteArrayOutputStream(10000); int prev = 0; int cur; while ((cur = bis.read()) >= 0 && _runThread) { if (prev == 0xFF && cur == 0xD8) { // reset the output stream if (!skipFrame) { jpgOut.reset(); jpgOut.write((byte) prev); } } if (!skipFrame) { if (jpgOut != null) { jpgOut.write((byte) cur); } } if (prev == 0xFF && cur == 0xD9) { if (!skipFrame) { synchronized (curFrame) { curFrame = jpgOut.toByteArray(); } skipFrame = true; Message threadMessage = mainHandler.obtainMessage(); threadMessage.obj = curFrame; mainHandler.sendMessage(threadMessage); } else { if (skipNum < frameDecrement) { skipNum++; } else { skipNum = 0; skipFrame = false; } } } prev = cur; } } catch (ClientProtocolException e) { Log.d(TAG, "Request failed-ClientProtocolException", e); } catch (IOException e) { Log.d(TAG, "Request failed-IOException", e); } }
From source file:com.google.code.maven.plugin.http.client.ProxyTest.java
@Test public void testPrepare() { proxy.setHost("localhost"); proxy.setPort(8080);//from ww w. j a va2 s . com DefaultHttpClient client = new DefaultHttpClient(); proxy.prepare(client); HttpHost httpHost = (HttpHost) client.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY); Assert.assertNotNull(httpHost); Assert.assertEquals(httpHost.getHostName(), proxy.getHost()); Assert.assertEquals(httpHost.getPort(), proxy.getPort()); Assert.assertEquals(httpHost.getSchemeName(), HttpHost.DEFAULT_SCHEME_NAME); Credentials credentials = new Credentials(); credentials.setLogin("login"); credentials.setPassword("password"); proxy.setCredentials(credentials); client = new DefaultHttpClient(); proxy.prepare(client); httpHost = (HttpHost) client.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY); Assert.assertNotNull(httpHost); Assert.assertEquals(httpHost.getHostName(), proxy.getHost()); Assert.assertEquals(httpHost.getPort(), proxy.getPort()); Assert.assertEquals(httpHost.getSchemeName(), HttpHost.DEFAULT_SCHEME_NAME); org.apache.http.auth.Credentials credentials2 = client.getCredentialsProvider() .getCredentials(new AuthScope("localhost", 8080)); Assert.assertNotNull(credentials2); Assert.assertEquals("login", credentials2.getUserPrincipal().getName()); Assert.assertEquals("password", credentials2.getPassword()); }
From source file:com.hoccer.http.AsyncHttpGetTest.java
public void testOwnUserAgentStringInRequestWithCustomHttpClient() throws Exception { DefaultHttpClient httpClient = new HttpClientWithKeystore(); httpClient.getParams().setParameter("http.useragent", "Y60/0.1 HTTP Unit Test"); mRequest = new AsyncHttpGet(getServer().getUri(), httpClient); mRequest.start();//from www . j a v a2s . c o m blockUntilRequestIsDone(mRequest); assertEquals("User-Agent string in HTTP header shuld be y60", "Y60/0.1 HTTP Unit Test", getServer().getLastRequest().header.getProperty("user-agent")); }
From source file:org.deegree.protocol.ows.http.OwsHttpClientImpl.java
private void setTimeouts(DefaultHttpClient client) { HttpConnectionParams.setConnectionTimeout(client.getParams(), connectionTimeoutMillis); HttpConnectionParams.setSoTimeout(client.getParams(), readTimeoutMillis); }
From source file:com.peopleapi.RegisterWithApi.java
@Override protected String doInBackground(String... params) { //the result from the api or errors go into this string String fromApiString = ""; DefaultHttpClient client = (DefaultHttpClient) getNewHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout Limit HttpResponse response;/* w w w . ja v a2s. co m*/ JSONObject json = new JSONObject(); try { HttpPost post = new HttpPost(context.getResources().getString(R.string.api_registerurl)); json.put("username", params[0]); json.put("password", params[1]); json.put("confirmPassword", params[2]); StringEntity se = new StringEntity(json.toString()); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(se); response = client.execute(post); int code = response.getStatusLine().getStatusCode(); //We have to go back and get the token and user data... /* Checking response */ if (response != null) { InputStream inputStream = response.getEntity().getContent(); // Get the entity data here if (inputStream != null) { ByteArrayOutputStream content = new ByteArrayOutputStream(); int readBytes = 0; byte[] sBuffer = new byte[512]; while ((readBytes = inputStream.read(sBuffer)) != -1) { content.write(sBuffer, 0, readBytes); } fromApiString = new String(content.toByteArray()) + code; inputStream.close(); } } } catch (Exception e) { fromApiString = e.getMessage().toString(); } return fromApiString; }
From source file:org.apache.olingo.client.core.http.ProxyWrappingHttpClientFactory.java
@Override public HttpClient create(final HttpMethod method, final URI uri) { // Use wrapped factory to obtain an httpclient instance for given method and uri final DefaultHttpClient httpclient = wrapped.create(method, uri); final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); // Sets usage of HTTP proxy httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); // Sets proxy authentication, if credentials were provided if (proxyUsername != null && proxyPassword != null) { httpclient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); }// www . java2s . c o m return httpclient; }
From source file:org.ebayopensource.twin.TwinConnection.java
private HttpClient getClient() { synchronized (TwinConnection.class) { if (connManager == null) { DefaultHttpClient client = new DefaultHttpClient(); params = client.getParams().copy(); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(50)); params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 200); connManager = new ThreadSafeClientConnManager(params, client.getConnectionManager().getSchemeRegistry()); }//from ww w . j av a2 s. c om } DefaultHttpClient client = new DefaultHttpClient(connManager, params); client.setRedirectHandler(new DefaultRedirectHandler()); return client; }