Author: fguillaume
Date: Mon Jan 4 13:44:38 2010
New Revision: 895624
URL: http://svn.apache.org/viewvc?rev=895624&view=rev
Log:
Fix JAX-RS path decoding, passes one more TCK test with JAX-RS
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=895624&r1=895623&r2=895624&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Mon Jan 4 13:44:38 2010
@@ -23,6 +23,7 @@
import javax.servlet.http.HttpServletRequestWrapper;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
+import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@@ -112,7 +113,7 @@
String cpath = httpRequest.getContextPath();
String spath = httpRequest.getServletPath();
// find this Resource path (remove some segments from it)
- String rpath = ui.getPath();
+ String rpath = ui.getPath(false);
while (segments > 0) {
segments--;
if (rpath.contains("/")) {
@@ -322,7 +323,7 @@
@GET
@Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
@Path("path/{path:.*}")
- public Response doGetObjectByPath(@PathParam("path") String path) {
+ public Response doGetObjectByPath(@Encoded @PathParam("path") String path)
{
int skipSegments = 2;
for (int i = 0; i < path.length(); i++) {
if (path.charAt(i) == '/') {
Modified:
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=895624&r1=895623&r2=895624&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Mon Jan 4 13:44:38 2010
@@ -526,4 +526,25 @@
assertEquals("new descr", ob.getValue("description"));
}
+ public void testUpdate() throws Exception {
+ byte[] blobBytes = "A file...\n".getBytes("UTF-8");
+ String filename = "doc.txt";
+ ContentStream cs = new SimpleContentStream(blobBytes,
+ "text/plain;charset=UTF-8", filename);
+
+ // update a doc with a content stream
+ ObjectEntry ob = spi.getObjectByPath("/folder 1/folder 2/doc 3", null);
+ Document doc = (Document) conn.getObject(ob);
+ doc.setContentStream(cs);
+ doc.setValue("title", "my doc 3");
+ doc.save();
+
+ // update a doc that doesn't have a content stream yet
+ ob = spi.getObjectByPath("/folder 1/doc 1", null);
+ doc = (Document) conn.getObject(ob);
+ doc.setContentStream(cs);
+ doc.setValue("title", "my doc 1");
+ doc.save();
+ }
+
}
Modified:
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java?rev=895624&r1=895623&r2=895624&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/MainServlet.java
Mon Jan 4 13:44:38 2010
@@ -16,10 +16,19 @@
*/
package org.apache.chemistry.test;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
import javax.servlet.Servlet;
import org.apache.chemistry.Repository;
+import org.apache.chemistry.atompub.server.jaxrs.AbderaResource;
import org.apache.chemistry.atompub.server.servlet.CMISServlet;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.jetty.Connector;
@@ -27,6 +36,7 @@
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.webapp.WebAppContext;
/**
* Test class that runs a servlet on a memory repository initialized with a few
@@ -43,23 +53,26 @@
public static final String DEFAULT_HOST = "0.0.0.0";
- public static final int DEFAULT_PORT = 8080;
+ public static final int DEFAULT_PORT = 8082;
public static void main(String[] args) throws Exception {
Repository repository = BasicHelper.makeSimpleRepository(ROOT_ID);
- MainServlet.run(args, repository, "/cmis", "/repository");
+ new MainServlet().run(args, repository, "/cmis", "/repository");
}
- public static void run(String[] args, Repository repository,
- String servletPath, String cmisService) throws Exception {
+ public void run(String[] args, Repository repository, String contextPath,
+ String cmisService) throws Exception {
String host = DEFAULT_HOST;
int port = DEFAULT_PORT;
int minutes = DEFAULT_MINUTES;
+ boolean jaxrs = false;
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if ("--help".equals(arg)) {
- System.err.println("Usage: ... [-h HOST] [-p PORT] [-t TIME
(minutes)]");
+ System.err.println("Usage: ... [--jaxrs] [-h HOST] [-p PORT]
[-t TIME (minutes)]");
System.exit(0);
+ } else if ("--jaxrs".equals(arg)) {
+ jaxrs = true;
}
if (i == args.length - 1) {
continue;
@@ -78,21 +91,80 @@
connector.setHost(host);
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
- Servlet servlet = new CMISServlet(repository);
- ServletHolder servletHolder = new ServletHolder(servlet);
- Context context = new Context(server, servletPath, Context.SESSIONS);
- context.addServlet(servletHolder, "/*");
+ if (jaxrs) {
+ setUpJAXRS(server, contextPath, repository);
+ } else {
+ setUpAbderaServlet(server, contextPath, repository);
+ }
server.start();
- String url = "http://" + host + ':' + port + servletPath + cmisService;
- log.info(getServerName(repository) + " started, AtomPub service url: "
+
+ String url = "http://" + host + ':' + port + contextPath + cmisService;
+ log.warn(getServerName(repository) + " started, AtomPub service url: "
+ url);
- Thread.sleep(1000 * 60 * minutes);
- server.stop();
- log.info(getServerName(repository) + " stopped");
+ try {
+ Thread.sleep(1000 * 60 * minutes);
+ server.stop();
+ } finally {
+ if (jaxrs) {
+ tearDownJAXRS();
+ } else {
+ tearDownAbderaServlet();
+ }
+ }
+
+ log.warn(getServerName(repository) + " stopped");
}
- private static String getServerName(Repository repository) {
+ protected static String getServerName(Repository repository) {
return "CMIS repository " + repository.getInfo().getProductName();
}
+ protected void setUpAbderaServlet(Server server, String contextPath,
+ Repository repository) throws Exception {
+ Servlet servlet = new CMISServlet(repository);
+ Context context = new Context(server, contextPath, Context.SESSIONS);
+ context.addServlet(new ServletHolder(servlet), "/*");
+ }
+
+ protected void tearDownAbderaServlet() {
+ }
+
+ protected File tmpDir;
+
+ protected void setUpJAXRS(Server server, String contextPath,
+ Repository repository) throws Exception {
+ if (!"/cmis".equals(contextPath)) {
+ throw new RuntimeException("AbderaResource implies a context of
/cmis");
+ }
+ AbderaResource.repository = repository; // TODO inject differently
+ AbderaResource.pathMunger = null; // TODO
+ tmpDir = makeTmpDir();
+ String webApp = makeWebApp(tmpDir);
+ Context context = new WebAppContext(server, webApp, "");
+ server.setHandler(context);
+ }
+
+ protected void tearDownJAXRS() throws IOException {
+ FileUtils.forceDelete(tmpDir);
+ }
+
+ protected static File makeTmpDir() throws IOException {
+ File tmpDir = File.createTempFile("test-chemistry-", null);
+ tmpDir.delete();
+ tmpDir.mkdir();
+ return tmpDir;
+ }
+
+ protected static String makeWebApp(File tmpDir) throws IOException {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl.getResourceAsStream("jaxrs/web.xml");
+ File war = new File(tmpDir, "war");
+ File webinf = new File(war, "WEB-INF");
+ webinf.mkdirs();
+ File web = new File(webinf, "web.xml");
+ OutputStream os = new FileOutputStream(web);
+ IOUtils.copy(is, os);
+ return war.getAbsolutePath();
+ }
+
}