cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r706482 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/ test/java/org/apache/cxf/jaxrs/fortest/ test/java/org/apache/cxf/jaxrs/provider/
Date Tue, 21 Oct 2008 00:23:50 GMT
Author: bimargulies
Date: Mon Oct 20 17:23:50 2008
New Revision: 706482

URL: http://svn.apache.org/viewvc?rev=706482&view=rev
Log:
Push the JAX-RS thing for Aegis along.

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java?rev=706482&r1=706481&r2=706482&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
Mon Oct 20 17:23:50 2008
@@ -94,7 +94,10 @@
             AegisContext context = classContexts.get(type);
             if (context == null) {
                 context = new AegisContext();
+                context.setWriteXsiTypes(true); // needed, since we know no element/type
maps.
+                context.setReadXsiTypes(true);
                 Set<Class<?>> rootClasses = new HashSet<Class<?>>();
+                rootClasses.add(type);
                 context.setRootClasses(rootClasses);
                 context.initialize();
                 classContexts.put(type, context);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java?rev=706482&r1=706481&r2=706482&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
Mon Oct 20 17:23:50 2008
@@ -36,6 +36,7 @@
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.AegisReader;
 import org.apache.cxf.aegis.AegisWriter;
+import org.apache.cxf.aegis.type.TypeUtil;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
@@ -58,12 +59,17 @@
     public void writeTo(Object obj, Class<?> type, Type genericType, Annotation[] anns,
 
         MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) 
         throws IOException {
+        if (type == null) {
+            type = obj.getClass();
+        }
         AegisContext context = getAegisContext(type, genericType);
+        org.apache.cxf.aegis.type.Type aegisType = TypeUtil.getWriteTypeStandalone(context,
obj, null);
         AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
         XMLStreamWriter xmlStreamWriter = StaxUtils.createXMLStreamWriter(os);
         try {
-            aegisWriter.write(obj, null, false, xmlStreamWriter, null);
-            
+            // use type qname as element qname?
+            aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType);
+            xmlStreamWriter.close();
         } catch (Exception e) {
             throw new WebApplicationException(e);
         }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java?rev=706482&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
Mon Oct 20 17:23:50 2008
@@ -0,0 +1,41 @@
+/**
+ * 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.jaxrs.fortest;
+
+/**
+ * A bean class. No corresponding .aegis.xml file.
+ */
+public class AegisTestBean {
+    private String strValue;
+    private Boolean boolValue;
+    public String getStrValue() {
+        return strValue;
+    }
+    public void setStrValue(String strValue) {
+        this.strValue = strValue;
+    }
+    public Boolean getBoolValue() {
+        return boolValue;
+    }
+    public void setBoolValue(Boolean boolValue) {
+        this.boolValue = boolValue;
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AegisTestBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java?rev=706482&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Mon Oct 20 17:23:50 2008
@@ -0,0 +1,76 @@
+/**
+ * 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.jaxrs.provider;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.cxf.jaxrs.fortest.AegisTestBean;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AegisProviderTest extends Assert {
+    
+    private static final String SIMPLE_BEAN_XML 
+        = "<ns1:AegisTestBean xmlns:ns1=\"http://fortest.jaxrs.cxf.apache.org\" "
+            + "xmlns:ns2=\"http://www.w3.org/2001/XMLSchema-instance\" ns2:type=\"ns1:AegisTestBean\">"
+            + "<ns1:boolValue>true</ns1:boolValue><ns1:strValue>hovercraft</ns1:strValue>"
+            + "</ns1:AegisTestBean>";
+    
+    @Test
+    public void testIsWriteable() {
+        MessageBodyWriter<Object> p = new AegisElementProvider();
+        assertTrue(p.isWriteable(AegisTestBean.class, null, null));
+    }
+    
+    @Test
+    public void testIsReadable() {
+        MessageBodyReader<Object> p = new AegisElementProvider();
+        assertTrue(p.isReadable(AegisTestBean.class, null, null));
+    }
+    
+    @org.junit.Ignore
+    @Test
+    public void testReadFrom() throws Exception {
+        MessageBodyReader<Object> p = new AegisElementProvider();
+        byte[] simpleBytes = SIMPLE_BEAN_XML.getBytes("utf-8");
+        Object beanObject = p.readFrom(Object.class, null, null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        AegisTestBean bean = (AegisTestBean) beanObject;
+        assertEquals("hovercraft", bean.getStrValue());
+        assertEquals(Boolean.TRUE, bean.getBoolValue());
+    }
+    
+    @Test
+    public void testWriteTo() throws Exception {
+        MessageBodyWriter<Object> p = new AegisElementProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        p.writeTo(bean, null, null, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+        assertEquals(SIMPLE_BEAN_XML, xml);
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message