cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6211] Updating HTTP Transport Headers helper to check Conent-Type in the headers map first
Date Tue, 20 Jan 2015 16:39:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/master dc8b98085 -> 62d904855


[CXF-6211] Updating HTTP Transport Headers helper to check Conent-Type in the headers map
first


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

Branch: refs/heads/master
Commit: 62d904855de555476bc6f91259d9cb983adaf124
Parents: dc8b980
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jan 20 16:38:55 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jan 20 16:38:55 2015 +0000

----------------------------------------------------------------------
 .../org/apache/cxf/transport/http/Headers.java  |  9 +++++-
 .../apache/cxf/systest/jaxrs/BookInterface.java |  4 +++
 .../systest/jaxrs/BookStoreWithInterface.java   | 11 +++++++
 .../systest/jaxrs/BookStoreWithInterface2.java  |  5 ++++
 .../jaxrs/CustomJaxbElementProvider.java        | 10 +++++++
 .../JAXRSClientServerProxySpringBookTest.java   | 31 +++++++++++++++++++-
 .../security/SecureBookStoreNoAnnotations.java  |  4 +++
 7 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
index baf8b71..19c1538 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
@@ -306,7 +306,14 @@ public class Headers {
     }
 
     public String determineContentType() {
-        String ct  = (String)message.get(Message.CONTENT_TYPE);
+        String ct = null;
+        List<Object> ctList = CastUtils.cast(headers.get(Message.CONTENT_TYPE));
+        if (ctList != null && ctList.size() == 1) {
+            ct = ctList.get(0).toString();
+        } else {
+            ct  = (String)message.get(Message.CONTENT_TYPE);
+        }
+        
         String enc = (String)message.get(Message.ENCODING);
 
         if (null != ct) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
index d739072..a7f5e5e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -42,4 +43,7 @@ public interface BookInterface {
     @Produces("application/xml")
     Book getThatBook() throws BookNotFoundFault;
     
+    @POST
+    @Path("/thosebooks")
+    Book echoBook(Book b);
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
index 741f1c6..d7eb4e7 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface.java
@@ -39,6 +39,8 @@
 package org.apache.cxf.systest.jaxrs;
 
 import org.apache.cxf.annotations.SchemaValidation;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
 
 
 
@@ -67,6 +69,15 @@ public class BookStoreWithInterface extends BookStoreStorage implements
BookInte
         return doGetBook(id);
     }
     
+    public Book echoBook(Book b) {
+        String ct = (String)JAXRSUtils.getCurrentMessage().get(Message.CONTENT_TYPE);
+        if ("application/xml;a=b".equals(ct)) {
+            return b;
+        } else {
+            throw new RuntimeException();
+        }
+    }
+    
     private Book doGetBook(Long id) throws BookNotFoundFault {
         //System.out.println("----invoking getBook with id: " + id);
         Book book = books.get(id);

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
index c692ad5..4e12566 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreWithInterface2.java
@@ -100,4 +100,9 @@ public class BookStoreWithInterface2 extends BookStoreStorage implements
BookInt
         return books.get(123L);
     }
 
+    public Book echoBook(Book b) {
+        
+        return b;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
index 76af000..dcc2705 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomJaxbElementProvider.java
@@ -18,11 +18,14 @@
  */
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.annotations.SchemaValidation;
@@ -45,4 +48,11 @@ public class CustomJaxbElementProvider extends JAXBElementProvider<Book>
{
         }
         
     }
+    @Override
+    public void writeTo(Book obj, Class<?> cls, Type genericType, Annotation[] anns,
 
+                        MediaType m, MultivaluedMap<String, Object> headers, OutputStream
os) 
+        throws IOException {
+        headers.putSingle("Content-Type", MediaType.valueOf(m.toString() + ";a=b"));
+        super.writeTo(obj, cls, genericType, anns, m, headers, os);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
index 7141218..a2d1052 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
@@ -24,8 +24,11 @@ import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Collections;
 import java.util.List;
 
+import javax.ws.rs.core.Response;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -114,7 +117,33 @@ public class JAXRSClientServerProxySpringBookTest extends AbstractBusClientServe
     
     @Test
     public void testGetThatBookInterfacePrototype() throws Exception {
-        getBook("http://localhost:" + PORT + "/test/5/bookstorestorage/thosebooks/123");
+        
+        URL url = new URL("http://localhost:" + PORT + "/test/5/bookstorestorage/thosebooks/123");
+        URLConnection connect = url.openConnection();
+        connect.addRequestProperty("Content-Type", "*/*");
+        connect.addRequestProperty("Accept", "application/xml");
+        connect.addRequestProperty("SpringProxy", "true");
+        InputStream in = connect.getInputStream();           
+
+        InputStream expected = getClass()
+            .getResourceAsStream("resources/expected_get_book123.txt");
+        assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)), 
+                     stripXmlInstructionIfNeeded(getStringFromInputStream(in)));
+        String ct = connect.getHeaderField("Content-Type");
+        assertEquals("application/xml;a=b", ct);
+    }
+    
+    @Test
+    public void testEchoBook() throws Exception {
+        
+        URL url = new URL("http://localhost:" + PORT + "/test/5/bookstorestorage/thosebooks");
+        WebClient wc = WebClient.create(url.toString(), 
+                                        Collections.singletonList(new CustomJaxbElementProvider()));
+        Response r = wc.post(new Book("proxy", 333L));
+        Book book = r.readEntity(Book.class);
+        assertEquals(333L, book.getId());
+        String ct = r.getHeaderString("Content-Type");
+        assertEquals("application/xml;a=b", ct);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/62d90485/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreNoAnnotations.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreNoAnnotations.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreNoAnnotations.java
index 5b61277..f980d89 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreNoAnnotations.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStoreNoAnnotations.java
@@ -53,4 +53,8 @@ public class SecureBookStoreNoAnnotations implements BookInterface {
     public Book getThatBook() throws BookNotFoundFault {
         return books.get(123L);
     }
+
+    public Book echoBook(Book b) {
+        return b;
+    }
 }


Mime
View raw message