cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1404710 - in /cxf/branches/2.6.x-fixes/rt: core/src/main/java/org/apache/cxf/transport/common/gzip/ transports/jms/src/main/java/org/apache/cxf/transport/jms/
Date Thu, 01 Nov 2012 18:22:27 GMT
Author: dkulp
Date: Thu Nov  1 18:22:26 2012
New Revision: 1404710

URL: http://svn.apache.org/viewvc?rev=1404710&view=rev
Log:
Merged revisions 1404700 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1404700 | dkulp | 2012-11-01 14:09:08 -0400 (Thu, 01 Nov 2012) | 2 lines

  [CXF-4572] Support a negotiation for the GZIP

........

Modified:
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPFeature.java
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPInInterceptor.java
    cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
    cxf/branches/2.6.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPFeature.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPFeature.java?rev=1404710&r1=1404709&r2=1404710&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPFeature.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPFeature.java
Thu Nov  1 18:22:26 2012
@@ -57,15 +57,22 @@ public class GZIPFeature extends Abstrac
      */
     int threshold = -1;
     
+    /**
+     * Force GZIP instead of negotiate
+     */
+    boolean force;
+    
+    
     @Override
     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
         provider.getInInterceptors().add(IN);
-        if (threshold == -1) {
+        if (threshold == -1 && !force) {
             provider.getOutInterceptors().add(OUT);
             provider.getOutFaultInterceptors().add(OUT);
         } else {
             GZIPOutInterceptor out = new GZIPOutInterceptor();
             out.setThreshold(threshold);
+            out.setForce(force);
             remove(provider.getOutInterceptors());
             remove(provider.getOutFaultInterceptors());
             provider.getOutInterceptors().add(out);
@@ -89,5 +96,21 @@ public class GZIPFeature extends Abstrac
     
     public int getThreshold() {
         return threshold;
-    }    
+    }
+    
+    
+    /**
+     * Set if GZIP is always used without negotiation 
+     * @param b
+     */
+    public void setForce(boolean b) {
+        force = b;
+    }
+    
+    /**
+     * Retrieve the value set with {@link #setForce(boolean)}.
+     */
+    public boolean getForce() {
+        return force;
+    }  
 }

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPInInterceptor.java?rev=1404710&r1=1404709&r2=1404710&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPInInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPInInterceptor.java
Thu Nov  1 18:22:26 2012
@@ -28,6 +28,7 @@ import java.util.zip.GZIPInputStream;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.interceptor.AttachmentInInterceptor;
@@ -91,6 +92,13 @@ public class GZIPInInterceptor extends A
                             break;
                         }
                     }
+                    
+                    if (isRequestor(message)) {
+                        //record the fact that is worked so future requests will 
+                        //automatically be FI enabled
+                        Endpoint ep = message.getExchange().getEndpoint();
+                        ep.put(GZIPOutInterceptor.USE_GZIP_KEY, GZIPOutInterceptor.UseGzip.YES);
+                    }
                 } catch (IOException ex) {
                     throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_UNZIP",
BUNDLE), ex);
                 }

Modified: cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java?rev=1404710&r1=1404709&r2=1404710&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/main/java/org/apache/cxf/transport/common/gzip/GZIPOutInterceptor.java
Thu Nov  1 18:22:26 2012
@@ -112,6 +112,7 @@ public class GZIPOutInterceptor extends 
      * compressed.
      */
     private int threshold = 1024;
+    private boolean force;
 
     public GZIPOutInterceptor() {
         super(Phase.PREPARE_SEND);
@@ -169,9 +170,16 @@ public class GZIPOutInterceptor extends 
      */
     private UseGzip gzipPermitted(Message message) throws Fault {
         UseGzip permitted = UseGzip.NO;
-        if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
+        if (isRequestor(message)) {
             LOG.fine("Requestor role, so gzip enabled");
-            permitted = UseGzip.YES;
+            Object o = message.getContextualProperty(USE_GZIP_KEY);
+            if (o instanceof UseGzip) {
+                permitted = (UseGzip)o;
+            } else if (o instanceof String) {
+                permitted = UseGzip.valueOf((String)o);
+            } else {
+                permitted = force ? UseGzip.YES : UseGzip.NO;
+            }
             message.put(GZIP_ENCODING_KEY, "gzip");
             addHeader(message, "Accept-Encoding", "gzip;q=1.0, identity; q=0.5, *;q=0");

         } else {
@@ -326,6 +334,9 @@ public class GZIPOutInterceptor extends 
         } else {
             header.set(0, header.get(0) + "," + value);
         }
+    }
+    public void setForce(boolean force) {
+        this.force = force;
     }    
 
 }

Modified: cxf/branches/2.6.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java?rev=1404710&r1=1404709&r2=1404710&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSUtils.java
Thu Nov  1 18:22:26 2012
@@ -51,7 +51,6 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.security.SecurityContext;
-import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
 import org.apache.cxf.transport.jms.spec.JMSSpecConstants;
 import org.apache.cxf.transport.jms.uri.JMSEndpoint;
 import org.apache.cxf.transport.jms.uri.JMSEndpointParser;
@@ -450,7 +449,15 @@ public final class JMSUtils {
     }
     
     public static String getContentEncoding(org.apache.cxf.message.Message message) {
-        return (String)message.get(GZIPOutInterceptor.GZIP_ENCODING_KEY);
+        Map<String, List<String>> headers 
+            = CastUtils.cast((Map<?, ?>)message.get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
+        if (headers != null) {
+            List<String> l = headers.get("Content-Encoding");
+            if (l != null && !l.isEmpty()) {
+                return l.get(0);
+            }
+        }
+        return null;
     }
 
     public static Message buildJMSMessageFromCXFMessage(JMSConfiguration jmsConfig,



Mime
View raw message