HttpHost httpHost = URIUtils.extractHost(URI.create(resolvedRedirect)); String sessionState = openIdSessionStateCalculator.calculate("", clientId, httpHost.toURI()); boolean implicit = stream(responseTypes).noneMatch("code"::equalsIgnoreCase); String redirectLocation;
if (locationHeader == null) { throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); if (uri.getFragment() != null) { try { HttpHost target = new HttpHost( uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex);
return URIUtils.createURI( target.getSchemeName(), target.getHostName(), target.getPort(), uri.getRawPath(), uri.getRawQuery(), dropFragment ? null : uri.getRawFragment()); } else { return URIUtils.createURI( null, null,
if (locationHeader == null) { throw new ProtocolException( "Received redirect response " + response.getStatusLine() + " but no location header"); if (!uri.isAbsolute()) { if (!config.isRelativeRedirectsAllowed()) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); final URI requestURI = new URI(request.getRequestLine().getUri()); final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false); uri = URIUtils.resolve(absoluteRequestURI, uri); throw new ProtocolException(ex.getMessage(), ex);
public AbstractHtmlClientImpl(String baseUrl, String user, String password) throws URISyntaxException { this.baseUrl = new URI(baseUrl); HttpHost targetHost = URIUtils.extractHost(this.baseUrl); BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(user, password)); this.client = HttpClientBuilder.create() .setDefaultCredentialsProvider(credsProvider) .setRedirectStrategy(new LaxRedirectStrategy()) .build(); }
public HttpUriRequest getHttpRequest() throws IllegalArgumentException, URISyntaxException, UnsupportedEncodingException { if("GET".equalsIgnoreCase(method)) { final String query = URLEncodedUtils.format(parameters, "UTF-8"); final URI uri = URIUtils.createURI(this.uri.getScheme(), this.uri.getHost(), this.uri.getPort(), this.uri.getPath(), query, null); return new HttpGet(uri); } else if("POST".equalsIgnoreCase(method)) { final HttpPost post = new HttpPost(uri); post.setEntity(new UrlEncodedFormEntity(parameters)); return post; } else { throw new IllegalArgumentException(method + " is not a supported HTTP method."); } }
Args.notNull(baseURI, "Base URI"); Args.notNull(reference, "Reference URI"); final String s = reference.toASCIIString(); if (s.startsWith("?")) { String baseUri = baseURI.toASCIIString(); final int i = baseUri.indexOf('?'); baseUri = i > -1 ? baseUri.substring(0, i) : baseUri; return URI.create(baseUri + s); return normalizeSyntax(resolved); } catch (URISyntaxException ex) { throw new IllegalArgumentException(ex);
/** * Resolves a URI reference against a base URI. Work-around for bug in * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI the base URI * @param reference the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, final String reference) { return URIUtils.resolve(baseURI, URI.create(reference)); }
protected void initTarget() throws ServletException { targetUri = getConfigParam(P_TARGET_URI); if (targetUri == null) throw new ServletException(P_TARGET_URI+" is required."); //test it's valid try { targetUriObj = new URI(targetUri); } catch (Exception e) { throw new ServletException("Trying to process targetUri init parameter: "+e,e); } targetHost = URIUtils.extractHost(targetUriObj); }
/** * Resolves a URI reference against a base URI. Work-around for bugs in * java.net.URI (e.g. <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI the base URI * @param reference the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, final URI reference){ Args.notNull(baseURI, "Base URI"); Args.notNull(reference, "Reference URI"); URI ref = reference; final String s = ref.toString(); if (s.startsWith("?")) { return resolveReferenceStartingWithQueryString(baseURI, ref); } final boolean emptyReference = s.length() == 0; if (emptyReference) { ref = URI.create("#"); } URI resolved = baseURI.resolve(ref); if (emptyReference) { final String resolvedString = resolved.toString(); resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#'))); } return normalizeSyntax(resolved); }
public static void markForumAsRead(IHttpClient httpClient, CharSequence forumId) throws Throwable { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("act", "login")); qparams.add(new BasicNameValuePair("CODE", "04")); qparams.add(new BasicNameValuePair("f", forumId.toString())); qparams.add(new BasicNameValuePair("fromforum", forumId.toString())); URI uri = URIUtils.createURI("http", "4pda.ru", -1, "/forum/index.php", URLEncodedUtils.format(qparams, "UTF-8"), null); httpClient.performGet(uri.toString()); } }
/** * Sets base path. Also set the host, based on if the path was Absolute * @param path Calendar Collection Root */ public void setCalendarCollectionRoot(String path) { URI temp = URI.create(path); if(temp.isAbsolute()) setHttpHost(URIUtils.extractHost(temp)); this.calendarCollectionRoot = UrlUtils.removeDoubleSlashes(UrlUtils.ensureTrailingSlash(temp.getPath())); }
/** * It configures the cookie domain with the domain of the Apache CloudStack that is being accessed. * The domain is extracted from {@link #url} variable. */ protected void configureDomainForCookie(BasicClientCookie cookie) { try { HttpHost httpHost = URIUtils.extractHost(new URI(url)); String domain = httpHost.getHostName(); cookie.setDomain(domain); } catch (URISyntaxException e) { throw new ApacheCloudStackClientRuntimeException(e); } }
/** * Creates absolute request URI with full path from passed in context. */ @Nonnull private URI getRequestURI(final HttpContext context) { final HttpClientContext clientContext = HttpClientContext.adapt(context); final HttpRequest httpRequest = clientContext.getRequest(); final HttpHost target = clientContext.getTargetHost(); try { URI uri; if (httpRequest instanceof HttpUriRequest) { uri = ((HttpUriRequest) httpRequest).getURI(); } else { uri = URI.create(httpRequest.getRequestLine().getUri()); } return uri.isAbsolute() ? uri : URIUtils.resolve(URI.create(target.toURI()), uri); } catch (Exception e) { log.warn("Could not create absolute request URI", e); return URI.create(target.toURI()); } } }
public ClientAuthorizationRequest(final HttpRequest httpRequest) { this.httpRequest = httpRequest; if (httpRequest instanceof HttpUriRequest) { URI uri = ((HttpUriRequest) httpRequest).getURI(); HttpHost httpHost = URIUtils.extractHost(uri); this.host = httpHost == null ? null : httpHost.toHostString(); this.uri = uri.getPath() + (uri.getRawQuery() == null ? "" : "?".concat(uri.getRawQuery())); } else { this.uri = null; this.host = null; } }
protected void rewriteRequestURI( final RequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { HttpHost target = route.getTargetHost(); uri = URIUtils.rewriteURI(uri, target); request.setURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null); request.setURI(uri); } } } catch (URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
static void rewriteRequestURI( final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { try { URI uri = request.getURI(); if (uri != null) { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null, true); } else { uri = URIUtils.rewriteURI(uri); } request.setURI(uri); } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
public void consume(Map<String, String> returnResult) { URI location; try { location = URIUtils.resolve(uri, targetHost, redirectLocations); } catch (URISyntaxException e) { //this is not a fatal error throw new IllegalArgumentException("could not determine '" + HttpClientService.FINAL_LOCATION + "': " + e.getMessage(), e); } returnResult.put(HttpClientService.FINAL_LOCATION, location.toASCIIString()); } }
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { target = route.getTargetHost(); if (target.getPort() < 0) { final Scheme scheme = connManager.getSchemeRegistry().getScheme(target); target = new HttpHost(target.getHostName(), scheme.getDefaultPort(), target.getSchemeName()); target, response, this.targetAuthStrategy, targetAuthState, context); HttpHost proxy = route.getProxyHost(); proxy = route.getTargetHost(); redirect.setHeaders(orig.getAllHeaders()); final HttpHost newTarget = URIUtils.extractHost(uri); if (newTarget == null) { throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
private HttpHost determineTarget(HttpUriRequest request) throws IllegalStateException { HttpHost target = null; URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) { throw new IllegalStateException("URI does not specify a valid host name: " + requestURI); } } return target; } public void makeInvoke(Server server, HttpUriRequest request, HTTPHandler handler){