cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r798816 - in /cxf/trunk: rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/ rt/frontend/jaxrs/ rt/frontend/jaxrs/s...
Date Wed, 29 Jul 2009 09:03:40 GMT
Author: sergeyb
Date: Wed Jul 29 09:03:39 2009
New Revision: 798816

URL: http://svn.apache.org/viewvc?rev=798816&view=rev
Log:
CXF-2314 : Initial support for wrapping CXF DataBindings into JAXRS providers, work in progress

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookDataBindingServer.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java   (with props)
    cxf/trunk/systests/src/test/resources/jaxrs_databinding/
    cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/
    cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml   (with props)
    cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml   (with props)
Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/DataReaderImpl.java
    cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/SDODataBinding.java
    cxf/trunk/rt/frontend/jaxrs/pom.xml
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java Wed Jul 29 09:03:39 2009
@@ -63,6 +63,7 @@
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotated;
+import org.apache.ws.commons.schema.XmlSchemaException;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
 
@@ -334,6 +335,9 @@
 
     protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container,
                                      int partType, Set<Type> deps) {
+        if (container == null) {
+            return;
+        }
         for (Iterator itr = container.getMessageParts().iterator(); itr.hasNext();) {
             MessagePartInfo part = (MessagePartInfo)itr.next();
 
@@ -374,6 +378,9 @@
     }
 
     protected void initializeMessageTypes(ServiceInfo s, AbstractMessageContainer container, int partType) {
+        if (container == null) {
+            return;
+        }
         SchemaCollection col = s.getXmlSchemaCollection();
         for (Iterator itr = container.getMessageParts().iterator(); itr.hasNext();) {
             MessagePartInfo part = (MessagePartInfo)itr.next();
@@ -475,7 +482,19 @@
                 schema.setAttributeFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
 
                 for (Type t : entry.getValue()) {
-                    t.writeSchema(schema);
+                    try {
+                        t.writeSchema(schema);
+                    } catch (XmlSchemaException ex) {
+                        QName name = t.getSchemaType();
+                        String expected = " Schema for namespace '" + name.getNamespaceURI() 
+                            + "' already contains type '" + name.getLocalPart() + "'";
+                        String message = ex.getMessage();
+                        if (expected.equals(message)) {
+                            continue;
+                        } else {
+                            throw ex;
+                        }
+                    }
                 }
 
                 if (schemaImportsXmime(schema)) {
@@ -588,12 +607,30 @@
     private Method getMethod(Service s, OperationInfo op) {
         MethodDispatcher md = (MethodDispatcher)s.get(MethodDispatcher.class.getName());
         SimpleMethodDispatcher smd = (SimpleMethodDispatcher)md;
-        return smd.getPrimaryMethod(op);
+        return smd != null ? smd.getPrimaryMethod(op) : null;
     }
 
     public Type getType(MessagePartInfo part) {
         return part2Type.get(part);
     }
+    
+    public MessagePartInfo getPartFromClass(Class<?> cls) {
+        for (Map.Entry<MessagePartInfo, Type> entry : part2Type.entrySet()) {
+            if (entry.getValue().getTypeClass() == cls) {
+                return entry.getKey();
+            }
+        }
+        return null;
+    }
+    
+    public Type getTypeFromClass(Class<?> cls) {
+        for (Type t : part2Type.values()) {
+            if (t.getTypeClass() == cls) {
+                return t;
+            }
+        }
+        return null;
+    }
 
     public Service getService() {
         return service;

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java Wed Jul 29 09:03:39 2009
@@ -52,7 +52,8 @@
     }
 
     public Object read(QName name, XMLStreamReader input, Class typeClass) {
-        return read(input);
+        MessagePartInfo info = databinding.getPartFromClass(typeClass);
+        return info == null ? read(input) : read(info, input);
     }
 
     public Object read(XMLStreamReader input) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataWriter.java Wed Jul 29 09:03:39 2009
@@ -62,7 +62,9 @@
 
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
         Type type = databinding.getType(part);
-
+        if (type == null) {
+            type = databinding.getTypeFromClass(obj.getClass());
+        }
         if (type == null) {
             throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG, part));
         }
@@ -87,7 +89,8 @@
                 }
             }
             ElementWriter writer = new ElementWriter(output);
-            MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
+            MessageWriter w2 = writer.getElementWriter(part != null ? part.getConcreteName() 
+                : type.getSchemaType());
             type.writeObject(obj, w2, context);
             w2.close();
         } catch (DatabindingException e) {

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Wed Jul 29 09:03:39 2009
@@ -328,13 +328,10 @@
 
         }
 
-        String tns = service.getName().getNamespaceURI();
+        String tns = getNamespaceToUse();
         CachedContextAndSchemas cachedContextAndSchemas = null;
         JAXBContext ctx = null;
         try {
-            if (service.getServiceInfos().size() > 0) {
-                tns = service.getServiceInfos().get(0).getInterface().getName().getNamespaceURI();
-            }
             cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
         } catch (JAXBException e1) {
             // load jaxb needed class and try to create jaxb context for more
@@ -437,6 +434,19 @@
         }
     }
     
+    private String getNamespaceToUse() {
+        if ("true".equals(service.get("org.apache.cxf.databinding.namespace"))) {
+            return null;    
+        }
+        String tns = null;
+        if (service.getServiceInfos().size() > 0) {
+            tns = service.getServiceInfos().get(0).getInterface().getName().getNamespaceURI();
+        } else {
+            tns = service.getName().getNamespaceURI();
+        }
+        return tns;
+    }
+    
     public void setExtraClass(Class[] userExtraClass) {
         extraClass = userExtraClass;
     }

Modified: cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/DataReaderImpl.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/DataReaderImpl.java (original)
+++ cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/DataReaderImpl.java Wed Jul 29 09:03:39 2009
@@ -67,7 +67,7 @@
     }
 
     public Object read(QName name, XMLStreamReader input, Class type) {        
-        return null;
+        return read(null, input);
     }
 
     

Modified: cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/SDODataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/SDODataBinding.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/SDODataBinding.java (original)
+++ cxf/trunk/rt/databinding/sdo/src/main/java/org/apache/cxf/sdo/SDODataBinding.java Wed Jul 29 09:03:39 2009
@@ -41,6 +41,7 @@
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.resource.ExtendedURIResolver;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.DescriptionInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.tuscany.sdo.api.SDOUtil;
 
@@ -148,11 +149,14 @@
             }
         }
         for (ServiceInfo serviceInfo : service.getServiceInfos()) {
-            String uri = serviceInfo.getDescription().getBaseURI();
-            ExtendedURIResolver resolver = new ExtendedURIResolver();
-            InputStream ins = resolver.resolve(uri, "").getByteStream();
-            context.getXSDHelper().define(ins, uri);
-            resolver.close();
+            DescriptionInfo dInfo = serviceInfo.getDescription();
+            if (dInfo != null) {
+                String uri = dInfo.getBaseURI();
+                ExtendedURIResolver resolver = new ExtendedURIResolver();
+                InputStream ins = resolver.resolve(uri, "").getByteStream();
+                context.getXSDHelper().define(ins, uri);
+                resolver.close();
+            }
         }        
     }
     void registerFactory(Class<?> factoryClass) throws Exception {

Modified: cxf/trunk/rt/frontend/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/pom.xml?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/pom.xml (original)
+++ cxf/trunk/rt/frontend/jaxrs/pom.xml Wed Jul 29 09:03:39 2009
@@ -156,6 +156,26 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency> 
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-bindings-soap</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope> 
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-databinding-jaxb</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+<!--
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-databinding-sdo</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency> 
+-->
 	<dependency>
             <groupId>org.apache.xmlbeans</groupId>
             <artifactId>xmlbeans</artifactId>

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=798816&r1=798815&r2=798816&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 Wed Jul 29 09:03:39 2009
@@ -18,11 +18,13 @@
  */
 package org.apache.cxf.jaxrs;
 
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
@@ -34,12 +36,14 @@
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.endpoint.AbstractEndpointFactory;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.EndpointImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.provider.DataBindingProvider;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
@@ -232,6 +236,9 @@
         if (entityProviders != null) {
             factory.setUserProviders(entityProviders); 
         }
+        if (getDataBinding() != null) {
+            setDataBindingProvider(factory, ep.getService());
+        }
         factory.setBus(getBus());
         if (schemaLocations != null) {
             factory.setSchemaLocations(schemaLocations);
@@ -240,6 +247,19 @@
         return factory;
     }
 
+    protected void setDataBindingProvider(ProviderFactory factory, Service s) {
+        DataBinding db = getDataBinding();
+        try {
+            Method m = db.getClass().getMethod("setAllClasses", new Class[]{Set.class});
+            Set<Class<?>> allClasses = ResourceUtils.getAllRequestResponseTypes(
+                                                         serviceFactory.getRealClassResourceInfo(), false);
+            m.invoke(db, new Object[]{allClasses});
+        } catch (Exception ex) { 
+            db.initialize(s);
+        }
+        factory.setUserProviders(Collections.singletonList(new DataBindingProvider(db)));
+    }
+    
     public void setModelBeans(UserResource... resources) {
         setModelBeans(Arrays.asList(resources));
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java Wed Jul 29 09:03:39 2009
@@ -19,12 +19,14 @@
 
 package org.apache.cxf.jaxrs;
 
-import java.util.Collections;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executor;
 
+import javax.ws.rs.core.Response;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.util.PackageUtils;
@@ -33,9 +35,18 @@
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.MessageInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.workqueue.SynchronousExecutor;
 
@@ -78,7 +89,62 @@
     }
     
     public List<ServiceInfo> getServiceInfos() {
-        return Collections.emptyList();
+        // try to convert to WSDL-centric model so that CXF DataBindings can get initialized
+        // might become useful too if we support wsdl2
+        
+        // make databindings to use databinding-specific information 
+        // like @XmlRootElement for ex to select a namespace
+        this.put("org.apache.cxf.databinding.namespace", "true");
+        
+        List<ServiceInfo> infos = new ArrayList<ServiceInfo>();
+        for (ClassResourceInfo cri : classResourceInfos) {
+            ServiceInfo si = new ServiceInfo();
+            infos.add(si);
+            QName qname = JAXRSUtils.getClassQName(cri.getServiceClass());
+            si.setName(qname);
+            InterfaceInfo inf = new InterfaceInfo(si, qname);
+            si.setInterface(inf);
+            for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
+                Method m = ori.getMethodToInvoke();
+                QName oname = new QName(qname.getNamespaceURI(), m.getName());
+                OperationInfo oi = inf.addOperation(oname);
+                createMessagePartInfo(oi, m.getReturnType(), qname, m, false);
+                for (Parameter pm : ori.getParameters()) {
+                    
+                    if (pm.getType() == ParameterType.REQUEST_BODY) {
+                        createMessagePartInfo(oi, 
+                                              ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()],
+                                              qname, m, true);    
+                    }
+                }
+            }
+            
+        }
+        return infos;
+    }
+
+    private void createMessagePartInfo(OperationInfo oi, Class<?> type, QName qname, Method m,
+                                       boolean input) {
+        if (type == void.class) {
+            return;
+        }
+        if (InjectionUtils.isPrimitive(type) || Response.class == type) {
+            return;
+        }
+        QName mName = new QName(qname.getNamespaceURI(), 
+                                (input ? "in" : "out") + m.getName());
+        MessageInfo ms = oi.createMessage(mName, 
+                                           input ? MessageInfo.Type.INPUT : MessageInfo.Type.OUTPUT);
+        if (input) {
+            oi.setInput("in", ms);
+        } else {
+            oi.setOutput("out", ms);
+        }
+        QName mpQName = JAXRSUtils.getClassQName(type);
+        MessagePartInfo mpi = ms.addMessagePart(mpQName);
+        mpi.setConcreteName(mpQName);
+        mpi.setTypeQName(mpQName);
+        mpi.setTypeClass(type);
     }
     
     public EndpointInfo getEndpointInfo(QName endpoint) {        

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java Wed Jul 29 09:03:39 2009
@@ -20,7 +20,6 @@
 
 import java.io.IOException;
 import java.io.StringWriter;
-import java.lang.annotation.Annotation;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
@@ -39,7 +38,6 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.namespace.QName;
@@ -72,8 +70,8 @@
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -111,7 +109,7 @@
         
         List<ClassResourceInfo> cris = getResourcesList(m, resource);
         
-        Set<Class<?>> jaxbTypes = getAllJaxbTypes(cris);
+        Set<Class<?>> jaxbTypes = ResourceUtils.getAllRequestResponseTypes(cris, true);
         JAXBContext context = createJaxbContext(jaxbTypes);
         SchemaCollection coll = getSchemaCollection(context);
         JAXBContextProxy proxy = null;
@@ -473,31 +471,6 @@
         return prefix;
     }
     
-    private Set<Class<?>> getAllJaxbTypes(List<ClassResourceInfo> cris) {
-        Set<Class<?>> types = new HashSet<Class<?>>();
-        for (ClassResourceInfo root : cris) {
-            for (OperationResourceInfo ori : root.getMethodDispatcher().getOperationResourceInfos()) {
-                checkJaxbType(ori.getMethodToInvoke().getReturnType(), types);
-                for (Parameter pm : ori.getParameters()) {
-                    if (pm.getType() == ParameterType.REQUEST_BODY) {
-                        checkJaxbType(ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()], types);
-                    }
-                }
-            }
-        }
-        
-        return types;
-    }
-
-    private void checkJaxbType(Class<?> type, Set<Class<?>> types) {
-        JAXBElementProvider provider = new JAXBElementProvider();
-        if (!InjectionUtils.isPrimitive(type) 
-            && !JAXBElement.class.isAssignableFrom(type)
-            && provider.isReadable(type, type, new Annotation[0], MediaType.APPLICATION_XML_TYPE)) {
-            types.add(type);
-        }        
-    }
-    
     private JAXBContext createJaxbContext(Set<Class<?>> classes) {
         if (classes.isEmpty()) {
             return null;

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java?rev=798816&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java Wed Jul 29 09:03:39 2009
@@ -0,0 +1,106 @@
+/**
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.staxutils.StaxUtils;
+
+@Provider
+@Produces({"application/xml", "application/*+xml", "text/xml" })
+@Consumes({"application/xml", "application/*+xml", "text/xml" })
+public class DataBindingProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
+
+    private DataBinding binding;
+    
+    public DataBindingProvider() {
+    }
+    
+    public DataBindingProvider(DataBinding db) {
+        binding = db;
+    }
+
+    public void setDataBinding(DataBinding db) {
+        binding = db;
+    }
+    
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
+        return true;
+    }
+
+    public Object readFrom(Class<Object> clazz, Type genericType, Annotation[] annotations, MediaType type, 
+                       MultivaluedMap<String, String> headers, InputStream is)
+        throws IOException {
+        XMLStreamReader reader = createReader(clazz, is);
+        DataReader<XMLStreamReader> dataReader = binding.createReader(XMLStreamReader.class);
+        return dataReader.read(null, reader, clazz);
+    }
+
+    protected XMLStreamReader createReader(Class<?> clazz, InputStream is) {
+        return StaxUtils.createXMLStreamReader(is);
+    }
+    
+    public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
+        if (byte[].class.isAssignableFrom(t.getClass())) {
+            return ((byte[])t).length;
+        }
+        return -1;
+    }
+
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
+        return true;
+    }
+
+    public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations, 
+                        MediaType type, MultivaluedMap<String, Object> headers, OutputStream os)
+        throws IOException {
+        XMLStreamWriter writer = createWriter(clazz, os);
+        DataWriter<XMLStreamWriter> dataWriter = binding.createWriter(XMLStreamWriter.class);
+        
+        dataWriter.write(o, writer);
+        try {
+            writer.flush();
+        } catch (Exception ex) {
+            // ignore
+        }
+    }
+    
+    protected XMLStreamWriter createWriter(Class<?> clazz, OutputStream os) {
+        return StaxUtils.createXMLStreamWriter(os);
+    }
+    
+}
+

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java Wed Jul 29 09:03:39 2009
@@ -29,10 +29,12 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.CookieParam;
@@ -44,6 +46,8 @@
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBElement;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -64,6 +68,7 @@
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.model.UserOperation;
 import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.resource.ResourceManager;
 
 public final class ResourceUtils {
@@ -391,6 +396,42 @@
         return resources;
     }
     
+
+    public static Set<Class<?>> getAllRequestResponseTypes(List<ClassResourceInfo> cris, boolean jaxbOnly) {
+        Set<Class<?>> types = new HashSet<Class<?>>();
+        for (ClassResourceInfo root : cris) {
+            for (OperationResourceInfo ori : root.getMethodDispatcher().getOperationResourceInfos()) {
+                if (jaxbOnly) {
+                    checkJaxbType(ori.getMethodToInvoke().getReturnType(), types);
+                } else {
+                    types.add(ori.getMethodToInvoke().getReturnType());
+                }
+                for (Parameter pm : ori.getParameters()) {
+                    if (pm.getType() == ParameterType.REQUEST_BODY) {
+                        Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+                        if (jaxbOnly) {
+                            checkJaxbType(inType, types);
+                        } else {
+                            types.add(inType);
+                        }
+                    }
+                }
+                
+            }
+        }
+        
+        return types;
+    }
+
+    private static void checkJaxbType(Class<?> type, Set<Class<?>> types) {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        if (!InjectionUtils.isPrimitive(type) 
+            && !JAXBElement.class.isAssignableFrom(type)
+            && provider.isReadable(type, type, new Annotation[0], MediaType.APPLICATION_XML_TYPE)) {
+            types.add(type);
+        }        
+    }
+    
     private static UserResource getResourceFromElement(Element e) {
         UserResource resource = new UserResource();
         resource.setName(e.getAttribute("name"));

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd Wed Jul 29 09:03:39 2009
@@ -37,6 +37,7 @@
             <xsd:element name="executor" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="features" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="binding" type="xsd:anyType" minOccurs="0" />  
+            <xsd:element name="dataBinding" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="inFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="invoker" type="xsd:anyType" minOccurs="0"/>
@@ -72,6 +73,7 @@
             <xsd:element name="executor" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="features" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="binding" type="xsd:anyType" minOccurs="0" />
+            <xsd:element name="dataBinding" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="inFaultInterceptors" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="outInterceptors" type="xsd:anyType" minOccurs="0"/>

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java?rev=798816&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingProviderTest.java Wed Jul 29 09:03:39 2009
@@ -0,0 +1,147 @@
+/**
+ * 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 java.lang.annotation.Annotation;
+import java.util.Collections;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.service.Service;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class DataBindingProviderTest extends Assert {
+
+    private ClassResourceInfo c;
+    
+    @Before
+    public void setUp() {
+        c = ResourceUtils.createClassResourceInfo(TheBooks.class, TheBooks.class, true, true);
+    }
+    
+    @Test
+    public void testAegisWrite() throws Exception {
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c));
+        s.put("writeXsiType", true);
+        AegisDatabinding binding = new AegisDatabinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        Book b = new Book("CXF", 127L);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        p.writeTo(b, Book.class, Book.class,
+            new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String data = "<ns1:Book xmlns:ns1=\"http://resources.jaxrs.cxf.apache.org\" "
+            + "xmlns:ns2=\"http://www.w3.org/2001/XMLSchema-instance\" ns2:type=\"ns1:Book\">"
+            + "<ns1:id>127</ns1:id><ns1:name>CXF</ns1:name><ns1:state></ns1:state></ns1:Book>";
+        assertEquals(bos.toString(), data);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testAegisRead() throws Exception {
+        String data = "<ns1:Book xmlns:ns1=\"http://resources.jaxrs.cxf.apache.org\" "
+            + "xmlns:ns2=\"http://www.w3.org/2001/XMLSchema-instance\" ns2:type=\"ns1:Book\">"
+            + "<ns1:id>127</ns1:id><ns1:name>CXF</ns1:name><ns1:state></ns1:state></ns1:Book>";
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c));
+        s.put("readXsiType", true);
+        AegisDatabinding binding = new AegisDatabinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Book book = (Book)p.readFrom((Class)Book.class, Book.class,
+                                      new Annotation[0], MediaType.APPLICATION_XML_TYPE, 
+                                      new MetadataMap<String, String>(), is);
+        assertEquals("CXF", book.getName());
+        assertEquals(127L, book.getId());
+    }
+    
+    @Test
+    public void testJAXBWrite() throws Exception {
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c));
+        DataBinding binding = new JAXBDataBinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        Book b = new Book("CXF", 127L);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        p.writeTo(b, Book.class, Book.class,
+            new Annotation[0], MediaType.TEXT_XML_TYPE, new MetadataMap<String, Object>(), bos);
+        String data = "<Book><id>127</id><name>CXF</name><state></state></Book>";
+        assertEquals(bos.toString(), data);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testJAXBRead() throws Exception {
+        String data = "<Book><id>127</id><name>CXF</name><state></state></Book>";
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c));
+        DataBinding binding = new JAXBDataBinding();
+        binding.initialize(s);
+        DataBindingProvider p = new DataBindingProvider(binding);
+        ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        Book book = (Book)p.readFrom((Class)Book.class, Book.class,
+                                      new Annotation[0], MediaType.APPLICATION_XML_TYPE, 
+                                      new MetadataMap<String, String>(), is);
+        assertEquals("CXF", book.getName());
+        assertEquals(127L, book.getId());
+    }
+    
+    @Path("/")
+    @Ignore
+    public static class TheBooks {
+
+        @Path("/books/{bookId}/{new}")
+        public Book getNewBook(Book b) {
+            return new Book();
+        }
+        
+        @Path("/books/{bookId}/{new}")
+        public Book getNewBook2() {
+            return new Book();
+        }
+        
+        @POST
+        public void setNewBook(Book b) {
+        }
+        
+        @Path("/books/{bookId}/{new}")
+        @POST
+        public void setNewBook2(@PathParam("new") String id, Book b) {
+        }
+    }
+    
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JSONProviderTest.java Wed Jul 29 09:03:39 2009
@@ -346,7 +346,7 @@
                   MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
         String s = os.toString();
         String data = "{\"books2\":{\"books\":{\"@xsins.type\":\"superBook\",\"id\":123,"
-            + "\"name\":\"CXF Rocks\",\"superId\":124}}}";
+            + "\"name\":\"CXF Rocks\",\"state\":\"\",\"superId\":124}}}";
         assertEquals(data, s);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Book.java Wed Jul 29 09:03:39 2009
@@ -70,6 +70,10 @@
         return "";
     }
     
+    
+    public void setState(String s) {
+    }
+    
     public int hashCode() { 
         return name.hashCode() * 37 + new Long(id).hashCode();
     }

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookDataBindingServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookDataBindingServer.java?rev=798816&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookDataBindingServer.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookDataBindingServer.java Wed Jul 29 09:03:39 2009
@@ -0,0 +1,89 @@
+/**
+ * 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 java.net.URISyntaxException;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.handler.DefaultHandler;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+
+public class BookDataBindingServer extends AbstractBusTestServerBase {
+
+    private org.mortbay.jetty.Server server;
+    
+    protected void run() {
+        System.out.println("Starting Server");
+
+        server = new org.mortbay.jetty.Server();
+
+        SelectChannelConnector connector = new SelectChannelConnector();
+        connector.setPort(9080);
+        server.setConnectors(new Connector[] {connector});
+
+        WebAppContext webappcontext = new WebAppContext();
+        String contextPath = null;
+        try {
+            contextPath = getClass().getResource("/jaxrs_databinding").toURI().getPath();
+        } catch (URISyntaxException e1) {
+            e1.printStackTrace();
+        }
+        webappcontext.setContextPath("/");
+
+        webappcontext.setWar(contextPath);
+
+        HandlerCollection handlers = new HandlerCollection();
+        handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
+
+        server.setHandler(handlers);
+        try {
+            server.start();
+                       
+        } catch (Exception e) {
+            e.printStackTrace();
+        }     
+    }
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (server != null) {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }    
+    
+    public static void main(String args[]) {
+        try {
+            BookDataBindingServer s = new BookDataBindingServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

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

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

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=798816&r1=798815&r2=798816&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Wed Jul 29 09:03:39 2009
@@ -64,6 +64,13 @@
     }
     
     @GET
+    @Path("/bookstore/books/{id}")
+    @Produces("application/xml")
+    public Book getBookXml(@PathParam("id") Long id) {
+        return books.get(id);
+    }
+    
+    @GET
     @Path("/bookinfo")
     public Book getBookByUriInfo() throws Exception {
         MultivaluedMap<String, String> params = ui.getQueryParameters();

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java?rev=798816&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java Wed Jul 29 09:03:39 2009
@@ -0,0 +1,60 @@
+/**
+ * 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 java.util.Collections;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.provider.AegisElementProvider;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSDataBindingTest extends AbstractBusClientServerTestBase {
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", 
+                   launchServer(BookDataBindingServer.class));
+    }
+    
+    
+    @Test
+    public void testGetBookJAXB() throws Exception {
+        WebClient client = WebClient.create("http://localhost:9080/databinding/jaxb/bookstore/books/123");
+        Book book = client.accept("application/xml").get(Book.class);
+        assertEquals(123L, book.getId());
+        assertEquals("CXF in Action", book.getName());
+    }
+    
+    @Test
+    @Ignore("Aegis Schema Validation gets in the way")
+    public void testGetBookAegis() throws Exception {
+        WebClient client = WebClient.create("http://localhost:9080/databinding/aegis/bookstore/books/123",
+                                            Collections.singletonList(new AegisElementProvider()));
+        Book book = client.accept("application/xml").get(Book.class);
+        assertEquals(123L, book.getId());
+        assertEquals("CXF in Action", book.getName());
+    }
+    
+    
+}

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

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

Added: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml?rev=798816&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml (added)
+++ cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml Wed Jul 29 09:03:39 2009
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- START SNIPPET: beans -->
+<!--beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:simple="http://cxf.apache.org/simple"
+  xsi:schemaLocation="
+  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+  http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:util="http://www.springframework.org/schema/util"
+  xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+  xmlns:cxf="http://cxf.apache.org/core"
+  xsi:schemaLocation="
+http://www.springframework.org/schema/beans 
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://www.springframework.org/schema/util 
+http://www.springframework.org/schema/util/spring-util-2.0.xsd
+http://cxf.apache.org/jaxrs
+http://cxf.apache.org/schemas/jaxrs.xsd
+http://cxf.apache.org/core
+http://cxf.apache.org/schemas/core.xsd">
+
+  <import resource="classpath:META-INF/cxf/cxf.xml" />
+  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+
+  <bean class="org.apache.cxf.systest.jaxrs.BookStoreSpring" id="serviceBean"/>
+  
+  <jaxrs:server id="jaxbbook" address="/jaxb">
+    <jaxrs:serviceBeans>
+      <ref bean="serviceBean" />
+    </jaxrs:serviceBeans>		   
+    <jaxrs:dataBinding> 
+      <bean class="org.apache.cxf.jaxb.JAXBDataBinding"/>
+    </jaxrs:dataBinding> 
+  </jaxrs:server>
+  <jaxrs:server id="aegisbook" address="/aegis">
+    <jaxrs:serviceBeans>
+      <ref bean="serviceBean" />
+    </jaxrs:serviceBeans>		   
+    <jaxrs:dataBinding> 
+      <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding">
+          <property name="aegisContext">
+              <bean class="org.apache.cxf.aegis.AegisContext">
+                  <property name="writeXsiTypes" value="true"/>
+              </bean>
+          </property>    
+        </bean> 
+    </jaxrs:dataBinding> 
+  </jaxrs:server>
+
+
+</beans>
+<!-- END SNIPPET: beans -->

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml?rev=798816&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml (added)
+++ cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml Wed Jul 29 09:03:39 2009
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<!--
+	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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+	<context-param>
+		<param-name>contextConfigLocation</param-name>
+		<param-value>WEB-INF/beans.xml</param-value>
+	</context-param>
+
+	<listener>
+		<listener-class>
+			org.springframework.web.context.ContextLoaderListener
+		</listener-class>
+	</listener>
+
+	<servlet>
+		<servlet-name>CXFServlet</servlet-name>
+		<display-name>CXF Servlet</display-name>
+		<servlet-class>
+			org.apache.cxf.transport.servlet.CXFServlet
+		</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+
+	<servlet-mapping>
+		<servlet-name>CXFServlet</servlet-name>
+		<url-pattern>/databinding/*</url-pattern>
+	</servlet-mapping>
+</web-app>
+<!-- END SNIPPET: webxml -->
\ No newline at end of file

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/src/test/resources/jaxrs_databinding/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message