use of javax.ws.rs.core.PathSegment in project cxf by apache.
the class UriBuilderImpl method doPath.
private UriBuilder doPath(String path, boolean checkSegments) {
if (path == null) {
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);
}
String pathEncoded = HttpUtils.pathEncode(path);
// Bad hack to bypass the TCK usage of bogus URI with empty paths containing matrix parameters,
// which even URI class chokes upon; cheaper to do the following than try to challenge,
// given that URI RFC mentions the possibility of empty paths, though no word on the possibility of
// such empty paths having matrix parameters...
int schemeIndex = pathEncoded.indexOf("//");
if (schemeIndex != -1) {
int pathComponentStart = pathEncoded.indexOf("/", schemeIndex + 2);
if (pathComponentStart == -1) {
this.originalPathEmpty = true;
pathComponentStart = pathEncoded.indexOf(";");
if (pathComponentStart != -1) {
pathEncoded = pathEncoded.substring(0, pathComponentStart) + "/" + pathEncoded.substring(pathComponentStart);
}
}
}
setUriParts(URI.create(pathEncoded));
}
return this;
}
if (paths.isEmpty()) {
leadingSlash = path.startsWith("/");
}
List<PathSegment> segments;
if (checkSegments) {
segments = JAXRSUtils.getPathSegments(path, false, false);
} else {
segments = new ArrayList<>();
path = path.replaceAll("/", "%2F");
segments.add(new PathSegmentImpl(path, false));
}
if (!paths.isEmpty() && !matrix.isEmpty()) {
PathSegment ps = paths.remove(paths.size() - 1);
paths.add(replacePathSegment(ps));
}
paths.addAll(segments);
matrix.clear();
if (!paths.isEmpty()) {
matrix = paths.get(paths.size() - 1).getMatrixParameters();
}
return this;
}
use of javax.ws.rs.core.PathSegment in project cxf by apache.
the class UriBuilderImpl method buildPath.
private String buildPath() {
StringBuilder sb = new StringBuilder();
Iterator<PathSegment> iter = paths.iterator();
while (iter.hasNext()) {
PathSegment ps = iter.next();
String p = ps.getPath();
if (p.length() != 0 || !iter.hasNext()) {
p = URITemplate.createExactTemplate(p).encodeLiteralCharacters(false);
if (sb.length() == 0 && leadingSlash) {
sb.append('/');
} else if (!p.startsWith("/") && sb.length() > 0) {
sb.append('/');
}
sb.append(p);
if (iter.hasNext()) {
buildMatrix(sb, ps.getMatrixParameters());
}
}
}
buildMatrix(sb, matrix);
return sb.toString();
}
use of javax.ws.rs.core.PathSegment in project cxf by apache.
the class URITemplate method match.
public boolean match(String uri, MultivaluedMap<String, String> templateVariableToValue) {
if (uri == null) {
return (templateRegexPattern == null) ? true : false;
}
if (templateRegexPattern == null) {
return false;
}
Matcher m = templateRegexPattern.matcher(uri);
if (!m.matches() || template.equals(SLASH) && uri.startsWith(SLASH_QUOTE)) {
if (uri.contains(";")) {
// we might be trying to match one or few path segments
// containing matrix
// parameters against a clear path segment as in @Path("base").
List<PathSegment> pList = JAXRSUtils.getPathSegments(template, false);
List<PathSegment> uList = JAXRSUtils.getPathSegments(uri, false);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < uList.size(); i++) {
String segment = null;
if (pList.size() > i && pList.get(i).getPath().indexOf('{') == -1) {
segment = uList.get(i).getPath();
} else {
segment = HttpUtils.fromPathSegment(uList.get(i));
}
if (segment.length() > 0) {
sb.append(SLASH);
}
sb.append(segment);
}
uri = sb.toString();
if (uri.length() == 0) {
uri = SLASH;
}
m = templateRegexPattern.matcher(uri);
if (!m.matches()) {
return false;
}
} else {
return false;
}
}
// Assign the matched template values to template variables
int groupCount = m.groupCount();
int i = 1;
for (String name : variables) {
while (i <= groupCount) {
String value = m.group(i++);
if ((value == null || value.length() == 0 && i < groupCount) && variables.size() + 1 < groupCount) {
continue;
}
templateVariableToValue.add(name, value);
break;
}
}
// The right hand side value, might be used to further resolve
// sub-resources.
String finalGroup = i > groupCount ? SLASH : m.group(groupCount);
if (finalGroup == null || finalGroup.startsWith(SLASH_QUOTE)) {
finalGroup = SLASH;
}
templateVariableToValue.putSingle(FINAL_MATCH_GROUP, finalGroup);
return true;
}
use of javax.ws.rs.core.PathSegment in project scheduling by ow2-proactive.
the class SchedulerRestWorkflowFromCatalogExecutionTest method getOneVariablePathSegment.
private PathSegment getOneVariablePathSegment(String key, String value) {
PathSegment pathSegment = mock(PathSegment.class);
MultivaluedMap<String, String> matrix = new MultivaluedHashMap<>();
if (key != null) {
matrix.put(key, Arrays.asList(value));
}
when(pathSegment.getMatrixParameters()).thenReturn(matrix);
return pathSegment;
}
use of javax.ws.rs.core.PathSegment in project scheduling by ow2-proactive.
the class WorkflowVariablesTransformerTest method testTwoVariablesEmptyMap.
@Test
public void testTwoVariablesEmptyMap() {
Map<String, String> expectedVariables = Maps.newHashMap();
expectedVariables.put("KEY1", "");
expectedVariables.put("KEY2", "");
PathSegment pathSegment = mock(PathSegment.class);
MultivaluedMap<String, String> multivalueMap = new MultivaluedHashMap();
multivalueMap.put("KEY1", Lists.newArrayList(""));
multivalueMap.put("KEY2", Lists.newArrayList(""));
when(pathSegment.getMatrixParameters()).thenReturn(multivalueMap);
Map<String, String> variables = workflowVariablesTransformer.getWorkflowVariablesFromPathSegment(pathSegment);
assertThat(variables, is(expectedVariables));
}
Aggregations