throws HttpException, IOException { HttpHost proxy = route.getProxyHost(); HttpHost target = route.getTargetHost(); HttpResponse response = null; connect.setParams(this.params); context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target); context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy); context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn); context.setAttribute(ClientContext.TARGET_AUTH_STATE, response.setParams(this.params); this.requestExec.postProcess(response, this.httpProcessor, context); int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); int status = response.getStatusLine().getStatusCode(); // can't be null
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
Args.notNull(credentials, "Credentials"); HttpHost host = target; if (host.getPort() <= 0) { host = new HttpHost(host.getHostName(), 80, host.getSchemeName()); final HttpRoute route = new HttpRoute( host, this.requestConfig.getLocalAddress(), proxy, false, TunnelType.TUNNELLED, LayerType.PLAIN); final int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } else { connect.removeHeaders(AUTH.PROXY_AUTH_RESP); } else { break; final int status = response.getStatusLine().getStatusCode();
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())); } }
final int timeout = config.getConnectTimeout(); final HttpHost target = route.getTargetHost(); final HttpHost proxy = route.getProxyHost(); HttpResponse response = null; final String authority = target.toHostString(); final HttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion()); connect.removeHeaders(AUTH.PROXY_AUTH_RESP); this.authenticator.generateAuthResponse(connect, proxyAuthState, context); final int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); if (config.isAuthenticationEnabled()) { if (this.authenticator.isAuthenticationRequested(proxy, response, this.proxyAuthStrategy, proxyAuthState, context)) { this.log.debug("Connection kept alive"); final HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); } else { final int status = response.getStatusLine().getStatusCode();
throws HttpException, IOException { HttpHost proxy = route.getProxyHost(); HttpHost target = route.getTargetHost(); HttpResponse response = null; connect.addHeader(HTTP.USER_AGENT, agent); connect.addHeader(HTTP.TARGET_HOST, target.toHostString()); int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); context.getAttribute(ClientContext.CREDS_PROVIDER); this.log.debug("Connection kept alive"); HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); int status = response.getStatusLine().getStatusCode();
void post(String content) throws IOException, HttpException { HttpPost post = new HttpPost(url); if (content != null) { httpclient = new DefaultHttpClient(); HttpEntity entity = new StringEntity(content, ContentType.APPLICATION_JSON); post.setEntity(entity); post.setHeader(new BasicHeader("Content-Type", "application/json")); HttpResponse response = httpclient.execute(post); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) { throw new HttpException(response.getStatusLine().toString()); } } }
@Override public void process(HttpResponse response, HttpContext context) throws HttpException, IOException { if (response.getStatusLine().getStatusCode() != 401) { Header[] signatures = response.getHeaders(HEADER_SIGNATURE); if (signatures == null || signatures.length != 1) { throw new HttpException("response is missing (or has more than one) " + HEADER_SIGNATURE + " header"); } RestAuthCredential credentials = getCredentials(context); if (credentials != null) { RESTResponseSigner responseSigner = new RESTResponseSigner((String) context.getAttribute(HEADER_NONCE), (String) context.getAttribute(REQUEST_AUTHZ), response.getStatusLine().getStatusCode()); Header[] excludeBodyHeaders = response.getHeaders(HEADER_EXCLUDEBODY); responseSigner.setExcludeContent(excludeBodyHeaders.length > 0 && Boolean.parseBoolean(excludeBodyHeaders[0].getValue())); HttpEntity entity = loadEntity(response, responseSizeLimit); byte[] content = getContent(entity); if (content != null) { responseSigner.setContent(content); } try { verifySignature(signatures[0].getValue(), responseSigner.getDataToSign(), credentials.getServerKey(), credentials.getDigestAlgorithm()); } catch (InvalidKeyException e) { throw new HttpException(e.getMessage(), e); } catch (SignatureException e) { throw new HttpException("Invalid response signature"); } } } }
public void logout(String token) { HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(LOG_ENDPOINT); LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: [" + LOG_ENDPOINT + "]"); NameValuePair[] data = { new BasicNameValuePair("subjectid", token) }; UrlEncodedFormEntity entity = null; try { entity = new UrlEncodedFormEntity(Arrays.asList(data), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } post.setEntity(entity); try { HttpResponse response1 = httpClient.execute(post); if (response1.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(response1.getStatusLine().toString()); } } catch (HttpException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } }
final InetAddress local = config.getLocalAddress(); HttpHost proxy = config.getProxy(); if (proxy == null) { proxy = determineProxy(host, request, context); if (host.getPort() <= 0) { try { target = new HttpHost( host.getHostName(), this.schemePortResolver.resolve(host), host.getSchemeName()); } catch (final UnsupportedSchemeException ex) { throw new HttpException(ex.getMessage()); final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { return new HttpRoute(target, local, secure); } else { return new HttpRoute(target, local, proxy, secure);
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.");
private int doMkCol( String url ) throws IOException { Repository repo = getRepository(); HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() ); AuthScope targetScope = getBasicAuthScope().getScope( targetHost ); if ( getCredentialsProvider().getCredentials( targetScope ) != null ) { BasicScheme targetAuth = new BasicScheme(); getAuthCache().put( targetHost, targetAuth ); } HttpMkcol method = new HttpMkcol( url ); try ( CloseableHttpResponse closeableHttpResponse = execute( method ) ) { return closeableHttpResponse.getStatusLine().getStatusCode(); } catch ( HttpException e ) { throw new IOException( e.getMessage(), e ); } finally { if ( method != null ) { method.releaseConnection(); } } }
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER); HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (authScheme != null) { Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); if (creds == null) { throw new HttpException("No credentials for preemptive authentication");
throws HttpException, IOException { log.fine("Processing HTTP request: " + httpRequest.getRequestLine().toString()); String requestMethod = httpRequest.getRequestLine().getMethod(); String requestURI = httpRequest.getRequestLine().getUri(); String msg = "Invalid request URI: " + requestURI + ": " + e.getMessage(); log.warning(msg); throw new HttpException(msg, e); httpResponse.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); httpResponse.setStatusLine( new BasicStatusLine( new ProtocolVersion("HTTP", 1, responseMsg.getOperation().getHttpMinorVersion()), log.fine("Response status line: " + httpResponse.getStatusLine());
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(), null); this.service = (OAuth10aService) getOauthService(isOAuth1, addEmptyTokenToBaseString); request.setHeader(entry.getKey(), entry.getValue()); throw new HttpException("Error rebuilding request URI", ex);
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); if (!isCookieEnabled || ((httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) == null && (cookieStore == null || (cookieStore != null && Utils.needToSendCredentials(cookieStore, cookieName, isSSL)))) || (httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) != null && httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY). equals(Utils.HIVE_SERVER2_RETRY_TRUE)))) { httpRequest.addHeader(entry.getKey(), entry.getValue()); Header cookieHeaderServer = httpRequest.getFirstHeader("Cookie"); if ((cookieHeaderServer != null) && (cookieHeaderServer.getValue() != null)) { cookieHeaderKeyValues = cookieHeaderServer.getValue(); cookieHeaderKeyValues = cookieHeaderKeyValues.substring(1); httpRequest.addHeader("Cookie", cookieHeaderKeyValues); throw new HttpException(e.getMessage(), e);
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()); result = new HttpHost(getHost(isa), isa.getPort());
@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); } }
credentials.setTimeDifferential(timeDifferential); RequestLine requestLine = request.getRequestLine(); RESTRequestSigner requestSigner = new RESTRequestSigner(requestLine.getMethod(), requestLine.getUri(), timeDifferential != null ? timeDifferential : 0, credentials.getIdentity()); request.addHeader(HEADER_NONCE, requestSigner.getNonce()); context.setAttribute(HEADER_NONCE, requestSigner.getNonce()); request.addHeader(HEADER_TIMESTAMP, requestSigner.getTimestamp()); request.addHeader(HEADER_IDENTITY, credentials.getIdentity()); context.setAttribute(REQUEST_AUTHZ, signature); request.addHeader(HEADER_SIGNATURE, signature); } catch (Exception e) { throw new HttpException(e.getMessage(), e);
ConnRouteParams.getForcedRoute(request.getParams()); if (route != null) { return route; ConnRouteParams.getLocalAddress(request.getParams()); final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams()); schm = this.schemeRegistry.getScheme(target.getSchemeName()); } catch (final IllegalStateException ex) { throw new HttpException(ex.getMessage()); route = new HttpRoute(target, local, secure); } else { route = new HttpRoute(target, local, proxy, secure);