cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r747806 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apach...
Date Wed, 25 Feb 2009 15:01:07 GMT
Author: sergeyb
Date: Wed Feb 25 15:01:06 2009
New Revision: 747806

URL: http://svn.apache.org/viewvc?rev=747806&view=rev
Log:
JAXRS: improving exception handling on client side and media type comparison

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
  (with props)
Modified:
    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/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore2.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.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/JAXRSSoapBookTest.java

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=747806&r1=747805&r2=747806&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 Feb 25 15:01:06 2009
@@ -20,11 +20,18 @@
 
 import java.util.Collections;
 import java.util.List;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
 
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.BindingConfiguration;
 import org.apache.cxf.binding.BindingFactory;
 import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.AbstractEndpointFactory;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
@@ -49,6 +56,9 @@
  */
 public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory {
     
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractJAXRSFactoryBean.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractJAXRSFactoryBean.class);
+    
     protected List<String> schemaLocations;
     protected JAXRSServiceFactoryBean serviceFactory;
     protected List<?> entityProviders;
@@ -190,4 +200,13 @@
         setProviders(Collections.singletonList(provider));
     }
 
+    protected void checkResources() {
+        if (!serviceFactory.resourcesAvailable()) {
+            org.apache.cxf.common.i18n.Message msg = 
+                new org.apache.cxf.common.i18n.Message("NO_RESOURCES_AVAILABLE", 
+                                                       BUNDLE);
+            LOG.severe(msg.toString());
+            throw new WebApplicationException(Response.Status.NOT_FOUND);
+        }
+    }
 }

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=747806&r1=747805&r2=747806&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
Wed Feb 25 15:01:06 2009
@@ -23,12 +23,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.ResourceBundle;
-import java.util.logging.Logger;
 
 import org.apache.cxf.BusException;
-import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.Server;
@@ -57,9 +53,6 @@
  */
 public class JAXRSServerFactoryBean extends AbstractJAXRSFactoryBean {
     
-    private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServerFactoryBean.class);
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSServerFactoryBean.class);
-    
     protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class,
ResourceProvider>();
     
     private Server server;
@@ -83,13 +76,7 @@
     
     public Server create() {
         try {
-            if (!serviceFactory.resourcesAvailable()) {
-                org.apache.cxf.common.i18n.Message msg = 
-                    new org.apache.cxf.common.i18n.Message("NO_RESOURCES_AVAILABLE", 
-                                                           BUNDLE);
-                LOG.severe(msg.toString());
-                throw new EndpointException(msg);
-            }
+            checkResources();
             if (serviceFactory.getService() == null) {
                 serviceFactory.create();
                 updateClassResourceProviders();
@@ -127,6 +114,8 @@
             throw new ServiceConstructionException(e);
         } catch (IOException e) {
             throw new ServiceConstructionException(e);
+        } catch (Exception e) {
+            throw new ServiceConstructionException(e);
         }
 
         applyFeatures();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/Messages.properties Wed
Feb 25 15:01:06 2009
@@ -18,7 +18,7 @@
 #    under the License.
 #
 #
-NO_RESOURCES_AVAILABLE=No resource classes found, endpoint can not be created
+NO_RESOURCES_AVAILABLE=No resource classes found
 NO_SUBRESOURCE_FOUND=No subresource locator found for path {0}
 NULL_SUBRESOURCE=Null subresource locator is returned for path {0}
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Wed Feb 25 15:01:06 2009
@@ -31,6 +31,8 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Cookie;
@@ -46,6 +48,8 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
 import org.apache.cxf.endpoint.ConduitSelector;
 import org.apache.cxf.endpoint.Endpoint;
@@ -70,6 +74,9 @@
  */
 public class AbstractClient implements Client {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);
+    
     protected List<Interceptor> inInterceptors = new ModCountCopyOnWriteArrayList<Interceptor>();
     protected List<Interceptor> outInterceptors = new ModCountCopyOnWriteArrayList<Interceptor>();
     protected ConduitSelector conduitSelector;
@@ -347,7 +354,7 @@
             }
              
         } else {
-            throw new WebApplicationException();
+            reportNoMessageHandler("NO_MSG_WRITER", cls);
         }
                                                                                  
     }
@@ -381,9 +388,18 @@
             }
              
         } else {
-            throw new WebApplicationException();
+            reportNoMessageHandler("NO_MSG_READER", cls);
         }
-                                                                                 
+        return null;                                                
+    }
+    
+    protected static void reportNoMessageHandler(String name, Class<?> cls) {
+        org.apache.cxf.common.i18n.Message errorMsg = 
+            new org.apache.cxf.common.i18n.Message(name, 
+                                                   BUNDLE,
+                                                   cls);
+        LOG.severe(errorMsg.toString());
+        throw new WebApplicationException(415);
     }
     
     private static MediaType getResponseContentType(Response r) {
@@ -457,14 +473,16 @@
     
     protected Message createMessage(String httpMethod, 
                                     MultivaluedMap<String, String> headers,
-                                    String address) {
+                                    URI currentURI) {
         Message m = conduitSelector.getEndpoint().getBinding().createMessage();
         m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
         m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
         
         m.put(Message.HTTP_REQUEST_METHOD, httpMethod);
         m.put(Message.PROTOCOL_HEADERS, headers);
-        m.put(Message.ENDPOINT_ADDRESS, address);
+        m.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
+        m.put(Message.REQUEST_URI, currentURI.toString());
+        
         m.put(Message.CONTENT_TYPE, headers.getFirst(HttpHeaders.CONTENT_TYPE));
         
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Feb 25 15:01:06 2009
@@ -27,6 +27,8 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
 
 import javax.ws.rs.CookieParam;
 import javax.ws.rs.FormParam;
@@ -42,6 +44,8 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -63,6 +67,9 @@
  */
 public class ClientProxyImpl extends AbstractClient implements InvocationHandler {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(ClientProxyImpl.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ClientProxyImpl.class);
+    
     private ClassResourceInfo cri;
     private boolean inheritHeaders;
     
@@ -89,15 +96,14 @@
         
         OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
         if (ori == null) {
-            throw new WebApplicationException(400);
+            reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
         }
         
-        
         MultivaluedMap<ParameterType, Parameter> types = 
             getParametersInfo(ori, m, params);
         List<Object> pathParams = getParamValues(types, params, ParameterType.PATH);
         
-        int bodyIndex = getBodyIndex(types, ori.isSubResourceLocator());
+        int bodyIndex = getBodyIndex(types, ori);
         
         UriBuilder builder = getCurrentBuilder().clone(); 
         if (cri.isRoot()) {
@@ -117,7 +123,7 @@
         if (ori.isSubResourceLocator()) {
             ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
             if (subCri == null) {
-                throw new WebApplicationException();
+                reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE");
             }
             ClientProxyImpl proxyImpl = new ClientProxyImpl(getBaseURI(), uri, subCri, inheritHeaders);
             proxyImpl.setBus(bus);
@@ -157,20 +163,21 @@
         }
         if (map.containsKey(ParameterType.REQUEST_BODY)) {
             if (map.get(ParameterType.REQUEST_BODY).size() > 1) {
-                throw new WebApplicationException();
+                reportInvalidResourceMethod(m, "SINGLE_BODY_ONLY");
             }
             if (map.containsKey(ParameterType.FORM)) {
-                throw new WebApplicationException();
+                reportInvalidResourceMethod(m, "ONLY_FORM_ALLOWED");
             }
         }
         return map;
     }
     
-    private static int getBodyIndex(MultivaluedMap<ParameterType, Parameter> map, boolean
subresource) {
+    private static int getBodyIndex(MultivaluedMap<ParameterType, Parameter> map, 
+                                    OperationResourceInfo ori) {
         List<Parameter> list = map.get(ParameterType.REQUEST_BODY);
         int index  = list == null ? -1 : list.get(0).getIndex(); 
-        if (subresource && index != -1) {
-            throw new WebApplicationException();
+        if (ori.isSubResourceLocator() && index != -1) {
+            reportInvalidResourceMethod(ori.getMethodToInvoke(), "NO_BODY_IN_SUBRESOURCE");
         }
         return index;
     }
@@ -318,7 +325,7 @@
         
         Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
         if (ctx != null) {
-            throw new WebApplicationException();
+            reportInvalidResourceMethod(ori.getMethodToInvoke(), "NO_CONTEXT_PARAMETERS");
         }
         
         boolean isEncoded = AnnotationUtils.isEncoded(anns, ori);
@@ -389,7 +396,7 @@
     private Object doChainedInvocation(URI uri, MultivaluedMap<String, String> headers,

                           OperationResourceInfo ori, Object[] params, int bodyIndex, 
                           MultivaluedMap<ParameterType, Parameter> types) throws Throwable
{
-        Message m = createMessage(ori.getHttpMethod(), headers, uri.toString());
+        Message m = createMessage(ori.getHttpMethod(), headers, uri);
 
         if (bodyIndex != -1 || types.containsKey(ParameterType.FORM)) {
             m.setContent(OperationResourceInfo.class, ori);
@@ -425,6 +432,16 @@
         return readBody(r, connect, inMessage, method.getReturnType(), 
                         method.getGenericReturnType(), method.getDeclaredAnnotations());
     }
+
+    protected static void reportInvalidResourceMethod(Method m, String name) {
+        org.apache.cxf.common.i18n.Message errorMsg = 
+            new org.apache.cxf.common.i18n.Message(name, 
+                                                   BUNDLE,
+                                                   m.getDeclaringClass().getName(), 
+                                                   m.getName());
+        LOG.severe(errorMsg.toString());
+        throw new WebApplicationException(405);
+    }
     
     private static class Parameter {
         private ParameterType type;
@@ -500,4 +517,5 @@
         }
         
     }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Wed Feb 25 15:01:06 2009
@@ -19,7 +19,6 @@
 package org.apache.cxf.jaxrs.client;
 
 import java.net.URI;
-import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.WebApplicationException;
@@ -97,15 +96,12 @@
     }
     
     public Client create() {
-        List<ClassResourceInfo> list = serviceFactory.getClassResourceInfo();
-        if (list.isEmpty()) {
-            throw new WebApplicationException();
-        }
+        checkResources();
         
         try {
             Endpoint ep = createEndpoint();
             URI baseURI = URI.create(getAddress());
-            ClassResourceInfo cri = list.get(0);
+            ClassResourceInfo cri = serviceFactory.getClassResourceInfo().get(0);
             
             ClientProxyImpl proxyImpl = new ClientProxyImpl(baseURI, baseURI, cri, inheritHeaders);
             initClient(proxyImpl, ep);    

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties?rev=747806&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
Wed Feb 25 15:01:06 2009
@@ -0,0 +1,28 @@
+#
+#
+#    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.
+#
+#
+INVALID_RESOURCE_METHOD=Method {0}.{1} is not a valid resource method
+INVALID_SUBRESOURCE=Method {0}.{1} is not a subresource locator or no annotations is available
+SINGLE_BODY_ONLY=Resource method {0}.{1} has more than one parameter representing a request
body
+ONLY_FORM_ALLOWED=Resource method {0}.{1} mixes JAXRS FormParam parameters with other types
of parameters
+NO_BODY_IN_SUBRESOURCE=SubResource method {0}.{1} expects request body, only URI-bound parameters
are supported
+NO_CONTEXT_PARAMETERS=Resource method {0}.{1} expects JAXRS Context parameter which is not
supported on the client side
+NO_MSG_READER =.No message body reader found for class : {0}, ContentType : {1}.
+NO_MSG_WRITER =.No message body writer found for class : {0}.

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

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Wed
Feb 25 15:01:06 2009
@@ -406,7 +406,7 @@
     protected Response doChainedInvocation(String httpMethod, 
         MultivaluedMap<String, String> headers, Object body, Class<?> responseClass)
{
 
-        Message m = createMessage(httpMethod, headers, getCurrentURI().toString());
+        Message m = createMessage(httpMethod, headers, getCurrentURI());
         
         if (body != null) {
             MessageContentsList contents = new MessageContentsList(body);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Wed Feb 25 15:01:06 2009
@@ -49,11 +49,19 @@
     }
     
     public List<MediaType> getAcceptableMediaTypes() {
-        return JAXRSUtils.sortMediaTypes((String)m.get(Message.ACCEPT_CONTENT_TYPE)); 
+        String lValues = headers.getFirst(HttpHeaders.ACCEPT);
+        if (lValues == null) {
+            return Collections.emptyList();
+        }
+        return JAXRSUtils.sortMediaTypes(lValues); 
     }
 
     public Map<String, Cookie> getCookies() {
-        List<String> cs = headers.get(HttpHeaders.COOKIE);
+        List<String> values = headers.get(HttpHeaders.COOKIE);
+        if (values == null || values.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        String[] cs =  values.get(0).split(",");
         Map<String, Cookie> cl = new HashMap<String, Cookie>(); 
         for (String c : cs) {
             Cookie cookie = Cookie.valueOf(c);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Wed
Feb 25 15:01:06 2009
@@ -90,10 +90,14 @@
     public static String getEndpointAddress(Message m) {
         String address = null;
         Destination d = m.getExchange().getDestination();
-        if (d instanceof ServletDestination) {
-            address = ((ServletDestination)d).getEndpointInfo().getAddress();
+        if (d != null) {
+            if (d instanceof ServletDestination) {
+                address = ((ServletDestination)d).getEndpointInfo().getAddress();
+            } else {
+                address = d.getAddress().getAddress().getValue();
+            }
         } else {
-            address = d.getAddress().getAddress().getValue();
+            address = (String)m.get(Message.ENDPOINT_ADDRESS);
         }
         
         return address;

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=747806&r1=747805&r2=747806&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 Wed
Feb 25 15:01:06 2009
@@ -330,14 +330,6 @@
     
     public static int compareMediaTypes(MediaType mt1, MediaType mt2) {
         
-        if (mt1.getType().equals(mt2.getType())
-            && mt1.getSubtype().equals(mt2.getSubtype())) {
-            float q1 = getMediaTypeQualityFactor(mt1.getParameters().get("q"));
-            float q2 = getMediaTypeQualityFactor(mt2.getParameters().get("q"));
-            int result = Float.compare(q1, q2);
-            return result == 0 ? result : result * -1;
-        }
-        
         if (mt1.isWildcardType() && !mt2.isWildcardType()) {
             return 1;
         }
@@ -353,7 +345,15 @@
                 return -1;
             }       
         }
-        return mt1.toString().compareTo(mt2.toString());
+        
+        float q1 = getMediaTypeQualityFactor(mt1.getParameters().get("q"));
+        float q2 = getMediaTypeQualityFactor(mt2.getParameters().get("q"));
+        int result = Float.compare(q1, q2);
+        if (result != 0) {
+            return result * -1;
+        }
+        
+        return 0;
         
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Wed Feb 25 15:01:06 2009
@@ -29,6 +29,7 @@
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -64,7 +65,7 @@
                                         "GET", values, contentTypes, 
                                         Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
         assertNotNull(ori);
-        assertEquals("listMethod needs to be selected", "unlimitedPath", 
+        assertEquals("listMethod needs to be selected", "readMethod", 
                      ori.getMethodToInvoke().getName());
         
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/HttpHeadersImplTest.java
Wed Feb 25 15:01:06 2009
@@ -23,13 +23,17 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
+import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -116,6 +120,20 @@
     }
     
     @Test
+    public void testGetCookies() throws Exception {
+        
+        Message m = new MessageImpl();
+        MetadataMap<String, String> headers = createHeaders();
+        headers.putSingle(HttpHeaders.COOKIE, "a=b,c=d");
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        HttpHeaders h = new HttpHeadersImpl(m);
+        Map<String, Cookie> cookies = h.getCookies();
+        assertEquals(2, cookies.size());
+        assertEquals("b", cookies.get("a").getValue());
+        assertEquals("d", cookies.get("c").getValue());
+    }
+    
+    @Test
     public void testMultipleAcceptableLanguages() throws Exception {
         
         Message m = control.createMock(Message.class);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Wed Feb 25 15:01:06 2009
@@ -71,6 +71,9 @@
     @Test
     public void testMultipleFactories() {
         assertSame(ProviderFactory.getInstance(), ProviderFactory.getInstance());
+        assertSame(ProviderFactory.getInstance("/"), ProviderFactory.getInstance("/"));
+        assertSame(ProviderFactory.getInstance(), ProviderFactory.getInstance("/"));
+        assertNotSame(ProviderFactory.getInstance(), ProviderFactory.getSharedInstance());
         assertSame(ProviderFactory.getInstance("/bar"), ProviderFactory.getInstance("/bar"));
         assertNotSame(ProviderFactory.getInstance("/bar"), ProviderFactory.getInstance("/"));
     }
@@ -150,10 +153,11 @@
     public void testSortEntityProvidersWithConfig() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         JSONProvider json1 = new JSONProvider();
+        json1.setConsumeMediaTypes(Collections.singletonList("application/json;q=0.9"));
         pf.registerUserProvider(json1);
         JSONProvider json2 = new JSONProvider();
-        json2.setConsumeMediaTypes(Collections.singletonList("application/abc"));
-        json2.setProduceMediaTypes(Collections.singletonList("application/sbc"));
+        json2.setConsumeMediaTypes(Collections.singletonList("application/json"));
+        json2.setProduceMediaTypes(Collections.singletonList("application/sbc;q=0.9"));
         pf.registerUserProvider(json2);
         
         List<ProviderInfo<MessageBodyReader>> readers = pf.getMessageReaders();

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=747806&r1=747805&r2=747806&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
Wed Feb 25 15:01:06 2009
@@ -405,9 +405,9 @@
         List<MediaType> types = 
             JAXRSUtils.sortMediaTypes("text/*,text/plain;q=.2,text/xml,TEXT/BAR");
         assertTrue(types.size() == 4
-                   && "text/bar".equals(types.get(0).toString())
-                   && "text/plain;q=.2".equals(types.get(1).toString())
-                   && "text/xml".equals(types.get(2).toString())
+                   && "text/xml".equals(types.get(0).toString())
+                   && "text/bar".equals(types.get(1).toString())
+                   && "text/plain;q=.2".equals(types.get(2).toString())
                    && "text/*".equals(types.get(3).toString()));
     }
     
@@ -424,10 +424,10 @@
         assertTrue("text/* should be equal to itself", 
                    JAXRSUtils.compareMediaTypes(m2, new MediaType("text", "*")) == 0);
         
-        assertTrue("text/plain is alphabetically earlier than text/xml", 
-                   JAXRSUtils.compareMediaTypes(MediaType.valueOf("text/plain"), m1) <
0);
-        assertTrue("text/xml is alphabetically later than text/plain", 
-                   JAXRSUtils.compareMediaTypes(m1, MediaType.valueOf("text/plain")) >
0);
+        assertTrue("text/plain and text/xml are just two specific media types", 
+                   JAXRSUtils.compareMediaTypes(MediaType.valueOf("text/plain"), m1) == 0);
+        assertTrue("text/xml and text/plain are just two specific media types", 
+                   JAXRSUtils.compareMediaTypes(m1, MediaType.valueOf("text/plain")) == 0);
         assertTrue("*/* is less specific than text/xml", 
                    JAXRSUtils.compareMediaTypes(JAXRSUtils.ALL_TYPES, m1) > 0);
         assertTrue("*/* is less specific than text/xml", 

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java Wed Feb
25 15:01:06 2009
@@ -77,7 +77,7 @@
     
     @GET
     @Path("/books/feed")
-    @Produces({"application/json", "application/atom+xml" })
+    @Produces({"application/atom+xml", "application/json" })
     public Feed getBooksAsFeed(@Context UriInfo uParam) {
         
         MediaType mt = headers.getMediaType();

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore2.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore2.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore2.java Wed
Feb 25 15:01:06 2009
@@ -34,7 +34,7 @@
     
     @GET
     @Path("/")
-    @Produces({"application/json", "application/atom+xml" })
+    @Produces({"application/atom+xml", "application/json" })
     public Feed getBooksAsFeed(@Context UriInfo uParam) {
         
         return super.getBooksAsFeed(uParam);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Wed Feb 25
15:01:06 2009
@@ -25,6 +25,7 @@
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.ws.rs.Consumes;
@@ -40,6 +41,9 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
@@ -62,7 +66,9 @@
     private String currentBookId;
     @PathParam("CDId")
     private String currentCdId;
-
+    @Context
+    private HttpHeaders httpHeaders;
+    
     public BookStore() {
         init();
     }
@@ -148,6 +154,18 @@
     @GET
     @Path("/bookheaders/")
     public Book getBookByHeader(@HeaderParam("BOOK") List<String> ids) throws Exception
{
+        List<MediaType> types = httpHeaders.getAcceptableMediaTypes();
+        if (types.size() != 2 
+            || !"text/xml".equals(types.get(0).toString())
+            || !MediaType.APPLICATION_XML_TYPE.isCompatible(types.get(1))) {
+            throw new WebApplicationException();
+        }
+        List<Locale> locales = httpHeaders.getAcceptableLanguages();
+        if (locales.size() != 2 
+            || !"en".equals(locales.get(0).getLanguage())
+            || !"da".equals(locales.get(1).getLanguage())) {
+            throw new WebApplicationException();
+        }
         
         return doGetBook(ids.get(0) + ids.get(1) + ids.get(2));
     }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Feb 25 15:01:06 2009
@@ -237,7 +237,7 @@
         
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
                                "resources/expected_get_book123json.txt",
-                               "application/xml,application/json", 200);
+                               "application/json, application/xml", 200);
     }
     
     @Test
@@ -273,7 +273,7 @@
     public void testGetBookByHeader() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders",
                                "resources/expected_get_book123.txt",
-                               "application/xml", 200);
+                               "application/xml;q=0.5,text/xml", 200);
     }
     
     @Test
@@ -298,7 +298,7 @@
         
         getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
                                "resources/expected_get_book123json.txt",
-                               "application/xml,application/json", 200);
+                               "application/xml;q=0.1,application/json", 200);
     }
     
     @Test
@@ -754,7 +754,7 @@
                                int expectedStatus) throws Exception {
         GetMethod get = new GetMethod(address);
         get.setRequestHeader("Accept", acceptType);
-        get.setRequestHeader("Accept-Language", "en,da;q=0.8");
+        get.setRequestHeader("Accept-Language", "da;q=0.8,en");
         get.setRequestHeader("BOOK", "1,2,3");
         HttpClient httpClient = new HttpClient();
         try {

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=747806&r1=747805&r2=747806&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Wed
Feb 25 15:01:06 2009
@@ -57,7 +57,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class, true));
+                   launchServer(BookServerRestSoap.class));
     }
     
     @Test



Mime
View raw message