protected ResourceAddress(ResourceAddressFactorySpi factory, URI resourceURI) { this(factory, URIUtils.uriToString(resourceURI), resourceURI); }
private String resolve(String uriString) { return uriToString(mockNetworkInterfaceURI.resolve(uriString)).replace(HOST_TEMPLATE, matchedToken); }
/** * Helper method for performing resolve as String * @param uriInitial * @param uriString * @return */ public static String resolve(String uriInitial, String uriString) { try { return uriToString((new URI(uriInitial)).resolve(uriString)); } catch (URISyntaxException e) { try { return (new NetworkInterfaceURI(uriInitial)).resolve(uriString); } catch (IllegalArgumentException ne) { throw new IllegalArgumentException(ne.getMessage(), ne); } } }
/** * 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); } } }
/** * Helper method for modifying URI port * @param uri * @param newPort * @return */ public static String modifyURIPort(String uri, int newPort) { try { URI uriObj = new URI(uri); return uriToString(URLUtils.modifyURIPort(uriObj, newPort)); } catch (URISyntaxException e) { try { return (new NetworkInterfaceURI(uri)).modifyURIPort(newPort); } catch (IllegalArgumentException ne) { throw new IllegalArgumentException(ne.getMessage(), ne); } } }
String uriWithModifiedAuthority = URIUtils.uriToString(modifiedURIAuthority).replace(MOCK_HOST, matchedToken); return uriWithModifiedAuthority;
/** * 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); } } }
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 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); }
URIUtils.uriToString(wseLocalAddressLocation), options);
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 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); }
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); }
String wsLocalAddressLocation = URIUtils.modifyURIScheme(URIUtils.uriToString(resource), schemeName);
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); }
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); }
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 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); }
candidateOptions.setOption(TRANSPORT, httpLocalAddress); ResourceAddress candidateAddress = resourceAddressFactory.newResourceAddress(URIUtils.uriToString(candidateURI), candidateOptions);
resourceAddressFactory.newResourceAddress(URIUtils.uriToString(localAddress.getResource()), options);