cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r802968 - in /cxf/trunk: api/src/main/java/org/apache/cxf/annotations/ rt/core/src/main/java/org/apache/cxf/feature/ rt/core/src/main/java/org/apache/cxf/service/factory/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/ ...
Date Tue, 11 Aug 2009 00:42:44 GMT
Author: dkulp
Date: Tue Aug 11 00:42:44 2009
New Revision: 802968

URL: http://svn.apache.org/viewvc?rev=802968&view=rev
Log:
Add GZIP and FastInfoset support annotations

Added:
    cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java   (with props)
    cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java   (with props)
Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/FastInfosetFeature.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/GZIPFeature.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java

Added: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java?rev=802968&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java (added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java Tue Aug 11 00:42:44
2009
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Enables FastInfoset negotiation
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE })
+public @interface FastInfoset {
+    boolean force() default false;
+}
+

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/FastInfoset.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java?rev=802968&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java (added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java Tue Aug 11 00:42:44 2009
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Enables GZIP compression negotiation
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE })
+public @interface GZIP {
+    int threshold() default -1;
+}
+

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/api/src/main/java/org/apache/cxf/annotations/GZIP.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/FastInfosetFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/FastInfosetFeature.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/FastInfosetFeature.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/FastInfosetFeature.java Tue Aug
11 00:42:44 2009
@@ -64,7 +64,7 @@
     }
     
     /**
-     * Retrieve the value set with {@link #setLimit(int)}.
+     * Retrieve the value set with {@link #setForce(int)}.
      * @return
      */
     public boolean getForce() {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
Tue Aug 11 00:42:44 2009
@@ -23,13 +23,21 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.annotations.FastInfoset;
+import org.apache.cxf.annotations.GZIP;
 import org.apache.cxf.annotations.SchemaValidation;
 import org.apache.cxf.annotations.WSDLDocumentation;
 import org.apache.cxf.annotations.WSDLDocumentation.Placement;
 import org.apache.cxf.annotations.WSDLDocumentationCollection;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.FIStaxInInterceptor;
+import org.apache.cxf.interceptor.FIStaxOutInterceptor;
+import org.apache.cxf.interceptor.InterceptorProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -62,34 +70,34 @@
         }
         case ENDPOINT_SELECTED: {
             Class<?> cls = (Class<?>)args[2];
-            SchemaValidation val = cls.getAnnotation(SchemaValidation.class);
-            if (val != null && val.enabled()) {
-                ((Endpoint)args[1]).put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
-            }
-            break;
+            Endpoint ep = (Endpoint)args[1];
+            addSchemaValidationSupport(ep, cls.getAnnotation(SchemaValidation.class));
+            addFastInfosetSupport(ep, cls.getAnnotation(FastInfoset.class));
+            addGZipSupport(ep, factory.getBus(), cls.getAnnotation(GZIP.class));
+            break; 
         }
         case SERVER_CREATED: {
             Class<?> cls = (Class<?>)args[2];
-            SchemaValidation val = cls.getAnnotation(SchemaValidation.class);
-            if (val != null && val.enabled()) {
-                ((Server)args[0]).getEndpoint().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
-            }
+            Server server = (Server)args[0];
+            addGZipSupport(server.getEndpoint(), factory.getBus(), cls.getAnnotation(GZIP.class));
+            addSchemaValidationSupport(server.getEndpoint(), cls.getAnnotation(SchemaValidation.class));
+            addFastInfosetSupport(server.getEndpoint(), cls.getAnnotation(FastInfoset.class));
             WSDLDocumentation doc = cls.getAnnotation(WSDLDocumentation.class);
             if (doc != null) {
-                addDocumentation((Server)args[0], WSDLDocumentation.Placement.SERVICE, doc);
+                addDocumentation(server, WSDLDocumentation.Placement.SERVICE, doc);
             }
             WSDLDocumentationCollection col = cls.getAnnotation(WSDLDocumentationCollection.class);
             if (col != null) {
-                addDocumentation((Server)args[0], WSDLDocumentation.Placement.SERVICE, col.value());
+                addDocumentation(server, WSDLDocumentation.Placement.SERVICE, col.value());
             }
-            InterfaceInfo i = ((Server)args[0]).getEndpoint().getEndpointInfo().getInterface();
+            InterfaceInfo i = server.getEndpoint().getEndpointInfo().getInterface();
             List<WSDLDocumentation> docs = CastUtils.cast((List<?>)i.removeProperty(EXTRA_DOCUMENTATION));
             if (docs != null) {
-                addDocumentation((Server)args[0], 
+                addDocumentation(server, 
                                  WSDLDocumentation.Placement.SERVICE,
                                  docs.toArray(new WSDLDocumentation[docs.size()]));
             }
-            addBindingOperationDocs((Server)args[0]);
+            addBindingOperationDocs(server);
             break;
         }
         case INTERFACE_OPERATION_BOUND: {
@@ -110,6 +118,40 @@
         }
     }
 
+    private void addGZipSupport(Endpoint ep, Bus bus, GZIP annotation) {
+        if (annotation != null) {
+            try {
+                Class<?> cls = ClassLoaderUtils
+                    .loadClass("org.apache.cxf.transport.http.gzip.GZIPFeature",
+                               this.getClass());
+                
+                AbstractFeature feature = (AbstractFeature)cls.newInstance();
+                cls.getMethod("setThreshold", new Class[] {Integer.TYPE})
+                    .invoke(feature, annotation.threshold());
+                feature.initialize(ep, bus);
+            } catch (Exception e) {
+                //ignore - just assume it's an unsupported/unknown annotation
+            }
+        }
+    }
+
+    private void addSchemaValidationSupport(Endpoint endpoint, SchemaValidation annotation)
{
+        if (annotation != null) {
+            endpoint.put(Message.SCHEMA_VALIDATION_ENABLED, annotation.enabled());
+        }
+    }
+
+    private void addFastInfosetSupport(InterceptorProvider provider, FastInfoset annotation)
{
+        if (annotation != null) {
+            FIStaxInInterceptor in = new FIStaxInInterceptor();
+            FIStaxOutInterceptor out = new FIStaxOutInterceptor(annotation.force());
+            provider.getInInterceptors().add(in);
+            provider.getInFaultInterceptors().add(in);
+            provider.getOutInterceptors().add(out);
+            provider.getOutFaultInterceptors().add(out);
+        }
+    }
+
     private void addBindingOperationDocs(Server server) {
         for (BindingOperationInfo binfo : server.getEndpoint().getBinding()
                 .getBindingInfo().getOperations()) {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/GZIPFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/GZIPFeature.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/GZIPFeature.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/gzip/GZIPFeature.java
Tue Aug 11 00:42:44 2009
@@ -18,8 +18,11 @@
  */
 package org.apache.cxf.transport.http.gzip;
 
+import java.util.List;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorProvider;
 
 /**
@@ -69,11 +72,23 @@
         } else {
             GZIPOutInterceptor out = new GZIPOutInterceptor();
             out.setThreshold(threshold);
+            remove(provider.getOutInterceptors());
+            remove(provider.getOutFaultInterceptors());
             provider.getOutInterceptors().add(out);
             provider.getOutFaultInterceptors().add(out);
         }
     }
 
+    private void remove(List<Interceptor> outInterceptors) {
+        int x = outInterceptors.size();
+        while (x > 0) {
+            --x;
+            if (outInterceptors.get(x) instanceof GZIPOutInterceptor) {
+                outInterceptors.remove(x);
+            }
+        }
+    }
+
     public void setThreshold(int threshold) {
         this.threshold = threshold;
     }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Tue Aug 11 00:42:44 2009
@@ -312,6 +312,10 @@
 
         int[] ret = port.echoIntArray(new int[] {1, 2});
         assertNotNull(ret);
+        ret = port.echoIntArray(new int[] {1, 2});
+        assertNotNull(ret);
+        ret = port.echoIntArray(new int[] {1, 2});
+        assertNotNull(ret);
         //port.arrayOutput();
     }
     

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
Tue Aug 11 00:42:44 2009
@@ -38,9 +38,10 @@
 import javax.xml.ws.RequestWrapper;
 import javax.xml.ws.ResponseWrapper;
 
+import org.apache.cxf.annotations.FastInfoset;
+import org.apache.cxf.annotations.GZIP;
 import org.apache.cxf.annotations.WSDLDocumentation;
 import org.apache.cxf.annotations.WSDLDocumentationCollection;
-import org.apache.cxf.feature.Features;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.systest.jaxws.types.Bar;
 
@@ -48,9 +49,6 @@
             targetNamespace = "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService")
 @SOAPBinding(style = SOAPBinding.Style.DOCUMENT,
              use = SOAPBinding.Use.LITERAL)
-//@Features(features = { "org.apache.cxf.feature.FastInfosetFeature" })
-@Features(features = { "org.apache.cxf.transport.http.gzip.GZIPFeature", 
-                       "org.apache.cxf.feature.FastInfosetFeature" })
 @WSDLDocumentationCollection(
     {
         @WSDLDocumentation("DocLitWrappedCodeFirstService interface"),
@@ -62,6 +60,8 @@
                            placement = WSDLDocumentation.Placement.SERVICE_PORT)   
     }
 )
+@GZIP
+@FastInfoset
 public interface DocLitWrappedCodeFirstService {
 
     @Oneway

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?rev=802968&r1=802967&r2=802968&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
Tue Aug 11 00:42:44 2009
@@ -29,8 +29,9 @@
 import javax.xml.ws.Holder;
 import javax.xml.ws.WebServiceContext;
 
+import org.apache.cxf.annotations.FastInfoset;
+import org.apache.cxf.annotations.GZIP;
 import org.apache.cxf.annotations.WSDLDocumentation;
-import org.apache.cxf.feature.Features;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.systest.jaxws.DocLitWrappedCodeFirstService.Foo;
 import org.apache.cxf.systest.jaxws.types.Bar;
@@ -40,10 +41,9 @@
             serviceName = "DocLitWrappedCodeFirstService",
             portName = "DocLitWrappedCodeFirstServicePort",
             targetNamespace = "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService")
-//@Features(features = { "org.apache.cxf.feature.FastInfosetFeature" })
-@Features(features = { "org.apache.cxf.transport.http.gzip.GZIPFeature", 
-                       "org.apache.cxf.feature.FastInfosetFeature" })
-@WSDLDocumentation("DocLitWrappedCodeFirstService impl")                       
+@WSDLDocumentation("DocLitWrappedCodeFirstService impl")
+@GZIP(threshold = 10)
+@FastInfoset(force = true)
 public class DocLitWrappedCodeFirstServiceImpl implements DocLitWrappedCodeFirstService {
     public static final String DATA[] = new String[] {"string1", "string2", "string3"};
     



Mime
View raw message