cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [2/2] cxf git commit: Making it easier to reuse JAXRS FeatureContextImpl
Date Thu, 05 May 2016 15:47:45 GMT
Making it easier to reuse JAXRS FeatureContextImpl


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

Branch: refs/heads/3.1.x-fixes
Commit: ebf80b597e06f26e681ca70464fe9f3135706280
Parents: 986231d
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu May 5 16:41:17 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu May 5 16:47:25 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/impl/ConfigurableImpl.java | 68 ---------------
 .../cxf/jaxrs/impl/FeatureContextImpl.java      | 91 ++++++++++++++++++++
 .../jaxrs/JAXRS20ClientServerBookTest.java      | 22 +++++
 3 files changed, 113 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ebf80b59/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
index e9c2cac..6d5c9dc 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
@@ -26,7 +26,6 @@ import javax.ws.rs.RuntimeType;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Feature;
-import javax.ws.rs.core.FeatureContext;
 
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 
@@ -116,71 +115,4 @@ public class ConfigurableImpl<C extends Configurable<C>>
implements Configurable
     private C doRegister(Object provider, int bindingPriority, Class<?>... contracts)
{
         return register(provider, ConfigurationImpl.initContractsMap(bindingPriority, contracts));
     }
-
-    public static class FeatureContextImpl implements FeatureContext {
-        private Configurable<?> cfg;
-        public FeatureContextImpl(Configurable<?> cfg) {
-            this.cfg = cfg;
-        }
-        
-        @Override
-        public Configuration getConfiguration() {
-            return cfg.getConfiguration();
-        }
-
-        @Override
-        public FeatureContext property(String name, Object value) {
-            cfg.property(name, value);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls) {
-            cfg.register(cls);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Object obj) {
-            cfg.register(obj);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, int priority) {
-            cfg.register(cls, priority);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, Class<?>... contract) {
-            cfg.register(cls, contract);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, Map<Class<?>, Integer>
map) {
-            cfg.register(cls, map);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Object obj, int priority) {
-            cfg.register(obj, priority);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Object obj, Class<?>... contract) {
-            cfg.register(obj, contract);
-            return this;
-        }
-
-        @Override
-        public FeatureContext register(Object obj, Map<Class<?>, Integer> map)
{
-            cfg.register(obj, map);
-            return this;
-        } 
-        
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ebf80b59/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
new file mode 100644
index 0000000..47fadf0
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
@@ -0,0 +1,91 @@
+/**
+ * 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.jaxrs.impl;
+
+import java.util.Map;
+
+import javax.ws.rs.core.Configurable;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.core.FeatureContext;
+
+public class FeatureContextImpl implements FeatureContext {
+    private Configurable<?> cfg;
+    public FeatureContextImpl(Configurable<?> cfg) {
+        this.cfg = cfg;
+    }
+    
+    @Override
+    public Configuration getConfiguration() {
+        return cfg.getConfiguration();
+    }
+
+    @Override
+    public FeatureContext property(String name, Object value) {
+        cfg.property(name, value);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Class<?> cls) {
+        cfg.register(cls);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Object obj) {
+        cfg.register(obj);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Class<?> cls, int priority) {
+        cfg.register(cls, priority);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Class<?> cls, Class<?>... contract) {
+        cfg.register(cls, contract);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Class<?> cls, Map<Class<?>, Integer>
map) {
+        cfg.register(cls, map);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Object obj, int priority) {
+        cfg.register(obj, priority);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Object obj, Class<?>... contract) {
+        cfg.register(obj, contract);
+        return this;
+    }
+
+    @Override
+    public FeatureContext register(Object obj, Map<Class<?>, Integer> map) {
+        cfg.register(obj, map);
+        return this;
+    } 
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/ebf80b59/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index f1838f9..09815e0 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -40,6 +40,8 @@ import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
 import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.HttpHeaders;
@@ -162,6 +164,17 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         book = target.request("application/xml").get(BookInfo.class);
         assertEquals(124L, book.getId());
     }
+    @Test
+    public void testGetBookSpecProviderWithFeature() {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        Client client = ClientBuilder.newClient();
+        client.register(new ClientTestFeature());
+        WebTarget target = client.target(address);
+        BookInfo book = target.request("application/xml").get(BookInfo.class);
+        assertEquals(124L, book.getId());
+        book = target.request("application/xml").get(BookInfo.class);
+        assertEquals(124L, book.getId());
+    }
     
     @Test
     public void testGetBookWebTargetProvider() {
@@ -855,4 +868,13 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         }
         
     }
+    private static class ClientTestFeature implements Feature {
+
+        @Override
+        public boolean configure(FeatureContext context) {
+            context.register(new BookInfoReader());
+            return true;
+        }
+        
+    }
 }


Mime
View raw message