Author: reto
Date: Thu Jun 9 12:51:35 2011
New Revision: 1133837
URL: http://svn.apache.org/viewvc?rev=1133837&view=rev
Log:
CLEREZZA-560: matching path section only to string with a slash after matching
part
Added:
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/TestSimplePathParam.java
Modified:
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
Modified:
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java?rev=1133837&r1=1133836&r2=1133837&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
(original)
+++
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
Thu Jun 9 12:51:35 2011
@@ -33,6 +33,9 @@ public class URITemplate implements Comp
private class TemplateSection {
public TemplateSection(String value, boolean variable) {
+ while (value.endsWith("/")) {
+ value = value.substring(0, value.length() -1);
+ }
this.variable = variable;
if (variable) {
int colonPos = value.indexOf(':');
@@ -215,7 +218,11 @@ public class URITemplate implements Comp
}
return -1;
}
- return i + subPathOffSet;
+ if ((subPath.length() == (i + subPathOffSet)) ||
(subPath.charAt(i + subPathOffSet) == '/')) {
+ return i + subPathOffSet;
+ } else {
+ return -1;
+ }
}
}
Added:
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/TestSimplePathParam.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/TestSimplePathParam.java?rev=1133837&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/TestSimplePathParam.java
(added)
+++
incubator/clerezza/trunk/parent/triaxrs/triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/TestSimplePathParam.java
Thu Jun 9 12:51:35 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.clerezza.triaxrs.blackbox;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.apache.clerezza.triaxrs.JaxRsHandler;
+import org.apache.clerezza.triaxrs.testutils.HandlerCreator;
+import org.wymiwyg.wrhapi.Method;
+import org.wymiwyg.wrhapi.Request;
+import org.wymiwyg.wrhapi.RequestURI;
+import org.wymiwyg.wrhapi.Response;
+
+
+public class TestSimplePathParam {
+
+ static String handlePathParamValue;
+
+ @Path("prefix")
+ public static class MyResource {
+
+ @GET
+ public void handleGet() {
+ handlePathParamValue = "no-sub";
+ }
+
+ @GET
+ @Path("{value:.+}")
+ public void handleSubPath() {
+ handlePathParamValue = "sub";
+ }
+ }
+
+ @Test
+ public void testQueryParam() throws Exception {
+
+ JaxRsHandler handler =
HandlerCreator.getHandler(MyResource.class);
+
+ Request requestMock = EasyMock.createNiceMock(Request.class);
+ Response responseMock = EasyMock.createNiceMock(Response.class);
+
expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
+ RequestURI requestURI =
EasyMock.createNiceMock(RequestURI.class);
+ String value = "a/path/with/slashes";
+
expect(requestURI.getPath()).andReturn("/prefix/"+value).anyTimes();
+
expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
+ replay(requestMock);
+ replay(requestURI);
+ replay(responseMock);
+ handler.handle(requestMock, responseMock);
+ assertEquals("sub", handlePathParamValue);
+
+ }
+
+ @Test
+ public void testNoSlashAfterClassPaths() throws Exception {
+
+ handlePathParamValue = null;
+ JaxRsHandler handler =
HandlerCreator.getHandler(MyResource.class);
+
+ Request requestMock = EasyMock.createNiceMock(Request.class);
+ Response responseMock = EasyMock.createNiceMock(Response.class);
+
expect(requestMock.getMethod()).andReturn(Method.GET).anyTimes();
+ RequestURI requestURI =
EasyMock.createNiceMock(RequestURI.class);
+
expect(requestURI.getPath()).andReturn("/prefixwithotherstuff/bla/bla").anyTimes();
+
expect(requestMock.getRequestURI()).andReturn(requestURI).anyTimes();
+ replay(requestMock);
+ replay(requestURI);
+ replay(responseMock);
+ handler.handle(requestMock, responseMock);
+ assertEquals(null, handlePathParamValue);
+
+ }
+}
+