Repository: cxf
Updated Branches:
  refs/heads/master 44ddee3a9 -> 1aefa51be


Adding a test binding a writer interceptor from Application


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

Branch: refs/heads/master
Commit: 1aefa51be1d0dbdd626c4000e55bccd0299662ea
Parents: 44ddee3
Author: Sergey Beryozkin <[email protected]>
Authored: Tue Apr 21 11:14:08 2015 +0100
Committer: Sergey Beryozkin <[email protected]>
Committed: Tue Apr 21 11:14:08 2015 +0100

----------------------------------------------------------------------
 .../cxf/systest/jaxrs/BookApplication.java      | 17 ++++++++++
 .../cxf/systest/jaxrs/GlobalNameBinding.java    | 33 ++++++++++++++++++++
 .../JAXRSClientServerNonSpringBookTest.java     | 11 +++++--
 3 files changed, 58 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1aefa51b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
index d6fe595..b3d83b4 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
@@ -29,13 +29,17 @@ import java.util.Set;
 import javax.annotation.Priority;
 import javax.servlet.ServletContext;
 import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
 
 @ApplicationPath("/thebooks")
+@GlobalNameBinding
 public class BookApplication extends Application {
 
     private String defaultName;
@@ -60,6 +64,7 @@ public class BookApplication extends Application {
         classes.add(org.apache.cxf.systest.jaxrs.RuntimeExceptionMapper.class);
         classes.add(BookRequestFilter.class);
         classes.add(BookRequestFilter2.class);
+        classes.add(BookWriter.class);
         return classes;
     }
 
@@ -94,6 +99,18 @@ public class BookApplication extends Application {
         defaultId = Long.valueOf(sb.toString());
     }
     
+    @GlobalNameBinding
+    public static class BookWriter implements WriterInterceptor {
+
+        @Override
+        public void aroundWriteTo(WriterInterceptorContext context) throws 
IOException,
+            WebApplicationException {
+            context.getHeaders().putSingle("BookWriter", "TheBook");
+            context.proceed();
+        }
+        
+    }
+    
     @Priority(1)
     public static class BookRequestFilter implements ContainerRequestFilter {
         private UriInfo ui;

http://git-wip-us.apache.org/repos/asf/cxf/blob/1aefa51b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GlobalNameBinding.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GlobalNameBinding.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GlobalNameBinding.java
new file mode 100644
index 0000000..a2d4224
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GlobalNameBinding.java
@@ -0,0 +1,33 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.ws.rs.NameBinding;
+
+@Target({ ElementType.TYPE, ElementType.METHOD })
+@Retention(value = RetentionPolicy.RUNTIME)
+@NameBinding
+public @interface GlobalNameBinding { 
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1aefa51b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
index 6009004..b8b3ec9 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
 
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
@@ -174,7 +175,9 @@ public class JAXRSClientServerNonSpringBookTest extends 
AbstractBusClientServerT
     
     @Test
     public void testGetBook123Application11PerRequest() throws Exception {
-        doTestPerRequest("http://localhost:"; + PORT + 
"/application11/thebooks/bookstore2/bookheaders");
+        Response r = 
+            doTestPerRequest("http://localhost:"; + PORT + 
"/application11/thebooks/bookstore2/bookheaders");
+        assertEquals("TheBook", r.getHeaderString("BookWriter"));
     }
     
     @Test
@@ -183,13 +186,15 @@ public class JAXRSClientServerNonSpringBookTest extends 
AbstractBusClientServerT
         doTestPerRequest("http://localhost:"; + PORT + 
"/application6/thebooks2/bookstore2/bookheaders");
     }
     
-    private void doTestPerRequest(String address) throws Exception {
+    private Response doTestPerRequest(String address) throws Exception {
         WebClient wc = WebClient.create(address);
         
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L);
         wc.accept("application/xml");
-        Book book = wc.get(Book.class);
+        Response r = wc.get();
+        Book book = r.readEntity(Book.class);
         assertEquals("CXF in Action", book.getName());
         assertEquals(123L, book.getId());
+        return r;
     }
     
     @Test

Reply via email to