public LocalClientState(URI baseURI, URI currentURI) { this.baseURI = baseURI; this.currentBuilder = new UriBuilderImpl().uri(currentURI); }
static URI convertStringToURI(String baseAddress) { try { return URI.create(baseAddress); } catch (RuntimeException ex) { // no need to check "https" scheme or indeed ':' // as the relative address will not work as the base address if (baseAddress.startsWith(HTTP_SCHEME)) { return new UriBuilderImpl().uriAsTemplate(baseAddress).build(); } throw ex; } }
private String buildQuery() { return buildParams(query, '&'); }
@Override public String toTemplate() { UriParts parts = doBuildUriParts(false, false, true); return buildUriString(parts.path, parts.query, parts.fragment); }
@Override public UriBuilder replacePath(String path) { if (path == null) { clearPathAndMatrix(); } else if (isAbsoluteUriPath(path)) { clearPathAndMatrix(); uri(URI.create(path)); } else { setPathAndMatrix(path); } return this; }
@Override public UriBuilder createUriBuilder() { return new UriBuilderImpl(); }
private URI doBuildFromMap(Map<String, ? extends Object> map, boolean fromEncoded, boolean encodePathSlash) throws IllegalArgumentException, UriBuilderException { try { Map<String, Object> alreadyResolvedTs = getResolvedTemplates(resolvedTemplates); Map<String, Object> alreadyResolvedTsPathEnc = getResolvedTemplates(resolvedTemplatesPathEnc); Map<String, Object> alreadyResolvedEncTs = getResolvedTemplates(resolvedEncodedTemplates); String thePath = buildPath(); thePath = substituteMapped(thePath, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, false, fromEncoded, encodePathSlash); String theQuery = buildQuery(); if (theQuery != null) { theQuery = substituteMapped(theQuery, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, true, fromEncoded, false); } String theFragment = fragment == null ? null : substituteMapped(fragment, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, true, fromEncoded, encodePathSlash); return buildURI(fromEncoded, thePath, theQuery, theFragment); } catch (URISyntaxException ex) { throw new UriBuilderException("URI can not be built", ex); } } //CHECKSTYLE:OFF
throw new IllegalArgumentException("path is null"); if (isAbsoluteUriPath(path)) { try { URI uri = URI.create(path); this.originalPathEmpty = StringUtils.isEmpty(uri.getPath()); uri(uri); } catch (IllegalArgumentException ex) { if (!URITemplate.createExactTemplate(path).getVariables().isEmpty()) { return uriAsTemplate(path); setUriParts(URI.create(pathEncoded)); paths.add(replacePathSegment(ps));
Map<String, Object> alreadyResolvedTs = getResolvedTemplates(resolvedTemplates); Map<String, Object> alreadyResolvedTsPathEnc = getResolvedTemplates(resolvedTemplatesPathEnc); Map<String, Object> alreadyResolvedEncTs = getResolvedTemplates(resolvedEncodedTemplates); final int resolvedTsSize = alreadyResolvedTs.size() + alreadyResolvedEncTs.size() + alreadyResolvedTsPathEnc.size(); String thePath = buildPath(); URITemplate pathTempl = URITemplate.createExactTemplate(thePath); thePath = substituteVarargs(pathTempl, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, values, 0, false, fromEncoded, allowUnresolved, encodePathSlash); int pathTemplateVarsSize = pathTempl.getVariables().size(); String theQuery = buildQuery(); int queryTemplateVarsSize = 0; if (theQuery != null) { - alreadyResolvedTs.size() - alreadyResolvedTsPathEnc.size() - alreadyResolvedEncTs.size() - pathTemplateVarsSize; theQuery = substituteVarargs(queryTempl, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, values, values.length - lengthDiff, true, fromEncoded, allowUnresolved, false); - alreadyResolvedTs.size() - alreadyResolvedTsPathEnc.size() - alreadyResolvedEncTs.size() - pathTemplateVarsSize - queryTemplateVarsSize; theFragment = substituteVarargs(fragmentTempl, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, values, values.length - lengthDiff, true, fromEncoded, allowUnresolved, false);
throw new IllegalArgumentException("path is null"); if (isAbsoluteUriPath(path)) { uri(URI.create(path)); return this; paths.add(replacePathSegment(ps));
public UriBuilder uri(String uriTemplate) throws IllegalArgumentException { if (StringUtils.isEmpty(uriTemplate)) { throw new IllegalArgumentException(); } try { return uri(URI.create(uriTemplate)); } catch (Exception ex) { if (URITemplate.createExactTemplate(uriTemplate).getVariables().isEmpty()) { throw new IllegalArgumentException(ex); } return uriAsTemplate(uriTemplate); } }
UriBuilderImpl uriBuilder = new UriBuilderImpl(uri); if (StringUtils.isNotEmpty(selector)) { uriBuilder.replacePath(urlPrefix+servletUrl+urlPostfix+"."+selector); } else { uriBuilder.replacePath(urlPrefix+servletUrl+urlPostfix); return uriBuilder.build("").toString(); } else { log.warn("URI ("+uri.toString()+") does not contain: "+requestPath);
private URI doBuild(boolean fromEncoded, boolean encodePathSlash, Object... values) { if (values == null) { throw new IllegalArgumentException("Template parameter values are set to null"); } for (int i = 0; i < values.length; i++) { if (values[i] == null) { throw new IllegalArgumentException("Template parameter value at position " + i + " is set to null"); } } UriParts parts = doBuildUriParts(fromEncoded, encodePathSlash, false, values); try { return buildURI(fromEncoded, parts.path, parts.query, parts.fragment); } catch (URISyntaxException ex) { throw new UriBuilderException("URI can not be built", ex); } }
private URI buildURI(boolean fromEncoded, String thePath, String theQuery, String theFragment) throws URISyntaxException { if (fromEncoded) { return buildURIFromEncoded(thePath, theQuery, theFragment); } else if (!isSchemeOpaque()) { if ((scheme != null || host != null || userInfo != null) && thePath.length() != 0 && !(thePath.startsWith("/") || thePath.startsWith(";"))) { thePath = "/" + thePath; } try { return buildURIFromEncoded(thePath, theQuery, theFragment); } catch (Exception ex) { // lets try the option below } URI uri = new URI(scheme, userInfo, host, port, thePath, theQuery, theFragment); if (thePath.contains("%2F")) { // TODO: the bogus case of segments containing encoded '/' // Not sure if we have a cleaner solution though. String realPath = uri.getRawPath().replace("%252F", "%2F"); uri = buildURIFromEncoded(realPath, uri.getRawQuery(), uri.getRawFragment()); } return uri; } else { return new URI(scheme, schemeSpecificPart, theFragment); } }
public UriBuilder uri(String uriTemplate) throws IllegalArgumentException { try { return uri(URI.create(uriTemplate)); } catch (Exception ex) { throw new IllegalArgumentException(ex); } }
private PathSegment replacePathSegment(PathSegment ps) { StringBuilder sb = new StringBuilder(); sb.append(ps.getPath()); buildMatrix(sb, matrix); return new PathSegmentImpl(sb.toString()); }
private URI buildURIFromEncoded(String thePath, String theQuery, String theFragment) throws URISyntaxException { return new URI(buildUriString(thePath, theQuery, theFragment)); }
@Override public UriBuilder createUriBuilder() { return new UriBuilderImpl(); }
private URI doBuildFromMap(Map<String, ? extends Object> map, boolean fromEncoded, boolean encodePathSlash) throws IllegalArgumentException, UriBuilderException { try { Map<String, Object> alreadyResolvedTs = getResolvedTemplates(resolvedTemplates); Map<String, Object> alreadyResolvedTsPathEnc = getResolvedTemplates(resolvedTemplatesPathEnc); Map<String, Object> alreadyResolvedEncTs = getResolvedTemplates(resolvedEncodedTemplates); String thePath = buildPath(); thePath = substituteMapped(thePath, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, false, fromEncoded, encodePathSlash); String theQuery = buildQuery(); if (theQuery != null) { theQuery = substituteMapped(theQuery, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, true, fromEncoded, false); } String theFragment = fragment == null ? null : substituteMapped(fragment, map, alreadyResolvedTs, alreadyResolvedTsPathEnc, alreadyResolvedEncTs, true, fromEncoded, encodePathSlash); return buildURI(fromEncoded, thePath, theQuery, theFragment); } catch (URISyntaxException ex) { throw new UriBuilderException("URI can not be built", ex); } } //CHECKSTYLE:OFF
@Override public UriBuilder replacePath(String path) { if (path == null) { clearPathAndMatrix(); } else if (isAbsoluteUriPath(path)) { clearPathAndMatrix(); uri(URI.create(path)); } else { setPathAndMatrix(path); } return this; }