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 6AE57DA6E for ; Wed, 8 Aug 2012 09:45:19 +0000 (UTC) Received: (qmail 471 invoked by uid 500); 8 Aug 2012 09:45:19 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 364 invoked by uid 500); 8 Aug 2012 09:45: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 340 invoked by uid 99); 8 Aug 2012 09:45:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 09:45: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; Wed, 08 Aug 2012 09:45:16 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F16EA238897F; Wed, 8 Aug 2012 09:44:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1370720 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Date: Wed, 08 Aug 2012 09:44:31 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120808094431.F16EA238897F@eris.apache.org> Author: sergeyb Date: Wed Aug 8 09:44:31 2012 New Revision: 1370720 URL: http://svn.apache.org/viewvc?rev=1370720&view=rev Log: Trying to calculate a correct base address in cases where the scheme is not http-based, as in Camel servlet Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1370720&r1=1370719&r2=1370720&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Wed Aug 8 09:44:31 2012 @@ -50,6 +50,7 @@ import org.apache.cxf.message.Message; import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.transport.Destination; import org.apache.cxf.transport.http.AbstractHTTPDestination; +import org.apache.cxf.transport.servlet.BaseUrlHelper; public final class HttpUtils { @@ -59,6 +60,7 @@ public final class HttpUtils { private static final String REQUEST_PATH_TO_MATCH = "path_to_match"; private static final String REQUEST_PATH_TO_MATCH_SLASH = "path_to_match_slash"; + private static final String HTTP_SCHEME = "http"; private static final String ANY_IP_ADDRESS = "0.0.0.0"; private static final String ANY_IP_ADDRESS_START = "://0.0.0.0"; private static final int DEFAULT_HTTP_PORT = 80; @@ -186,6 +188,16 @@ public final class HttpUtils { || HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(headerName); } + public static boolean isHttpRequest(Message message) { + return message.get(AbstractHTTPDestination.HTTP_REQUEST) != null; + } + + public static URI toAbsoluteUri(String relativePath, Message message) { + String base = BaseUrlHelper.getBaseURL( + (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST)); + return URI.create(base + relativePath); + } + public static URI toAbsoluteUri(URI u, Message message) { HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST); @@ -240,7 +252,13 @@ public final class HttpUtils { public static String getBaseAddress(Message m) { String endpointAddress = getEndpointAddress(m); try { - String path = new URI(endpointAddress).getRawPath(); + URI uri = new URI(endpointAddress); + String path = uri.getRawPath(); + String scheme = uri.getScheme(); + if (scheme != null && !scheme.startsWith(HttpUtils.HTTP_SCHEME) + && HttpUtils.isHttpRequest(m)) { + path = HttpUtils.toAbsoluteUri(path, m).getRawPath(); + } return path.length() == 0 ? "/" : path; } catch (URISyntaxException ex) { return endpointAddress == null ? "/" : endpointAddress;