cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r762784 [1/2] - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/or...
Date Tue, 07 Apr 2009 14:09:38 GMT
Author: sergeyb
Date: Tue Apr  7 14:09:36 2009
New Revision: 762784

URL: http://svn.apache.org/viewvc?rev=762784&view=rev
Log:
JAXRS: introducing non-spring JAXRS servlet, moving XMLSource to its final destination, plus few minor fixes

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/XMLSourceTest.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProviderTest.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNonSpringServer.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStorePerRequest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/formRequest.txt   (with props)
    cxf/trunk/systests/src/test/resources/jaxrs_non_spring/
    cxf/trunk/systests/src/test/resources/jaxrs_non_spring/WEB-INF/
    cxf/trunk/systests/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml   (with props)
Removed:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/XMLSource.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/XMLSourceTest.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    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/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.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/utils/AnnotationTestUtilsTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFNonSpringServlet.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationServer.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/PetStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Tue Apr  7 14:09:36 2009
@@ -58,20 +58,11 @@
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInvoker.class);
     private static final String SERVICE_LOADER_AS_CONTEXT = "org.apache.cxf.serviceloader-context";
     
-    private List<Object> resourceObjects;
-
     public JAXRSInvoker() {
     }
 
-    public JAXRSInvoker(List<Object> resourceObjects) {
-        this.resourceObjects = resourceObjects;
-    }
-    public Object invoke(Exchange exchange, Object request) {
-        return invoke(exchange, request, resourceObjects);
-    }
     @SuppressWarnings("unchecked")
-    public Object invoke(Exchange exchange, Object request, List<Object> resources) {
-
+    public Object invoke(Exchange exchange, Object request) {
         Response response = exchange.get(Response.class);
         if (response != null) {
             // this means a blocking request filter provided a Response
@@ -83,11 +74,16 @@
             //      in the out interceptor instead of dealing with the contents list ?
             return new MessageContentsList(response);
         }
+        
+        return invoke(exchange, request, getServiceObject(exchange));
+    }
+
+    @SuppressWarnings("unchecked")
+    public Object invoke(Exchange exchange, Object request, Object resourceObject) {
 
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
         ClassResourceInfo cri = ori.getClassResourceInfo();
         
-        Object resourceObject = getServiceObject(exchange, resources);
         pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), exchange.getInMessage());
                 
         Method methodToInvoke = InjectionUtils.checkProxy(
@@ -154,9 +150,6 @@
 
                 result = checkResultObject(result, subResourcePath);
 
-                List<Object> newResourceObjects = new ArrayList<Object>();
-                newResourceObjects.add(result);
-
                 ClassResourceInfo subCri = cri.getSubResource(
                      methodToInvoke.getReturnType(),
                      ClassHelper.getRealClass(result));
@@ -188,7 +181,7 @@
                 List<Object> newParams = JAXRSUtils.processParameters(subOri, values, msg);
                 msg.setContent(List.class, newParams);
 
-                return this.invoke(exchange, newParams, newResourceObjects);
+                return this.invoke(exchange, newParams, result);
             } catch (WebApplicationException ex) {
                 Response excResponse = JAXRSUtils.convertFaultToResponse(ex, 
                                                                          exchange.getInMessage());
@@ -205,29 +198,10 @@
     }
     
     public Object getServiceObject(Exchange exchange) {
-        return getServiceObject(exchange, resourceObjects);
-    }
-    public Object getServiceObject(Exchange exchange, List<Object> resources) {
-        Object serviceObject = null;
-
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
         ClassResourceInfo cri = ori.getClassResourceInfo();
 
-        if (resources != null) {
-            Class c  = cri.getResourceClass();
-            for (Object resourceObject : resources) {
-                if (c.isInstance(resourceObject)) {
-                    serviceObject = resourceObject;
-                    break;
-                }
-            }
-        }
-
-        if (serviceObject == null) {
-            serviceObject = cri.getResourceProvider().getInstance();
-        }
-
-        return serviceObject;
+        return cri.getResourceProvider().getInstance(exchange.getInMessage());
     }
 
     private static Object checkResultObject(Object result, String subResourcePath) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java Tue Apr  7 14:09:36 2009
@@ -58,7 +58,6 @@
     private Server server;
     private Invoker invoker;
     private boolean start = true;
-    private List<Object> serviceBeans;
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
     
@@ -126,11 +125,7 @@
     }
 
     protected Invoker createInvoker() {
-        if (serviceBeans == null) {
-            return new JAXRSInvoker();
-        } else {
-            return new JAXRSInvoker(serviceBeans);           
-        }
+        return new JAXRSInvoker();
     }
 
     public void setLanguageMappings(Map<Object, Object> lMaps) {
@@ -164,7 +159,6 @@
     }
     
     public void setServiceBeans(List<Object> beans) {
-        this.serviceBeans = beans;
         serviceFactory.setResourceClassesFromBeans(beans);
     }
     
@@ -184,7 +178,7 @@
         for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
             if (cri.isSingleton()) {
                 InjectionUtils.injectContextProxies(cri, 
-                                                    cri.getResourceProvider().getInstance());
+                                                    cri.getResourceProvider().getInstance(null));
             }
         }
     }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties?rev=762784&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties Tue Apr  7 14:09:36 2009
@@ -0,0 +1,21 @@
+#
+#
+#    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.
+#
+#
+NO_SOURCE_MARK=InputStream used by XMLSource does not support buffering mode

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java?rev=762784&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java Tue Apr  7 14:09:36 2009
@@ -0,0 +1,211 @@
+/**
+ * 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.ext.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.net.URI;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+
+/**
+ * Utiliity class for manipulating XML response using XPath and XSLT
+ *
+ */
+public class XMLSource {
+    private static final Logger LOG = LogUtils.getL7dLogger(XMLSource.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(XMLSource.class);
+    
+    private static final String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"; 
+    
+    private InputStream stream; 
+    private boolean buffering;
+    
+    public XMLSource(InputStream is) {
+        stream = is;
+    }
+    
+    public void setBuffering(boolean enable) {
+        buffering = enable;
+        if (!stream.markSupported()) {
+            try {
+                stream = IOUtils.loadIntoBAIS(stream);
+            } catch (IOException ex) {
+                LOG.warning(new org.apache.cxf.common.i18n.Message("NO_SOURCE_MARK", BUNDLE).toString());
+            }
+        }
+    }
+    
+    public <T> T getNode(String expression, Class<T> cls) {
+        return getNode(expression, CastUtils.cast(Collections.emptyMap(), String.class, String.class), cls);
+    }
+    
+    public <T> T getNode(String expression, Map<String, String> namespaces, Class<T> cls) {
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
+        try {
+            Node node = (Node)xpath.evaluate(expression, getSource(), XPathConstants.NODE);
+            if (node == null) {
+                return null;
+            }
+            DOMSource ds = new DOMSource(node);
+            return readFromSource(ds, cls);
+        } catch (XPathExpressionException ex) {
+            throw new IllegalArgumentException("Illegal XPath expression '" + expression + "'", ex);
+        }
+    }
+    
+    public <T> T[] getNodes(String expression, Class<T> cls) {
+        return getNodes(expression, CastUtils.cast(Collections.emptyMap(), String.class, String.class), cls);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public <T> T[] getNodes(String expression, Map<String, String> namespaces, Class<T> cls) {
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
+        try {
+            NodeList nodes = (NodeList)xpath.evaluate(expression, getSource(), XPathConstants.NODESET);
+            if (nodes == null || nodes.getLength() == 0) {
+                return null;
+            }
+            T[] values = (T[])Array.newInstance(cls, nodes.getLength());
+ 
+            for (int i = 0; i < nodes.getLength(); i++) {
+                DOMSource ds = new DOMSource(nodes.item(i));
+                values[i] = readFromSource(ds, cls);
+            }
+                  
+            return values;
+            
+        } catch (XPathExpressionException ex) {
+            throw new IllegalArgumentException("Illegal XPath expression '" + expression + "'", ex);
+        }
+    }
+
+    public URI getLink(String expression) {
+        return getLink(expression, CastUtils.cast(Collections.emptyMap(), String.class, String.class));
+    }
+    
+    public URI getLink(String expression, Map<String, String> namespaces) {
+        String value = getValue(expression, namespaces);
+        return value == null ? null : URI.create(value);
+    }
+    
+    public URI getBaseURI() {
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("xml", XML_NAMESPACE);
+        return getLink("/*/@xml:base", map);
+    }
+    
+    public String getValue(String expression) {
+        return getValue(expression, CastUtils.cast(Collections.emptyMap(), String.class, String.class));
+    }
+    
+    public String getValue(String expression, Map<String, String> namespaces) {
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
+        try {
+            return (String)xpath.evaluate(expression, getSource(), XPathConstants.STRING);
+        } catch (XPathExpressionException ex) {
+            throw new IllegalArgumentException("Illegal XPath expression '" + expression + "'", ex);
+        }
+    }
+    
+    private static class NamespaceContextImpl implements NamespaceContext {
+        
+        private Map<String, String> namespaces;
+        
+        public NamespaceContextImpl(Map<String, String> namespaces) {
+            this.namespaces = namespaces;    
+        }
+
+        public String getNamespaceURI(String prefix) {
+            return namespaces.get(prefix);
+        }
+
+        public String getPrefix(String namespace) {
+            for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                if (entry.getValue().equals(namespace)) {
+                    return entry.getKey();
+                }
+            }
+            return null;
+        }
+
+        public Iterator getPrefixes(String namespace) {
+            String prefix = namespaces.get(namespace);
+            if (prefix == null) {
+                return null;
+            }
+            return Collections.singletonList(prefix).iterator();
+        }
+    }
+    
+    private <T> T readFromSource(Source s, Class<T> cls) {
+        try {
+            JAXBElementProvider provider = new JAXBElementProvider();
+            JAXBContext c = provider.getPackageContext(cls);
+            if (c == null) {
+                c = provider.getClassContext(cls);
+            }
+            Unmarshaller u = c.createUnmarshaller();
+            return cls.cast(u.unmarshal(s));
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+    
+    private InputSource getSource() {
+        try {
+            if (buffering) {
+                stream.reset();
+                stream.mark(stream.available());
+            }
+        } catch (IOException ex) {
+            LOG.warning(new org.apache.cxf.common.i18n.Message("NO_SOURCE_MARK", BUNDLE).toString());
+        }
+        return new InputSource(stream);
+    }
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/CookieHeaderProvider.java Tue Apr  7 14:09:36 2009
@@ -29,7 +29,7 @@
     
     public Cookie fromString(String c) {
         
-        int version = -1;
+        int version = Cookie.DEFAULT_VERSION;
         String name = null;
         String value = null;
         String path = null;
@@ -64,7 +64,7 @@
     public String toString(Cookie c) {
         StringBuilder sb = new StringBuilder();
         
-        if (c.getVersion() != -1) {
+        if (c.getVersion() != Cookie.DEFAULT_VERSION) {
             sb.append(VERSION).append('=').append(c.getVersion()).append(';');
         }
         sb.append(c.getName()).append('=').append(c.getValue());

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProvider.java Tue Apr  7 14:09:36 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
@@ -89,7 +90,9 @@
         if (value.isSecure()) {
             sb.append(';').append(SECURE);
         }
-        sb.append(';').append(VERSION).append('=').append(1);
+        if (value.getVersion() != Cookie.DEFAULT_VERSION) {
+            sb.append(';').append(VERSION).append('=').append(1);
+        }
         return sb.toString();
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java Tue Apr  7 14:09:36 2009
@@ -61,6 +61,9 @@
     }
 
     public ResponseBuilder status(int s) {
+        if (status < 100 || status > 599) {
+            throw new IllegalArgumentException("Illegal status value : " + s);
+        }
         status = s;
         return this;
     }
@@ -71,77 +74,58 @@
     }
 
     public ResponseBuilder type(MediaType type) {
-        return type(type.toString());
+        return type(type == null ? null : type.toString());
     }
 
     public ResponseBuilder type(String type) {
-        metadata.putSingle("Content-Type", type);
-        return this;
+        return setHeader(HttpHeaders.CONTENT_TYPE, type);
     }
 
+    @Override
+    public ResponseBuilder language(Locale locale) {
+        return language(locale == null ? null : locale.toString());
+    }
+    
     public ResponseBuilder language(String language) {
-        metadata.putSingle("Content-Language", language.toString());
-        return this;
+        return setHeader(HttpHeaders.CONTENT_LANGUAGE, language);
     }
 
     public ResponseBuilder location(URI location) {
-        metadata.putSingle("Location", location.toString());
-        return this;
+        return setHeader(HttpHeaders.LOCATION, location);
     }
 
     public ResponseBuilder contentLocation(URI location) {
-        metadata.putSingle("Content-Location", location.toString());
-        return this;
+        return setHeader(HttpHeaders.CONTENT_LOCATION, location);
     }
 
     public ResponseBuilder tag(EntityTag tag) {
-        return tag(tag.toString());
+        return tag(tag == null ? null : tag.toString());
     }
 
     public ResponseBuilder tag(String tag) {
-        metadata.putSingle(HttpHeaders.ETAG, tag.toString());
-        return this;
+        return setHeader(HttpHeaders.ETAG, tag);
     }
 
-    public ResponseBuilder lastModified(Date lastModified) {
-        metadata.putSingle(HttpHeaders.LAST_MODIFIED, lastModified.toString());
-        return this;
+    public ResponseBuilder lastModified(Date date) {
+        return setHeader(HttpHeaders.LAST_MODIFIED, date == null ? null : toHttpDate(date));
     }
 
     public ResponseBuilder cacheControl(CacheControl cacheControl) {
-        metadata.putSingle(HttpHeaders.CACHE_CONTROL, 
-                           cacheControl.toString());
-        return this;
-    }
-
-    public ResponseBuilder cookie(NewCookie cookie) {
-        metadata.putSingle(HttpHeaders.SET_COOKIE, cookie.toString());
-        return this;
+        return setHeader(HttpHeaders.CACHE_CONTROL, cacheControl);
     }
 
     @Override
     public ResponseBuilder expires(Date date) {
-        metadata.putSingle(HttpHeaders.EXPIRES, toHttpDate(date));
-        return this;
+        return setHeader(HttpHeaders.EXPIRES, date == null ? null : toHttpDate(date));
     }
 
     @Override
-    public ResponseBuilder language(Locale language) {
-        metadata.putSingle(HttpHeaders.CONTENT_LANGUAGE, language.toString());
-        return this;
-    }
-    
-    @Override
     public ResponseBuilder cookie(NewCookie... cookies) {
-        for (NewCookie cookie : cookies) {
-            metadata.add(HttpHeaders.SET_COOKIE, cookie.toString());
-        }
-        return this;
+        return addHeader(HttpHeaders.SET_COOKIE, (Object[])cookies);
     }
     
     public ResponseBuilder header(String name, Object value) {
-        metadata.add(name, value.toString());
-        return this;
+        return addHeader(name, value);
     }
 
     
@@ -184,4 +168,24 @@
         SimpleDateFormat format = HttpUtils.getHttpDateFormat();
         return format.format(date);
     }
+    
+    private ResponseBuilder setHeader(String name, Object value) {
+        if (value == null) {
+            metadata.remove(name);
+        } else {
+            metadata.putSingle(name, value.toString());
+        }
+        return this;
+    }
+    
+    private ResponseBuilder addHeader(String name, Object... values) {
+        if (values != null && values.length >= 1 && values[0] != null) {
+            for (Object value : values) {
+                metadata.add(name, value.toString());
+            }
+        } else {
+            metadata.remove(name);
+        }    
+        return this;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Tue Apr  7 14:09:36 2009
@@ -23,7 +23,9 @@
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.text.SimpleDateFormat;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -31,6 +33,7 @@
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.xml.stream.XMLStreamWriter;
@@ -45,6 +48,7 @@
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
@@ -119,7 +123,13 @@
                                   Response response, 
                                   OperationResourceInfo ori,
                                   boolean firstTry) {
-        message.put(Message.RESPONSE_CODE, response.getStatus());
+        int status = response.getStatus();
+        Object responseObj = response.getEntity();
+        if (status == -1) {
+            status = responseObj == null ? 204 : 200;
+        }
+        
+        message.put(Message.RESPONSE_CODE, status);
         Map<String, List<String>> theHeaders = 
             (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
         if (firstTry && theHeaders != null) {
@@ -128,8 +138,9 @@
         } else {
             message.put(Message.PROTOCOL_HEADERS, response.getMetadata());
         }
-        
-        Object responseObj = response.getEntity();
+        MultivaluedMap<String, Object> responseHeaders = 
+            (MultivaluedMap)message.get(Message.PROTOCOL_HEADERS);
+        setResponseDate(responseHeaders, firstTry);
         if (responseObj == null) {
             return;
         }
@@ -177,8 +188,12 @@
                                invoked != null ? invoked.getGenericReturnType() : null, 
                                invoked != null ? invoked.getAnnotations() : new Annotation[]{}, 
                                responseType, 
-                               response.getMetadata(), 
+                               responseHeaders, 
                                message.getContent(OutputStream.class));
+                Object newContentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
+                if (newContentType != null) {
+                    message.put(Message.CONTENT_TYPE, newContentType.toString());
+                }
                 checkCachedStream(message, outOriginal, enabled);
             } finally {
                 if (enabled) {
@@ -303,19 +318,18 @@
         if (mt.isWildcardType() || mt.isWildcardSubtype()) {
             return MediaType.APPLICATION_OCTET_STREAM_TYPE;
         } else if (mt.getParameters().containsKey("q")) {
-            StringBuilder sb = new StringBuilder();
-            sb.append(mt.getType()).append('/').append(mt.getSubtype());
-            if (mt.getParameters().size() > 1) {
-                for (String key : mt.getParameters().keySet()) {
-                    if (!"q".equals(key)) {
-                        sb.append(';').append(key).append('=').append(mt.getParameters().get(key));
-                    }
-                }
-            }
-            return MediaType.valueOf(sb.toString());
+            return MediaType.valueOf(JAXRSUtils.removeMediaTypeParameter(mt, "q"));
         } else {
             return mt;
         }
         
     }
+    
+    private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry) {
+        if (!firstTry) {
+            return;
+        }
+        SimpleDateFormat format = HttpUtils.getHttpDateFormat();
+        headers.putSingle(HttpHeaders.DATE, format.format(new Date()));
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java Tue Apr  7 14:09:36 2009
@@ -19,23 +19,67 @@
 
 package org.apache.cxf.jaxrs.lifecycle;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.message.Message;
+
 public class PerRequestResourceProvider implements ResourceProvider {
-    private Class<?> resourceClass;
+    private Constructor<?> c;
    
     public PerRequestResourceProvider(Class<?> clazz) {
-        resourceClass = clazz;
+        c = ResourceUtils.findResourceConstructor(clazz);
+        if (c == null) {
+            throw new RuntimeException("Resource class " + clazz
+                                       + " has no valid constructor");
+        }
     }
     
+    public boolean isSingleton() {
+        return false;
+    }
 
+    public Object getInstance(Message m) {  
+        return createInstance(m);
+    }
+    
     public Object getInstance() {  
-        Object resourceInstance = null;
+        if (c.getParameterTypes().length > 0) {
+            throw new RuntimeException("Resource class constructor has context parameters "
+                          + "but no request message is available");
+        }
+        return createInstance(null);
+    }
+    
+    protected Object createInstance(Message m) {
+        
+        Class<?>[] params = c.getParameterTypes();
+        Type[] genericTypes = c.getGenericParameterTypes();
+        Object[] values = new Object[]{params.length};
+        for (int i = 0; i < params.length; i++) {
+            values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
+        }
         try {
-            resourceInstance = resourceClass.newInstance();
+            return params.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{});
         } catch (InstantiationException ex) {
-            //TODO
+            String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated";
+            throw new WebApplicationException(Response.serverError().entity(msg).build());
         } catch (IllegalAccessException ex) {
-            //TODO
-        }        
-        return resourceInstance;
+            String msg = "Resource class " + c.getDeclaringClass().getName() + " can not be instantiated"
+                + " due to IllegalAccessException";
+            throw new WebApplicationException(Response.serverError().entity(msg).build());
+        } catch (InvocationTargetException ex) {
+            String msg = "Resource class "
+                + c.getDeclaringClass().getName() + " can not be instantiated"
+                + " due to InvocationTargetException";
+            throw new WebApplicationException(Response.serverError().entity(msg).build());
+        }
+        
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java Tue Apr  7 14:09:36 2009
@@ -19,8 +19,11 @@
 
 package org.apache.cxf.jaxrs.lifecycle;
 
+import org.apache.cxf.message.Message;
+
 public interface ResourceProvider {
 
     Object getInstance();
-    //void setResourceClass(Class<?> clazz);
+    Object getInstance(Message m);
+    boolean isSingleton();
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java Tue Apr  7 14:09:36 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs.lifecycle;
 
+import org.apache.cxf.message.Message;
+
 public class SingletonResourceProvider implements ResourceProvider {
     private Object resourceInstance;
     
@@ -26,7 +28,14 @@
         resourceInstance = o;
     }
     
-
+    public boolean isSingleton() {
+        return true;
+    }
+    
+    public Object getInstance(Message m) {
+        return resourceInstance;
+    }
+    
     public Object getInstance() {
         return resourceInstance;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java Tue Apr  7 14:09:36 2009
@@ -25,7 +25,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.Consumes;
@@ -33,7 +35,6 @@
 import javax.ws.rs.Produces;
 
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
@@ -104,6 +105,17 @@
         return Collections.unmodifiableCollection(subResources.values());
     }
     
+    public Set<String> getAllowedMethods() {
+        Set<String> methods = new HashSet<String>();
+        for (OperationResourceInfo o : methodDispatcher.getOperationResourceInfos()) {
+            String method = o.getHttpMethod();
+            if (method != null) {
+                methods.add(method);
+            }
+        }
+        return methods;
+    }
+    
     private void initParamFields() {
         if (getResourceClass() == null || !isRoot()) {
             return;
@@ -211,6 +223,6 @@
     
     @Override
     public boolean isSingleton() {
-        return resourceProvider instanceof SingletonResourceProvider;
+        return resourceProvider != null && resourceProvider.isSingleton();
     }
 }

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=762784&r1=762783&r2=762784&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 Tue Apr  7 14:09:36 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.List;
@@ -28,7 +29,9 @@
 import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -49,16 +52,16 @@
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 
 public abstract class AbstractJAXBProvider extends AbstractConfigurableProvider
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
     
     protected static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractJAXBProvider.class);
-
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractJAXBProvider.class);
-    private static final String CHARSET_PARAMETER = "charset"; 
-        
+    
+    private static final String CHARSET_PARAMETER = "charset";
     private static Map<String, JAXBContext> packageContexts = new WeakHashMap<String, JAXBContext>();
     private static Map<Class<?>, JAXBContext> classContexts = new WeakHashMap<Class<?>, JAXBContext>();
    
@@ -198,20 +201,40 @@
         return unmarshaller;        
     }
     
-    protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, MediaType m)
+    protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, String enc)
         throws JAXBException {
         
         Class<?> objClazz = JAXBElement.class.isAssignableFrom(cls) 
                             ? ((JAXBElement)obj).getDeclaredType() : cls;
         JAXBContext context = getJAXBContext(objClazz, genericType);
         Marshaller marshaller = context.createMarshaller();
-        String enc = m.getParameters().get(CHARSET_PARAMETER);
         if (enc != null) {
             marshaller.setProperty(Marshaller.JAXB_ENCODING, enc);
         }
         return marshaller;
     }
     
+    protected String getEncoding(MediaType mt, MultivaluedMap<String, Object> headers) {
+        String enc = mt.getParameters().get(CHARSET_PARAMETER);
+        if (enc == null) {
+            return null;
+        }
+        try {
+            "0".getBytes(enc);
+            return enc;
+        } catch (UnsupportedEncodingException ex) {
+            String message = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_ENCODING", 
+                                 BUNDLE, enc).toString();
+            LOG.warning(message);
+            headers.putSingle(HttpHeaders.CONTENT_TYPE, 
+                JAXRSUtils.removeMediaTypeParameter(mt, CHARSET_PARAMETER) 
+                + ';' + CHARSET_PARAMETER + "=UTF-8");
+        }
+        return null;
+    }
+        
+
+    
     protected Class<?> getActualType(Class<?> type, Type genericType, Annotation[] anns) {
         Class<?> theType = null;
         if (JAXBElement.class.isAssignableFrom(type)) {

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=762784&r1=762783&r2=762784&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 Tue Apr  7 14:09:36 2009
@@ -132,21 +132,8 @@
             if (cls == genericType) {
                 genericType = actualClass;
             }
-            Marshaller ms = createMarshaller(actualObject, actualClass, genericType, m);
-            for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
-                ms.setProperty(entry.getKey(), entry.getValue());
-            }
-            if (enableStreaming) {
-                XMLStreamWriter writer = 
-                    (XMLStreamWriter)getContext().get(XMLStreamWriter.class.getName());
-                if (writer == null) {
-                    writer = StaxUtils.createXMLStreamWriter(os);
-                }
-                ms.marshal(actualObject, writer);
-            } else {
-                ms.marshal(actualObject, os);
-            }
-            
+            String encoding = getEncoding(m, headers);
+            marshal(actualObject, actualClass, genericType, encoding, os);
         } catch (JAXBException e) {
             handleJAXBException(e);
         }  catch (WebApplicationException e) {
@@ -156,6 +143,23 @@
         }
     }
 
-    
+    protected void marshal(Object obj, Class<?> cls, Type genericType, String enc, OutputStream os)
+        throws Exception {
+        
+        Marshaller ms = createMarshaller(obj, cls, genericType, enc);
+        for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
+            ms.setProperty(entry.getKey(), entry.getValue());
+        }
+        if (enableStreaming) {
+            XMLStreamWriter writer = 
+                (XMLStreamWriter)getContext().get(XMLStreamWriter.class.getName());
+            if (writer == null) {
+                writer = StaxUtils.createXMLStreamWriter(os);
+            }
+            ms.marshal(obj, writer);
+        } else {
+            ms.marshal(obj, os);
+        }
+    }
     
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java Tue Apr  7 14:09:36 2009
@@ -145,13 +145,17 @@
             if (cls == genericType) {
                 genericType = actualClass;
             }
-            Marshaller ms = createMarshaller(actualObject, actualClass, genericType, m);
+            String encoding = getEncoding(m, headers);
+            if (encoding == null) {
+                encoding = "UTF-8";
+            }
+            Marshaller ms = createMarshaller(actualObject, actualClass, genericType, encoding);
 
             Configuration c = new Configuration(namespaceMap);
             MappedNamespaceConvention convention = new MappedNamespaceConvention(c);
             AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter(
                                                convention, 
-                                               new OutputStreamWriter(os, "UTF-8"));
+                                               new OutputStreamWriter(os, encoding));
             if (serializeAsArray) {
                 if (arrayKeys != null) {
                     for (String key : arrayKeys) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties Tue Apr  7 14:09:36 2009
@@ -19,4 +19,5 @@
 #
 #
 JAXB_EXCEPTION=JAXBException occurred : {0}
+UNSUPPORTED_ENCODING=Unsupported encoding : {0}, defaulting to UTF-8 
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java Tue Apr  7 14:09:36 2009
@@ -45,7 +45,7 @@
 
 import org.w3c.dom.Document;
 
-import org.apache.cxf.jaxrs.utils.XMLSource;
+import org.apache.cxf.jaxrs.ext.xml.XMLSource;
 
 @Provider
 @Produces({"application/xml", "application/*+xml", "text/xml" })

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=762784&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java Tue Apr  7 14:09:36 2009
@@ -0,0 +1,226 @@
+/**
+ * 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.servlet;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
+
+public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
+
+    private static final String SERVICE_ADDRESS_PARAM = "jaxrs.address";
+    private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses";
+    private static final String PROVIDERS_PARAM = "jaxrs.providers";
+    private static final String SERVICE_SCOPE_PARAM = "jaxrs.scope";
+    private static final String SERVICE_SCOPE_SINGLETON = "singleton";
+    private static final String SERVICE_SCOPE_REQUEST = "prototype";
+    
+    private static final String JAXRS_APPLICATION_PARAM = "javax.ws.rs.Application";
+    
+    @Override
+    public void loadBus(ServletConfig servletConfig) throws ServletException {
+        super.loadBus(servletConfig);
+        
+        String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
+        if (applicationClass != null) {
+            createServerFromApplication(applicationClass);
+            return;
+        }
+        
+        String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM);
+        if (address == null) {
+            address = "/";
+        }
+        List<Class> resourceClasses = getServiceClasses(servletConfig);
+        Map<Class, ResourceProvider> resourceProviders = 
+            getResourceProviders(servletConfig, resourceClasses);
+        
+        List<?> providers = getProviders(servletConfig);
+        
+        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
+        bean.setAddress(address);
+        bean.setResourceClasses(resourceClasses);
+        bean.setProviders(providers);
+        for (Map.Entry<Class, ResourceProvider> entry : resourceProviders.entrySet()) {
+            bean.setResourceProvider(entry.getKey(), entry.getValue());
+        }
+        bean.create();
+    }
+
+    protected List<Class> getServiceClasses(ServletConfig servletConfig) throws ServletException {
+        String serviceBeans = servletConfig.getInitParameter(SERVICE_CLASSES_PARAM);
+        if (serviceBeans == null) {
+            throw new ServletException("At least one resource class should be specified");
+        }
+        String[] classNames = serviceBeans.split(" ");
+        List<Class> resourceClasses = new ArrayList<Class>();
+        for (String cName : classNames) {
+            if (cName.length() != 0) {
+                try {
+                    Class<?> cls = CXFNonSpringJaxrsServlet.class.getClassLoader().loadClass(cName.trim());
+                    resourceClasses.add(cls);
+                } catch (ClassNotFoundException ex) {
+                    ex.printStackTrace();
+                    throw new ServletException("Resource class " + cName.trim() + " can not be loaded"); 
+                }
+            }
+        }
+        if (resourceClasses.isEmpty()) {
+            throw new ServletException("At least one resource class should be specified");
+        }
+        return resourceClasses;
+    }
+    
+    protected List<?> getProviders(ServletConfig servletConfig) throws ServletException {
+        String providersList = servletConfig.getInitParameter(PROVIDERS_PARAM);
+        if (providersList == null) {
+            return Collections.EMPTY_LIST;
+        }
+        String[] classNames = providersList.split(" ");
+        List<Object> providers = new ArrayList<Object>();
+        for (String cName : classNames) {
+            if (cName.length() != 0) {
+                Class<?> cls = loadClass(cName);
+                providers.add(createSingletonInstance(cls, servletConfig));
+            }
+        }
+        return providers;
+    }
+    
+    protected Map<Class, ResourceProvider> getResourceProviders(ServletConfig servletConfig,
+        List<Class> resourceClasses) throws ServletException {
+        String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
+        if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope)
+            && !SERVICE_SCOPE_REQUEST.equals(scope)) {
+            throw new ServletException("Only singleton and prototype scopes are supported");
+        }
+        boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope);
+        Map<Class, ResourceProvider> map = new HashMap<Class, ResourceProvider>();
+        for (Class c : resourceClasses) {
+            map.put(c, isPrototype ? new PerRequestResourceProvider(c)
+                                   : new SingletonResourceProvider(
+                                         createSingletonInstance(c, servletConfig)));
+        }
+        return map;
+    }    
+    
+    
+    private Object createSingletonInstance(Class<?> cls, ServletConfig sc) throws ServletException {
+        Constructor c = ResourceUtils.findResourceConstructor(cls);
+        if (c == null) {
+            throw new ServletException("No valid constructor found for " + cls.getName());
+        }
+        boolean isDefault = c.getParameterTypes().length == 0; 
+        if (!isDefault && (c.getParameterTypes().length != 1 
+            || c.getParameterTypes()[0] != ServletConfig.class
+            && c.getParameterTypes()[0] != ServletContext.class)) {
+            throw new ServletException("Resource classes with singleton scope can only have "
+                + "ServletConfig or ServletContext instances injected through their constructors");
+        }
+        Object[] values = isDefault ? new Object[]{} 
+            : new Object[]{c.getParameterTypes()[0] == ServletConfig.class ? sc : sc.getServletContext()}; 
+        try {
+            return c.newInstance(values);
+        } catch (InstantiationException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Resource class " + cls.getName()
+                                       + " can not be instantiated"); 
+        } catch (IllegalAccessException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Resource class " + cls.getName()
+                                       + " can not be instantiated due to IllegalAccessException"); 
+        } catch (InvocationTargetException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Resource class " + cls.getName()
+                                       + " can not be instantiated due to InvocationTargetException"); 
+        }
+    }
+    
+    protected void createServerFromApplication(String cName) throws ServletException {
+        Class<?> appClass = loadClass(cName);
+        Application app = null;
+        try {
+            app = (Application)appClass.newInstance();
+        } catch (InstantiationException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Application class " + cName
+                                       + " can not be instantiated"); 
+        } catch (IllegalAccessException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Application class " + cName
+                                       + " can not be instantiated due to IllegalAccessException"); 
+        }
+        
+        List<Class> resourceClasses = new ArrayList<Class>();
+        List<Object> providers = new ArrayList<Object>();
+        Map<Class, ResourceProvider> map = new HashMap<Class, ResourceProvider>();
+        
+        // at the moment we don't support per-request providers, only resource classes
+        for (Class<?> c : app.getClasses()) {
+            resourceClasses.add(c);
+            map.put(c, new PerRequestResourceProvider(c));
+        }
+        
+        // we can get either a provider or resource class here        
+        for (Object o : app.getSingletons()) {
+            boolean isProvider = o.getClass().getAnnotation(Provider.class) != null;
+            if (isProvider) {
+                providers.add(o);
+            } else {
+                resourceClasses.add(o.getClass());
+                map.put(o.getClass(), new SingletonResourceProvider(o));
+            }
+        }
+        
+        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
+        bean.setAddress("/");
+        bean.setResourceClasses(resourceClasses);
+        bean.setProviders(providers);
+        for (Map.Entry<Class, ResourceProvider> entry : map.entrySet()) {
+            bean.setResourceProvider(entry.getKey(), entry.getValue());
+        }
+        bean.create();
+    }
+    
+    private Class<?> loadClass(String cName) throws ServletException {
+        try {
+            return CXFNonSpringJaxrsServlet.class.getClassLoader().loadClass(cName.trim());
+        } catch (ClassNotFoundException ex) {
+            ex.printStackTrace();
+            throw new ServletException("Resource class " + cName.trim() + " can not be loaded"); 
+        }
+    }
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Apr  7 14:09:36 2009
@@ -61,6 +61,7 @@
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ContextResolver;
@@ -301,8 +302,13 @@
                                                    requestType.toString(),
                                                    convertTypesToString(acceptContentTypes));
         LOG.warning(errorMsg.toString());
-        
-        throw new WebApplicationException(status);
+        ResponseBuilder rb = Response.status(status);
+        if (methodMatched == 0) {
+            for (String m : resource.getAllowedMethods()) {
+                rb.header("Allow", m);
+            }
+        }
+        throw new WebApplicationException(rb.build());
         
     }    
 
@@ -965,19 +971,29 @@
         ExceptionMapper mapper = 
             ProviderFactory.getInstance(inMessage).createExceptionMapper(ex.getClass(), inMessage);
         if (mapper != null) {
-            Response excResponse = mapper.toResponse(ex);
-            if (excResponse != null) {
-                return excResponse;
-            }
-        } else if (ex instanceof WebApplicationException) {
-            WebApplicationException wex = (WebApplicationException)ex;
-            return wex.getResponse();
+            try {
+                return mapper.toResponse(ex);
+            } catch (Exception mapperEx) {
+                mapperEx.printStackTrace();
+                return Response.serverError().build();
+            }
         }
         
         return null;
         
     }
     
-    
+    public static String removeMediaTypeParameter(MediaType mt, String paramName) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(mt.getType()).append('/').append(mt.getSubtype());
+        if (mt.getParameters().size() > 1) {
+            for (String key : mt.getParameters().keySet()) {
+                if (!paramName.equals(key)) {
+                    sb.append(';').append(key).append('=').append(mt.getParameters().get(key));
+                }
+            }
+        }    
+        return sb.toString();
+    }
         
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties Tue Apr  7 14:09:36 2009
@@ -32,4 +32,3 @@
 NO_SUBRESOURCE_METHOD_FOUND=No operation matching request path {0} is found on subresource, ContentType : {1}, Accept : {2}.
 NO_OP_EXC =.No operation matching request path {0} is found, ContentType : {1}, Accept : {2}.
 MULTTIPART_ID_NOT_FOUND=No multipart with content id {0} found, request content type : {1}
-NO_SOURCE_MARK=InputStream used by XMLSource does not support buffering mode
\ No newline at end of file

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=762784&r1=762783&r2=762784&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 Tue Apr  7 14:09:36 2009
@@ -19,11 +19,14 @@
 
 package org.apache.cxf.jaxrs.utils;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -86,6 +89,31 @@
         cri.setMethodDispatcher(md);
     }
     
+    public static Constructor findResourceConstructor(Class<?> resourceClass) {
+        Constructor defaultConstructor = null;
+        for (Constructor c : resourceClass.getConstructors()) {
+            Class<?>[] params = c.getParameterTypes();
+            if (params.length == 0) {
+                defaultConstructor = c;
+                continue;
+            }
+            
+            Annotation[][] anns = c.getParameterAnnotations();
+            boolean match = true;
+            for (int i = 0; i < params.length; i++) {
+                if (AnnotationUtils.getAnnotation(anns[i], Context.class) == null
+                    || !AnnotationUtils.isContextClass(params[i])) {
+                    match = false;
+                    break;
+                }
+            }
+            if (match) {
+                return c;
+            }
+        }
+        return defaultConstructor;
+    }
+    
     private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod, 
                                                       ClassResourceInfo cri, Path path, String httpMethod) {
         OperationResourceInfo ori = new OperationResourceInfo(m, cri);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Apr  7 14:09:36 2009
@@ -91,6 +91,14 @@
     @QueryParam("b")
     private String b;
     private String name;
+
+    public Customer() {
+        
+    }
+    
+    public Customer(@Context UriInfo info) {
+        uriInfo = info;
+    }
     
     public String getName() {
         return name;

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/XMLSourceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/XMLSourceTest.java?rev=762784&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/XMLSourceTest.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/xml/XMLSourceTest.java Tue Apr  7 14:09:36 2009
@@ -0,0 +1,159 @@
+/**
+ * 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.ext.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class XMLSourceTest extends Assert {
+
+    @Test
+    public void testGetNodeNoNamespace() {
+        InputStream is = new ByteArrayInputStream("<foo><bar/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        Bar bar = xp.getNode("/foo/bar", Bar.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace() {
+        String data = "<x:foo xmlns:x=\"http://baz\"><x:bar/></x:foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeBuffering() {
+        String data = "<x:foo xmlns:x=\"http://baz\"><x:bar/></x:foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        xp.setBuffering(true);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+        bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace2() {
+        String data = "<z:foo xmlns:z=\"http://baz\"><z:bar/></z:foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeNamespace3() {
+        String data = "<x:foo xmlns:x=\"http://foo\" xmlns:z=\"http://baz\"><z:bar/></x:foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://foo");
+        map.put("y", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/y:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+    
+    @Test
+    public void testGetNodeDefaultNamespace() {
+        String data = "<foo xmlns=\"http://baz\"><bar/></foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2 bar = xp.getNode("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bar);
+    }
+
+    @Test
+    public void testGetNodesNoNamespace() {
+        InputStream is = new ByteArrayInputStream("<foo><bar/><bar/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        Bar[] bars = xp.getNodes("/foo/bar", Bar.class);
+        assertNotNull(bars);
+        assertEquals(2, bars.length);
+        assertNotSame(bars[0], bars[1]);
+    }
+    
+    @Test
+    public void testGetNodesNamespace() {
+        String data = "<x:foo xmlns:x=\"http://baz\"><x:bar/><x:bar/></x:foo>"; 
+        InputStream is = new ByteArrayInputStream(data.getBytes());
+        XMLSource xp = new XMLSource(is);
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        map.put("x", "http://baz");
+        Bar2[] bars = xp.getNodes("/x:foo/x:bar", map, Bar2.class);
+        assertNotNull(bars);
+        assertNotNull(bars);
+        assertEquals(2, bars.length);
+        assertNotSame(bars[0], bars[1]);
+    }
+    
+    @Test
+    public void testGetStringValue() {
+        InputStream is = new ByteArrayInputStream("<foo><bar/><bar id=\"2\"/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        String value = xp.getValue("/foo/bar/@id");
+        assertEquals("2", value);
+    }
+    
+    @Test
+    public void testGetRelativeLink() {
+        InputStream is = new ByteArrayInputStream("<foo><bar/><bar href=\"/2\"/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        URI value = xp.getLink("/foo/bar/@href");
+        assertEquals("/2", value.toString());
+    }
+    
+    @Test
+    public void testBaseURI() {
+        InputStream is = new ByteArrayInputStream(
+            "<foo xml:base=\"http://bar\"><bar/><bar href=\"/2\"/></foo>".getBytes());
+        XMLSource xp = new XMLSource(is);
+        URI value = xp.getBaseURI();
+        assertEquals("http://bar", value.toString());
+    }
+    
+    @XmlRootElement
+    private static class Bar {
+        
+    }
+    
+    @XmlRootElement(name = "bar", namespace = "http://baz")
+    private static class Bar2 {
+        
+    }
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/NewCookieHeaderProviderTest.java Tue Apr  7 14:09:36 2009
@@ -51,7 +51,7 @@
     @Test
     public void testToString() {
         NewCookie c = new NewCookie("foo", "bar", "path", "domain", "comment", 2, true);
-        assertEquals("foo=bar;Comment=comment;Domain=domain;Max-Age=2;Path=path;Secure;Version=1", 
+        assertEquals("foo=bar;Comment=comment;Domain=domain;Max-Age=2;Path=path;Secure", 
                      c.toString());
                
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java Tue Apr  7 14:09:36 2009
@@ -22,7 +22,10 @@
 import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
 
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -42,6 +45,34 @@
     }
     
     @Test
+    public void testLanguageReplace() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.putSingle("Content-Language", "en");
+        checkBuild(Response.ok().language("de").language((Locale)null)
+                   .language("en").build(), 200, null, m);
+    }
+    
+    @Test
+    public void testAddHeader() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.putSingle("Content-Language", "en");
+        checkBuild(Response.ok().header(HttpHeaders.CONTENT_LANGUAGE, "de")
+                                .header(HttpHeaders.CONTENT_LANGUAGE, null)
+                                .header(HttpHeaders.CONTENT_LANGUAGE, "en").build(), 
+                  200, null, m);
+    }
+    
+    @Test
+    public void testAddCookie() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.add("Set-Cookie", "a=b");
+        m.add("Set-Cookie", "c=d");
+        checkBuild(Response.ok().cookie(new NewCookie("a", "b"))
+                                .cookie(new NewCookie("c", "d")).build(), 
+                  200, null, m);
+    }
+    
+    @Test
     public void testExpires() throws Exception {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         m.putSingle("Expires", "Tue, 21 Oct 2008 17:00:00 GMT");

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProviderTest.java?rev=762784&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProviderTest.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProviderTest.java Tue Apr  7 14:09:36 2009
@@ -0,0 +1,38 @@
+/**
+ * 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.lifecycle;
+
+import org.apache.cxf.jaxrs.Customer;
+import org.apache.cxf.message.MessageImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PerRequestResourceProviderTest extends Assert {
+    
+    @Test
+    public void testGetInstance() {
+        PerRequestResourceProvider rp = new PerRequestResourceProvider(Customer.class);
+        Customer c = (Customer)rp.getInstance(new MessageImpl());
+        assertNotNull(c.getUriInfo());
+    }
+}
+
+
+

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java Tue Apr  7 14:09:36 2009
@@ -30,12 +30,15 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -81,6 +84,11 @@
         public void getIt() { 
             
         }
+        
+        @HEAD
+        public void head() { 
+            
+        }
     }
     
     @Test
@@ -182,4 +190,13 @@
         assertNotSame(c1, c2);
         
     }
+    
+    @Test
+    public void testAllowedMethods() {
+        ClassResourceInfo c = ResourceUtils.createClassResourceInfo(
+                                  TestClass3.class, TestClass3.class, false, false);
+        Set<String> methods = c.getAllowedMethods();
+        assertEquals(2, methods.size());
+        assertTrue(methods.contains("HEAD") && methods.contains("GET"));
+    }
 }

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=762784&r1=762783&r2=762784&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 Tue Apr  7 14:09:36 2009
@@ -47,6 +47,8 @@
 
 import org.xml.sax.ContentHandler;
 
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -99,14 +101,15 @@
         
         JAXBElementProvider provider = new JAXBElementProvider() {
             @Override
-            protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, MediaType mt)
+            protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, String enc)
                 throws JAXBException {
                 return m;    
             }
         };
         
         provider.setMarshallerProperties(props);
-        provider.writeTo("123", String.class, (Type)String.class, new Annotation[]{}, null, null,
+        provider.writeTo("123", String.class, (Type)String.class, new Annotation[]{}, 
+                         MediaType.APPLICATION_XML_TYPE, new MetadataMap<String, Object>(), 
                          new ByteArrayOutputStream());
         
         assertEquals("Marshall properties have not been set", props, m.getProperties());

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/AnnotationTestUtilsTest.java Tue Apr  7 14:09:36 2009
@@ -19,8 +19,13 @@
 
 package org.apache.cxf.jaxrs.utils;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 import java.lang.reflect.Method;
 
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.jaxrs.Customer;
@@ -53,5 +58,22 @@
         assertSame(m, annotatedMethod);
     }
     
+    @Test
+    public void testCustomHttpMethodValue() throws Exception {
+        Method m = ResourceClass.class.getMethod("update", new Class[]{});
+        assertEquals("UPDATE", AnnotationUtils.getHttpMethodValue(m));
+    }
     
+    @Target({ElementType.METHOD })
+    @Retention(RetentionPolicy.RUNTIME)
+    @HttpMethod("UPDATE")
+    public @interface UPDATE { 
+    }
+    
+    public class ResourceClass {
+        @UPDATE
+        public void update() {
+            
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=762784&r1=762783&r2=762784&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Apr  7 14:09:36 2009
@@ -966,7 +966,7 @@
         HttpServletResponse httpResponse = EasyMock.createNiceMock(HttpServletResponse.class);
         m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
         
-        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
         InjectionUtils.injectContextFields(c, cri, m);
         InjectionUtils.injectContextMethods(c, cri, m);
         assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
@@ -1008,7 +1008,7 @@
         m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
         HttpServletResponse httpResponse = EasyMock.createNiceMock(HttpServletResponse.class);
         m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
-        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
         InjectionUtils.injectResourceFields(c, cri, m);
         assertSame(servletContextMock, 
                    ((ThreadLocalProxy)c.getServletContextResource()).get());
@@ -1024,7 +1024,7 @@
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         Customer c = new Customer();
         cri.setResourceProvider(new SingletonResourceProvider(c));
-        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
         
         OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
                                                               cri); 



Mime
View raw message