List of usage examples for java.net URI getRawFragment
public String getRawFragment()
From source file:org.ldp4j.tutorial.client.CachedRepresentationManager.java
private File createFile(String resource) { URI uri = URI.create(resource); StringBuilder builder = new StringBuilder(); builder.append(uri.getScheme()).append("_"); String userInfo = uri.getUserInfo(); if (userInfo != null) { builder.append(userInfo).append("@"); }//w w w. ja v a 2 s.co m builder.append(uri.getHost()); if (uri.getPort() >= 0) { builder.append("_").append(uri.getPort()); } if (uri.getPath() != null) { builder.append(uri.getRawPath().replace("/", "_")); } if (uri.getQuery() != null) { builder.append("?").append(uri.getRawQuery()); } if (uri.getFragment() != null) { builder.append("#").append(uri.getRawFragment()); } builder.append(".dat"); File file = new File(this.cacheDirectory, builder.toString()); return file; }
From source file:com.gistlabs.mechanize.util.apache.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.android.idtt.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8)); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.box.restclientv2.httpclientsupport.HttpClientURIBuilder.java
private void digestURI(final URI uri) throws URISyntaxException { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), HttpClientConsts.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:org.mcxiaoke.commons.http.util.URIBuilderEx.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), URIUtilsEx.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.machinepublishers.jbrowserdriver.StreamConnection.java
private void exec() throws IOException { try {//ww w.jav a 2 s . c o m if (exec.compareAndSet(false, true)) { connect(); if (req.get() != null) { if ("POST".equals(method.get())) { ((HttpPost) req.get()).setEntity(new ByteArrayEntity(reqData.get().toByteArray())); } else if ("PUT".equals(method.get())) { ((HttpPut) req.get()).setEntity(new ByteArrayEntity(reqData.get().toByteArray())); } response.set(client.get().execute(req.get(), context.get())); if (response.get() != null && response.get().getEntity() != null) { entity.set(response.get().getEntity()); response.get().setHeader("Cache-Control", "no-store, no-cache"); } if (this.urlFragment != null && response.get() != null) { Header header = response.get().getFirstHeader("Location"); String location = header == null ? null : header.getValue(); if (!StringUtils.isEmpty(location)) { try { URI uri = new URIBuilder(location).build(); if (StringUtils.isEmpty(uri.getRawFragment())) { String path = uri.getPath(); path = StringUtils.isEmpty(path) ? "/" : path; response.get().setHeader("Location", new URIBuilder(location).setPath(path) .setFragment(this.urlFragment).build().toString()); } } catch (Throwable t) { if (!location.contains("#")) { int fromIndex = location.indexOf("//") + 2; if (fromIndex <= location.length() && location.substring(fromIndex).contains("/")) { response.get().setHeader("Location", new StringBuilder().append(location) .append("#").append(this.urlFragment).toString()); } else { response.get().setHeader("Location", new StringBuilder().append(location) .append("/#").append(this.urlFragment).toString()); } } } } } } } } catch (Throwable t) { throw new IOException(t.getMessage() + ": " + urlString, t); } }
From source file:com.mcxiaoke.next.http.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Charsets.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.nesscomputing.service.discovery.client.ServiceURI.java
public ServiceURI(final URI uri) throws URISyntaxException { if (!"srvc".equals(uri.getScheme())) { throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs"); }/* w ww. j a v a2 s . com*/ if (!StringUtils.startsWith(uri.getSchemeSpecificPart(), "//")) { throw new URISyntaxException(uri.toString(), "ServiceURI only supports srvc:// URIs"); } final String schemeSpecificPart = uri.getSchemeSpecificPart().substring(2); final int slashIndex = schemeSpecificPart.indexOf('/'); if (slashIndex == -1) { throw new URISyntaxException(uri.toString(), "ServiceURI requires a slash at the end of the service!"); } final int colonIndex = schemeSpecificPart.indexOf(':'); if (colonIndex == -1 || colonIndex > slashIndex) { serviceName = schemeSpecificPart.substring(0, slashIndex); serviceType = null; } else { serviceName = schemeSpecificPart.substring(0, colonIndex); serviceType = schemeSpecificPart.substring(colonIndex + 1, slashIndex); } path = uri.getRawPath(); query = uri.getRawQuery(); fragment = uri.getRawFragment(); }
From source file:io.curly.artifact.web.remote.PaperclipLinkCatcher.java
private String reconstructURI(String host, String href) { URI original; try {/*ww w.ja v a2 s.com*/ original = new URI(href); } catch (URISyntaxException e) { throw new IllegalArgumentException("Cannot create URI from: " + href); } int port = 80; if ("https".equals(original.getScheme())) { port = 443; } if (host.contains(":")) { String[] pair = host.split(":"); host = pair[0]; port = Integer.valueOf(pair[1]); } if (host.equals(original.getHost()) && port == original.getPort()) { return href; } String scheme = original.getScheme(); if (scheme == null) { scheme = port == 443 ? "https" : "http"; } StringBuilder sb = new StringBuilder(); sb.append(scheme).append("://"); if (StringUtils.hasText(original.getRawUserInfo())) { sb.append(original.getRawUserInfo()).append("@"); } sb.append(host); if (port >= 0) { sb.append(":").append(port); } sb.append(original.getPath()); if (StringUtils.hasText(original.getRawQuery())) { sb.append("?").append(original.getRawQuery()); } if (StringUtils.hasText(original.getRawFragment())) { sb.append("#").append(original.getRawFragment()); } return sb.toString(); }
From source file:io.curly.commons.web.hateoas.ZuulAwareMappingResolver.java
/** * <a href="https://github.com/spring-cloud-samples/customers-stores/blob/master/rest-microservices-customers/src/main/java/example/customers/integration/StoreIntegration.java#L89">Github Spring Cloud Sample implementation<a/> * * @param host the current request host//from w ww. j a v a 2 s.c om * @param href the #resolve builder returns * @return reconstructed URI based on the current request host and port comparing them with the service host and port */ public String reconstructURI(String host, String href) { URI original; try { original = new URI(href); } catch (URISyntaxException e) { throw new IllegalArgumentException("Cannot create URI from: " + href); } int port = 80; if ("https".equals(original.getScheme())) { port = 443; } if (host.contains(":")) { String[] pair = host.split(":"); host = pair[0]; port = Integer.valueOf(pair[1]); } if (host.equals(original.getHost()) && port == original.getPort()) { return href; } String scheme = original.getScheme(); if (scheme == null) { scheme = port == 443 ? "https" : "http"; } StringBuilder sb = new StringBuilder(); sb.append(scheme).append("://"); if (StringUtils.hasText(original.getRawUserInfo())) { sb.append(original.getRawUserInfo()).append("@"); } sb.append(host); if (port >= 0) { sb.append(":").append(port); } sb.append(original.getPath()); if (StringUtils.hasText(original.getRawQuery())) { sb.append("?").append(original.getRawQuery()); } if (StringUtils.hasText(original.getRawFragment())) { sb.append("#").append(original.getRawFragment()); } return sb.toString(); }