private static Realm getRealm(final HttpTransactionContext httpTransactionContext) { final Realm realm = httpTransactionContext.getAhcRequest().getRealm(); return realm != null ? realm : httpTransactionContext.provider.getClientConfig().getRealm(); }
private HttpURLConnection createUrlConnection(Request request) throws IOException, URISyntaxException { ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); Proxy proxy = null; if (proxyServer != null || realm != null) { try { proxy = configureProxyAndAuth(proxyServer, realm); } catch (AuthenticationException e) { throw new IOException(e.getMessage()); } } HttpURLConnection urlConnection = (HttpURLConnection) request.getUri().toJavaNetURI().toURL().openConnection(proxy == null ? Proxy.NO_PROXY : proxy); if (request.getUri().getScheme().equals("https")) { HttpsURLConnection secure = (HttpsURLConnection) urlConnection; SSLContext sslContext; try { sslContext = SslUtils.getInstance().getSSLContext(config); } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } secure.setSSLSocketFactory(sslContext.getSocketFactory()); secure.setHostnameVerifier(config.getHostnameVerifier()); } return urlConnection; }
public void operationComplete(ChannelFuture cf) { if (!abortOnThrowable(cf.getCause(), cf.getChannel())) { future.touch(); /** * We need to make sure we aren't in the middle of an authorization process before publishing events as we will re-publish again the same event after the authorization, * causing unpredictable behavior. */ Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : config.getRealm(); boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth(); if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) { if (notifyHeaders) { ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); } else { ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteCompleted(); } } } }
@Override public Realm getRealm() { return delegate.getRealm(); }
private boolean handleHttpResponse(final HttpResponse response,// final Channel channel,// final NettyResponseFuture<?> future,// AsyncHandler<?> handler) throws Exception { HttpRequest httpRequest = future.getNettyRequest().getHttpRequest(); ProxyServer proxyServer = future.getProxyServer(); logger.debug("\n\nRequest {}\n\nResponse {}\n", httpRequest, response); // store the original headers so we can re-send all them to // the handler in case of trailing headers future.setHttpHeaders(response.headers()); future.setKeepAlive(connectionStrategy.keepAlive(httpRequest, response)); NettyResponseStatus status = new NettyResponseStatus(future.getUri(), config, response); int statusCode = response.getStatus().getCode(); Request request = future.getRequest(); Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); NettyResponseHeaders responseHeaders = new NettyResponseHeaders(response.headers()); return exitAfterProcessingFilters(channel, future, handler, status, responseHeaders) || exitAfterHandling401(channel, future, response, request, statusCode, realm) || // exitAfterHandling407(channel, future, response, request, statusCode, proxyServer) || // exitAfterHandling100(channel, future, statusCode) || // exitAfterHandlingRedirect(channel, future, response, request, statusCode, realm) || // exitAfterHandlingConnect(channel, future, request, proxyServer, statusCode, httpRequest) || // exitAfterHandlingStatus(channel, future, response, handler, status) || // exitAfterHandlingHeaders(channel, future, response, handler, responseHeaders) || // exitAfterHandlingBody(channel, future, response, handler); }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
.setRealm(request.getRealm())//
private static Realm getRealm(final HttpTransactionContext httpTransactionContext) { final Realm realm = httpTransactionContext.getAhcRequest().getRealm(); return realm != null ? realm : httpTransactionContext.provider.getClientConfig().getRealm(); }
private static Realm getRealm(final HttpTransactionContext httpTransactionContext) { final Realm realm = httpTransactionContext.getAhcRequest().getRealm(); return realm != null ? realm : httpTransactionContext.provider.getClientConfig().getRealm(); }
private void addAuthorizationHeader(final Request request, final HttpRequestPacket requestPacket) { Realm realm = request.getRealm(); if (realm == null) { realm = config.getRealm(); } if (realm != null && realm.getUsePreemptiveAuth()) { final String authHeaderValue = generateAuthHeader(realm); if (authHeaderValue != null) { requestPacket.addHeader(Header.Authorization, authHeaderValue); } } }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }