cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r803419 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/ systests/src/test/java/or...
Date Wed, 12 Aug 2009 09:11:08 GMT
Author: sergeyb
Date: Wed Aug 12 09:11:08 2009
New Revision: 803419

URL: http://svn.apache.org/viewvc?rev=803419&view=rev
Log:
JAX-RS : Adding global marshalAsJaxbElement property, ignorable Aegis collection tests, RuntimeExceptionMapper
test 

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
    cxf/trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Wed Aug 12 09:11:08 2009
@@ -85,6 +85,7 @@
     
     protected Map<String, String> jaxbElementClassMap;
     protected boolean unmarshalAsJaxbElement;
+    protected boolean marshalAsJaxbElement;
     
     private MessageContext mc;
     private Schema schema;
@@ -96,6 +97,10 @@
         unmarshalAsJaxbElement = value;
     }
     
+    public void setMarshallAsJaxbElement(boolean value) {
+        marshalAsJaxbElement = value;
+    }
+    
     public void setJaxbElementClassNames(List<String> names) {
         jaxbElementClassNames = names;
     }
@@ -107,17 +112,21 @@
     @SuppressWarnings("unchecked")
     protected Object convertToJaxbElementIfNeeded(Object obj, Class<?> cls, Type genericType)

         throws Exception {
+        
+        QName name = null;
         if (jaxbElementClassNames != null && jaxbElementClassNames.contains(cls.getName())

             || jaxbElementClassMap != null && jaxbElementClassMap.containsKey(cls.getName()))
{
-            QName name = null;
             if (jaxbElementClassMap != null) {
                 name = convertStringToQName(jaxbElementClassMap.get(cls.getName()));
             } else {
                 name = getJaxbQName(cls, genericType, obj, false);
             }
-            if (name != null) {
-                return new JAXBElement(name, cls, null, obj);
-            }
+        }
+        if (name == null && marshalAsJaxbElement) {
+            name = convertStringToQName(cls.getName());
+        }
+        if (name != null) {
+            return new JAXBElement(name, cls, null, obj);
         }
         return obj;
     }
@@ -249,7 +258,7 @@
     }
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType
mt) {
-        return isSupported(type, genericType, anns);
+        return marshalAsJaxbElement || isSupported(type, genericType, anns);
     }
 
     public void setSchemaLocations(List<String> locations) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Wed Aug 12 09:11:08 2009
@@ -83,7 +83,7 @@
             }
         }
         
-        return isSupported(type, genericType, anns);
+        return super.isReadable(type, genericType, anns, mt);
     }
     
     @Context

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
Wed Aug 12 09:11:08 2009
@@ -21,7 +21,10 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
@@ -30,11 +33,13 @@
 
 import org.apache.cxf.jaxrs.fortest.AegisTestBean;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.resources.CollectionsResource;
 import org.apache.cxf.jaxrs.resources.ManyTags;
 import org.apache.cxf.jaxrs.resources.TagVO;
 import org.apache.cxf.jaxrs.resources.Tags;
 
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class AegisJSONProviderTest extends Assert {
@@ -129,6 +134,27 @@
     }
     
     @Test
+    @Ignore
+    public void testWriteCollection() throws Exception {
+        AegisJSONProvider p = new AegisJSONProvider();
+        AbstractAegisProvider.clearContexts();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        List<AegisTestBean> beans = new ArrayList<AegisTestBean>();
+        beans.add(bean);
+        Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[]{});
+        p.writeTo(beans, (Class)m.getReturnType(), m.getGenericReturnType(), 
+                  AegisTestBean.class.getAnnotations(), 
+                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        byte[] bytes = os.toByteArray();
+        String json = new String(bytes, "utf-8");
+        System.out.println(json);
+        //assertEquals(data, json);
+    }
+    
+    @Test
     public void testManyTags() throws Exception {
         AegisJSONProvider p = new AegisJSONProvider();
         AbstractAegisProvider.clearContexts();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
Wed Aug 12 09:11:08 2009
@@ -186,6 +186,11 @@
             return new Book();
         }
         
+//        @Path("/books/{bookId}/{new}")
+//        public List<Book> getNewBook3() {
+//            return null;
+//        }
+        
         @POST
         public void setNewBook(Book b) {
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Wed Aug 12 09:11:08 2009
@@ -176,25 +176,35 @@
     
     @Test
     public void testWriteWithoutXmlRootElement() throws Exception {
-        doTestWriteWithoutXmlRootElement("SuperBook", false);
+        doTestWriteWithoutXmlRootElement("SuperBook", false, false);
     }
     
     @Test
     public void testWriteWithoutXmlRootElement2() throws Exception {
-        doTestWriteWithoutXmlRootElement("SuperBook", true);
+        doTestWriteWithoutXmlRootElement("SuperBook", true, false);
     }
     
     @Test
     public void testWriteWithoutXmlRootElement3() throws Exception {
-        doTestWriteWithoutXmlRootElement("{http://books}SuperBook", false);
+        doTestWriteWithoutXmlRootElement("{http://books}SuperBook", false, false);
     }
     
-    public void doTestWriteWithoutXmlRootElement(String name, boolean unmarshalAsJaxbElement)

+    @Test
+    public void testWriteWithoutXmlRootElement4() throws Exception {
+        doTestWriteWithoutXmlRootElement("SuperBook", true, true);
+    }
+    
+    public void doTestWriteWithoutXmlRootElement(String name, boolean unmarshalAsJaxbElement,
+                                                 boolean marshalAsJaxbElement) 
         throws Exception {
         JAXBElementProvider provider = new JAXBElementProvider();
-        provider.setJaxbElementClassMap(Collections.singletonMap(
-            org.apache.cxf.jaxrs.fortest.jaxb.SuperBook.class.getName(), 
-            name));
+        if (!marshalAsJaxbElement) {
+            provider.setJaxbElementClassMap(Collections.singletonMap(
+                org.apache.cxf.jaxrs.fortest.jaxb.SuperBook.class.getName(), 
+                name));
+        } else {
+            provider.setMarshallAsJaxbElement(marshalAsJaxbElement);
+        }
         org.apache.cxf.jaxrs.fortest.jaxb.SuperBook b = 
             new org.apache.cxf.jaxrs.fortest.jaxb.SuperBook("CXF in Action", 123L, 124L);
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/CollectionsResource.java
Wed Aug 12 09:11:08 2009
@@ -26,7 +26,15 @@
 import javax.ws.rs.POST;
 import javax.xml.bind.JAXBElement;
 
+import org.apache.cxf.jaxrs.fortest.AegisTestBean;
+
 public class CollectionsResource {
+    
+    @GET
+    public List<AegisTestBean> getAegisBeans() {
+        return null;
+    }
+    
     @GET
     public List<Book> getBooks() {
         return null;

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
Wed Aug 12 09:11:08 2009
@@ -142,6 +142,23 @@
     }
     
     @Test
+    public void testGetBookNotExistent() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/webapp/bookstore/nonexistent"; 
+        URL url = new URL(endpointAddress);
+        HttpURLConnection connect = (HttpURLConnection)url.openConnection();
+        connect.addRequestProperty("Accept", "application/xml");
+        assertEquals(405, connect.getResponseCode());
+        InputStream in = connect.getErrorStream();
+        assertNotNull(in);           
+
+        assertEquals("Exception is not mapped correctly", 
+                     "Nonexistent method",
+                     getStringFromInputStream(in).trim());
+    }
+    
+    @Test
     public void testPostPetStatus() throws Exception {
         
         String endpointAddress =

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java?rev=803419&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
(added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
Wed Aug 12 09:11:08 2009
@@ -0,0 +1,39 @@
+/**
+ * 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 javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
+
+    @Context 
+    private UriInfo ui;
+    
+    public Response toResponse(RuntimeException exception) {
+        String path = ui.getPath();
+        if (path.endsWith("nonexistent")) {
+            return Response.status(405).type("text/plain").entity("Nonexistent method").build();
+        }
+        return null;
+    }
+
+}

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml?rev=803419&r1=803418&r2=803419&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs_spring_providers/WEB-INF/beans.xml Wed Aug
12 09:11:08 2009
@@ -35,6 +35,7 @@
         <jaxrs:providers>
             <bean class="org.apache.cxf.systest.jaxrs.BadgerFishProvider"/>
             <ref bean="exceptionMapper"/>
+            <ref bean="exceptionMapper2"/>
         </jaxrs:providers>
     </jaxrs:server>
     <bean id="bookstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStore"/>
@@ -42,4 +43,5 @@
     <bean id="exceptionMapper" class="org.apache.cxf.systest.jaxrs.BookExceptionMapper">
         <property name="toHandle" value="true"/>
     </bean>   
+    <bean id="exceptionMapper2" class="org.apache.cxf.systest.jaxrs.RuntimeExceptionMapper"/>
 </beans>



Mime
View raw message