Author: sergeyb
Date: Fri Dec 12 08:16:14 2008
New Revision: 726066
URL: http://svn.apache.org/viewvc?rev=726066&view=rev
Log:
JAXRS : ensuring Path.limited value is still honoured
Added:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
(with props)
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Added:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java?rev=726066&view=auto
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
(added)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
Fri Dec 12 08:16:14 2008
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+import java.util.Comparator;
+
+public class ClassResourceInfoComparator implements
Comparator<ClassResourceInfo> {
+
+ public int compare(ClassResourceInfo cr1, ClassResourceInfo cr2) {
+
+ return URITemplate.compareTemplates(
+ cr1.getURITemplate(),
+ cr2.getURITemplate());
+ }
+}
+
+
Propchange:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfoComparator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=726066&r1=726065&r2=726066&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Fri Dec 12 08:16:14 2008
@@ -36,6 +36,7 @@
public static final String TEMPLATE_PARAMETERS =
"jaxrs.template.parameters";
public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
+ public static final String UNLIMITED_REGEX_SUFFIX = "(/)?";
public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
/**
@@ -45,6 +46,8 @@
Pattern.compile("\\{(\\w[-\\w\\.]*)(\\:(.+?))?\\}");
private static final String DEFAULT_PATH_VARIABLE_REGEX = "([^/]+?)";
+ private static final String PATH_UNLIMITED_VARIABLE_REGEX = "(.*?)";
+
private static final String CHARACTERS_TO_ESCAPE = ".";
private final String template;
@@ -53,8 +56,11 @@
private final Pattern templateRegexPattern;
private final String literals;
-
public URITemplate(String theTemplate) {
+ this(theTemplate, true);
+ }
+
+ public URITemplate(String theTemplate, boolean limited) {
this.template = theTemplate;
@@ -77,7 +83,11 @@
patternBuilder.append(')');
customTemplateVariables.add(matcher.group(1).trim());
} else {
- patternBuilder.append(DEFAULT_PATH_VARIABLE_REGEX);
+ if (!limited && i == template.length()) {
+ patternBuilder.append(PATH_UNLIMITED_VARIABLE_REGEX);
+ } else {
+ patternBuilder.append(DEFAULT_PATH_VARIABLE_REGEX);
+ }
}
}
String substr = escapeCharacters(template.substring(i,
template.length()));
@@ -91,7 +101,7 @@
if (endsWithSlash) {
patternBuilder.deleteCharAt(endPos);
}
- patternBuilder.append(LIMITED_REGEX_SUFFIX);
+ patternBuilder.append(limited ? LIMITED_REGEX_SUFFIX :
UNLIMITED_REGEX_SUFFIX);
templateRegexPattern = Pattern.compile(patternBuilder.toString());
}
@@ -190,7 +200,7 @@
pathValue = "/" + pathValue;
}
- return new URITemplate(pathValue);
+ return new URITemplate(pathValue, path.limited());
}
public static int compareTemplates(URITemplate t1, URITemplate t2) {
Modified:
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=726066&r1=726065&r2=726066&view=diff
==============================================================================
---
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Fri Dec 12 08:16:14 2008
@@ -34,6 +34,19 @@
}
@Test
+ public void testUnlimited() throws Exception {
+ URITemplate uriTemplate = new URITemplate("/customers/{id}", false);
+ MultivaluedMap<String, String> values = new MetadataMap<String,
String>();
+
+ assertTrue(uriTemplate.match("/customers/123", values));
+ assertEquals("123", values.getFirst("id"));
+ values.clear();
+
+ assertTrue(uriTemplate.match("/customers/123/456", values));
+ assertEquals("123/456", values.getFirst("id"));
+ }
+
+ @Test
public void testMatchBasic() throws Exception {
URITemplate uriTemplate = new URITemplate("/customers/{id}");
MultivaluedMap<String, String> values = new MetadataMap<String,
String>();