cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Optionally keeping 127.0.0.1
Date Tue, 03 Nov 2015 21:49:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 509341667 -> cb538a459


Optionally keeping 127.0.0.1


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/cb538a45
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/cb538a45
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/cb538a45

Branch: refs/heads/3.0.x-fixes
Commit: cb538a4595dd86d22b13b1dc3e1e13c9be252ebf
Parents: 5093416
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Nov 3 21:47:32 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Nov 3 21:49:07 2015 +0000

----------------------------------------------------------------------
 .../java/org/apache/cxf/jaxrs/utils/HttpUtils.java     | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/cb538a45/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index c6c8dc1..61664b4 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -46,6 +46,7 @@ import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.helpers.CastUtils;
@@ -71,6 +72,7 @@ public final class HttpUtils {
     
     private static final String HTTP_SCHEME = "http";
     private static final String LOCAL_HOST_IP_ADDRESS = "127.0.0.1";
+    private static final String REPLACE_LOOPBACK_PROPERTY = "replace.loopback.address.with.localhost";
     private static final String LOCAL_HOST_IP_ADDRESS_SCHEME = "://" + LOCAL_HOST_IP_ADDRESS;
     private static final String ANY_IP_ADDRESS = "0.0.0.0";
     private static final String ANY_IP_ADDRESS_SCHEME = "://" + ANY_IP_ADDRESS;
@@ -351,7 +353,7 @@ public final class HttpUtils {
             (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
         boolean absolute = u.isAbsolute();
         StringBuilder uriBuf = new StringBuilder(); 
-        if (request != null && (!absolute || isLocalHostOrAnyIpAddress(u, uriBuf)))
{
+        if (request != null && (!absolute || isLocalHostOrAnyIpAddress(u, uriBuf,
message))) {
             String serverAndPort = request.getServerName();
             boolean localAddressUsed = false;
             if (absolute) {
@@ -384,14 +386,19 @@ public final class HttpUtils {
         return u;
     }
     
-    private static boolean isLocalHostOrAnyIpAddress(URI u, StringBuilder uriStringBuffer)
{
+    private static boolean isLocalHostOrAnyIpAddress(URI u, StringBuilder uriStringBuffer,
Message m) {
         String uriString = u.toString();
-        boolean result = uriString.contains(LOCAL_HOST_IP_ADDRESS_SCHEME) 
+        boolean result = uriString.contains(LOCAL_HOST_IP_ADDRESS_SCHEME) && replaceLoopBackAddress(m)

             || uriString.contains(ANY_IP_ADDRESS_SCHEME);
         uriStringBuffer.append(uriString);
         return result;
     }
     
+    private static boolean replaceLoopBackAddress(Message m) {
+        Object prop = m.getContextualProperty(REPLACE_LOOPBACK_PROPERTY);
+        return prop == null || PropertyUtils.isTrue(prop);
+    }
+
     public static void resetRequestURI(Message m, String requestURI) {
         m.remove(REQUEST_PATH_TO_MATCH_SLASH);
         m.remove(REQUEST_PATH_TO_MATCH);


Mime
View raw message