protected final ResourceAddress resolve(String oldPath, String newPath) { URI addressURI = getResource(); String externalURI = getExternalURI(); boolean newPathDiffersFromOld = !oldPath.equals(newPath); if ( !newPathDiffersFromOld ) { return this; } boolean shouldResolveNewPath = oldPath.equals(addressURI.getPath()); if (!shouldResolveNewPath) { return this; } URI newResourceURI = addressURI.resolve(newPath); String newExternalURI = URIUtils.resolve(externalURI, newPath); ResourceOptions newOptions = FACTORY.newResourceOptions(this); resolve(oldPath, newPath, newOptions); String externalUriToString = newExternalURI; String newResourceUriToString = URIUtils.uriToString(newResourceURI); return factory.newResourceAddress0(externalUriToString, newResourceUriToString, newOptions); }
private List<ResourceAddress> asResourceAddressList(ResourceAddress addr) { List<ResourceAddress> result = new ArrayList<>(); List<ResourceAddress> topLevelAddresses = new ArrayList<>(); ResourceAddress cursor = addr; do { topLevelAddresses.add(cursor); cursor = cursor.getOption(ResourceAddress.ALTERNATE); } while (cursor != null); //recurse for ( ResourceAddress resourceAddress: topLevelAddresses ) { ResourceAddress transport = resourceAddress.getTransport(); if ( transport != null ) { for (ResourceAddress transportAddress: asResourceAddressList(transport)) { ResourceOptions newResultOptions = ResourceOptions.FACTORY.newResourceOptions(resourceAddress); newResultOptions.setOption(TRANSPORT, transportAddress); ResourceAddress newResult = addressFactory.newResourceAddress(resourceAddress.getExternalURI(), newResultOptions); result.add(newResult); } } else { result.add(resourceAddress); } } return result; } }
private ResourceAddress createCandidateAddress(IoSession session, HttpRequestMessage httpRequest, String nextProtocol) { URI requestURI = httpRequest.getRequestURI(); String authority = httpRequest.getHeader(HEADER_HOST); String scheme = httpRequest.isSecure() ? "https" : "http"; // handle missing Host header if (authority == null) { return null; } URI candidateURI = URI.create(format("%s://%s/", scheme, authority)).resolve(requestURI); ResourceAddress transport = LOCAL_ADDRESS.get(session); if (transport == null) { throw new NullPointerException("transport"); } ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(NEXT_PROTOCOL, nextProtocol); options.setOption(TRANSPORT, transport); return addressFactory.newResourceAddress(URIUtils.uriToString(candidateURI), options); }
private void setOptions(T address, String location, ResourceOptions options, Object qualifier) { // default the transport ResourceAddress transport = options.getOption(TRANSPORT); String transportURI = options.getOption(TRANSPORT_URI); if (transport == null && addressFactory != null) { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(options); if (transportURI == null) { ResourceFactory factory = getTransportFactory(); if (factory != null) { transportURI = factory.createURI(location); newOptions.setOption(TRANSPORT_URI, transportURI); } } if (transportURI != null) { // TODO: make ResourceOptions hierarchical to provide options here? ResourceOptions transportOptions = ResourceOptions.FACTORY.newResourceOptions(); transportOptions.setOption(NEXT_PROTOCOL, getProtocolName()); URI locationURI = URI.create(location); transportOptions.setOption(TRANSPORTED_URI, locationURI); transport = addressFactory.newResourceAddress(transportURI, transportOptions); } newOptions.setOption(TRANSPORT, transport); options = newOptions; } setOptions(address, options, qualifier); }
private ResourceAddress httpxeAddressNoSecurity(ResourceAddress httpxeAddress, IdentityResolver resolver) { // Remove REALM_NAME option at http layer (upstream and downstream requests shouldn't have to // go through authentication/authorization) ResourceAddress httpAddress = httpxeAddress.getTransport(); ResourceOptions noSecurityOptions = new NoSecurityResourceOptions(httpAddress); noSecurityOptions.setOption(ResourceAddress.IDENTITY_RESOLVER, resolver); ResourceAddress httpAddressNoSecurity = resourceAddressFactory.newResourceAddress( httpAddress.getExternalURI(), noSecurityOptions, httpAddress.getOption(ResourceAddress.QUALIFIER)); // Remove REALM_NAME option at httpxe layer but preserve all other options like // ORIGIN_SECURITY etc. Otherwise, upstream and downstream requests will be subjected // to different origin security constraints. Then finally add http as transport to httpxe ResourceOptions httpxeOptions = ResourceOptions.FACTORY.newResourceOptions(httpxeAddress); httpxeOptions.setOption(TRANSPORT, httpAddressNoSecurity); httpxeOptions.setOption(ResourceAddress.IDENTITY_RESOLVER, resolver); httpxeOptions = new NoSecurityResourceOptions(httpxeOptions); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(httpxeAddress.getResource()), httpxeOptions); }
private ResourceAddress getSslSessionLocalAddress(IoSession session) { // note: bound address is unified in SSL options during bind to avoid conflicts like different cipher suites ResourceAddress boundAddress = SslAcceptor.SSL_RESOURCE_ADDRESS.remove(session); assert (boundAddress != null); // construct the candidate address with observed transport and next protocol String candidateURI = boundAddress.getExternalURI(); ResourceOptions candidateOptions = ResourceOptions.FACTORY.newResourceOptions(boundAddress); candidateOptions.setOption(NEXT_PROTOCOL, NEXT_PROTOCOL_KEY.get(session)); candidateOptions.setOption(TRANSPORT, LOCAL_ADDRESS.get(session)); ResourceAddress candidateAddress = resourceAddressFactory.newResourceAddress(candidateURI, candidateOptions); // lookup the binding for this candidate address Binding binding = bindings.getBinding(candidateAddress); return (binding != null) ? binding.bindAddress() : null; }
private ResourceAddress createWsrRtmpAddress(ResourceAddress address) { // wsr[wsr/1.0] | tcp or wsr[wsr/1.0] | ssl // so find http[http/1.1] layer's transport either way and you'll get ssl or tcp. ResourceAddress wsrRtmpTransportAddress; wsrRtmpTransportAddress = address.findTransport("http[http/1.1]").getTransport(); ResourceOptions wsrRtmpTransportAddressOptions = ResourceOptions.FACTORY.newResourceOptions(wsrRtmpTransportAddress); wsrRtmpTransportAddressOptions.setOption(NEXT_PROTOCOL, "rtmp/1.0"); wsrRtmpTransportAddressOptions.setOption(ResourceAddress.ALTERNATE, null); wsrRtmpTransportAddress = resourceAddressFactory.newResourceAddress(wsrRtmpTransportAddress.getExternalURI(), wsrRtmpTransportAddressOptions); ResourceOptions wsrRtmpAddressOptions = ResourceOptions.FACTORY.newResourceOptions(address); wsrRtmpAddressOptions.setOption(TRANSPORT, wsrRtmpTransportAddress); return resourceAddressFactory.newResourceAddress(address.getExternalURI(), wsrRtmpAddressOptions); }
private ResourceAddress getResourcesAddress(HttpBinding newHttpBinding) { ResourceAddress bindAddress = newHttpBinding.bindAddress(); String location = bindAddress.getExternalURI(); String resourcesURI = URIUtils.resolve(location, "/;resource"); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT_URI, bindAddress.getOption(TRANSPORT_URI)); options.setOption(TRANSPORT, bindAddress.getOption(TRANSPORT)); options.setOption(TEMP_DIRECTORY, bindAddress.getOption(TEMP_DIRECTORY)); options.setOption(NEXT_PROTOCOL, bindAddress.getOption(NEXT_PROTOCOL)); options.setOption(ORIGIN_SECURITY, bindAddress.getOption(ORIGIN_SECURITY)); options.setOption(GATEWAY_ORIGIN_SECURITY, bindAddress.getOption(GATEWAY_ORIGIN_SECURITY)); options.setOption(BALANCE_ORIGINS, bindAddress.getOption(BALANCE_ORIGINS)); return addressFactory.newResourceAddress(resourcesURI, options); }
public NoSecurityResourceOptions(ResourceOptions defaultsAddress) { options = ResourceOptions.FACTORY.newResourceOptions(defaultsAddress); }
public ResourceAddress newResourceAddress(ResourceAddress uriAddress, ResourceAddress transportAddress) { ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(TRANSPORT, transportAddress); options.setOption(NEXT_PROTOCOL, uriAddress.getOption(NEXT_PROTOCOL)); return newResourceAddress(uriToString(uriAddress.getResource()), options); }
public ResourceAddress newResourceAddress(String location, String nextProtocol) { if (nextProtocol != null) { ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(); options.setOption(NEXT_PROTOCOL, nextProtocol); return newResourceAddress(location, options); } else { return newResourceAddress(location); } }
private ResourceAddress createReadAddress(URI readUri, HttpSession transport, WsebSession wsebSession) { ResourceAddress httpxeAddress = REMOTE_ADDRESS.get(transport); ResourceAddress readAddress = httpxeAddress.resolve(readUri.getPath()); String readSessionIdentity = format("%s#%sd", getTransportMetadata().getName(), wsebSession.getId()); IdentityResolver resolver = new FixedIdentityResolver(readSessionIdentity); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(readAddress); options.setOption(ResourceAddress.IDENTITY_RESOLVER, resolver); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(readAddress.getResource()), options); }
private ResourceAddress getCandidateResourceAddress(IoSessionEx session) { // Build candidate address from session final ResourceAddress candidateTransportAddress = REMOTE_ADDRESS.get(session); URI candidateURI = candidateTransportAddress.getOption(TRANSPORTED_URI); ResourceOptions candidateOptions = ResourceOptions.FACTORY.newResourceOptions(); candidateOptions.setOption(NEXT_PROTOCOL, NEXT_PROTOCOL_KEY.get(session)); candidateOptions.setOption(TRANSPORT, candidateTransportAddress); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(candidateURI), candidateOptions); }
@Override public ResourceOptions newResourceOptions() { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(); newOptions.setOption(NEXT_PROTOCOL, nextProtocol); return newOptions; } });
private ResourceAddress createWriteAddress(URI writeUri, HttpSession transport, WsebSession wsebSession) { ResourceAddress httpxeAddress = REMOTE_ADDRESS.get(transport); ResourceAddress writeAddress = httpxeAddress.resolve(writeUri.getPath()); String writeSessionIdentity = format("%s#%su", getTransportMetadata().getName(), wsebSession.getId()); IdentityResolver resolver = new FixedIdentityResolver(writeSessionIdentity); ResourceOptions options = ResourceOptions.FACTORY.newResourceOptions(writeAddress); options.setOption(ResourceAddress.IDENTITY_RESOLVER, resolver); return resourceAddressFactory.newResourceAddress(URIUtils.uriToString(writeAddress.getResource()), options); }
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); }
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); }
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); }
@Override public ResourceOptions newResourceOptions(ResourceOptions defaults) { ResourceOptions newOptions = ResourceOptions.FACTORY.newResourceOptions(defaults); newOptions.setOption(NEXT_PROTOCOL, nextProtocol); return newOptions; }
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); }