List of usage examples for org.apache.http.protocol HttpContext getAttribute
Object getAttribute(String str);
From source file:org.apache.synapse.transport.nhttp.ConnectionPool.java
public void forget(NHttpClientConnection conn) { HttpContext ctx = conn.getContext(); Axis2HttpRequest axis2Req = (Axis2HttpRequest) ctx.getAttribute(ClientHandler.AXIS2_HTTP_REQUEST); if (axis2Req != null) { HttpRoute route = axis2Req.getRoute(); List<NHttpClientConnection> connections = (List<NHttpClientConnection>) connMap.get(route); if (connections != null) { synchronized (connections) { connections.remove(conn); }/*from w ww. jav a2 s . c om*/ } } }
From source file:com.alibaba.openapi.client.rpc.AliNHttpRequstExecutionHandler.java
public HttpRequest submitRequest(HttpContext context) { //System.out.println("AliNHttpRequstExecutionHandler submitRequest"); InvokeContext invokeContext = (InvokeContext) context.getAttribute(CONTEXT_ATTACHMENT); if (invokeContext.isCompleted()) return null; HttpRequest request = protocolProvider.getRequestBuilder(invokeContext.getPolicy().getRequestProtocol()) .getHttpRequest(invokeContext); LoggerHelper.getClientLogger().finer("--submit Request--" + request.toString()); return request; }
From source file:com.louding.frame.http.download.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // ??// w w w. j a v a 2 s . c o m boolean retry = true; // ? Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // ???? retry = false; } else if (isInList(exceptionBlacklist, exception)) { // ?????? retry = false; } else if (isInList(exceptionWhitelist, exception)) { // ???? retry = true; } else if (!sent) { // ????? retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:org.apache.synapse.transport.nhttp.ConnectionPool.java
public void release(NHttpClientConnection conn) { HttpContext ctx = conn.getContext(); Axis2HttpRequest axis2Req = (Axis2HttpRequest) ctx.getAttribute(ClientHandler.AXIS2_HTTP_REQUEST); HttpRoute route = axis2Req.getRoute(); List<NHttpClientConnection> connections = null; synchronized (connMap) { // use double locking to make sure connections = (List<NHttpClientConnection>) connMap.get(route); if (connections == null) { connections = Collections.synchronizedList(new LinkedList<NHttpClientConnection>()); connMap.put(route, connections); }//from w w w .ja v a2s .com } cleanConnectionReferences(conn); connections.add(conn); if (log.isDebugEnabled()) { log.debug("Released a connection : " + route + " to the connection pool of current size : " + connections.size()); } }
From source file:com.unboundid.scim.sdk.PreemptiveAuthInterceptor.java
/** * {@inheritDoc}/*www . jav a 2 s . com*/ */ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target.getPort() < 0) { SchemeRegistry schemeRegistry = (SchemeRegistry) context.getAttribute(ClientContext.SCHEME_REGISTRY); Scheme scheme = schemeRegistry.getScheme(target); target = new HttpHost(target.getHostName(), scheme.resolvePort(target.getPort()), target.getSchemeName()); } AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE); if (authCache == null) { authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(target, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); return; } CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); if (credsProvider == null) { return; } final AuthState targetState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target); if (authScheme != null) { doPreemptiveAuth(target, authScheme, targetState, credsProvider); } } final HttpHost proxy = (HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST); final AuthState proxyState = (AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE); if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(proxy); if (authScheme != null) { doPreemptiveAuth(proxy, authScheme, proxyState, credsProvider); } } }
From source file:ResponseGzipCompress.java
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); }/*from w w w .j a v a 2 s .c o m*/ HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); Header aeheader = request.getFirstHeader(ACCEPT_ENCODING); if (aeheader != null) { HeaderElement[] codecs = aeheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase(GZIP_CODEC) && response.getEntity() != null) { response.setEntity(new NGzipCompressingEntity(response.getEntity())); return; } } } }
From source file:org.mobicents.slee.ra.httpclient.nio.ra.HttpClientNIORequestActivityImpl.java
private HttpContext processHttpContext(HttpContext context) { // Maintains HttpSession on server side if (context == null) { context = new BasicHttpContext(); }/*w ww . j a va 2s .c o m*/ if (context.getAttribute(ClientContext.COOKIE_STORE) == null) { BasicCookieStore cookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, cookieStore); } return context; }
From source file:com.norconex.collector.http.crawler.TargetURLRedirectStrategy.java
public boolean isRedirected(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { boolean isRedirected = nested.isRedirected(request, response, context); HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST); HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); if (!isRedirected) { if (currentReq.getURI().isAbsolute()) { CURRENT_URL.set(currentReq.getURI().toString()); } else {/*from www. j a v a2s . co m*/ CURRENT_URL.set(currentHost.toURI() + currentReq.getURI()); } } return isRedirected; }
From source file:com.lurencun.cfuture09.androidkit.http.async.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // ??/*from ww w . j a v a 2 s . com*/ boolean retry = true; // ? Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // ???? retry = false; } else if (isInList(exceptionBlacklist, exception)) { // ?????? retry = false; } else if (isInList(exceptionWhitelist, exception)) { // ???? retry = true; } else if (!sent) { // ????? retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); log.w(exception); } return retry; }
From source file:de.vanita5.twittnuker.util.net.ssl.HostResolvedSSLConnectionSocketFactory.java
private String getHostname(final String hostname, final HttpContext context) { if (context == null) return hostname; final Object attr = context.getAttribute(HTTP_CONTEXT_KEY_ORIGINAL_HOST); if (attr instanceof String) return (String) attr; return hostname; }