List of usage examples for org.apache.http.params HttpParams setParameter
HttpParams setParameter(String str, Object obj);
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static String getHTTPResponse(String path) { String response = null;//from w ww . ja va 2 s . co m try { // source for http 1.1 // http://stackoverflow.com/questions/3046424/http-post-requests-using-httpclient-take-2-seconds-why HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpClient client = new DefaultHttpClient(params); HttpGet get = new HttpGet(path); HttpResponse responseGet = client.execute(get); HttpEntity resEntity = responseGet.getEntity(); response = EntityUtils.toString(resEntity, "utf-8").trim(); return response; } // end try catch (Exception e) { e.printStackTrace(); return null; } // end catch }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static String postHTTP(String path, ArrayList<String> parameters, ArrayList<String> values) { String response = null;//from ww w . jav a 2s . com try { // source for http 1.1 // http://stackoverflow.com/questions/3046424/http-post-requests-using-httpclient-take-2-seconds-why HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpClient httpclient = new DefaultHttpClient(params); HttpPost httpPost = new HttpPost(path); List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(parameters.size()); int i = 0; for (i = 0; i < parameters.size(); i++) { nameValuePairs.add(new BasicNameValuePair(parameters.get(i), values.get(i))); } // end for httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse httpResponse = httpclient.execute(httpPost); // Execute HTTP Post Request HttpEntity resEntity = httpResponse.getEntity(); response = EntityUtils.toString(resEntity, "utf-8").trim(); Log.e("error", response); return response; } // end try catch (Exception e) { e.printStackTrace(); return null; } // end catch }
From source file:Main.java
public static DefaultHttpClient setHttpPostProxyParams() { Log.d(TAG, "() default called "); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); //schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); //Log.d(TAG, "----Add Proxy---"); /*HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT);/* w w w .j a va 2 s . c o m*/ params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/ params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params); return mHttpClient; }
From source file:org.apache.camel.component.box.internal.BoxClientHelper.java
@SuppressWarnings("deprecation") public static CachedBoxClient createBoxClient(final BoxConfiguration configuration) { final String clientId = configuration.getClientId(); final String clientSecret = configuration.getClientSecret(); final IAuthSecureStorage authSecureStorage = configuration.getAuthSecureStorage(); final String userName = configuration.getUserName(); final String userPassword = configuration.getUserPassword(); if ((authSecureStorage == null && ObjectHelper.isEmpty(userPassword)) || ObjectHelper.isEmpty(userName) || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) { throw new IllegalArgumentException("Missing one or more required properties " + "clientId, clientSecret, userName and either authSecureStorage or userPassword"); }//from w w w . ja v a2 s . c om LOG.debug("Creating BoxClient for login:{}, client_id:{} ...", userName, clientId); // if set, use configured connection manager builder final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder(); final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null ? connectionManagerBuilder : new BoxConnectionManagerBuilder(); // create REST client for BoxClient final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1]; final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) { @Override public HttpClient getRawHttpClient() { final HttpClient httpClient = super.getRawHttpClient(); clientConnectionManager[0] = httpClient.getConnectionManager(); // set custom HTTP params final Map<String, Object> configParams = configuration.getHttpParams(); if (configParams != null && !configParams.isEmpty()) { LOG.debug("Setting {} HTTP Params", configParams.size()); final HttpParams httpParams = httpClient.getParams(); for (Map.Entry<String, Object> param : configParams.entrySet()) { httpParams.setParameter(param.getKey(), param.getValue()); } } return httpClient; } }; final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null, restClient, configuration.getBoxConfig()); // enable OAuth auto-refresh boxClient.setAutoRefreshOAuth(true); // wrap the configured storage in a caching storage final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage); // set up a listener to notify secure storage and user provided listener, store it in configuration! final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener()); boxClient.addOAuthRefreshListener(listener); final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage, listener, clientConnectionManager); LOG.debug("BoxClient created {}", cachedBoxClient); return cachedBoxClient; }
From source file:Main.java
public static DefaultHttpClient setHttpPostProxyParams(int connTimeOut) { Log.d(TAG, "connTimeout -- called"); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); //schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); /*Log.d(TAG, "----Add Proxy---"); HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(), Constants.PROXY_PORT);// w ww.ja va 2 s .com params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/ params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, connTimeOut); HttpConnectionParams.setSoTimeout(params, connTimeOut); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params); return mHttpClient; }
From source file:com.delicious.deliciousfeeds4J.DeliciousUtil.java
public static String doGetRequest(String url, String userAgent, boolean constainAPILimit) throws DeliciousFeedsException { logger.info("Executing GET-Request to url: " + url); final HttpGet getRequest = new HttpGet(url); final HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); getRequest.setParams(params);/* w w w.j a v a2 s . co m*/ final ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { if (constainAPILimit) { logger.info("Waiting for 1 second to not reach the API limit and get banned!"); Thread.sleep(1000); } return HTTP_CLIENT.execute(getRequest, responseHandler); } catch (Exception ex) { //Check if you maybe got banned... if (ex instanceof HttpResponseException) if (((HttpResponseException) ex).getStatusCode() == 503) throw new YouGotBannedException(ex); throw new DeliciousFeedsException("Error occured while executing GET-Request to url: " + url, ex); } }
From source file:bkampfbot.Utils.java
public final static boolean fightAvailable(int retry) { for (int i = retry; i > 0; i--) { if (i != retry) { Control.sleep(600);// w w w . ja va 2 s . com Output.println(" - versuche erneut", 1); } try { // HTTP parameters stores header etc. HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); HttpGet httpget = new HttpGet(Config.getHost() + "fights/start"); httpget.setParams(params); HttpResponse response = Control.current.httpclient.execute(httpget); // obtain redirect target Header locationHeader = response.getFirstHeader("location"); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } if (locationHeader == null) { return true; } } catch (IOException e) { } Output.printTab("Kampf nicht verfgbar", 1); } Output.println(" - Abbruch", 1); return false; }
From source file:bkampfbot.Utils.java
public static final String getString(String url, String location) throws LocationChangedException { try {//from ww w . ja v a 2s . c om if (Config.getDebug()) Output.println("getString: " + Config.getHost() + url, 2); HttpGet httpget = new HttpGet(Config.getHost() + url); if (location != "") { // HTTP parameters stores header etc. HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); httpget.setParams(params); } // Create a response handler HttpResponse response = Control.current.httpclient.execute(httpget); if (location != "") { Header locationHeader = response.getFirstHeader("location"); if (locationHeader != null) { if (locationHeader.getValue().equalsIgnoreCase(Config.getHost() + location)) { HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } throw new LocationChangedException(); } } } Header date = response.getFirstHeader("date"); if (date != null) { try { Config.setLastDate(DateUtils.parseDate(date.getValue())); } catch (DateParseException e) { } } HttpEntity entity = response.getEntity(); Control.sleep(1); if (entity != null) { String ret = EntityUtils.toString(entity); // for debugging Control.current.lastResponse = ret; if (entity != null) { entity.consumeContent(); } return ret; } else { return ""; } } catch (IOException e) { return ""; } }
From source file:neembuu.release1.httpclient.NHttpClient.java
public static DefaultHttpClient getNewInstance() { DefaultHttpClient new_httpClient = null; new_httpClient = new DefaultHttpClient(); GlobalTestSettings.ProxySettings proxySettings = GlobalTestSettings.getGlobalProxySettings(); HttpContext context = new BasicHttpContext(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", new PlainSocketFactory(), 80)); try {// w w w . j a v a2 s . c o m KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 8080)); } catch (Exception a) { a.printStackTrace(System.err); } context.setAttribute(ClientContext.SCHEME_REGISTRY, schemeRegistry); context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, new BasicScheme()/*file.httpClient.getAuthSchemes()*/); context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, new_httpClient.getCookieSpecs()/*file.httpClient.getCookieSpecs()*/ ); BasicCookieStore basicCookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, basicCookieStore/*file.httpClient.getCookieStore()*/); context.setAttribute(ClientContext.CREDS_PROVIDER, new BasicCredentialsProvider()/*file.httpClient.getCredentialsProvider()*/); HttpConnection hc = new DefaultHttpClientConnection(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, hc); //System.out.println(file.httpClient.getParams().getParameter("http.useragent")); HttpParams httpParams = new BasicHttpParams(); if (proxySettings != null) { AuthState as = new AuthState(); as.setCredentials(new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); as.setAuthScope(AuthScope.ANY); as.setAuthScheme(new BasicScheme()); httpParams.setParameter(ClientContext.PROXY_AUTH_STATE, as); httpParams.setParameter("http.proxy_host", new HttpHost(proxySettings.host, proxySettings.port)); } new_httpClient = new DefaultHttpClient( new SingleClientConnManager(httpParams/*file.httpClient.getParams()*/, schemeRegistry), httpParams/*file.httpClient.getParams()*/); if (proxySettings != null) { new_httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); } return new_httpClient; }
From source file:main.DOORS_Service.java
private static void validateTokens(OslcOAuthClient client, String redirect, String user, String password, String authURL) throws Exception { HttpGet request2 = new HttpGet(redirect); HttpClientParams.setRedirecting(request2.getParams(), false); HttpResponse response = client.getHttpClient().execute(request2); EntityUtils.consume(response.getEntity()); // Get the location Header location = response.getFirstHeader("Location"); HttpGet request3 = new HttpGet(location.getValue()); HttpClientParams.setRedirecting(request3.getParams(), false); response = client.getHttpClient().execute(request3); EntityUtils.consume(response.getEntity()); //POST to login form // The server requires an authentication: Create the login form // Following line should be like : "https://server:port/dwa/j_acegi_security_check" HttpPost formPost = new HttpPost(authURL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("j_username", user)); nvps.add(new BasicNameValuePair("j_password", password)); formPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse formResponse = client.getHttpClient().execute(formPost); EntityUtils.consume(formResponse.getEntity()); location = formResponse.getFirstHeader("Location"); //Third GET//ww w .java 2 s . com HttpGet request4 = new HttpGet(location.getValue()); HttpClientParams.setRedirecting(request4.getParams(), false); response = client.getHttpClient().execute(request4); EntityUtils.consume(response.getEntity()); location = response.getFirstHeader("Location"); Map<String, String> oAuthMap = getQueryMap(location.getValue()); String oauthToken = oAuthMap.get("oauth_token"); String oauthverifier = oAuthMap.get("oauth_verifier"); // The server requires an authentication: Create the login form HttpPost formPost2 = new HttpPost(location.getValue()); formPost2.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); HttpParams params = new BasicHttpParams(); params.setParameter("oauth_token", oauthToken); params.setParameter("oauth_verifier", oauthverifier); params.setParameter("authorize", "true"); formPost2.setParams(params); formResponse = client.getHttpClient().execute(formPost2); EntityUtils.consume(formResponse.getEntity()); Header header = formResponse.getFirstHeader("Content-Length"); if ((header != null) && (!("0".equals(header.getValue())))) { // The login failed throw new InvalidCredentialsException("Authentication failed"); } else { // The login succeed // Step (3): Request again the protected resource EntityUtils.consume(formResponse.getEntity()); } }