private static URI pathlessUri(URI uri) { try { return new URI(uri.getScheme(), uri.getRawAuthority(), null, null, null); } catch (URISyntaxException e) { throw new Error(e); // Should never happen. } } }
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) { io.netty.handler.codec.http.HttpMethod nettyMethod = io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name()); String authority = this.uri.getRawAuthority(); String path = this.uri.toString().substring(this.uri.toString().indexOf(authority) + authority.length()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, nettyMethod, path, this.body.buffer()); nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost() + ":" + getPort(this.uri)); nettyRequest.headers().set(HttpHeaders.CONNECTION, "close"); headers.forEach((headerName, headerValues) -> nettyRequest.headers().add(headerName, headerValues)); if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) { nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes()); } return nettyRequest; }
private ArmeriaClientHttpRequest createRequest(HttpMethod method, URI uri) { final String scheme = uri.getScheme(); final String authority = uri.getRawAuthority(); final String path = uri.getRawPath(); final String query = uri.getRawQuery(); checkArgument(!Strings.isNullOrEmpty(authority), "URI is not absolute: " + uri); checkArgument(!Strings.isNullOrEmpty(path), "path is undefined: " + uri); final URI baseUri = URI.create(Strings.isNullOrEmpty(scheme) ? authority : scheme + "://" + authority); final HttpClientBuilder builder = new HttpClientBuilder(baseUri); configurators.forEach(c -> c.configure(builder)); final String pathAndQuery = Strings.isNullOrEmpty(query) ? path : path + '?' + query; return new ArmeriaClientHttpRequest(builder.build(), method, pathAndQuery, uri, factoryWrapper); }
private static void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } String rawPath = uri.getRawPath(); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException("Found fragment in URI: " + uri); } }
private void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException(); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException(); } String temp = uri.getScheme(); if (temp == null || !temp.equals("file")) { throw new IllegalArgumentException(); } temp = uri.getRawPath(); if (temp == null || temp.length() == 0) { throw new IllegalArgumentException(); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException(); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException(); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException(); } }
public static String extractHost(URI uri) { // Extract the host part from the URI. String host = uri.getHost(); if (host != null) { return host; } // According to Issue#74, URI.getHost() method returns null in // the following environment when the host part of the URI is // a host name. // // - Samsung Galaxy S3 + Android API 18 // - Samsung Galaxy S4 + Android API 21 // // The following is a workaround for the issue. // Extract the host part from the authority part of the URI. host = extractHostFromAuthorityPart(uri.getRawAuthority()); if (host != null) { return host; } // Extract the host part from the entire URI. return extractHostFromEntireUri(uri.toString()); }
this.ssp = null; if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null;
if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null;
if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null;
if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null;
private FullHttpRequest createFullHttpRequest(HttpHeaders headers) { io.netty.handler.codec.http.HttpMethod nettyMethod = io.netty.handler.codec.http.HttpMethod.valueOf(this.method.name()); String authority = this.uri.getRawAuthority(); String path = this.uri.toString().substring(this.uri.toString().indexOf(authority) + authority.length()); FullHttpRequest nettyRequest = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, nettyMethod, path, this.body.buffer()); nettyRequest.headers().set(HttpHeaders.HOST, this.uri.getHost() + ":" + getPort(this.uri)); nettyRequest.headers().set(HttpHeaders.CONNECTION, "close"); headers.forEach((headerName, headerValues) -> nettyRequest.headers().add(headerName, headerValues)); if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) { nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes()); } return nettyRequest; }
private Client<HttpRequest, HttpResponse> newHttpClient(URI uri, Scheme scheme, ClientOptions options) { try { @SuppressWarnings("unchecked") final Client<HttpRequest, HttpResponse> client = delegate().newClient( new URI(Scheme.of(SerializationFormat.NONE, scheme.sessionProtocol()).uriText(), uri.getRawAuthority(), null, null, null), Client.class, options); return client; } catch (URISyntaxException e) { throw new Error(e); // Should never happen. } }
authority = firstNonNull(uri.getRawAuthority(), FALLBACK_AUTHORITY);
/** * Constructor to create from a URI. * @param uri The URI */ @SuppressWarnings("unchecked") DefaultUriBuilder(URI uri) { this.scheme = uri.getScheme(); this.userInfo = uri.getRawUserInfo(); this.authority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.path = new StringBuilder(); final String rawPath = uri.getRawPath(); if (rawPath != null) { this.path.append(rawPath); } this.fragment = uri.getRawFragment(); final String query = uri.getQuery(); if (query != null) { final Map parameters = new QueryStringDecoder(uri).parameters(); this.queryParams = new MutableConvertibleMultiValuesMap<String>(parameters); } else { this.queryParams = new MutableConvertibleMultiValuesMap<>(); } }
/** * Returns base URL which includes scheme, host, port, Servlet context and servlet paths * @param request current HttpServletRequest * @return base URL */ public static String getBaseURL(HttpServletRequest request) { String reqPrefix = request.getRequestURL().toString(); String pathInfo = request.getPathInfo(); if (!"/".equals(pathInfo) || reqPrefix.contains(";")) { StringBuilder sb = new StringBuilder(); // request.getScheme(), request.getLocalName() and request.getLocalPort() // should be marginally cheaper - provided request.getLocalName() does // return the actual name used in request URI as opposed to localhost // consistently across the Servlet stacks URI uri = URI.create(reqPrefix); sb.append(uri.getScheme()).append("://").append(uri.getRawAuthority()); String contextPath = request.getContextPath(); if (contextPath != null) { sb.append(contextPath); } String servletPath = request.getServletPath(); if (servletPath != null) { sb.append(servletPath); } reqPrefix = sb.toString(); } return reqPrefix; }
if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null;
@Override protected Path filter(final Path f) { URI uri = f.toUri(); return new Path("https", uri.getRawAuthority(), uri.getRawPath()); }
/** * Determines if a given URI contains only a path and does not have a scheme, authority, query, and/or fragment. * @param uri The URI to check to for path status. * @throws NullPointerException if the given URI is <code>null</code>. * @return <code>true</code> if the URI has a path and does not specify a scheme (i.e. the URI is not absolute), authority, query, or fragment. */ public static boolean isPathURI(final URI uri) { requireNonNull(uri, "URI cannot be null"); return uri.getScheme() == null && uri.getRawAuthority() == null && uri.getPath() != null && isPlainURI(uri); //see if there is no scheme, no authority, a path, no query, and no fragment }
URI oldUri; Uri newUri = new Uri.Builder().scheme(oldUri.getScheme()) .encodedAuthority(oldUri.getRawAuthority()) .encodedPath(oldUri.getRawPath()) .query(oldUri.getRawQuery()) .fragment(oldUri.getRawFragment()) .build();
private Client<HttpRequest, HttpResponse> newHttpClient(URI uri, Scheme scheme, ClientOptions options) { try { @SuppressWarnings("unchecked") final Client<HttpRequest, HttpResponse> client = delegate().newClient( new URI(Scheme.of(SerializationFormat.NONE, scheme.sessionProtocol()).uriText(), uri.getRawAuthority(), null, null, null), Client.class, options); return client; } catch (URISyntaxException e) { throw new Error(e); // Should never happen. } }