List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:eu.masconsult.bgbanking.banks.procreditbank.ProcreditClient.java
/** * Configures the httpClient to connect to the URL provided. * // w ww. j a v a 2 s . co m * @param authToken */ private static DefaultHttpClient getHttpClient(final String authToken) { DefaultHttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpClientParams.setRedirecting(params, false); httpClient.addRequestInterceptor(new CookieRequestInterceptor(Arrays.asList(authToken))); return httpClient; }
From source file:ch.lipsch.deshortener.Deshortener.java
/** * Deshortens the provided uri./*from w ww . j a va2s . com*/ * * @param uriToDeshorten * The uri to deshorten. * @return Returns the result of the deshorten process. The result is only * successful when the given uri returns an 30x. Then value of the * Location header is returned within the result. * @throws IllegalArgumentException * If the provided uri is invalid. */ public static Result deshorten(Uri uriToDeshorten) { // Checks if the url shortener shows a preview if (checkForPreview(uriToDeshorten)) { return new Result(ResultType.SHOWS_PREVIEW); } // Open the network connetion HttpGet get = new HttpGet(uriToDeshorten.toString()); DefaultHttpClient client = new DefaultHttpClient(); HttpParams clientParams = client.getParams(); HttpClientParams.setRedirecting(clientParams, false); HttpResponse response = null; try { response = client.execute(get); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "Unable to communicate to shortened url: " + uriToDeshorten.toString(), e); return new Result(ResultType.NETWORK_ERROR); } catch (IOException e) { Log.e(LOG_TAG, "Unable to communicate to shortened url: " + uriToDeshorten.toString(), e); return new Result(ResultType.NETWORK_ERROR); } // Check for redirection boolean isRedirection = ((response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY) || (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) || (response.getStatusLine().getStatusCode() == HttpStatus.SC_SEE_OTHER)); if (response != null && isRedirection) { Header header = response.getFirstHeader("Location"); String redirectValue = header.getValue(); Uri deshortenedUri = Uri.parse(redirectValue); return new Result(deshortenedUri); } else { return new Result(ResultType.CANNOT_DESHORTEN); } }
From source file:com.ilearnrw.reader.utils.HttpHelper.java
public static HttpResponse get(String url) { DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = null;/*from ww w . j a v a 2s . c o m*/ HttpConnectionParams.setSoTimeout(client.getParams(), 25000); HttpGet get = new HttpGet(url); get.setHeader("Authorization", "Basic " + authString); try { response = client.execute(get); } catch (ClientProtocolException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } return response; }
From source file:eu.masconsult.bgbanking.banks.fibank.ebanking.EFIBankClient.java
/** * Configures the httpClient to connect to the URL provided. *///from w w w .j a v a 2 s . c om private static DefaultHttpClient getHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); httpClient.addRequestInterceptor(new DumpHeadersRequestInterceptor()); httpClient.addResponseInterceptor(new DumpHeadersResponseInterceptor()); return httpClient; }
From source file:com.jonbanjo.cups.operations.HttpPoster.java
static OperationResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentStream, final AuthInfo auth) throws IOException { final OperationResult opResult = new OperationResult(); if (ippBuf == null) { return null; }/*from w ww .j a va2 s .c o m*/ if (url == null) { return null; } DefaultHttpClient client = new DefaultHttpClient(); // will not work with older versions of CUPS! client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); client.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT); client.getParams().setParameter("http.connection.timeout", CONNECTION_TIMEOUT); client.getParams().setParameter("http.protocol.content-charset", "UTF-8"); client.getParams().setParameter("http.method.response.buffer.warnlimit", new Integer(8092)); // probabaly not working with older CUPS versions client.getParams().setParameter("http.protocol.expect-continue", Boolean.valueOf(true)); HttpPost httpPost; try { httpPost = new HttpPost(url.toURI()); } catch (Exception e) { System.out.println(e.toString()); return null; } httpPost.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT); byte[] bytes = new byte[ippBuf.limit()]; ippBuf.get(bytes); ByteArrayInputStream headerStream = new ByteArrayInputStream(bytes); // If we need to send a document, concatenate InputStreams InputStream inputStream = headerStream; if (documentStream != null) { inputStream = new SequenceInputStream(headerStream, documentStream); } // set length to -1 to advice the entity to read until EOF InputStreamEntity requestEntity = new InputStreamEntity(inputStream, -1); requestEntity.setContentType(IPP_MIME_TYPE); httpPost.setEntity(requestEntity); if (auth.reason == AuthInfo.AUTH_REQUESTED) { AuthHeader.makeAuthHeader(httpPost, auth); if (auth.reason == AuthInfo.AUTH_OK) { httpPost.addHeader(auth.getAuthHeader()); //httpPost.addHeader("Authorization", "Basic am9uOmpvbmJveQ=="); } } ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() { @Override public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { if (response.getStatusLine().getStatusCode() == 401) { auth.setHttpHeader(response.getFirstHeader("WWW-Authenticate")); } else { auth.reason = AuthInfo.AUTH_OK; } HttpEntity entity = response.getEntity(); opResult.setHttResult(response.getStatusLine().toString()); if (entity != null) { return EntityUtils.toByteArray(entity); } else { return null; } } }; if (url.getProtocol().equals("https")) { Scheme scheme = JfSSLScheme.getScheme(); if (scheme == null) return null; client.getConnectionManager().getSchemeRegistry().register(scheme); } byte[] result = client.execute(httpPost, handler); //String test = new String(result); IppResponse ippResponse = new IppResponse(); opResult.setIppResult(ippResponse.getResponse(ByteBuffer.wrap(result))); opResult.setAuthInfo(auth); client.getConnectionManager().shutdown(); return opResult; }
From source file:messenger.YahooFinanceAPI.java
public static String httpget(String url) { DefaultHttpClient httpclient = new DefaultHttpClient(); if (use_proxy) { HttpHost proxy = new HttpHost(PROXY_NAME, PROXY_PORT); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }//from w w w . ja v a2 s. c om HttpGet httpget = new HttpGet(url); // Override the default policy for this request httpget.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); HttpResponse response = null; String responseString = null; try { response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { cookiestore = httpclient.getCookieStore(); responseString = EntityUtils.toString(response.getEntity()); // pG^O 200 OK ~X // System.out.println(responseString); // } else { System.out.println(response.getStatusLine()); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return responseString; }
From source file:eu.masconsult.bgbanking.banks.fibank.my.MyFIBankClient.java
/** * Configures the httpClient to connect to the URL provided. *//*w ww . ja va2s. co m*/ private static DefaultHttpClient getHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); // HttpClientParams.setRedirecting(params, false); httpClient.addRequestInterceptor(new DumpHeadersRequestInterceptor()); httpClient.addResponseInterceptor(new DumpHeadersResponseInterceptor()); return httpClient; }
From source file:dictinsight.utils.io.HttpUtils.java
public static boolean postData(String[] keys, String[] values) { DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setSoTimeout(params, 1000 * 60); HttpConnectionParams.setConnectionTimeout(params, 1000 * 5); if (null == SEND_MESSAGE_URL) SEND_MESSAGE_URL = FileUtils.getStringConfig("course-server.conf", "pushHost", "http://livetest.youdao.com/pushMsgSingle"); HttpPost post = new HttpPost(SEND_MESSAGE_URL); try {//from w w w.j av a2 s. com List<NameValuePair> nvps = new ArrayList<NameValuePair>(); if (keys != null && values != null) { if (keys.length != values.length) { return false; } else { for (int i = 0; i < keys.length; i++) { nvps.add(new BasicNameValuePair(keys[i], values[i])); } } } post.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = client.execute(post); int code = response.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { String strResult = EntityUtils.toString(response.getEntity()); JSONObject result = JSONObject.parseObject(strResult); if (result == null) { return false; } int suc = result.getIntValue(SUCCESS); return suc == 1; } } catch (Exception e) { e.printStackTrace(); } finally { post.releaseConnection(); } return false; }
From source file:eu.masconsult.bgbanking.banks.dskbank.DskClient.java
/** * Configures the httpClient to connect to the URL provided. * //w ww .java2s. c o m * @param authToken */ private static DefaultHttpClient getHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); return httpClient; }
From source file:org.red5.server.util.HttpConnectionUtil.java
/** * Returns a client with all our selected properties / params. * /* ww w.j av a2 s . co m*/ * @return client */ public static final DefaultHttpClient getClient() { // create a singular HttpClient object DefaultHttpClient client = new DefaultHttpClient(connectionManager); // dont retry client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); // get the params for the client HttpParams params = client.getParams(); // establish a connection within x seconds params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout); // no redirects params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); // set custom ua params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); // set the proxy if the user has one set if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) { HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(), Integer.valueOf(System.getProperty("http.proxyPort"))); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } return client; }