Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 909E6D332 for ; Fri, 29 Jun 2012 14:10:18 +0000 (UTC) Received: (qmail 24766 invoked by uid 500); 29 Jun 2012 14:10:18 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 24721 invoked by uid 500); 29 Jun 2012 14:10:18 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 24714 invoked by uid 99); 29 Jun 2012 14:10:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Jun 2012 14:10:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Fri, 29 Jun 2012 14:10:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9D2F3238899C; Fri, 29 Jun 2012 14:09:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1355397 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests... Date: Fri, 29 Jun 2012 14:09:47 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120629140948.9D2F3238899C@eris.apache.org> Author: sergeyb Date: Fri Jun 29 14:09:46 2012 New Revision: 1355397 URL: http://svn.apache.org/viewvc?rev=1355397&view=rev Log: Merged revisions 1355395 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes ................ r1355395 | sergeyb | 2012-06-29 15:02:39 +0100 (Fri, 29 Jun 2012) | 9 lines Merged revisions 1355380 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1355380 | sergeyb | 2012-06-29 14:38:13 +0100 (Fri, 29 Jun 2012) | 1 line [CXF-4400] Better handling of redirect and static resource requests in AbstractHttpServlet ........ ................ Added: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/welcomeBook.html - copied unchanged from r1355395, cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/welcomeBook.html Modified: cxf/branches/2.5.x-fixes/ (props changed) cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/trunk:r1355380 Merged /cxf/branches/2.6.x-fixes:r1355395 Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1355397&r1=1355396&r2=1355397&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java Fri Jun 29 14:09:46 2012 @@ -127,30 +127,15 @@ public class CXFNonSpringJaxrsServlet ex } protected void setExtensions(JAXRSServerFactoryBean bean, ServletConfig servletConfig) { - bean.setExtensionMappings(handleMapSequence(servletConfig.getInitParameter(EXTENSIONS_PARAM))); - bean.setLanguageMappings(handleMapSequence(servletConfig.getInitParameter(LANGUAGES_PARAM))); + bean.setExtensionMappings( + CastUtils.cast((Map)parseMapSequence(servletConfig.getInitParameter(EXTENSIONS_PARAM)))); + bean.setLanguageMappings( + CastUtils.cast((Map)parseMapSequence(servletConfig.getInitParameter(LANGUAGES_PARAM)))); bean.setProperties(CastUtils.cast( - handleMapSequence(servletConfig.getInitParameter(PROPERTIES_PARAM)), + parseMapSequence(servletConfig.getInitParameter(PROPERTIES_PARAM)), String.class, Object.class)); } - protected Map handleMapSequence(String sequence) { - if (sequence != null) { - sequence = sequence.trim(); - Map map = new HashMap(); - String[] pairs = sequence.split(" "); - for (String pair : pairs) { - String[] value = pair.split("="); - if (value.length == 2) { - map.put(value[0].trim(), value[1].trim()); - } - } - return map; - } else { - return Collections.emptyMap(); - } - } - protected void setAllInterceptors(JAXRSServerFactoryBean bean, ServletConfig servletConfig) { setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM); setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM); @@ -268,8 +253,7 @@ public class CXFNonSpringJaxrsServlet ex String theName = cName.trim(); int ind = theName.indexOf("("); if (ind != -1 && theName.endsWith(")")) { - props.putAll(CastUtils.cast(handleMapSequence(theName.substring(ind + 1, theName.length() - 1)), - String.class, String.class)); + props.putAll(parseMapSequence(theName.substring(ind + 1, theName.length() - 1))); theName = theName.substring(0, ind).trim(); } return theName; Modified: cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=1355397&r1=1355396&r2=1355397&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java (original) +++ cxf/branches/2.5.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java Fri Jun 29 14:09:46 2012 @@ -21,10 +21,12 @@ package org.apache.cxf.transport.servlet import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; @@ -38,6 +40,7 @@ import javax.servlet.http.HttpServletReq import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; +import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.transport.http.AbstractHTTPDestination; @@ -52,10 +55,12 @@ public abstract class AbstractHTTPServle Arrays.asList(new String[]{"POST", "GET", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"}); private static final String STATIC_RESOURCES_PARAMETER = "static-resources-list"; + private static final String STATIC_WELCOME_FILE_PARAMETER = "static-welcome-file"; private static final String REDIRECTS_PARAMETER = "redirects-list"; private static final String REDIRECT_SERVLET_NAME_PARAMETER = "redirect-servlet-name"; private static final String REDIRECT_SERVLET_PATH_PARAMETER = "redirect-servlet-path"; + private static final String REDIRECT_ATTRIBUTES_PARAMETER = "redirect-attributes"; private static final String REDIRECT_QUERY_CHECK_PARAMETER = "redirect-query-check"; private static final Map STATIC_CONTENT_TYPES; @@ -70,31 +75,38 @@ public abstract class AbstractHTTPServle // TODO : add more types if needed } - private List staticResourcesList; - private List redirectList; + private List staticResourcesList; + private String staticWelcomeFile; + private List redirectList; private String dispatcherServletPath; private String dispatcherServletName; + private Map redirectAttributes; private boolean redirectQueryCheck; public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); staticResourcesList = parseListSequence(servletConfig.getInitParameter(STATIC_RESOURCES_PARAMETER)); + staticWelcomeFile = servletConfig.getInitParameter(STATIC_WELCOME_FILE_PARAMETER); redirectList = parseListSequence(servletConfig.getInitParameter(REDIRECTS_PARAMETER)); redirectQueryCheck = Boolean.valueOf(servletConfig.getInitParameter(REDIRECT_QUERY_CHECK_PARAMETER)); dispatcherServletName = servletConfig.getInitParameter(REDIRECT_SERVLET_NAME_PARAMETER); dispatcherServletPath = servletConfig.getInitParameter(REDIRECT_SERVLET_PATH_PARAMETER); + + redirectAttributes = parseMapSequence(servletConfig.getInitParameter(REDIRECT_ATTRIBUTES_PARAMETER)); + + } - private static List parseListSequence(String values) { + protected static List parseListSequence(String values) { if (values != null) { - List list = new LinkedList(); + List list = new LinkedList(); String[] pathValues = values.split(" "); for (String value : pathValues) { String theValue = value.trim(); if (theValue.length() > 0) { - list.add(theValue); + list.add(Pattern.compile(theValue)); } } return list; @@ -103,6 +115,25 @@ public abstract class AbstractHTTPServle } } + protected static Map parseMapSequence(String sequence) { + if (sequence != null) { + sequence = sequence.trim(); + Map map = new HashMap(); + String[] pairs = sequence.split(" "); + for (String pair : pairs) { + String[] value = pair.split("="); + if (value.length == 2) { + map.put(value[0].trim(), value[1].trim()); + } else { + map.put(pair.trim(), ""); + } + } + return map; + } else { + return Collections.emptyMap(); + } + } + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException { handleRequest(request, response); @@ -178,14 +209,17 @@ public abstract class AbstractHTTPServle } if (staticResourcesList != null - && matchPath(staticResourcesList, request)) { - serveStaticContent(request, response, request.getPathInfo()); + && matchPath(staticResourcesList, request) + || staticWelcomeFile != null + && (StringUtils.isEmpty(request.getPathInfo()) || request.getPathInfo().equals("/"))) { + serveStaticContent(request, response, + staticWelcomeFile != null ? staticWelcomeFile : request.getPathInfo()); return; } invoke(request, response); } - private boolean matchPath(List values, HttpServletRequest request) { + private boolean matchPath(List values, HttpServletRequest request) { String path = request.getPathInfo(); if (path == null) { path = "/"; @@ -196,8 +230,8 @@ public abstract class AbstractHTTPServle path += "?" + queryString; } } - for (String value : values) { - if (path.matches(value)) { + for (Pattern pattern : values) { + if (pattern.matcher(path).matches()) { return true; } } @@ -247,6 +281,9 @@ public abstract class AbstractHTTPServle throw new ServletException(errorMessage); } try { + for (Map.Entry entry : redirectAttributes.entrySet()) { + request.setAttribute(entry.getKey(), entry.getValue()); + } HttpServletRequestFilter servletRequest = new HttpServletRequestFilter(request, pathInfo, theServletPath); rd.forward(servletRequest, response); Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1355397&r1=1355396&r2=1355397&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Fri Jun 29 14:09:46 2012 @@ -554,6 +554,26 @@ public class BookStore { } @GET + @Path("/books/{fiql}/chapter/{i}") + @Produces("application/xml") + public Chapter getInChapterFromSelectedBook(@Context SearchContext searchContext, + @PathParam("fiql") PathSegment fiqlSegment, + @PathParam("i") int chapterIndex) throws BookNotFoundFault { + + SearchCondition sc = searchContext.getCondition(Book.class); + if (sc == null) { + throw new BookNotFoundFault("Search exception"); + } + List found = sc.findAll(books.values()); + if (found.size() != 1) { + throw new BookNotFoundFault("Single book is expected"); + } + + Book book = found.get(0); + return book.getChapter(chapterIndex); + } + + @GET @Path("/books/text/xml/{bookId}") @Produces("text/xml") public Book getBookTextXml(@PathParam("bookId") String id) throws BookNotFoundFault { Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java?rev=1355397&r1=1355396&r2=1355397&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSRequestDispatcherTest.java Fri Jun 29 14:09:46 2012 @@ -97,4 +97,33 @@ public class JAXRSRequestDispatcherTest String value = source.getValue("xhtml:html/xhtml:body/xhtml:ul/books:bookTag", namespaces); assertEquals("CXF Rocks", value); } + @Test + public void testGetBookHTMLFromWelcomeList() throws Exception { + String endpointAddress = "http://localhost:" + PORT + "/welcome"; + doTestGetBookHTMLFromWelcomeList(endpointAddress); + } + + @Test + public void testGetBookHTMLFromWelcomeList2() throws Exception { + String endpointAddress = "http://localhost:" + PORT + "/the"; + doTestGetBookHTMLFromWelcomeList(endpointAddress); + } + + @Test + public void testGetBookHTMLFromStaticWelcomeFile() throws Exception { + String endpointAddress = "http://localhost:" + PORT + "/welcome2"; + doTestGetBookHTMLFromWelcomeList(endpointAddress); + } + + private void doTestGetBookHTMLFromWelcomeList(String address) throws Exception { + WebClient client = WebClient.create(address); + client.accept("text/html"); + WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(100000000); + XMLSource source = client.accept("text/html").get(XMLSource.class); + Map namespaces = new HashMap(); + namespaces.put("xhtml", "http://www.w3.org/1999/xhtml"); + namespaces.put("books", "http://www.w3.org/books"); + String value = source.getValue("xhtml:html/xhtml:body/xhtml:ul/books:bookTag", namespaces); + assertEquals("Welcome to CXF", value); + } } Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml?rev=1355397&r1=1355396&r2=1355397&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml Fri Jun 29 14:09:46 2012 @@ -28,7 +28,7 @@ contextConfigLocation WEB-INF/beans.xml - + org.springframework.web.context.ContextLoaderListener @@ -41,6 +41,22 @@ org.apache.cxf.transport.servlet.CXFServlet + + redirects-list + + / + + + + redirect-attributes + + javax.servlet.include.request_uri + + + + redirect-servlet-name + default + 1 @@ -48,7 +64,6 @@ CXFServlet /the/* - RedirectCXFServlet Redirect CXF Servlet @@ -57,14 +72,10 @@ redirects-list - /(\w)+.html + + /(\w)+.html + - redirect-servlet-path /static @@ -74,9 +85,8 @@ RedirectCXFServlet - /* + /book.html - DefaultCXFServlet Default CXF Servlet @@ -89,11 +99,63 @@ 1 - - + + DefaultCXFServlet /static/* + + WelcomeCXFServlet + Welcome CXF Servlet + + org.apache.cxf.transport.servlet.CXFServlet + + + redirects-list + + / + + + + redirect-attributes + + javax.servlet.include.request_uri + + + + redirect-servlet-name + default + + 1 + + + + + WelcomeCXFServlet + /welcome/* + + + + WelcomeCXFServlet2 + Welcome CXF Servlet2 + + org.apache.cxf.transport.servlet.CXFServlet + + + static-welcome-file + /welcomeBook.html + + 1 + + + + WelcomeCXFServlet2 + /welcome2/* + + + + welcomeBook.html + \ No newline at end of file