@Override protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext) throws Exception { try { // Generate the service ticket for sending to the server. // Locking ensures the tokens are unique in case of concurrent requests kerberosLock.lock(); String kerberosAuthHeader = HttpAuthUtils.getKerberosServiceTicket(principal, host, serverHttpUrl, loggedInSubject); // Set the session key token (Base64 encoded) in the headers httpRequest.addHeader(HttpAuthUtils.AUTHORIZATION + ": " + HttpAuthUtils.NEGOTIATE + " ", kerberosAuthHeader); } catch (Exception e) { throw new HttpException(e.getMessage(), e); } finally { kerberosLock.unlock(); } } }
Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials for preemptive authentication");
throw new HttpException(e.getMessage(), e);
throw new HttpException("Error rebuilding request URI", ex);
if (uri != null && uri.length() > 0) { if (!uri.startsWith("/")) { throw new HttpException("Unexpected uri: '" + uri + "' does not start with a slash");
if (uri != null && uri.length() > 0) { if (!uri.startsWith("/")) { throw new HttpException("Unexpected uri: '" + uri + "' does not start with a slash");
targetURI = new URI(target.toURI()); } catch (URISyntaxException usx) { throw new HttpException ("Cannot convert host to URI: " + target, usx); throw new HttpException ("Unable to handle non-Inet proxy address: "+p.address());
throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine());
throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine());
/** {@inheritDoc} */ public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials given for preemptive authentication"); } authState.update(authScheme, creds); } } }
httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); (...) static class PreemptiveAuthInterceptor implements HttpRequestInterceptor { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); // If no auth scheme avaialble yet, try to initialize it // preemptively if (authState.getAuthScheme() == null) { CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) throw new HttpException("No credentials for preemptive authentication"); authState.setAuthScheme(new BasicScheme()); authState.setCredentials(creds); } } }
throw new HttpException("Received no reply from server."); } else if (statusLine.getStatusCode() != HttpStatus.SC_SWITCHING_PROTOCOLS) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); throw new HttpException("Bad Sec-WebSocket-Accept header value."); throw new HttpException("No Sec-WebSocket-Accept header.");
public void process(HttpRequest request, HttpContext ctx) throws HttpException, IOException { try { HttpHost host = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST); final URI requestURI = new URI(host.toURI()).resolve(request.getRequestLine().getUri()); Verb verb = Verb.valueOf(request.getRequestLine().getMethod().toUpperCase()); OAuthRequest oauthRequest = new OAuthRequest(verb, requestURI.toString()); this.service = getOauthService(isOAuth1); service.signRequest(token, oauthRequest); if (signature == OAuthSignature.HEADER) { //If signature is to be added as header for (Map.Entry<String, String> entry : oauthRequest.getHeaders().entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } } else { //If signature is to be added as query param URI uri = new URI(oauthRequest.getCompleteUrl()); ((RequestWrapper) request).setURI(uri); } } catch (URISyntaxException ex) { throw new HttpException("Error rebuilding request URI", ex); } }
String msg = "Invalid request URI: " + requestURI + ": " + e.getMessage(); log.warning(msg); throw new HttpException(msg, e);
private String encode(final String val) throws HttpException { try { return URLEncoder.encode(val, "UTF-8"); } catch (final Throwable t) { throw new HttpException(t.getMessage(), t); } }
public void release() throws HttpException { try { http.close(); } catch (final Throwable t) { throw new HttpException(t.getMessage(), t); } }
/** * The web service always returns a HTTP header code of 200 and communicates errors * through a 'cod' field in the JSON payload of the response body. */ public Observable filterWebServiceErrors() { if (httpCode == 200) { return Observable.just(this); } else { return Observable.error( new HttpException("There was a problem fetching the weather data.")); } } }
private static HttpEntity executeRemoteContent(final HttpClient client, final boolean unsafe, final HttpUriRequest request, final HttpClientContext localContext) throws ClientProtocolException, IOException, ParseException, HttpException { final HttpResponse httpResponse = client.execute(request); if (unsafe || httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return httpResponse.getEntity(); } else { throw new HttpException(httpResponse.getStatusLine().toString() + EntityUtils.toString(httpResponse.getEntity())); } }
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { try { StringBuilder sb = new StringBuilder(); sb.append(BEARER); sb.append(accessTokens.get(tokenId)); request.setHeader(AUTHORIZATION_HEADER_NAME, sb.toString()); } catch (Exception e) { throw new HttpException("Unable to place header 'access_token' into request.", e); } }
@Override /* HttpClientConnection */ public void sendRequestHeader(HttpRequest request) throws HttpException, IOException { try { RequestLine rl = request.getRequestLine(); req = c.request(rl.getMethod(), rl.getUri(), null); for (Header h : request.getAllHeaders()) req.header(h.getName(), h.getValue()); } catch (Exception e) { throw new HttpException(e.getMessage(), e); } }