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 BFF3A754C for ; Fri, 5 Aug 2011 09:39:36 +0000 (UTC) Received: (qmail 6332 invoked by uid 500); 5 Aug 2011 09:39:35 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 6099 invoked by uid 500); 5 Aug 2011 09:39:27 -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 6092 invoked by uid 99); 5 Aug 2011 09:39:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Aug 2011 09:39:23 +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, 05 Aug 2011 09:39:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0780D23889B1 for ; Fri, 5 Aug 2011 09:38:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1154145 - in /cxf/branches/2.4.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java Date: Fri, 05 Aug 2011 09:38:55 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110805093856.0780D23889B1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergeyb Date: Fri Aug 5 09:38:55 2011 New Revision: 1154145 URL: http://svn.apache.org/viewvc?rev=1154145&view=rev Log: Merged revisions 1154143 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1154143 | sergeyb | 2011-08-05 10:35:22 +0100 (Fri, 05 Aug 2011) | 1 line [CXF-3709] Removing index-based calculation of base URL ........ Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ svn:mergeinfo = /cxf/trunk:1154143 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java?rev=1154145&r1=1154144&r2=1154145&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java (original) +++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java Fri Aug 5 09:38:55 2011 @@ -18,6 +18,8 @@ */ package org.apache.cxf.transport.servlet; +import java.net.URI; + import javax.servlet.http.HttpServletRequest; import org.apache.cxf.transport.AbstractDestination; @@ -28,36 +30,31 @@ public final class BaseUrlHelper { private BaseUrlHelper() { } + /** + * Returns base URL which includes scheme, host, port, Servlet context and servlet paths + * @param request current HttpServletRequest + * @return base URL + */ public static String getBaseURL(HttpServletRequest request) { String reqPrefix = request.getRequestURL().toString(); String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo(); //fix for CXF-898 if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) { - String basePath = request.getContextPath() + request.getServletPath(); - int index; - if (basePath.length() == 0) { - index = reqPrefix.indexOf(request.getRequestURI()); - } else { - index = reqPrefix.indexOf(basePath); - } - reqPrefix = reqPrefix.substring(0, index + basePath.length()); + StringBuilder sb = new StringBuilder(); + // request.getScheme(), request.getLocalName() and request.getLocalPort() + // should be marginally cheaper - provided request.getLocalName() does + // return the actual name used in request URI as opposed to localhost + // consistently across the Servlet stacks + + URI uri = URI.create(reqPrefix); + sb.append(uri.getScheme()).append("://").append(uri.getRawAuthority()); + sb.append(request.getContextPath()).append(request.getServletPath()); + + reqPrefix = sb.toString(); } return reqPrefix; } - public static void makeAddressesAbsolute(HttpServletRequest request, String baseAddress, - AbstractDestination[] destinations) { - for (AbstractDestination dest : destinations) { - String addr = dest.getEndpointInfo().getAddress(); - if (addr == null || addr.length() == 0) { - addr = "/"; - } - if (addr != null && !addr.startsWith("http")) { - String base = baseAddress == null ? BaseUrlHelper.getBaseURL(request) : baseAddress; - setAddress(dest, base + addr); - } - } - } public static void setAddress(AbstractDestination dest, String absAddress) { dest.getEndpointInfo().setAddress(absAddress); Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java?rev=1154145&r1=1154144&r2=1154145&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java (original) +++ cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java Fri Aug 5 09:38:55 2011 @@ -52,6 +52,12 @@ public class BaseUrlHelperTest { } @Test + public void testGetRequestURLWithRepeatingValues() throws Exception { + String url = testGetBaseURL("http://services.com/services/bar", "/services", "", "/bar"); + Assert.assertEquals("http://services.com/services", url); + } + + @Test public void testGetRequestURL() throws Exception { String url = testGetBaseURL("http://localhost:8080/services/bar", "", "/services", "/bar"); Assert.assertEquals("http://localhost:8080/services", url);