cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1518943 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 30 Aug 2013 11:52:10 GMT
Author: sergeyb
Date: Fri Aug 30 11:52:10 2013
New Revision: 1518943

URL: http://svn.apache.org/r1518943
Log:
[CXF-5243,CXF-5244] Adding a test to confirm a stream can be obtained from the filter on the
trunk, fixing issues with updating content or accept types

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1518943&r1=1518942&r2=1518943&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Fri Aug 30 11:52:10 2013
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
@@ -117,23 +118,44 @@ public class JAXRSInInterceptor extends 
         if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, true, null, false))
{
             return;
         }
+        // HTTP method
         String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD,

                                                         HttpMethod.POST, true);
         
-        String requestContentType = (String)message.get(Message.CONTENT_TYPE);
+        // Path to match
+        String rawPath = HttpUtils.getPathToMatch(message, true);
+        
+        Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?,
?>)message.get(Message.PROTOCOL_HEADERS));
+        
+        // Content-Type
+        String requestContentType = null;
+        List<String> ctHeaderValues = protocolHeaders.get(Message.CONTENT_TYPE);
+        if (ctHeaderValues != null) {
+            requestContentType = ctHeaderValues.get(0);
+            message.put(Message.CONTENT_TYPE, requestContentType);
+        }
         if (requestContentType == null) {
-            requestContentType = MediaType.WILDCARD;
+            requestContentType = (String)message.get(Message.CONTENT_TYPE);
+        
+            if (requestContentType == null) {
+                requestContentType = MediaType.WILDCARD;
+            }
         }
         
-        String rawPath = HttpUtils.getPathToMatch(message, true);
+        // Accept
+        String acceptTypes = null;
+        List<String> acceptHeaderValues = protocolHeaders.get(Message.ACCEPT_CONTENT_TYPE);
+        if (acceptHeaderValues != null) {
+            acceptTypes = acceptHeaderValues.get(0);
+            message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
+        }
         
-        //1. Matching target resource class
-        List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(message);
-
-        String acceptTypes = HttpUtils.getProtocolHeader(message, Message.ACCEPT_CONTENT_TYPE,
null);
         if (acceptTypes == null) {
-            acceptTypes = "*/*";
-            message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
+            acceptTypes = HttpUtils.getProtocolHeader(message, Message.ACCEPT_CONTENT_TYPE,
null);
+            if (acceptTypes == null) {
+                acceptTypes = "*/*";
+                message.put(Message.ACCEPT_CONTENT_TYPE, acceptTypes);
+            }
         }
         List<MediaType> acceptContentTypes = null;
         try {
@@ -143,6 +165,8 @@ public class JAXRSInInterceptor extends 
         }
         message.getExchange().put(Message.ACCEPT_CONTENT_TYPE, acceptContentTypes);
 
+        //1. Matching target resource class
+        List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(message);
         Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources
= 
             JAXRSUtils.selectResourceClass(resources, rawPath, message);
         if (matchedResources == null) {
@@ -158,8 +182,7 @@ public class JAXRSInInterceptor extends 
         }
 
         MultivaluedMap<String, String> matchedValues = new MetadataMap<String, String>();
-        
-        
+                
         OperationResourceInfo ori = null;     
         
         try {                

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1518943&r1=1518942&r2=1518943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Fri Aug 30 11:52:10 2013
@@ -59,6 +59,7 @@ import javax.ws.rs.ext.WriterInterceptor
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -139,6 +140,15 @@ public class BookServer20 extends Abstra
                     Response.status(500).type("text/plain")
                         .entity("Prematch filter error").build());
             }
+            
+            MediaType mt = context.getMediaType();
+            if (mt != null && mt.toString().equals("text/xml")) {
+                context.getHeaders().putSingle("Content-Type", "application/xml");
+            }
+            List<MediaType> acceptTypes = context.getAcceptableMediaTypes();
+            if (acceptTypes.size() == 1 && acceptTypes.get(0).toString().equals("text/mistypedxml"))
{
+                context.getHeaders().putSingle("Accept", "text/xml");
+            }
         }
         
     }
@@ -171,6 +181,12 @@ public class BookServer20 extends Abstra
             if (path.endsWith("books/checkN")) {
                 URI requestURI = URI.create(path.replace("N", "2"));
                 context.setRequestUri(requestURI);
+                
+                String body = IOUtils.readStringFromStream(context.getEntityStream());
+                if (!"s".equals(body)) {
+                    throw new RuntimeException();
+                }
+                
                 replaceStream(context);
             } else if (path.endsWith("books/check2")) {
                 replaceStream(context);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1518943&r1=1518942&r2=1518943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Fri Aug 30 11:52:10 2013
@@ -275,6 +275,18 @@ public class JAXRS20ClientServerBookTest
     }
     
     @Test
+    public void testPostReplaceBookMistypedCT() throws Exception {
+        
+        String endpointAddress = "http://localhost:" + PORT + "/bookstore/books2"; 
+        WebClient wc = WebClient.create(endpointAddress,
+                                        Collections.singletonList(new ReplaceBodyFilter()));
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
+        wc.accept("text/mistypedxml").type("text/xml");
+        Book book = wc.post(new Book("book", 555L), Book.class);
+        assertEquals(561L, book.getId());
+    }
+    
+    @Test
     public void testPostGetCollectionGenericEntityAndType() throws Exception {
         
         String endpointAddress =



Mime
View raw message