cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Adding a test binding a writer interceptor from Application
Date Tue, 21 Apr 2015 10:16:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4da6c1592 -> 22bc02ff3


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/22bc02ff
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/22bc02ff
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/22bc02ff

Branch: refs/heads/3.0.x-fixes
Commit: 22bc02ff306aba39fc89bbd205d73523a0c4b566
Parents: 4da6c15
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Apr 21 11:14:08 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Apr 21 11:15:55 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/22bc02ff/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/22bc02ff/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/22bc02ff/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


Mime
View raw message