cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1052541 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/ systests/jaxrs/src/test/resources/jaxr...
Date Fri, 24 Dec 2010 17:54:32 GMT
Author: sergeyb
Date: Fri Dec 24 17:54:32 2010
New Revision: 1052541

URL: http://svn.apache.org/viewvc?rev=1052541&view=rev
Log:
[CXF-3217] Initial support for DataBinding annotation in the JAX-RS frontend

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    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/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1052541&r1=1052540&r2=1052541&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Fri Dec 24 17:54:32 2010
@@ -276,9 +276,8 @@ public class AbstractJAXRSFactoryBean ex
         if (entityProviders != null) {
             factory.setUserProviders(entityProviders); 
         }
-        if (getDataBinding() != null) {
-            setDataBindingProvider(factory, ep.getService());
-        }
+        setDataBindingProvider(factory, ep.getService());
+        
         factory.setBus(getBus());
         if (schemaLocations != null) {
             factory.setSchemaLocations(schemaLocations);
@@ -288,10 +287,25 @@ public class AbstractJAXRSFactoryBean ex
     }
 
     protected void setDataBindingProvider(ProviderFactory factory, Service s) {
+        
+        List<ClassResourceInfo> cris = serviceFactory.getRealClassResourceInfo();
+        if (getDataBinding() == null && cris.size() > 0) {
+            org.apache.cxf.annotations.DataBinding ann = 
+                cris.get(0).getServiceClass().getAnnotation(org.apache.cxf.annotations.DataBinding.class);
+            if (ann != null) {
+                try {
+                    setDataBinding(ann.value().newInstance());
+                } catch (Exception ex) {
+                    LOG.warning("DataBinding " + ann.value() + " can not be loaded");
+                }
+            }
+        }
         DataBinding db = getDataBinding();
+        if (db == null) {
+            return;
+        }
         if (db instanceof PropertiesAwareDataBinding) {
-            Map<Class<?>, Type> allClasses = ResourceUtils.getAllRequestResponseTypes(
-                                                 serviceFactory.getRealClassResourceInfo(),
false);
+            Map<Class<?>, Type> allClasses = ResourceUtils.getAllRequestResponseTypes(cris,
false);
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(PropertiesAwareDataBinding.TYPES_PROPERTY, allClasses);
             ((PropertiesAwareDataBinding)db).initialize(props);

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=1052541&r1=1052540&r2=1052541&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
Fri Dec 24 17:54:32 2010
@@ -71,9 +71,18 @@ public class JAXRSDataBindingTest extend
     
     @Test
     public void testSDOStructure() throws Exception {
+        doTestSDOStructure("http://localhost:" + PORT + "/databinding/sdo");
+    }
+    
+    @Test
+    public void testSDOStructureWithAnnotation() throws Exception {
+        doTestSDOStructure("http://localhost:" + PORT + "/databinding/sdo2");
+    }
+    
+    private void doTestSDOStructure(String address) throws Exception {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setDataBinding(new SDODataBinding());
-        bean.setAddress("http://localhost:" + PORT + "/databinding/sdo");
+        bean.setAddress(address);
         bean.setResourceClass(SDOResource.class);
         SDOResource client = bean.create(SDOResource.class);
         Structure struct = client.getStructure();

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.java?rev=1052541&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.java
Fri Dec 24 17:54:32 2010
@@ -0,0 +1,26 @@
+/**
+ * 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.sdo;
+
+import org.apache.cxf.annotations.DataBinding;
+
+@DataBinding(org.apache.cxf.sdo.SDODataBinding.class)
+public class SDOResource2 extends SDOResource {    
+}

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

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/sdo/SDOResource2.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=1052541&r1=1052540&r2=1052541&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 Fri Dec
24 17:54:32 2010
@@ -46,6 +46,7 @@ http://cxf.apache.org/schemas/core.xsd">
   <bean class="org.apache.cxf.systest.jaxrs.BookStoreSpring" id="serviceBean"/>
   
   <bean class="org.apache.cxf.systest.jaxrs.sdo.SDOResource" id="sdoBean"/>
+  <bean class="org.apache.cxf.systest.jaxrs.sdo.SDOResource2" id="sdoBean2"/>
   
   <jaxrs:server id="jaxbbook" address="/jaxb">
     <jaxrs:serviceBeans>
@@ -83,6 +84,12 @@ http://cxf.apache.org/schemas/core.xsd">
     </jaxrs:providers>
   </jaxrs:server>
 
+  <jaxrs:server id="sdo2" address="/sdo2">
+    <jaxrs:serviceBeans>
+      <ref bean="sdoBean2" />
+    </jaxrs:serviceBeans>		   
+  </jaxrs:server>
+
   <bean id="sdoDatabinding" class="org.apache.cxf.sdo.SDODataBinding"/>
   <bean id="jsonSdoBean" class="org.apache.cxf.jaxrs.provider.DataBindingJSONProvider">
       <property name="dataBinding" ref="sdoDatabinding"/>



Mime
View raw message