Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 66601 invoked from network); 25 Aug 2009 19:01:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Aug 2009 19:01:51 -0000 Received: (qmail 32104 invoked by uid 500); 25 Aug 2009 19:02:16 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 32070 invoked by uid 500); 25 Aug 2009 19:02:16 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 32060 invoked by uid 99); 25 Aug 2009 19:02:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Aug 2009 19:02:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Aug 2009 19:02:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A4D6323888CB; Tue, 25 Aug 2009 19:01:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r807762 - in /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src: main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java Date: Tue, 25 Aug 2009 19:01:54 -0000 To: chemistry-commits@incubator.apache.org From: fguillaume@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090825190154.A4D6323888CB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fguillaume Date: Tue Aug 25 19:01:53 2009 New Revision: 807762 URL: http://svn.apache.org/viewvc?rev=807762&view=rev Log: CMIS-48: Allow use of AtomPub server behind a rewriting reverse proxy Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.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=807762&r1=807761&r2=807762&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 Tue Aug 25 19:01:53 2009 @@ -39,6 +39,7 @@ import org.apache.chemistry.atompub.AtomPub; import org.apache.chemistry.atompub.AtomPubCMIS; import org.apache.chemistry.atompub.server.CMISProvider; +import org.apache.chemistry.atompub.server.jaxrs.AbderaResource.PathMunger.ContextAndServletPath; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,6 +63,20 @@ // TODO inject repository somehow public static Repository repository; + // TODO configure somehow + public static PathMunger pathMunger; + + public interface PathMunger { + public static class ContextAndServletPath { + public String contextPath; + + public String servletPath; + } + + ContextAndServletPath munge(HttpServletRequest request, + String contextPath, String servletPath); + } + public AbderaResource() throws Exception { try { provider = new CMISProvider(repository); @@ -76,8 +91,8 @@ /** * Gets a {@link ServletRequestContext} wrapping the httpRequest. *

- * Wrapping is needed to fixup the servlet path to take include this - * Resource's path. + * Wrapping is needed to fixup the servlet path to include this Resource's + * path. *

* We need to pass an explicit number of segments because * UriInfo.getMatchedURIs is buggy for RESTEasy @@ -87,7 +102,8 @@ * to determine the Resource path */ protected ServletRequestContext getRequestContext(int segments) { - // actual servlet path + // actual context & servlet path + String cpath = httpRequest.getContextPath(); String spath = httpRequest.getServletPath(); // find this Resource path (remove some segments from it) String rpath = ui.getPath(); @@ -97,18 +113,45 @@ rpath = rpath.substring(0, rpath.lastIndexOf('/')); } } + // find the pretend context & servlet path + final String contextPath; + final String servletPath; + final String resourcePath = rpath; + if (pathMunger == null) { + contextPath = cpath; + servletPath = spath; + } else { + ContextAndServletPath cs = pathMunger.munge(httpRequest, cpath, + spath); + contextPath = cs.contextPath; + servletPath = cs.servletPath; + } HttpServletRequest wrapper; - if (rpath.length() == 0) { - // no resource path to fake + if (cpath.equals(contextPath) + && spath.equals(servletPath + resourcePath)) { + // no path to fake wrapper = httpRequest; } else { - // this gives the pretend servlet path - final String pspath = spath + rpath; - // wrap HttpServletRequest to pretend to have this servlet path + // wrap HttpServletRequest to pretend to have this context & servlet + // path wrapper = new HttpServletRequestWrapper(httpRequest) { @Override + public String getContextPath() { + return contextPath; + } + + @Override public String getServletPath() { - return pspath; + return servletPath + resourcePath; + } + + @Override + public String getRequestURI() { + String uri = super.getRequestURI(); + String cs = super.getContextPath() + super.getServletPath(); + // strip original context + servlet, add our own + return contextPath + servletPath + + uri.substring(cs.length()); } }; } @@ -124,18 +167,27 @@ protected Response getAbderaFeed(int skipSegments) { RequestContext requestContext = getRequestContext(skipSegments); CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext); + if (adapter == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } return Response.ok(adapter.getFeed(requestContext)).build(); } protected Response getAbderaEntry(int skipSegments) { RequestContext requestContext = getRequestContext(skipSegments); CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext); + if (adapter == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } return Response.ok(adapter.getEntry(requestContext)).build(); } protected Response getAbderaPostFeed(int skipSegments) { RequestContext requestContext = getRequestContext(skipSegments); CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext); + if (adapter == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } return Response.ok(adapter.postEntry(requestContext)).build(); } Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java?rev=807762&r1=807761&r2=807762&view=diff ============================================================================== --- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java (original) +++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/TestAtomPubJaxrs.java Tue Aug 25 19:01:53 2009 @@ -53,6 +53,7 @@ @Override public void startServer() throws Exception { AbderaResource.repository = repository; // TODO inject differently + AbderaResource.pathMunger = null; // TODO server = new Server(PORT); server.setHandler(new WebAppContext(server, makeWar(), CONTEXT_PATH)); server.start();