Refine search
@Override public int compare(OperationResourceInfo op1, OperationResourceInfo op2) { boolean sub1 = op1.getHttpMethod() == null; boolean sub2 = op2.getHttpMethod() == null; if (sub1 && !sub2) { return 1; } else if (!sub1 && sub2) { return -1; } URITemplate ut1 = op1.getURITemplate(); URITemplate ut2 = op2.getURITemplate(); int result = ut1.getValue().compareTo(ut2.getValue()); if (result == 0 && !(sub1 && sub2)) { result = op1.getHttpMethod().compareTo(op2.getHttpMethod()); } if (result == 0 && ignoreOverloadedMethods && op1.getMethodToInvoke().getName().equals(op2.getMethodToInvoke().getName())) { Integer paramLen1 = op1.getMethodToInvoke().getParameterTypes().length; Integer paramLen2 = op2.getMethodToInvoke().getParameterTypes().length; result = paramLen1.compareTo(paramLen2) * -1; } return result; }
public static boolean checkRequestURI(String servletPath, String uri) { boolean wildcard = uri.endsWith("*"); String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri; try { URITemplate template = new URITemplate(theURI); MultivaluedMap<String, String> map = new MetadataMap<>(); if (template.match(servletPath, map)) { String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP); if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) { return true; } } } catch (Exception ex) { // ignore } return false; }
protected MultivaluedMap<String, String> getTemplateParametersMap(URITemplate template, List<Object> values) { if (values != null && !values.isEmpty()) { List<String> vars = template.getVariables(); MultivaluedMap<String, String> templatesMap = new MetadataMap<>(vars.size()); for (int i = 0; i < vars.size(); i++) { if (i < values.size()) { templatesMap.add(vars.get(i), values.get(i).toString()); } } return templatesMap; } return null; }
final URITemplate template = new URITemplate("http://www.example.com/fetch.php?title={title}"); final VariableMap varmap = VariableMap.newBuilder() .addScalar("title", "yourtitlehere") .build(); final URL url = template.toURL(varmap);
final URITemplate tmpl = new URITemplate("http://my.site/some/where?word={word}"); final VariableMapBuilder builder = VariableMap.newBuilder(); builder.addScalarValue("word", "Conformément"); tmpl.toString(builder.freeze()); // returns the correct result // Or: tmpl.toURI(builder.freeze()); tmpl.toURL(builder.freeze());
// Immutable, can be reused as many times as you wish final URITemplate template = new URITemplate("https://graph.facebook.com/{userId}" + "/notifications?template={template}" + "&href=processThis.jsp?param={value}" + "&access_token=abc123"); final Map<String, VariableValue> vars = new HashMap<String, VariableValue>(); vars.put("userId", new ScalarValue("Ankur")); vars.put("template", new ScalarValue("HelloAnkur")); vars.put("value", new ScalarValue("ParamValue"); // Build the expanded string final String expanded = template.expand(vars); // Go with the string
boolean added = false; URITemplate uriTemplate = ori.getURITemplate(); MultivaluedMap<String, String> map = new MetadataMap<>(values); if (uriTemplate != null && uriTemplate.match(path, map)) { String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP); boolean finalPath = StringUtils.isEmpty(finalGroup) || PATH_SEGMENT_SEP.equals(finalGroup); if (ori.isSubResourceLocator()) { candidateList.put(ori, map); if (finalPath) { } else if (finalPath) { pathMatched++; if (matchHttpMethod(ori.getHttpMethod(), httpMethod)) { methodMatched++; Map.Entry<OperationResourceInfo, MultivaluedMap<String, String>> firstEntry = candidateList.entrySet().iterator().next(); matchedValues.clear(); matchedValues.putAll(firstEntry.getValue()); OperationResourceInfo ori = firstEntry.getKey(); if (headMethodPossible(ori.getHttpMethod(), httpMethod)) {
public List<ClassResourceInfo> getResourcesList(Message m, UriInfo ui) { final String slash = "/"; String path = ui.getPath(); if (!path.startsWith(slash)) { path = slash + path; } List<ClassResourceInfo> all = ((JAXRSServiceImpl)m.getExchange().getService()) .getClassResourceInfos(); boolean absolutePathSlashOn = checkAbsolutePathSlash && ui.getAbsolutePath().getPath().endsWith(slash); if (slash.equals(path) && !absolutePathSlashOn) { return all; } List<ClassResourceInfo> cris = new LinkedList<>(); for (ClassResourceInfo cri : all) { MultivaluedMap<String, String> map = new MetadataMap<>(); if (cri.getURITemplate().match(path, map) && slash.equals(map.getFirst(URITemplate.FINAL_MATCH_GROUP))) { cris.add(cri); } } return cris; }
addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue()); addNonEmptyPath(builder, ori.getURITemplate().getValue()); handleCookies(m, params, paramHeaders, beanParamsList, types); if (ori.isSubResourceLocator()) { ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType()); if (subCri == null) { subHeaders.putAll(headers); headers.putAll(paramHeaders); setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), bodyIndex == -1 || params[bodyIndex] == null ? null : params[bodyIndex].getClass(), m.getReturnType());
List<Object> list = new LinkedList<>(); List<String> methodVars = ori.getURITemplate().getVariables(); List<Parameter> paramsList = getParameters(map, ParameterType.PATH); Map<String, BeanPair> beanParamValues = new HashMap<>(beanParams.size()); }); if (!beanParamValues.isEmpty() && !methodVars.containsAll(beanParamValues.keySet())) { List<String> classVars = ori.getClassResourceInfo().getURITemplate().getVariables(); classVars.forEach(classVar -> { BeanPair pair = beanParamValues.get(classVar); MultivaluedMap<String, Object> values = InjectionUtils.extractValuesFromBean(params[p.getIndex()], ""); methodVars.forEach(var -> { list.addAll(values.get(var)); }); } else {
private static void addTemplateVarValues(List<String> values, MultivaluedMap<String, String> params, URITemplate template) { if (template != null) { for (String var : template.getVariables()) { List<String> paramValues = params.get(var); if (paramValues != null) { values.addAll(paramValues); } } } }
boolean isQuery = separator == '&'; StringBuilder b = new StringBuilder(); for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator(); it.hasNext();) { Map.Entry<String, List<String>> entry = it.next(); for (Iterator<String> sit = entry.getValue().iterator(); sit.hasNext();) { val = HttpUtils.encodePartiallyEncoded(val, isQuery); } else { val = new URITemplate(val).encodeLiteralCharacters(isQuery);
list.addAll(valuesMap.values()); List<String> methodVars = ori.getURITemplate().getVariables(); InjectionUtils.extractValuesFromBean(params[p.getIndex()], ""); for (String var : methodVars) { list.addAll(values.get(var));
uri(uri); } catch (IllegalArgumentException ex) { if (!URITemplate.createExactTemplate(path).getVariables().isEmpty()) { return uriAsTemplate(path); segments.add(new PathSegmentImpl(path, false)); if (!paths.isEmpty() && !matrix.isEmpty()) { PathSegment ps = paths.remove(paths.size() - 1); paths.add(replacePathSegment(ps)); matrix.clear(); if (!paths.isEmpty()) { matrix = paths.get(paths.size() - 1).getMatrixParameters();
if (HttpMethod.HEAD.equals(e1.getHttpMethod())) { return -1; } else if (HttpMethod.HEAD.equals(e2.getHttpMethod())) { return 1; int result = URITemplate.compareTemplates( e1.getURITemplate(), e2.getURITemplate());
public int compare(OperationResourceInfo op1, OperationResourceInfo op2) { boolean sub1 = op1.getHttpMethod() == null; boolean sub2 = op2.getHttpMethod() == null; if (sub1 && !sub2) { return 1; } else if (!sub1 && sub2) { return -1; } URITemplate ut1 = op1.getURITemplate(); URITemplate ut2 = op2.getURITemplate(); int result = ut1.getValue().compareTo(ut2.getValue()); if (result == 0 && !(sub1 && sub2)) { result = op1.getHttpMethod().compareTo(op2.getHttpMethod()); } return result; }
if (httpMethod.equals(ori.getHttpMethod())) { ignore = false; break; final String jaxrsPattern = (base + '/' + ori.getClassResourceInfo().getURITemplate().getValue() + '/' + ori.getURITemplate().getValue()).replace("//", "/"); for (final String pattern : collection.findPatterns()) { if (pattern.endsWith("*")) {
protected boolean compareOperations(OperationResourceInfo ori1, OperationResourceInfo ori2) { if (ori1 == null || ori2 == null || !ori1.getURITemplate().getValue().equals(ori2.getURITemplate().getValue()) || ori1.getHttpMethod() != null && ori2.getHttpMethod() == null || ori2.getHttpMethod() != null && ori1.getHttpMethod() == null) { return false; } int ori1PathParams = 0; int ori1MatrixParams = 0; for (Parameter p : ori1.getParameters()) { if (p.getType() == ParameterType.PATH) { ori1PathParams++; } else if (p.getType() == ParameterType.MATRIX) { ori1MatrixParams++; } } int ori2PathParams = 0; int ori2MatrixParams = 0; for (Parameter p : ori2.getParameters()) { if (p.getType() == ParameterType.PATH) { ori2PathParams++; } else if (p.getType() == ParameterType.MATRIX) { ori2MatrixParams++; } } return ori1PathParams == ori2PathParams && ori1MatrixParams == ori2MatrixParams; }
String path = ori.getURITemplate().getValue(); if (!resourceTagOpened && openResource(path)) { resourceTagOpened = true; URITemplate template = ori.getClassResourceInfo().getURITemplate(); if (template != null) { String parentPath = template.getValue(); if (parentPath.endsWith("/") && path.startsWith("/") && path.length() > 1) { path = path.substring(1); doHandleJaxrsBeanParamClassParams(sb, classParams, isJson, ParameterType.QUERY, ParameterType.HEADER); for (Parameter p : ori.getParameters()) { if (isForm && p.getType() == ParameterType.REQUEST_BODY) { continue;
return resources.get(0).getURITemplate().match(path, values) ? resources.get(0) : null; if (cri.getURITemplate().match(path, map)) { candidateList.put(cri, map); if (isFineLevelLoggable) { cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString()); Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> firstEntry = candidateList.entrySet().iterator().next(); values.putAll(firstEntry.getValue()); ClassResourceInfo cri = firstEntry.getKey(); if (isFineLevelLoggable) { BUNDLE, cri.getServiceClass().getName(), path, cri.getURITemplate().getValue()).toString());