cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1482966 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ main/java/org/apache/cxf/jaxrs/impl/ main/java/org/apache/cxf/jaxrs/interceptor/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/ test/java...
Date Wed, 15 May 2013 17:11:52 GMT
Author: sergeyb
Date: Wed May 15 17:11:51 2013
New Revision: 1482966

URL: http://svn.apache.org/r1482966
Log:
[CXF-5007] More updates to ResponseBuilder, ResponseImpl, etc

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed May
15 17:11:51 2013
@@ -28,7 +28,6 @@ import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.AsyncResponse;
@@ -102,7 +101,7 @@ public class JAXRSInvoker extends Abstra
             Object serviceObject = getActualServiceObject(exchange, rootInstance);
             
             return invoke(exchange, request, serviceObject);
-        } catch (InternalServerErrorException ex) {
+        } catch (WebApplicationException ex) {
             responseList = checkExchangeForResponse(exchange);
             if (responseList != null) {
                 return responseList; 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
Wed May 15 17:11:51 2013
@@ -100,6 +100,7 @@ public abstract class AbstractResponseCo
     }
 
     public MediaType getMediaType() {
+        //return r.getEntity() != null ? r.getMediaType() : null;
         return r.getMediaType();
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
Wed May 15 17:11:51 2013
@@ -66,12 +66,12 @@ public class ContainerResponseContextImp
     
     @Override
     public OutputStream getEntityStream() {
-        return m.get(OutputStream.class);
+        return m.getContent(OutputStream.class);
     }
 
     @Override
     public void setEntityStream(OutputStream os) {
-        m.put(OutputStream.class, os);
+        m.setContent(OutputStream.class, os);
 
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed May 15 17:11:51 2013
@@ -29,6 +29,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -272,7 +273,15 @@ public final class ResponseImpl extends 
     }
 
     public Set<Link> getLinks() {
-        return new HashSet<Link>(getAllLinks().values());
+        List<Object> linkValues = metadata.get(HttpHeaders.LINK);
+        Set<Link> links = new HashSet<Link>();
+        if (linkValues != null) {
+            for (Object o : linkValues) {
+                Link link = o instanceof Link ? (Link)o : Link.valueOf(o.toString());
+                links.add(link);
+            }
+        }
+        return links;
     }
 
     private Map<String, Link> getAllLinks() {
@@ -280,9 +289,9 @@ public final class ResponseImpl extends 
         if (linkValues == null) {
             return Collections.emptyMap();
         } else {
-            Map<String, Link> links = new HashMap<String, Link>();
+            Map<String, Link> links = new LinkedHashMap<String, Link>();
             for (Object o : linkValues) {
-                Link link = Link.valueOf(o.toString());
+                Link link = o instanceof Link ? (Link)o : Link.valueOf(o.toString());
                 links.put(link.getRel(), link);
             }
             return links;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Wed May 15 17:11:51 2013
@@ -190,10 +190,13 @@ public class JAXRSOutInterceptor extends
         if (firstTry && userHeaders != null) {
             responseHeaders.putAll(userHeaders);
         }
-        
-        String initialResponseContentType = (String)message.get(Message.CONTENT_TYPE);
-        if (initialResponseContentType != null && !responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE))
{
-            responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, initialResponseContentType);
+        if (entity != null) {
+            String initialResponseContentType = (String)message.get(Message.CONTENT_TYPE);
+            if (initialResponseContentType != null && !responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE))
{
+                responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, initialResponseContentType);
+            }
+        } else {
+            message.remove(Message.CONTENT_TYPE);
         }
         
         message.put(Message.PROTOCOL_HEADERS, responseHeaders);
@@ -415,7 +418,7 @@ public class JAXRSOutInterceptor extends
     }
     
     private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry)
{
-        if (!firstTry) {
+        if (!firstTry || headers.containsKey(HttpHeaders.DATE)) {
             return;
         }
         SimpleDateFormat format = HttpUtils.getHttpDateFormat();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed May 15 17:11:51 2013
@@ -360,12 +360,13 @@ public final class InjectionUtils {
         } catch (WebApplicationException ex) {
             throw ex;
         } catch (Exception ex) {
+            Throwable t = getOrThrowActualException(ex);
             result = createFromParameterHandler(value, cls, message);
             if (result == null) {
                 LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE",

                                                                    BUNDLE, 
                                                                    pClass.getName()).toString());
-                throw new ClientErrorException(HttpUtils.getParameterFailureStatus(pType),
ex);
+                throw new ClientErrorException(HttpUtils.getParameterFailureStatus(pType),
t);
             }
         }
         if (result == null) {
@@ -451,8 +452,7 @@ public final class InjectionUtils {
         } catch (NoSuchMethodException ex) {
             // no luck
         } catch (Exception ex) {
-            Throwable t = ex instanceof InvocationTargetException 
-                ? ((InvocationTargetException)ex).getTargetException() : ex; 
+            Throwable t = getOrThrowActualException(ex);
             LOG.severe(new org.apache.cxf.common.i18n.Message("CLASS_VALUE_OF_FAILURE", 
                                                                BUNDLE, 
                                                                pClass.getName()).toString());
@@ -461,6 +461,14 @@ public final class InjectionUtils {
         return null;
     }
     
+    private static Throwable getOrThrowActualException(Throwable ex) {
+        Throwable t = ex instanceof InvocationTargetException ? ((InvocationTargetException)ex).getCause()
: ex; 
+        if (t instanceof WebApplicationException) {    
+            throw (WebApplicationException)t;
+        }
+        return t;
+    }
+    
     public static Object handleBean(Class<?> paramType, Annotation[] paramAnns, 
                                     MultivaluedMap<String, String> values,
                                     ParameterType pType, Message message, boolean decoded)
{

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Wed
May 15 17:11:51 2013
@@ -1033,9 +1033,17 @@ public final class JAXRSUtils {
         if (pClass.isAssignableFrom(Cookie.class)) {
             return c;
         }
-        
-        return InjectionUtils.handleParameter(c.getValue(), false, pClass, paramAnns, 
-                                              ParameterType.COOKIE, m);
+        String value = InjectionUtils.isSupportedCollectionOrArray(pClass) 
+            && InjectionUtils.getActualType(genericType) == Cookie.class
+            ? c.toString() : c.getValue();
+        return InjectionUtils.createParameterObject(Collections.singletonList(value), 
+                                                    pClass, 
+                                                    genericType,
+                                                    paramAnns,
+                                                    null,
+                                                    false,
+                                                    ParameterType.COOKIE,
+                                                    m);
     }
     
     public static Object createBeanParamValue(Message m, Class<?> clazz, OperationResourceInfo
ori) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Wed May 15
17:11:51 2013
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.annotation.PostConstruct;
@@ -148,6 +149,7 @@ public class Customer extends AbstractCu
     @Context private UriInfo uriInfo2;
     private String queryParam;
     
+    @DefaultValue("bQuery")
     @QueryParam("b")
     private String b;
     private String name;
@@ -439,7 +441,9 @@ public class Customer extends AbstractCu
     }
     
     public void testCookieParam(@CookieParam("c1") String c1,
-                                @CookieParam("c2") @DefaultValue("c2Value") String c2) {
+                                @CookieParam("c1") Set<Cookie> c11,
+                                @CookieParam("c2") @DefaultValue("c2Value") String c2,
+                                @CookieParam("c2") @DefaultValue("c2Value") Set<String>
c22) {
         // complete
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Wed May 15 17:11:51 2013
@@ -226,6 +226,23 @@ public class ResponseBuilderImplTest ext
         Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
         checkBuild(Response.ok().links(prevLink, nextLink).build(), 200, null, m);
     }
+    
+    @Test
+    public void testLinks2() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
+        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
+        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
+        Link.Builder linkBuilder = delegate.createLinkBuilder();
+        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
+        // Reset linkbuilder
+        linkBuilder = delegate.createLinkBuilder();
+        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
+        Link[] links = new Link[2];
+        links[0] = prevLink;
+        links[1] = nextLink;
+        checkBuild(Response.ok().links(links).build(), 200, null, m);
+    }
 
     @Test
     public void testLinksNoReset() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Wed May 15 17:11:51 2013
@@ -273,6 +273,21 @@ public class ResponseImplTest extends As
     }
     
     @Test
+    public void testGetLinksSameRel() {
+        ResponseImpl ri = new ResponseImpl(200);
+        MetadataMap<String, Object> meta = new MetadataMap<String, Object>();
+        ri.addMetadata(meta);
+        
+        meta.add(HttpHeaders.LINK, "<http://link1>");
+        meta.add(HttpHeaders.LINK, "<http://link2>");
+        
+        Set<Link> links = ri.getLinks();
+        assertEquals(2, links.size());
+        assertTrue(links.contains(Link.valueOf("<http://link1>")));
+        assertTrue(links.contains(Link.valueOf("<http://link2>")));
+    }
+    
+    @Test
     public void testGetLinks() {
         ResponseImpl ri = new ResponseImpl(200);
         MetadataMap<String, Object> meta = new MetadataMap<String, Object>();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1482966&r1=1482965&r2=1482966&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Wed May 15 17:11:51 2013
@@ -31,6 +31,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
 import javax.servlet.ServletConfig;
@@ -856,7 +857,7 @@ public class JAXRSUtilsTest extends Asse
     
     @Test
     public void testCookieParameters() throws Exception {
-        Class<?>[] argType = {String.class, String.class};
+        Class<?>[] argType = {String.class, Set.class, String.class, Set.class};
         Method m = Customer.class.getMethod("testCookieParam", argType);
         MessageImpl messageImpl = new MessageImpl();
         MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
@@ -865,10 +866,15 @@ public class JAXRSUtilsTest extends Asse
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null),
                                                            null, 
                                                            messageImpl);
-        assertEquals(params.size(), 2);
+        assertEquals(params.size(), 4);
         assertEquals("c1Value", params.get(0));
-        assertEquals("c2Value", params.get(1));
-        
+        Set<Cookie> set1 = CastUtils.cast((Set<?>)params.get(1));
+        assertEquals(1, set1.size());
+        assertTrue(set1.contains(Cookie.valueOf("c1=c1Value")));
+        assertEquals("c2Value", params.get(2));
+        Set<Cookie> set2 = CastUtils.cast((Set<?>)params.get(3));
+        assertTrue(set2.contains("c2Value"));
+        assertEquals(1, set2.size());
         
     }
     
@@ -1809,6 +1815,20 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
+    public void testDefaultValueOnField() throws Exception {
+
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
+                                                              cri);
+        Message m = createMessage();
+        
+        m.put(Message.QUERY_STRING, "");
+        JAXRSUtils.injectParameters(ori, c, m);
+        assertEquals("bQuery", c.getB());
+    }
+    
+    @Test
     public void testContextResolverParam() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);



Mime
View raw message