String createResolvePath(URI httpUri, final String suffixWithLeadingSlash) { return appendURI(ensureTrailingSlash(httpUri),suffixWithLeadingSlash).getPath(); }
private ResourceAddress createApiHttpAddress(ResourceAddress httpTransport) { String path = URIUtils.getPath(appendURI(ensureTrailingSlash(httpTransport.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); String httpLocation = modifyURIPath(httpTransport.getExternalURI(), path); ResourceOptions httpOptions = ResourceOptions.FACTORY.newResourceOptions(httpTransport); httpOptions.setOption(NEXT_PROTOCOL, null); // terminal endpoint, so next protocol null httpOptions.setOption(ALTERNATE, null); return resourceAddressFactory.newResourceAddress(httpLocation, httpOptions); }
public static URI truncateURI(URI uri, String postfix) { String scheme = uri.getScheme(); String authority = uri.getAuthority(); String path = uri.getPath(); String query = uri.getQuery(); String fragment = uri.getFragment(); assert (path.endsWith(postfix)); path = (path.equals(postfix) ? SINGLE_SLASH : path.substring(0, path.length() - postfix.length())); try { return new URI(scheme, authority, replaceMultipleSlashesWithSingleSlash(path), query, fragment); } catch (URISyntaxException x) { IllegalArgumentException y = new IllegalArgumentException(); y.initCause(x); throw y; } }
resource = truncateURI(resource, CREATE_SUFFIX); resource = truncateURI(resource, CREATE_TEXT_SUFFIX); resource = truncateURI(resource, CREATE_TEXT_ESCAPED_SUFFIX); resource = truncateURI(resource, CREATE_MIXED_SUFFIX); resource = truncateURI(resource, CREATE_MIXED_TEXT_SUFFIX); resource = truncateURI(resource, CREATE_MIXED_TEXT_ESCAPED_SUFFIX); options.setOption(NEXT_PROTOCOL, nextProtocol); URI wseLocalAddressLocation = modifyURIScheme(resource, "ws"); ResourceAddress candidate = resourceAddressFactory.newResourceAddress( URIUtils.uriToString(wseLocalAddressLocation), options);
URI remoteLocation = ensureTrailingSlash(modifyURIScheme(remoteBridgeAddress.getResource(), "wse")); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT, remoteBridgeAddress);
/** * Helper method for modifying URI scheme * @param uri * @param newScheme * @return */ public static String modifyURIScheme(String uri, String newScheme) { try { URI uriObj = new URI(uri); return uriToString(URLUtils.modifyURIScheme(uriObj, newScheme)); } catch (URISyntaxException e) { try { return (new NetworkInterfaceURI(uri)).modifyURIScheme(newScheme); } catch (IllegalArgumentException ne) { throw new IllegalArgumentException(ne.getMessage(), ne); } } }
/** * Follows a redirect. * @param httpSession * @param session * @return * @throws URISyntaxException */ private DefaultConnectFuture followRedirect(DefaultHttpSession httpSession, IoSessionEx session) throws URISyntaxException { HashMap<ResourceOption<?>, Object> overrides = new HashMap<>(); // fix redirects Integer maxRedirects = new Integer((httpSession.getRemoteAddress().getOption(MAXIMUM_REDIRECTS)) - 1); overrides.put(MAXIMUM_REDIRECTS, maxRedirects); // fix location URI newLocation = new URI(httpSession.getReadHeader("location")); URI oldLocation = httpSession.getRequestURL(); newLocation = resolveFragement(newLocation, oldLocation); if (!newLocation.isAbsolute()) { newLocation = URLUtils.modifyURIPath(oldLocation, newLocation.getPath()); } String oldQuery = oldLocation.getQuery(); if (oldQuery != null && appendQueryWhenFollowingRedirect) { newLocation = URLUtils.modifyURIQuery(newLocation, oldQuery); } httpSession.setRequestURI(URLUtils.getPathAndQueryURI(newLocation)); ResourceAddress newConnectAddress = addressFactory.newResourceAddress(newLocation.toString(), new WrappedResourceOptionsForConnectionRetry(httpSession, overrides)); return retryConnect(httpSession, session, newConnectAddress); }
/** * Helper method for modiffying the URI path * @param uri * @param newPath * @return */ public static String modifyURIPath(String uri, String newPath) { try { URI uriObj = new URI(uri); return uriToString(URLUtils.modifyURIPath(uriObj, newPath)); } catch (URISyntaxException e) { try { return (new NetworkInterfaceURI(uri)).modifyURIPath(newPath); } catch (IllegalArgumentException ne) { throw new IllegalArgumentException(ne.getMessage(), ne); } } }
private ResourceAddress createCookiesAddress(ResourceAddress httpAddress) { // /;e/cookies is a terminal endpoint so next protocol should == null ResourceOptions cookieOptions = ResourceOptions.FACTORY.newResourceOptions(httpAddress); cookieOptions.setOption(NEXT_PROTOCOL, null); cookieOptions.setOption(TRANSPORT, httpAddress.getTransport()); cookieOptions.setOption(BIND_ALTERNATE, Boolean.FALSE); URI cookiesLocation = appendURI(httpAddress.getResource(), COOKIES_SUFFIX); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(cookiesLocation), cookieOptions); }
URI resource = session.getLocalAddress().getResource(); if (resource.getPath().endsWith(CREATE_SUFFIX)) { resource = truncateURI(resource, CREATE_SUFFIX); URI wsLocalAddressLocation = URLUtils.modifyURIScheme(resource, schemeName);
List<String> availableBalanceeURIs = (List<String>) balancerKeys; URI balanceURI = URI.create(availableBalanceeURIs.get((int) (Math.random() * availableBalanceeURIs.size()))); String redirectURI = URLUtils.modifyURIScheme(balanceURI, balanceURI.getScheme().replaceFirst("^ws", "http")).toString(); session.setStatus(HttpStatus.REDIRECT_FOUND); session.setWriteHeader("location", redirectURI);
String createResolvePath(URI httpUri, final String suffixWithLeadingSlash) { return appendURI(ensureTrailingSlash(httpUri),suffixWithLeadingSlash).getPath(); }
private ResourceAddress createApiHttpxeAddress(ResourceAddress httpxeTransport) { String path = URIUtils.getPath(appendURI(ensureTrailingSlash(httpxeTransport.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); httpxeTransport = httpxeTransport.resolve(path); String httpxeLocation = modifyURIPath(httpxeTransport.getExternalURI(), path); ResourceOptions httpxeOptions = ResourceOptions.FACTORY.newResourceOptions(httpxeTransport); httpxeOptions.setOption(NEXT_PROTOCOL, null); // terminal endpoint, so next protocol null return resourceAddressFactory.newResourceAddress(httpxeLocation, httpxeOptions); }
URI candidateURI = URLUtils.modifyURIScheme(httpLocalAddress.getResource(), "sse"); ResourceOptions candidateOptions = ResourceOptions.FACTORY.newResourceOptions(); candidateOptions.setOption(TRANSPORT, httpLocalAddress);
if (WsProtocol.WS.equals(protocol) || WsProtocol.WSS.equals(protocol)) { httpURIs.add(buildURIAsString(httpScheme, httpAuthority, URLUtils.replaceMultipleSlashesWithSingleSlash(httpPath + WsebAcceptor.EMULATED_SUFFIX), httpQuery, null));
private String createResolvePath(String httpUri, final String suffixWithLeadingSlash) { return URIUtils.getPath(appendURI(ensureTrailingSlash(httpUri),suffixWithLeadingSlash)); }
private ResourceAddress createApiAddress(ResourceAddress address) { ResourceAddress transport = address.getTransport(); ResourceOptions apiAddressOptions = ResourceOptions.FACTORY.newResourceOptions(transport); // /;api/operation is a terminal endpoint so next protocol should be null apiAddressOptions.setOption(NEXT_PROTOCOL, null); // even if the address has an alternate, do not bind the alternate apiAddressOptions.setOption(BIND_ALTERNATE, Boolean.FALSE); String path = URIUtils.getPath(appendURI(ensureTrailingSlash(address.getExternalURI()), HttpProtocolCompatibilityFilter.API_PATH)); String apiLocation = URIUtils.modifyURIPath(URIUtils.uriToString(transport.getResource()), path); return resourceAddressFactory.newResourceAddress(apiLocation, apiAddressOptions); }
String uri = appendURI(ensureTrailingSlash(httpxeAddress.getExternalURI()), CREATE_SUFFIX); String query = URIUtils.getQuery(uri); String pathAndQuery = URIUtils.getPath(uri);