cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1329277 - in /cxf/trunk: rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/ systests/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/ systests/jaxrs/src/t...
Date Mon, 23 Apr 2012 15:14:40 GMT
Author: sergeyb
Date: Mon Apr 23 15:14:40 2012
New Revision: 1329277

URL: http://svn.apache.org/viewvc?rev=1329277&view=rev
Log:
[CXF-4245] Making JAX-RS DataBindingProvider and CXF JibxDataBinding work together, thanks
to Don Corley

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/JibxResource.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/resources/jibx/
    cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd   (with props)
Modified:
    cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java
    cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java
    cxf/trunk/systests/jaxrs/pom.xml
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml

Modified: cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java?rev=1329277&r1=1329276&r2=1329277&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java (original)
+++ cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataReader.java Mon
Apr 23 15:14:40 2012
@@ -62,7 +62,12 @@ public class JibxDataReader implements D
     }
 
     public Object read(QName elementQName, XMLStreamReader input, Class<?> type) {
-        throw new UnsupportedOperationException("Not Implemented");
+        try {
+            UnmarshallingContext ctx = getUnmarshallingContext(input, type);
+            return ctx.unmarshalElement(type);
+        } catch (JiBXException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void setAttachments(Collection<Attachment> attachments) {

Modified: cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java?rev=1329277&r1=1329276&r2=1329277&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java (original)
+++ cxf/trunk/rt/databinding/jibx/src/main/java/org/apache/cxf/jibx/JibxDataWriter.java Mon
Apr 23 15:14:40 2012
@@ -40,6 +40,15 @@ import org.jibx.runtime.impl.StAXWriter;
 public class JibxDataWriter implements DataWriter<XMLStreamWriter> {
 
     public void write(Object obj, XMLStreamWriter output) {
+        try {
+            IBindingFactory factory = BindingDirectory.getFactory(obj.getClass());
+            IMarshallingContext ctx = getMarshallingContext(obj);
+            StAXWriter writer = new StAXWriter(factory.getNamespaces(), output);
+            ctx.setXmlWriter(writer);
+            ((IMarshallable)obj).marshal(ctx);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {

Modified: cxf/trunk/systests/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/pom.xml?rev=1329277&r1=1329276&r2=1329277&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/pom.xml (original)
+++ cxf/trunk/systests/jaxrs/pom.xml Mon Apr 23 15:14:40 2012
@@ -182,6 +182,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-databinding-jibx</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-management-web</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>
@@ -353,6 +358,41 @@
                 </executions>
             </plugin>
             <plugin>
+        <groupId>org.jibx</groupId>
+        <artifactId>jibx-maven-plugin</artifactId>
+        <version>${cxf.jibx.version}</version>
+        <executions>
+            <execution>
+                <id>generate-java-code-from-schema</id>
+                <goals>
+                    <goal>schema-codegen</goal>
+                </goals>
+                <configuration>
+                    <schemaLocation>${basedir}/src/test/resources/jibx</schemaLocation>
+                    <schemaBindingDirectory>${basedir}/target/generated/src/main/java</schemaBindingDirectory>
+                    <options>
+                        <package>org.apache.cxf.systest.jaxrs.codegen.jibx</package>
+                    </options>
+                </configuration>
+            </execution>
+            <execution>
+                <id>compile-binding</id>
+                <goals>
+                    <goal>bind</goal>
+                </goals>
+                <configuration>
+                    <schemaBindingDirectory>${basedir}/target/generated/src/main/java</schemaBindingDirectory>
+                    <includeSchemaBindings>
+                      <includeSchemaBindings>binding.xml</includeSchemaBindings>
+                    </includeSchemaBindings>
+                    <load>true</load>
+                    <validate>true</validate>
+                    <verify>true</verify>
+                </configuration>
+            </execution>
+        </executions>
+    </plugin>
+            <plugin>
                 <groupId>org.apache.cxf</groupId>
                 <artifactId>cxf-wadl2java-plugin</artifactId>
                 <version>${project.version}</version>

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java?rev=1329277&r1=1329276&r2=1329277&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
Mon Apr 23 15:14:40 2012
@@ -30,8 +30,10 @@ import org.apache.cxf.jaxrs.client.JAXRS
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider;
 import org.apache.cxf.jaxrs.provider.json.DataBindingJSONProvider;
+import org.apache.cxf.jibx.JibxDataBinding;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.sdo.SDODataBinding;
+import org.apache.cxf.systest.jaxrs.jibx.JibxResource;
 import org.apache.cxf.systest.jaxrs.sdo.SDOResource;
 import org.apache.cxf.systest.jaxrs.sdo.Structure;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -58,7 +60,17 @@ public class JAXRSDataBindingTest extend
         assertEquals("CXF in Action", book.getName());
     }
     
-    //@org.junit.Ignore
+    @Test
+    public void testGetBookJIBX() throws Exception {
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setDataBinding(new JibxDataBinding());
+        bean.setAddress("http://localhost:" + PORT + "/databinding/jibx");
+        bean.setResourceClass(JibxResource.class);
+        JibxResource client = bean.create(JibxResource.class);
+        org.apache.cxf.systest.jaxrs.codegen.jibx.Book b = client.getBook();
+        assertEquals("JIBX", b.getName());
+    }
+    
     @Test
     public void testGetBookAegis() throws Exception {
         WebClient client = WebClient.create("http://localhost:"

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/JibxResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/JibxResource.java?rev=1329277&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/JibxResource.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jibx/JibxResource.java
Mon Apr 23 15:14:40 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.jibx;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.cxf.systest.jaxrs.codegen.jibx.Book;
+
+@Path("books")
+public class JibxResource {
+    @GET
+    @Produces("application/xml")
+    public Book getBook() {
+        Book b = new Book();
+        b.setName("JIBX");
+        b.setId(1L);
+        return b;
+    }
+}

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

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

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml?rev=1329277&r1=1329276&r2=1329277&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml Mon Apr
23 15:14:40 2012
@@ -55,6 +55,15 @@ http://cxf.apache.org/schemas/core.xsd">
       <bean class="org.apache.cxf.jaxb.JAXBDataBinding"/>
     </jaxrs:dataBinding> 
   </jaxrs:server>
+  <jaxrs:server id="jibx" address="/jibx">
+    <jaxrs:serviceBeans>
+      <bean class="org.apache.cxf.systest.jaxrs.jibx.JibxResource" />
+    </jaxrs:serviceBeans>		   
+    <jaxrs:dataBinding> 
+      <bean class="org.apache.cxf.jibx.JibxDataBinding"/>
+    </jaxrs:dataBinding> 
+  </jaxrs:server>
+  
   <jaxrs:server id="aegisbook" address="/aegis">
     <jaxrs:serviceBeans>
       <ref bean="serviceBean" />

Added: cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd?rev=1329277&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd (added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd Mon Apr 23 15:14:40 2012
@@ -0,0 +1,9 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://books/types"
elementFormDefault="qualified" targetNamespace="http://books/types">
+  <xs:complexType name="book">
+    <xs:sequence>
+      <xs:element type="xs:string" name="name"/>
+      <xs:element type="xs:long" name="id"/>
+    </xs:sequence>
+  </xs:complexType>
+  <xs:element type="tns:book" name="book"/>
+</xs:schema>

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jibx/types.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message