cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1294621 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 28 Feb 2012 12:30:29 GMT
Author: sergeyb
Date: Tue Feb 28 12:30:29 2012
New Revision: 1294621

URL: http://svn.apache.org/viewvc?rev=1294621&view=rev
Log:
Merged revisions 1294615 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes

................
  r1294615 | sergeyb | 2012-02-28 12:21:29 +0000 (Tue, 28 Feb 2012) | 16 lines
  
  Merged revisions 1294614 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
  
  ................
    r1294614 | sergeyb | 2012-02-28 12:18:57 +0000 (Tue, 28 Feb 2012) | 9 lines
    
    Merged revisions 1294611 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1294611 | sergeyb | 2012-02-28 12:12:13 +0000 (Tue, 28 Feb 2012) | 1 line
      
      [CXF-4141] Setting 500 directly on HttpServletResponse in case of write failures
    ........
  ................
................

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb 28 12:30:29 2012
@@ -1,3 +1,3 @@
-/cxf/branches/2.4.x-fixes:1292807,1293259
-/cxf/branches/2.5.x-fixes:1292793,1293258
-/cxf/trunk:1292792,1293255
+/cxf/branches/2.4.x-fixes:1292807,1293259,1294615
+/cxf/branches/2.5.x-fixes:1292793,1293258,1294614
+/cxf/trunk:1292792,1293255,1294611

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1294621&r1=1294620&r2=1294621&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Tue Feb 28 12:30:29 2012
@@ -297,7 +297,7 @@ public class WebClient extends AbstractC
      * @return JAXRS Response
      */
     public Response form(Map<String, List<Object>> values) {
-        type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
+        type(MediaType.APPLICATION_FORM_URLENCODED);
         return doInvoke("POST", values, InputStream.class, InputStream.class);
     }
     
@@ -307,7 +307,7 @@ public class WebClient extends AbstractC
      * @return JAXRS Response
      */
     public Response form(Form form) {
-        type(MediaType.APPLICATION_FORM_URLENCODED_TYPE);
+        type(MediaType.APPLICATION_FORM_URLENCODED);
         return doInvoke("POST", form.getData(), InputStream.class, InputStream.class);
     }
     
@@ -621,7 +621,11 @@ public class WebClient extends AbstractC
         MultivaluedMap<String, String> headers = getHeaders();
         boolean contentTypeNotSet = headers.getFirst(HttpHeaders.CONTENT_TYPE) == null;
         if (contentTypeNotSet) {
-            String ct = body != null ? MediaType.APPLICATION_XML_TYPE.toString() : "*/*";
+            String ct = "*/*";
+            if (body != null) { 
+                ct = body instanceof Form ? MediaType.APPLICATION_FORM_URLENCODED 
+                                          : MediaType.APPLICATION_XML;
+            }
             headers.putSingle(HttpHeaders.CONTENT_TYPE, ct);
         }
         if (responseClass != null && headers.getFirst(HttpHeaders.ACCEPT) == null)
{

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1294621&r1=1294620&r2=1294621&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Tue Feb 28 12:30:29 2012
@@ -166,8 +166,7 @@ public class JAXRSOutInterceptor extends
             status = isResponseNull(responseObj) ? 204 : 200;
         }
         
-        boolean responseHeadersCopied = isResponseHeadersCopied(message);
-        setResponseStatus(message, status, responseHeadersCopied);
+        setResponseStatus(message, status);
         
         Map<String, List<Object>> theHeaders = 
             (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
@@ -358,7 +357,7 @@ public class JAXRSOutInterceptor extends
                 ex.printStackTrace();
             }
         }
-        message.put(Message.RESPONSE_CODE, 500);
+        setResponseStatus(message, 500);
         writeResponseErrorMessage(out, "SERIALIZE_ERROR", 
                                   responseObj.getClass().getSimpleName()); 
             
@@ -470,8 +469,9 @@ public class JAXRSOutInterceptor extends
         }
     }
    
-    private void setResponseStatus(Message message, int status, boolean responseHeadersCopied)
{
+    private void setResponseStatus(Message message, int status) {
         message.put(Message.RESPONSE_CODE, status);   
+        boolean responseHeadersCopied = isResponseHeadersCopied(message);
         if (responseHeadersCopied) {
             HttpServletResponse response = 
                 (HttpServletResponse)message.get(AbstractHTTPDestination.HTTP_RESPONSE);

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java?rev=1294621&r1=1294620&r2=1294621&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerStreamingTest.java
Tue Feb 28 12:30:29 2012
@@ -19,8 +19,11 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -28,6 +31,8 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLStreamWriter;
@@ -35,6 +40,7 @@ import javax.xml.stream.XMLStreamWriter;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.staxutils.CachingXmlEventWriter;
@@ -101,6 +107,15 @@ public class JAXRSClientServerStreamingT
     }
     
     @Test
+    public void testGetBook123Fail() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
+        wc.accept("text/xml");
+        wc.header("fail-write", "");
+        Response r = wc.get();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
     public void testGetBookUsingStaxWriter() throws Exception {
         getAndCompare("http://localhost:" + PORT + "/bookstore/books/123",
                       "text/xml", 200);
@@ -139,5 +154,16 @@ public class JAXRSClientServerStreamingT
                 throw new RuntimeException();
             }
         }
+        @Override
+        public void writeTo(Object obj, Class<?> cls, Type genericType, Annotation[]
anns,  
+            MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws
IOException {
+            List<String> failHeaders = getContext().getHttpHeaders().getRequestHeader("fail-write");
+            if (failHeaders.size() > 0) {
+                os.write("fail".getBytes());
+                throw new IOException();
+            } else {
+                super.writeTo(obj, cls, genericType, anns, m, headers, os);
+            }
+        }
     }
 }



Mime
View raw message