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);
|