List of usage examples for org.apache.http.protocol HttpContext getAttribute
Object getAttribute(String str);
From source file:com.facebook.stetho.websocket.WebSocketHandler.java
@Override public void handleSecured(HttpRequest request, HttpResponse response, HttpContext context) throws IOException, HttpException { if (!isSupportableUpgradeRequest(request)) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); response.setReasonPhrase("Not Implemented"); response.setEntity(new StringEntity("Not a supported WebSocket upgrade request\n")); return;// w w w . j a v a2s . c o m } HttpConnection conn = (HttpConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION); try { // This will not return on successful WebSocket upgrade, but rather block until the session is // shut down or a socket error occurs. doUpgrade(request, response, context); } finally { try { conn.close(); } catch (IOException e) { // LocalSocket has strange behaviour with respect to flushing the socket output // stream. In particular, it will throw if the socket has been closed even if there // is no data to flush. Moreover, the socket will seemingly be automatically closed // when read to exhaustion even though it is not explicitly closed. } } // Throw on graceful shutdown (*sigh*) to signal to the server component that we need // to abort the HTTP stream loop we were previously stuck in. throw new ConnectionClosedException("EOF"); }
From source file:org.mobicents.client.slee.resource.http.HttpClientResourceAdaptorSbbInterfaceImpl.java
@Override public HttpClientActivity createHttpClientActivity(boolean endOnReceivingResponse, HttpContext context) throws StartActivityException { if (tracer.isFinestEnabled()) { tracer.finest("createHttpClientActivity(endOnReceivingResponse=" + endOnReceivingResponse + ",context=" + context + ")"); }/*from ww w .j a v a2 s . c om*/ if (!this.ra.isActive) { throw new IllegalStateException("ra is not in active state"); } // Maintain HttpSession on server side if (context == null) { context = new BasicHttpContext(); } if (context.getAttribute(ClientContext.COOKIE_STORE) == null) { BasicCookieStore cookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, cookieStore); } HttpClientActivity activity = new HttpClientActivityImpl(this.ra, endOnReceivingResponse, context); HttpClientActivityHandle handle = new HttpClientActivityHandle(activity.getSessionId()); // this happens with a tx context this.ra.getResourceAdaptorContext().getSleeEndpoint().startActivitySuspended(handle, activity, ACTIVITY_FLAGS); this.ra.addActivity(handle, activity); if (tracer.isFineEnabled()) { tracer.fine("Started activity " + activity.getSessionId() + ", context is " + context + ", endOnReceivingResponse is " + endOnReceivingResponse); } return activity; }
From source file:org.blocks4j.reconf.infra.http.layer.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { if (exception instanceof SocketException && executionCount <= 1) { return true; }//from w w w . java 2s . com if (executionCount >= maxRetry) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (exception instanceof SSLHandshakeException) { // Do not retry on SSL handshake exception return false; } HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST); boolean idempotent = !(request instanceof HttpEntityEnclosingRequest); if (idempotent) { // Retry if the request is considered idempotent return true; } return false; }
From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java
private URI buildUri(HttpContext context, String location) throws URISyntaxException { URI uri;//w w w . j ava 2s . co m uri = new URI(location); if (!uri.isAbsolute()) { HttpHost host = (HttpHost) context.getAttribute(HTTP_TARGET_HOST); uri = new URI(host.toURI() + location); } return uri; }
From source file:com.flicklib.service.HttpClientSourceLoader.java
private Source buildSource(String url, HttpResponse response, HttpRequestBase httpMethod, HttpContext ctx) throws IOException { LOGGER.info("Finished loading at " + httpMethod.getURI().toString()); final HttpEntity entity = response.getEntity(); String responseCharset = EntityUtils.getContentCharSet(entity); String contentType = EntityUtils.getContentMimeType(entity); LOGGER.info("Response charset = " + responseCharset); String content = EntityUtils.toString(entity); HttpUriRequest req = (HttpUriRequest) ctx.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost target = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST); URI resultUri;//from w ww.j a va 2 s. co m try { resultUri = (target != null && req != null) ? new URI(target.toURI() + req.getURI().toString()) : httpMethod.getURI(); } catch (URISyntaxException e) { e.printStackTrace(); resultUri = httpMethod.getURI(); } // String contentType = URLConnection.guessContentTypeFromName(url) return new Source(resultUri.toString(), content, contentType, url); }
From source file:org.opensaml.security.httpclient.impl.SecurityEnhancedTLSSocketFactory.java
/** * Load the {@link ThreadLocalX509CredentialContext} with the client TLS credential obtained from * the {@link HttpContext}./* w w w . jav a 2s .c om*/ * * @param context the HttpContext instance */ protected void setup(@Nullable final HttpContext context) { log.trace("Attempting to setup thread-local client TLS X509Credential"); if (context == null) { log.trace("HttpContext was null, skipping thread-local setup"); return; } if (!ThreadLocalX509CredentialContext.haveCurrent()) { X509Credential credential = (X509Credential) context .getAttribute(HttpClientSecurityConstants.CONTEXT_KEY_CLIENT_TLS_CREDENTIAL); if (credential != null) { log.trace("Loading ThreadLocalX509CredentialContext with client TLS credential: {}", credential); ThreadLocalX509CredentialContext.loadCurrent(credential); } else { log.trace("HttpContext did not contain a client TLS credential, nothing to do"); } } else { log.trace( "ThreadLocalX509CredentialContext was already loaded with client TLS credential, skipping setup"); } }
From source file:org.bungeni.ext.integration.bungeniportal.BungeniAppConnector.java
private String getRequestEndContextURL(HttpContext context) { HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); // this gives the login page String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI()); return currentUrl; }