You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by mi...@apache.org on 2010/03/02 13:49:21 UTC

svn commit: r918006 - in /incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs: ./ org.apache.clerezza.triaxrs.tests/ org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/ org.apache.clerezza.triaxrs/ ...

Author: mir
Date: Tue Mar  2 12:49:20 2010
New Revision: 918006

URL: http://svn.apache.org/viewvc?rev=918006&view=rev
Log:
CLEREZZA-129: removed problematic code from sun. Now using the org.apache.clerezza.utils.UriUtil for encoding

Added:
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TemplateEncoderTest.java
      - copied, changed from r915817, incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TestTemplateEncoder.java
Removed:
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TestTemplateEncoder.java
Modified:
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/   (props changed)
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/pom.xml
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/AbstractServiceRootResourceTest.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/FelixServiceRootResourceTest.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/SimpleRootResource.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/pom.xml
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/TemplateEncoder.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/TestTemplate.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/FormParamTest.java
    incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/ResourcePathTest.java

Propchange: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar  2 12:49:20 2010
@@ -3,3 +3,4 @@
 /incubator/clerezza/issues/CLEREZZA-48/org.apache.clerezza.triaxrs:893435-898896
 /incubator/clerezza/issues/CLEREZZA-86/org.apache.clerezza.triaxrs:903135-910335
 /incubator/clerezza/issues/CLEREZZA-94/org.apache.clerezza.triaxrs:905562-905566
+/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs:910457-917940

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/pom.xml?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/pom.xml (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/pom.xml Tue Mar  2 12:49:20 2010
@@ -69,7 +69,17 @@
 			<groupId>org.apache.httpcomponents</groupId>
 			<artifactId>httpclient-osgi</artifactId>
 			<scope>provided</scope>
-			<version>4.0</version>
+			<version>4.0.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.utils</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.httpcomponents</groupId>
+			<artifactId>httpcore-osgi</artifactId>
+			<scope>provided</scope>
 		</dependency>
 <!-- pax exam related stuff -->
 		<dependency>
@@ -86,15 +96,7 @@
 			<groupId>org.ops4j.pax.exam</groupId>
 			<artifactId>pax-exam-container-default</artifactId>
 			<scope>test</scope>
-		</dependency>
-		
-		<dependency>
-			<groupId>org.apache.httpcomponents</groupId>
-			<artifactId>httpcore-osgi</artifactId>
-			<version>4.0.1</version>
-			<scope>test</scope>
-		</dependency>
-		
+		</dependency>		
 	</dependencies>
 	<build>
 		<plugins>
@@ -111,7 +113,6 @@
 			<plugin>
 				<groupId>org.ops4j.pax.exam</groupId>
 				<artifactId>maven-paxexam-plugin</artifactId>
-				<version>1.2.0</version>
 				<executions>
 					<execution>
 						<id>generate-depends-file</id>

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/AbstractServiceRootResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/AbstractServiceRootResourceTest.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/AbstractServiceRootResourceTest.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/AbstractServiceRootResourceTest.java Tue Mar  2 12:49:20 2010
@@ -69,6 +69,8 @@
 	@Test
 	public void getHello() throws Exception {
 		URL serverURL = new URL("http://localhost:" + testHttpPort + "/foo");
+		System.out.println("I AM HERE!");
+		Thread.sleep(40000);
 		HttpURLConnection connection = (HttpURLConnection) serverURL.openConnection();
 		Assert.assertEquals("text/plain", connection.getHeaderField("Content-Type"));
 		Reader reader = new InputStreamReader(connection.getInputStream());

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/FelixServiceRootResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/FelixServiceRootResourceTest.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/FelixServiceRootResourceTest.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/FelixServiceRootResourceTest.java Tue Mar  2 12:49:20 2010
@@ -50,11 +50,20 @@
 				/*dsProfile(),*/
 				configProfile(),
 				webProfile(),
+				profile("felix.webconsole"),
 				junitBundles(),
 				frameworks(
 				felix()),
 				systemProperty("org.osgi.service.http.port").value(
-				Integer.toString(testHttpPort)));
+				Integer.toString(testHttpPort))
+				// this just adds all what you write here to java vm argumenents of the (new) osgi process.
+				//,vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006"),
+				// this is necessary to let junit runner not timout the remote process before attaching debugger
+				// setting timeout to 0 means wait as long as the remote service comes available.
+				// starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+				// will not be triggered till the framework is not started
+				//waitForFrameworkStartup()
+				);
 	}
 
 	

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/SimpleRootResource.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/SimpleRootResource.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/SimpleRootResource.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs.tests/src/test/java/org/apache/clerezza/triaxrs/blackbox/osgi/SimpleRootResource.java Tue Mar  2 12:49:20 2010
@@ -26,7 +26,7 @@
  *
  * @author reto
  */
-@Path("foo")
+@Path("/foo")
 public class SimpleRootResource {
 
 	static final public String greeting = "hello";

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/pom.xml?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/pom.xml (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/pom.xml Tue Mar  2 12:49:20 2010
@@ -29,6 +29,10 @@
 			<artifactId>org.apache.clerezza.jaxrs.extensions</artifactId>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>org.apache.clerezza.utils</artifactId>
+		</dependency>
+		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
 			<scope>test</scope>

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java Tue Mar  2 12:49:20 2010
@@ -24,7 +24,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Annotation;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
@@ -60,7 +59,6 @@
 import org.apache.clerezza.triaxrs.providers.ProvidersImpl;
 import org.apache.clerezza.triaxrs.util.MethodUtil;
 import org.apache.clerezza.triaxrs.util.PathMatching;
-import org.apache.clerezza.triaxrs.util.TemplateEncoder;
 import org.wymiwyg.wrhapi.Handler;
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResourceExecutorImpl.java Tue Mar  2 12:49:20 2010
@@ -18,17 +18,16 @@
  */
 package org.apache.clerezza.triaxrs;
 
-import java.io.StringWriter;
 import java.util.Iterator;
 import org.apache.clerezza.jaxrs.extensions.ResourceMethodException;
 import org.apache.clerezza.jaxrs.extensions.HttpRequest;
 import org.apache.clerezza.jaxrs.extensions.MethodResponse;
 import org.apache.clerezza.jaxrs.extensions.RootResourceExecutor;
-import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.security.AccessControlException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -60,6 +59,7 @@
 import org.apache.clerezza.triaxrs.util.PathMatching;
 import org.apache.clerezza.triaxrs.util.TemplateEncoder;
 import org.apache.clerezza.triaxrs.util.URITemplate;
+import org.apache.clerezza.utils.UriException;
 import org.wymiwyg.wrhapi.HandlerException;
 import org.wymiwyg.wrhapi.HeaderName;
 
@@ -546,6 +546,9 @@
 			throw new WebApplicationException(500);
 		} catch (InvocationTargetException ex) {
 			logger.error("Exception {}", ex);
+			if (ex.getCause() instanceof AccessControlException) {
+				throw (AccessControlException) ex.getCause();
+			}
 			throw new WebApplicationException(500);
 		}
 	}
@@ -589,7 +592,7 @@
 	private String templateUrlEncode(String value) {
 		try {
 			return TemplateEncoder.encode(value, "utf-8");
-		} catch (UnsupportedEncodingException e) {
+		} catch (UriException e) {
 			throw new RuntimeException(e);
 		}
 	}

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/RootResources.java Tue Mar  2 12:49:20 2010
@@ -16,131 +16,140 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.clerezza.triaxrs;
-
+package org.apache.clerezza.triaxrs;
+
 import java.util.Iterator;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.clerezza.triaxrs.util.PathMatching;
+import org.apache.clerezza.triaxrs.util.TemplateEncoder;
+import org.apache.clerezza.utils.UriException;
+import org.apache.clerezza.utils.UriUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.wymiwyg.wrhapi.HandlerException;
-
-/**
- * Manages a set of root-resources delivering a suitable root-resource given a
- * path.
- * 
- * @author reto
- */
-public class RootResources {
-
-	/**
-	 * @author mir
-	 * 
-	 */
-	public static class ResourceAndPathMatching {
-
-		private Object rootResource;
-		private PathMatching pathMatching;
-
-		public ResourceAndPathMatching(Object rootResource,
-				PathMatching pathMatching) {
-			this.rootResource = rootResource;
-			this.pathMatching = pathMatching;
-		}
-
-		public Object getRootResource() {
-			return rootResource;
-		}
-
-		public PathMatching getPathMatching() {
-			return pathMatching;
-		}
-
-	}
-
-	private static ThreadLocal<String> requestUri = new ThreadLocal<String>() {
-	};
-
-	public static String getCurrentRequestUri() {
-		return requestUri.get();
-	}
-
-	final static private Logger logger = LoggerFactory
-			.getLogger(RootResources.class);
-
-	/**
-	 * we store the resource descriptors
-	 */
-	SortedSet<RootResourceDescriptor> rootResourceDescriptors = new TreeSet<RootResourceDescriptor>();
-
-	/**
-	 * adds a {@link RootResourceDescriptor}
-	 * 
-	 * @param descriptor
-	 */
-	public void add(RootResourceDescriptor descriptor) {
-		// TODO Flag an error if the set includes more than one instance
-		// of the same class.
-		rootResourceDescriptors.add(descriptor);
-	}
-
-	/**
-	 * removes a {@link RootResourceDescriptor}
-	 * 
-	 * @param descriptor
-	 */
-	public void remove(RootResourceDescriptor descriptor) {
-		rootResourceDescriptors.remove(descriptor);
-	}
-
-	/**
-	 * 
-	 * @return the number of available root resources
-	 */
-	public int size() {
-		return rootResourceDescriptors.size();
-	}
-
-	/**
-	 * Get the best matching root-resource for a path
-	 * 
-	 * @param uriPath
-	 * @return the matching root-resource or null if no root resources matches
-	 */
-	public RootResourceDescriptor getDescriptor(String uriPath) {
-		for (RootResourceDescriptor descriptor : rootResourceDescriptors) {
-
-			PathMatching pathMatching = descriptor.getUriTemplate().match(
-					uriPath);
-			if (pathMatching != null) {
-				return descriptor;
-			}
-		}
-		return null;
-	}
-
-	ResourceAndPathMatching getResourceAndPathMatching(WebRequest request)
-			throws HandlerException, NoMatchingRootResourceException {
-		String uriPath = request.getWrhapiRequest().getRequestURI().getPath();
-		requestUri.set(uriPath);
-		PathMatching pathMatching = null;
-		RootResourceDescriptor descriptor = null;
-		Iterator<RootResourceDescriptor> descriptorIter = rootResourceDescriptors
-				.iterator();
-		while (descriptorIter.hasNext()) {
-			descriptor = descriptorIter.next();
-			pathMatching = descriptor.getUriTemplate().match(uriPath);
-			if (pathMatching != null) {
-				break;
-			}
-		}
-
-		if (pathMatching == null) {
-			throw new NoMatchingRootResourceException();
-		}
-		return new ResourceAndPathMatching(descriptor.getInstance(request,
-				pathMatching.getParameters()), pathMatching);
-	}
-}
+
+/**
+ * Manages a set of root-resources delivering a suitable root-resource given a
+ * path.
+ * 
+ * @author reto
+ */
+public class RootResources {
+
+	/**
+	 * @author mir
+	 * 
+	 */
+	public static class ResourceAndPathMatching {
+
+		private Object rootResource;
+		private PathMatching pathMatching;
+
+		public ResourceAndPathMatching(Object rootResource,
+				PathMatching pathMatching) {
+			this.rootResource = rootResource;
+			this.pathMatching = pathMatching;
+		}
+
+		public Object getRootResource() {
+			return rootResource;
+		}
+
+		public PathMatching getPathMatching() {
+			return pathMatching;
+		}
+
+	}
+
+	private static ThreadLocal<String> requestUri = new ThreadLocal<String>() {
+	};
+
+	public static String getCurrentRequestUri() {
+		return requestUri.get();
+	}
+
+	final static private Logger logger = LoggerFactory
+			.getLogger(RootResources.class);
+
+	/**
+	 * we store the resource descriptors
+	 */
+	SortedSet<RootResourceDescriptor> rootResourceDescriptors = new TreeSet<RootResourceDescriptor>();
+
+	/**
+	 * adds a {@link RootResourceDescriptor}
+	 * 
+	 * @param descriptor
+	 */
+	public void add(RootResourceDescriptor descriptor) {
+		// TODO Flag an error if the set includes more than one instance
+		// of the same class.
+		rootResourceDescriptors.add(descriptor);
+	}
+
+	/**
+	 * removes a {@link RootResourceDescriptor}
+	 * 
+	 * @param descriptor
+	 */
+	public void remove(RootResourceDescriptor descriptor) {
+		rootResourceDescriptors.remove(descriptor);
+	}
+
+	/**
+	 * 
+	 * @return the number of available root resources
+	 */
+	public int size() {
+		return rootResourceDescriptors.size();
+	}
+
+	/**
+	 * Get the best matching root-resource for a path
+	 * 
+	 * @param uriPath
+	 * @return the matching root-resource or null if no root resources matches
+	 */
+	public RootResourceDescriptor getDescriptor(String uriPath) {
+		for (RootResourceDescriptor descriptor : rootResourceDescriptors) {
+
+			PathMatching pathMatching = descriptor.getUriTemplate().match(
+					uriPath);
+			if (pathMatching != null) {
+				return descriptor;
+			}
+		}
+		return null;
+	}
+
+	ResourceAndPathMatching getResourceAndPathMatching(WebRequest request)
+			throws HandlerException, NoMatchingRootResourceException {
+		String uriPath;
+		try {
+			uriPath = UriUtil.encodePartlyEncodedPath(request.getWrhapiRequest().getRequestURI().getPath(), "UTF-8");
+		} catch (UriException ex) {
+			throw new RuntimeException(ex);
+		}
+		requestUri.set(uriPath);
+
+		PathMatching pathMatching = null;
+		RootResourceDescriptor descriptor = null;
+		Iterator<RootResourceDescriptor> descriptorIter = rootResourceDescriptors
+				.iterator();
+		while (descriptorIter.hasNext()) {
+			descriptor = descriptorIter.next();
+			pathMatching = descriptor.getUriTemplate().match(uriPath);
+			if (pathMatching != null) {
+				break;
+			}
+		}
+
+		if (pathMatching == null) {
+			throw new NoMatchingRootResourceException();
+		}
+		return new ResourceAndPathMatching(descriptor.getInstance(request,
+				pathMatching.getParameters()), pathMatching);
+	}
+}

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/TemplateEncoder.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/TemplateEncoder.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/TemplateEncoder.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/TemplateEncoder.java Tue Mar  2 12:49:20 2010
@@ -1,126 +1,12 @@
 package org.apache.clerezza.triaxrs.util;
 
-//copied and modified from java.net.URLEncoder
-
-/*
- * @(#)URLEncoder.java	1.32 06/04/22
- *
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
-
-import java.io.CharArrayWriter;
-import java.io.UnsupportedEncodingException;
+import java.io.StringWriter;
 import java.net.URLDecoder;
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
-import java.util.BitSet;
+import org.apache.clerezza.utils.UriException;
+import org.apache.clerezza.utils.UriUtil;
 
-/**
- * Utility class for HTML form encoding. This class contains static methods for
- * converting a String to the <CODE>application/x-www-form-urlencoded</CODE>
- * MIME format. For more information about HTML form encoding, consult the HTML
- * <A HREF="http://www.w3.org/TR/html4/">specification</A>.
- * 
- * <p>
- * When encoding a String, the following rules apply:
- * 
- * <p>
- * <ul>
- * <li>The alphanumeric characters &quot;<code>a</code>&quot; through &quot;
- * <code>z</code>&quot;, &quot;<code>A</code>&quot; through &quot;<code>Z</code>
- * &quot; and &quot;<code>0</code>&quot; through &quot;<code>9</code>&quot;
- * remain the same.
- * <li>The special characters &quot;<code>.</code>&quot;, &quot;<code>-</code>
- * &quot;, &quot;<code>*</code>&quot;, and &quot;<code>_</code>&quot; remain the
- * same.
- * <li>All other characters are unsafe and are first converted into one or more
- * bytes using some encoding scheme. Then each byte is represented by the
- * 3-character string &quot;<code>%<i>xy</i></code>&quot;, where <i>xy</i> is
- * the two-digit hexadecimal representation of the byte. The recommended
- * encoding scheme to use is UTF-8. However, for compatibility reasons, if an
- * encoding is not specified, then the default encoding of the platform is used.
- * </ul>
- * 
- * <p>
- * For example using UTF-8 as the encoding scheme the string &quot;The string
- * &#252;@foo-bar&quot; would get converted to
- * &quot;The+string+%C3%BC%40foo-bar&quot; because in UTF-8 the character &#252;
- * is encoded as two bytes C3 (hex) and BC (hex), and the character @ is encoded
- * as one byte 40 (hex).
- * 
- * @author Herb Jellinek
- * @version 1.32, 04/22/06
- * @since JDK1.0
- */
 public class TemplateEncoder {
-	static BitSet dontNeedEncoding;
-	static final int caseDiff = ('a' - 'A');
-	static String dfltEncName = "utf-8";
-
-	static {
-
-		/*
-		 * The list of characters that are not encoded has been determined as
-		 * follows:
-		 * 
-		 * RFC 2396 states: ----- Data characters that are allowed in a URI but
-		 * do not have a reserved purpose are called unreserved. These include
-		 * upper and lower case letters, decimal digits, and a limited set of
-		 * punctuation marks and symbols.
-		 * 
-		 * unreserved = alphanum | mark
-		 * 
-		 * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
-		 * 
-		 * Unreserved characters can be escaped without changing the semantics
-		 * of the URI, but this should not be done unless the URI is being used
-		 * in a context that does not allow the unescaped character to appear.
-		 * -----
-		 * 
-		 * It appears that both Netscape and Internet Explorer escape all
-		 * special characters from this list with the exception of "-", "_",
-		 * ".", "*". While it is not clear why they are escaping the other
-		 * characters, perhaps it is safest to assume that there might be
-		 * contexts in which the others are unsafe if not escaped. Therefore, we
-		 * will use the same list. It is also noteworthy that this is consistent
-		 * with O'Reilly's "HTML: The Definitive Guide" (page 164).
-		 * 
-		 * As a last note, Intenet Explorer does not encode the "@" character
-		 * which is clearly not unreserved according to the RFC. We are being
-		 * consistent with the RFC in this matter, as is Netscape.
-		 */
-
-		dontNeedEncoding = new BitSet(256);
-		int i;
-		for (i = 'a'; i <= 'z'; i++) {
-			dontNeedEncoding.set(i);
-		}
-		for (i = 'A'; i <= 'Z'; i++) {
-			dontNeedEncoding.set(i);
-		}
-		for (i = '0'; i <= '9'; i++) {
-			dontNeedEncoding.set(i);
-		}
-
-		dontNeedEncoding.set('-');
-		dontNeedEncoding.set('_');
-		dontNeedEncoding.set('.');
-		dontNeedEncoding.set('*');
-		dontNeedEncoding.set('{');
-		dontNeedEncoding.set('}');
-		dontNeedEncoding.set('/');
-		/*
-		 * https://jsr311.dev.java.net/nonav/releases/0.10/javax/ws/rs/Path.html:
-		 * Note that percent encoded values are allowed in the literal part of
-		 * the value, an implementation will recognize such values and will not
-		 * double encode the '%' character.
-		 */
-		dontNeedEncoding.set('%');
-
-	}
-
+	
 	/**
 	 * You can't call the constructor.
 	 */
@@ -128,31 +14,6 @@
 	}
 
 	/**
-	 * Translates a string into <code>x-www-form-urlencoded</code> format. This
-	 * method uses the platform's default encoding as the encoding scheme to
-	 * obtain the bytes for unsafe characters.
-	 * 
-	 * @param s
-	 *            <code>String</code> to be translated.
-	 * @deprecated The resulting string may vary depending on the platform's
-	 *             default encoding. Instead, use the encode(String,String)
-	 *             method to specify the encoding.
-	 * @return the translated <code>String</code>.
-	 */
-	public static String encode(String s) {
-
-		String str = null;
-
-		try {
-			str = encode(s, dfltEncName);
-		} catch (UnsupportedEncodingException e) {
-			// The system should always have the platform default
-		}
-
-		return str;
-	}
-
-	/**
 	 * Translates a string into <code>application/x-www-form-urlencoded</code>
 	 * format using a specific encoding scheme. This method uses the supplied
 	 * encoding scheme to obtain the bytes for unsafe characters.
@@ -163,7 +24,7 @@
 	 * UTF-8 should be used. Not doing so may introduce
 	 * incompatibilites.</em>
 	 * 
-	 * @param s
+	 * @param pathTemplate
 	 *            <code>String</code> to be translated.
 	 * @param enc
 	 *            The name of a supported <a
@@ -175,111 +36,25 @@
 	 * @see URLDecoder#decode(java.lang.String, java.lang.String)
 	 * @since 1.4
 	 */
-	public static String encode(String s, String enc)
-			throws UnsupportedEncodingException {
-
-		boolean needToChange = false;
-		StringBuffer out = new StringBuffer(s.length());
-		Charset charset;
-		CharArrayWriter charArrayWriter = new CharArrayWriter();
-
-		if (enc == null)
-			throw new NullPointerException("charsetName");
-
-		try {
-			charset = Charset.forName(enc);
-		} catch (IllegalCharsetNameException e) {
-			throw new UnsupportedEncodingException(enc);
-		} catch (UnsupportedCharsetException e) {
-			throw new UnsupportedEncodingException(enc);
-		}
-		boolean inVariableName = false;
-		for (int i = 0; i < s.length();) {
-			int c = (int) s.charAt(i);
-			if (c == '{') {
-				out.append((char) c);
-				inVariableName = true;
-				i++;
-				continue;
+	public static String encode(String pathTemplate, String enc)
+			throws UriException {
+		StringWriter sw = new StringWriter();
+		int index = 0;
+		while(true) {
+			int openCurlyIndex = pathTemplate.indexOf('{', index);
+			if (openCurlyIndex == -1) {
+				break;
 			}
-			if (inVariableName) {
-				out.append((char) c);
-				i++;
-				if (c == '}') {
-					inVariableName = false;
-				}
-				continue;
-			}
-			// System.out.println("Examining character: " + c);
-			if (dontNeedEncoding.get(c)) {
-				if (c == ' ') {
-					c = '+';
-					needToChange = true;
-				}
-				// System.out.println("Storing: " + c);
-				out.append((char) c);
-				i++;
-			} else {
-				// convert to external encoding before hex conversion
-				do {
-					charArrayWriter.write(c);
-					/*
-					 * If this character represents the start of a Unicode
-					 * surrogate pair, then pass in two characters. It's not
-					 * clear what should be done if a bytes reserved in the
-					 * surrogate pairs range occurs outside of a legal surrogate
-					 * pair. For now, just treat it as if it were any other
-					 * character.
-					 */
-					if (c >= 0xD800 && c <= 0xDBFF) {
-						/*
-						 * System.out.println(Integer.toHexString(c) +
-						 * " is high surrogate");
-						 */
-						if ((i + 1) < s.length()) {
-							int d = (int) s.charAt(i + 1);
-							/*
-							 * System.out.println("\tExamining " +
-							 * Integer.toHexString(d));
-							 */
-							if (d >= 0xDC00 && d <= 0xDFFF) {
-								/*
-								 * System.out.println("\t" +
-								 * Integer.toHexString(d) +
-								 * " is low surrogate");
-								 */
-								charArrayWriter.write(d);
-								i++;
-							}
-						}
-					}
-					i++;
-				} while (i < s.length()
-						&& !dontNeedEncoding.get((c = (int) s.charAt(i))));
-
-				charArrayWriter.flush();
-				String str = new String(charArrayWriter.toCharArray());
-				byte[] ba = str.getBytes(charset);
-				for (int j = 0; j < ba.length; j++) {
-					out.append('%');
-					char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
-					// converting to use uppercase letter as part of
-					// the hex value if ch is a letter.
-					if (Character.isLetter(ch)) {
-						ch -= caseDiff;
-					}
-					out.append(ch);
-					ch = Character.forDigit(ba[j] & 0xF, 16);
-					if (Character.isLetter(ch)) {
-						ch -= caseDiff;
-					}
-					out.append(ch);
-				}
-				charArrayWriter.reset();
-				needToChange = true;
+			int closeCurlyIndex = pathTemplate.indexOf('}', openCurlyIndex);
+			if (closeCurlyIndex == -1) {
+				break;
 			}
+			sw.append(UriUtil.encodePartlyEncodedPath(pathTemplate.substring(index, openCurlyIndex), enc));
+			sw.append(pathTemplate.substring(openCurlyIndex, closeCurlyIndex + 1));
+			index = closeCurlyIndex + 1;
 		}
-
-		return (needToChange ? out.toString() : s);
+		sw.append(UriUtil.encodePartlyEncodedPath(pathTemplate.substring(index, pathTemplate.length()),enc));
+		return sw.toString();
 	}
+	
 }

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/util/URITemplate.java Tue Mar  2 12:49:20 2010
@@ -21,13 +21,13 @@
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.apache.clerezza.utils.UriException;
 
 public class URITemplate implements Comparable<URITemplate> {
 
@@ -70,7 +70,7 @@
 	public URITemplate(String rawTemplateString) {
 		try {
 			rawTemplateString = TemplateEncoder.encode(rawTemplateString, "UTF-8");
-		} catch (UnsupportedEncodingException ex) {
+		} catch (UriException ex) {
 			throw new RuntimeException(ex);
 		}
 		if ((rawTemplateString.length() > 0) && (rawTemplateString.charAt(0) == '/')) {

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/TestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/TestTemplate.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/TestTemplate.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/TestTemplate.java Tue Mar  2 12:49:20 2010
@@ -23,7 +23,6 @@
 
 import org.junit.Before;
 import org.junit.Test;
-import org.apache.clerezza.triaxrs.JaxRsHandler;
 import org.apache.clerezza.triaxrs.delegate.RuntimeDelegateImpl;
 import org.apache.clerezza.triaxrs.mock.RequestImpl;
 import org.apache.clerezza.triaxrs.mock.RequestURIImpl;

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/FormParamTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/FormParamTest.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/FormParamTest.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/FormParamTest.java Tue Mar  2 12:49:20 2010
@@ -25,7 +25,6 @@
 import java.nio.channels.Channels;
 import java.nio.channels.WritableByteChannel;
 
-import javax.ws.rs.DefaultValue;
 import javax.ws.rs.FormParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;

Modified: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/ResourcePathTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/ResourcePathTest.java?rev=918006&r1=918005&r2=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/ResourcePathTest.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/blackbox/ResourcePathTest.java Tue Mar  2 12:49:20 2010
@@ -75,6 +75,15 @@
 		}
 	}
 
+	@Path("test+resource")
+	public static class MyResource4 {
+
+		@GET
+		public void handleGet() {
+			methodInvokedForGet = true;
+		}
+	}
+
 	@Before
 	public void reset() {
 		methodInvokedForGet = false;
@@ -105,6 +114,18 @@
 	}
 
 	@Test
+	public void requestOnResourcePathContainingPlusTest() throws Exception {
+		JaxRsHandler handler = HandlerCreator.getHandler(MyResource4.class);
+		RequestImpl requestMock = new RequestImpl();
+		RequestURIImpl requestUri = new RequestURIImpl();
+		requestUri.setPath("/test+resource");
+		requestMock.setRequestURI(requestUri);
+		requestMock.setMethod(Method.GET);
+		handler.handle(requestMock, new ResponseImpl());
+		assertTrue(methodInvokedForGet);
+	}
+
+	@Test
 	public void requestOnResourcePathContainingSpaceTest() throws Exception {
 		JaxRsHandler handler = HandlerCreator.getHandler(MyResource3.class);
 		RequestImpl requestMock = new RequestImpl();

Copied: incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TemplateEncoderTest.java (from r915817, incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TestTemplateEncoder.java)
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TemplateEncoderTest.java?p2=incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TemplateEncoderTest.java&p1=incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TestTemplateEncoder.java&r1=915817&r2=918006&rev=918006&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TestTemplateEncoder.java (original)
+++ incubator/clerezza/issues/CLEREZZA-129/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/test/java/org/apache/clerezza/triaxrs/util/TemplateEncoderTest.java Tue Mar  2 12:49:20 2010
@@ -22,12 +22,13 @@
 
 import org.junit.Test;
 
-public class TestTemplateEncoder {
+public class TemplateEncoderTest {
 	@Test
 	public void simpleEncoding() throws Exception {
-		String s = "/föö/{blüü}/blä";
+		String s = "/föö/{blüü}/blä{euo}+{";
 		String encoded = TemplateEncoder.encode(s, "utf-8");
-		Assert.assertTrue(encoded.indexOf("{blüü}") != -1);
+		System.out.println(encoded);
+		Assert.assertEquals("/f%C3%B6%C3%B6/{blüü}/bl%C3%A4{euo}%2B%7B", encoded);
 	}
 
 	@Test
@@ -36,4 +37,11 @@
 		String encoded = TemplateEncoder.encode(s, "utf-8");
 		Assert.assertEquals("/foo%20bar", encoded);
 	}
+
+	@Test
+	public void containsAlreadyEncodedCharsTest() throws Exception {
+		String s = "/++/%20 %20/äöü%GG";
+		String encoded = TemplateEncoder.encode(s, "utf-8");
+		Assert.assertEquals("/%2B%2B/%20%20%20/%C3%A4%C3%B6%C3%BC%25GG", encoded);
+	}
 }