private URI getBaseURI(final URI baseUri) { String stagingHostName = AccessController.doPrivileged(PropertiesHelper.getSystemProperty(JERSEY_TEST_HOST)); if (stagingHostName != null) { return UriBuilder.fromUri(baseUri).host(stagingHostName).build(); } return baseUri; }
private URI getRedirectBaseUri(URI locationURI) { if (locationURI == null) { throw new TransportException("Missing Location header in the redirect reply"); } Matcher pathMatcher = REDIRECT_PATH_REGEX.matcher(locationURI.getPath()); if (pathMatcher.matches()) { return UriBuilder.fromUri(locationURI) .host(dnsService.resolveIp(locationURI.getHost())) .replacePath(pathMatcher.group(1)) .replaceQuery(null) .build(); } logger.warn("Invalid redirect URL {}", locationURI); return null; } }
public Result makeRequest(RemoteInstanceRequestClient client, String methodName, Object... values) { String remoteResponse; String errorMessage; { try { URI remoteUri = UriBuilder .fromPath(getPath()) .scheme(exhibitor.getRestScheme()) .host(hostname) .port(exhibitor.getRestPort()) .path(ClusterResource.class, methodName) .build(values); remoteResponse = client.getWebResource(remoteUri, MediaType.APPLICATION_JSON_TYPE, String.class); errorMessage = ""; } catch ( Exception e ) { remoteResponse = "{}"; errorMessage = e.getMessage(); if ( errorMessage == null ) { errorMessage = "Unknown"; } } } return new Result(remoteResponse, errorMessage); }
private static URI externalUri( UriBuilder builder, String xForwardedHost, String xForwardedProto ) { ForwardedHost forwardedHost = new ForwardedHost( xForwardedHost ); ForwardedProto forwardedProto = new ForwardedProto( xForwardedProto ); if ( forwardedHost.isValid ) { builder.host( forwardedHost.getHost() ); if ( forwardedHost.hasExplicitlySpecifiedPort() ) { builder.port( forwardedHost.getPort() ); } } if ( forwardedProto.isValid() ) { builder.scheme( forwardedProto.getScheme() ); } return builder.build(); }
private URI getBaseURI(final URI baseUri) { String stagingHostName = AccessController.doPrivileged(PropertiesHelper.getSystemProperty(JERSEY_TEST_HOST)); if (stagingHostName != null) { return UriBuilder.fromUri(baseUri).host(stagingHostName).build(); } return baseUri; }
private UriBuilder makeURIAbsolute(URI uri) { UriBuilder uriBuilder = UriBuilder.fromUri(uri); if (!uri.isAbsolute() && uri.getHost() == null) { uriBuilder .scheme(apiEndpoint.getScheme()) .host(apiEndpoint.getHost()) .port(apiEndpoint.getPort()) .replacePath(apiEndpoint.getPath() + uri.toString()); } return uriBuilder; }
public static UriBuilder updateURLWithPlatformValues( UriBuilder builder, String scheme, String host, Integer port ) { if ( StringUtils.isNotBlank( scheme ) && StringUtils.isNotBlank( host ) ) { LOGGER.debug( "Using values from Platform Configuration for Atom Links host[" + host + "], scheme[" + scheme + "], and port[" + port + "]" ); builder.scheme( scheme ); builder.host( host ); if ( port != null ) { builder.port( port ); } } return builder; }
public URI fromResourceUri(URI resourceUri) { URI baseUri = UriBuilder.fromUri(this.baseUri).build(); return UriBuilder.fromUri(resourceUri) .userInfo(baseUri.getUserInfo()) .scheme(baseUri.getScheme()) .host(baseUri.getHost()) .port(baseUri.getPort()) .replacePath(baseUri.getPath()).path(resourceUri.getPath()) .build(); }
private URI constructUrl(URI overrideUrl, String scheme, String host, int port, String path) { if (overrideUrl != null) { return overrideUrl; } checkState(scheme != null, "scheme"); checkState(host != null, "host"); checkState(port != 0, "port"); checkState(path != null, "path"); return UriBuilder.fromPath(path).scheme(scheme).host(host).port(port).build(); }
@Override public URI getSocketUri() { if (this.contextPath.indexOf('/') != -1) { // see GrizzlyWebContainerFactory.create() this.logger.warn("Only first path segment will be used as context path, the rest will be ignored."); } if (this.contextPath.isEmpty()) { this.contextPath = "/"; } String ip = this.local ? IP_LOCAL : IP_GLOBAL; return UriBuilder.fromPath(this.contextPath).scheme("http").host(ip).port(this.serverPort).build(); }
private static String constructPublicUriBase(final String scheme, final String hostName, final int serverPort, final String contextPath) { return UriBuilder.fromPath(contextPath) .scheme(scheme) .host(hostName) .port(serverPort) .build() .normalize() .toString(); }
public static HttpServer startServer(String host, int port) { final ResourceConfig rc = ResourceConfig.forApplicationClass(MyApplication.class); URI baseUri = UriBuilder.fromUri(BASE_URI).host(host).port(port).build(); return GrizzlyHttpServerFactory.createHttpServer(baseUri, rc); }
public static Server startServer(String host, int port) { final ResourceConfig rc = ResourceConfig.forApplicationClass(MyApplication.class); URI baseUri = UriBuilder.fromUri(BASE_URI).host(host).port(port).build(); return JettyHttpContainerFactory.createServer(baseUri, rc); }
public Response buildResponse(final UriInfo uriInfo, final Class<? extends JaxrsResource> theClass, final String getMethodName, final Object objectId) { final UriBuilder uriBuilder = UriBuilder.fromResource(theClass) .path(theClass, getMethodName) .scheme(uriInfo.getAbsolutePath().getScheme()) .host(uriInfo.getAbsolutePath().getHost()) .port(uriInfo.getAbsolutePath().getPort()); final URI location = objectId != null ? uriBuilder.build(objectId) : uriBuilder.build(); return Response.created(location).build(); }
@Override public URI getRequestUri() { if (requestURI == null) { requestURI = delegate.getRequestUriBuilder().scheme(scheme).host(hostname).port(port).build(); } return requestURI; }
@Override public URI getAbsolutePath() { if (absolutePath == null) { absolutePath = delegate.getAbsolutePathBuilder().scheme(scheme).host(hostname).port(port).build(); } return absolutePath; }
private URI getRedirectionUrl(ClusterData differentClusterData) throws MalformedURLException { URL webUrl = null; if (isRequestHttps() && pulsar.getConfiguration().isTlsEnabled() && StringUtils.isNotBlank(differentClusterData.getServiceUrlTls())) { webUrl = new URL(differentClusterData.getServiceUrlTls()); } else { webUrl = new URL(differentClusterData.getServiceUrl()); } return UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build(); }
@Override public URI getBaseUri() { if (baseURI == null) { baseURI = delegate.getBaseUriBuilder().scheme(scheme).host(hostname).port(port).build(); } return baseURI; }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { final String currentLocker = competitive.currentLocker(); final String localIp = NetworkUtils.getLocalIp(); if (!Objects.equals(currentLocker, localIp)) { URI masterLocation = requestContext.getUriInfo().getAbsolutePathBuilder().host(currentLocker).build(); LOGGER.info("Redirect url to {}.", masterLocation); Response response = javax.ws.rs.core.Response.seeOther(masterLocation).build(); requestContext.abortWith(response); } }
@Override public <T> T createClient(Class<T> apiClass, HostName hostName, int port, String pathPrefix, String scheme) { UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme); return createClient(new Params<>(apiClass, uriBuilder.build())); } }