cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r641894 - in /incubator/cxf/trunk: rt/frontend/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/fro...
Date Thu, 27 Mar 2008 17:00:09 GMT
Author: dkulp
Date: Thu Mar 27 09:59:48 2008
New Revision: 641894

URL: http://svn.apache.org/viewvc?rev=641894&view=rev
Log:
[CXF-1012] Exception handling for jaxrs (patch from Sergey applied, with modifications to get tests running)

Added:
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/Messages.properties   (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxrs/pom.xml
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/MetadataMap.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AcceptTypeQueryHandler.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriInfoImpl.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Chapter.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/pom.xml?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/pom.xml (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/pom.xml Thu Mar 27 09:59:48 2008
@@ -74,10 +74,12 @@
         <dependency>
             <groupId>org.apache.abdera</groupId>
             <artifactId>abdera-core</artifactId>
+            <version>0.3.0-incubating</version>
         </dependency>
         <dependency>
             <groupId>org.apache.abdera</groupId>
             <artifactId>abdera-parser</artifactId>
+            <version>0.3.0-incubating</version>  
         </dependency>
         <dependency>
             <groupId>org.apache.abdera</groupId>

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Thu Mar 27 09:59:48 2008
@@ -24,12 +24,16 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
@@ -51,8 +55,11 @@
         ClassResourceInfo cri = ori.getClassResourceInfo();
         Method m = cri.getMethodDispatcher().getMethod(ori);
         Object resourceObject = getServiceObject(exchange);
+        
         if (cri.isRoot()) {
-            JAXRSUtils.injectHttpContextValues(resourceObject, ori, exchange.getInMessage());
+            JAXRSUtils.injectHttpContextValues(resourceObject, 
+                                               ori, 
+                                               exchange.getInMessage());
         }
 
         List<Object> params = null;
@@ -62,7 +69,21 @@
             params = new MessageContentsList(request);
         }
 
-        Object result = invoke(exchange, resourceObject, m, params);
+        Object result = null;
+        try {
+            result = invoke(exchange, resourceObject, m, params);
+        } catch (Fault ex) {
+            if (ex.getCause() instanceof WebApplicationException) {
+                WebApplicationException wex = (WebApplicationException)ex.getCause();
+                if (wex.getResponse() != null) {
+                    result = wex.getResponse();
+                } else {
+                    result = Response.serverError().build();
+                }
+                return new MessageContentsList(result);
+            }
+            throw ex;
+        }
         
         if (ori.isSubResourceLocator()) {
             //the result becomes the object that will handle the request
@@ -77,9 +98,9 @@
             }
             resourceObjects = new ArrayList<Object>();
             resourceObjects.add(result);
-            
-            MultivaluedMap<String, String> values = new MetadataMap<String, String>();                 
+        
             Message msg = exchange.getInMessage();
+            MultivaluedMap<String, String> values = new MetadataMap<String, String>();                 
             String subResourcePath = (String)msg.get(JAXRSInInterceptor.RELATIVE_PATH);
             String httpMethod = (String)msg.get(Message.HTTP_REQUEST_METHOD); 
             String contentType = (String)msg.get(Message.CONTENT_TYPE);
@@ -98,7 +119,8 @@
                                                                        contentType, 
                                                                        acceptContentType);
             exchange.put(OperationResourceInfo.class, subOri);
-            msg.put(JAXRSInInterceptor.RELATIVE_PATH, subResourcePath);
+            msg.put(JAXRSInInterceptor.RELATIVE_PATH, values.getFirst(URITemplate.FINAL_MATCH_GROUP));
+            msg.put(URITemplate.TEMPLATE_PARAMETERS, values);
             // work out request parameters for the sub-resouce class. Here we
             // presume Inputstream has not been consumed yet by the root resource class.
             //I.e., only one place either in the root resource or sub-resouce class can

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSUtils.java Thu Mar 27 09:59:48 2008
@@ -128,7 +128,7 @@
             URITemplate uriTemplate = resource.getURITemplate();
             MultivaluedMap<String, String> map = new MetadataMap<String, String>();
             if (uriTemplate.match(path, map)) {
-                String subResourcePath = map.getFirst(URITemplate.RIGHT_HAND_VALUE);
+                String subResourcePath = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
                 OperationResourceInfo ori = findTargetMethod(resource, subResourcePath, httpMethod, map,
                                                              requestContentType, acceptContentTypes);
                 if (ori != null) {
@@ -157,14 +157,13 @@
             for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
                 
                 URITemplate uriTemplate = ori.getURITemplate();
-                MultivaluedMap<String, String> map = new MetadataMap<String, String>();
-                map.putAll(values);
+                MultivaluedMap<String, String> map = cloneMap(values);
                 if (uriTemplate != null && uriTemplate.match(path, map)) {
                     if (ori.isSubResourceLocator() && matchMimeTypes(requestType, acceptType, ori)) {
                         candidateList.put(ori, map);
                     } else if (ori.getHttpMethod().equalsIgnoreCase(httpMethod)
                                && matchMimeTypes(requestType, acceptType, ori)) {
-                        String finalGroup = map.getFirst(URITemplate.RIGHT_HAND_VALUE);
+                        String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP);
                         if (finalGroup == null || StringUtils.isEmpty(finalGroup)
                             || finalGroup.equals("/")) {
                             candidateList.put(ori, map);    
@@ -312,7 +311,7 @@
                                          ori.getConsumeTypes());
         } else if (parameterAnnotations[0].annotationType() == Context.class
                    && ori.getClassResourceInfo().isRoot()) {
-            return createHttpContextValue(message, parameterClass, ori);
+            return createHttpContextValue(message, parameterClass);
         } else if (parameterAnnotations[0].annotationType() == PathParam.class) {
             return readFromUriParam((PathParam)parameterAnnotations[0], parameterClass, parameterType,
                                       parameterAnnotations, path, values);
@@ -339,7 +338,10 @@
         if (segments.size() > 0) {
             MultivaluedMap<String, String> params = 
                 segments.get(segments.size() - 1).getMatrixParameters();
-            value = params.getFirst(key);
+            List<String> values = params.get(key);
+            if (values != null && values.size() > 0) {
+                value = values.get(0);
+            }
         }
         
         return value == null ? defaultValue : value;
@@ -367,11 +369,13 @@
         return sb.length() > 0 ? sb.toString() : defaultValue;
     }
     
-    public static Object createHttpContextValue(Message m, 
-                                                 Class<?> clazz,
-                                                 OperationResourceInfo ori) {
+    @SuppressWarnings("unchecked")
+    public static Object createHttpContextValue(Message m, Class<?> clazz) {
+                
         if (UriInfo.class.isAssignableFrom(clazz)) {
-            return new UriInfoImpl(m, ori.getURITemplate());
+            MultivaluedMap<String, String> templateParams =
+                (MultivaluedMap<String, String>)m.get(URITemplate.TEMPLATE_PARAMETERS);
+            return new UriInfoImpl(m, templateParams);
         }
         if (HttpHeaders.class.isAssignableFrom(clazz)) {
             return new HttpHeadersImpl(m);
@@ -398,9 +402,12 @@
             return null;
         }
 
-        Object result = values.getFirst(parameterName);
-
-        if (parameter.isPrimitive()) {
+        Object result = null;
+        List<String> results = values.get(parameterName);
+        if (values != null && values.size() > 0) {
+            result = results.get(results.size() - 1);
+        }
+        if (result != null && parameter.isPrimitive()) {
             result = PrimitiveUtils.read((String)result, parameter);
         }
         return result;
@@ -463,13 +470,20 @@
         for (MediaType type : types) { 
             provider = ProviderFactory.getInstance()
                 .createMessageBodyReader(targetTypeClass, type);
+            // TODO : make the exceptions
             if (provider != null) {
                 try {
                     return provider.readFrom(targetTypeClass, contentType, null, is);
                 } catch (IOException e) {
                     e.printStackTrace();
-                    return null;
+                    throw new RuntimeException("Error deserializing input stream into target class "
+                                               + targetTypeClass.getSimpleName() 
+                                               + ", content type : " + contentType);
                 }    
+            } else {
+                throw new RuntimeException("No message body reader found for target class "
+                                           + targetTypeClass.getSimpleName() 
+                                           + ", content type : " + contentType);
             }
         }
 
@@ -566,11 +580,11 @@
     }
     
     public static void injectHttpContextValues(Object o,
-                                         OperationResourceInfo ori,
-                                         Message m) {
+                                               OperationResourceInfo ori,
+                                               Message m) {
         
         for (Field f : ori.getClassResourceInfo().getHttpContexts()) {
-            Object value = createHttpContextValue(m, f.getType(), ori);
+            Object value = createHttpContextValue(m, f.getType());
             f.setAccessible(true);
             try {
                 f.set(o, value);
@@ -578,5 +592,15 @@
                 // ignore
             }
         }
+    }
+    
+    private static <K, V> MultivaluedMap<K, V> cloneMap(MultivaluedMap<K, V> map1) {
+        
+        MultivaluedMap<K, V> map2 = new MetadataMap<K, V>();
+        for (Map.Entry<K, List<V>> entry : map1.entrySet()) {
+            map2.put(entry.getKey(), new ArrayList<V>(entry.getValue()));
+        }
+        return map2;
+        
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/MetadataMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/MetadataMap.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/MetadataMap.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/MetadataMap.java Thu Mar 27 09:59:48 2008
@@ -117,4 +117,8 @@
     public boolean equals(Object o) {
         return m.equals(o);
     }
+    
+    public String toString() {
+        return m.toString();
+    }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java Thu Mar 27 09:59:48 2008
@@ -20,11 +20,14 @@
 package org.apache.cxf.jaxrs.interceptor;
 
 import java.util.List;
+import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import javax.ws.rs.core.MultivaluedMap;
 
+import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.JAXRSUtils;
 import org.apache.cxf.jaxrs.MetadataMap;
@@ -43,7 +46,7 @@
     public static final String RELATIVE_PATH = "relative.path";
 
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSInInterceptor.class);
-    //private static final ResourceBundle BUNDLE = BundleUtils.getBundle(RESTDispatchInterceptor.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInInterceptor.class);
 
     public JAXRSInInterceptor() {
         super(Phase.PRE_STREAM);
@@ -75,17 +78,16 @@
         if (!path.endsWith("/")) {
             path = path + "/";
         }
-        message.put(RELATIVE_PATH, path);
         
-        
-        //TODO : make sure we do this parsing ony once, not expensove though
+        //TODO : make sure we do this parsing only once
         MultivaluedMap<String, String> queries = 
             JAXRSUtils.getStructuredParams((String)message.get(Message.QUERY_STRING), 
                                             "&", true);
         SystemQueryHandler sqh = ProviderFactory.getInstance().getQueryHandler(queries);
         if (sqh != null) {
             // TODO : if Response != null then make sure no invocations happen
-            sqh.handleSystemQuery(message, queries);
+            // TODO : root resource class needs be selected earlier
+            sqh.handleQuery(message, null, queries);
         }
         
         String acceptContentTypes = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
@@ -112,14 +114,20 @@
                                                                        acceptContentTypes);
 
         if (ori == null) {
-            LOG.severe("No operation found for path: " + path + ", contentType: " 
-                       + requestContentType + ", Accept contentType: " + acceptContentTypes);
-            //throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OP", BUNDLE, method, path));
+            String errorMessage = "No operation found for path: " + path + ", contentType: " 
+                + requestContentType + ", Accept contentType: " + acceptContentTypes;
+            LOG.severe(errorMessage);
+            throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OP_EXC", 
+                                                                   BUNDLE, 
+                                                                   path,
+                                                                   requestContentType,
+                                                                   acceptContentTypes));
         }
         LOG.info("Found operation: " + ori.getMethod().getName());
         
         message.getExchange().put(OperationResourceInfo.class, ori);
-        message.put(RELATIVE_PATH, values.getFirst(URITemplate.RIGHT_HAND_VALUE));
+        message.put(RELATIVE_PATH, values.getFirst(URITemplate.FINAL_MATCH_GROUP));
+        message.put(URITemplate.TEMPLATE_PARAMETERS, values);
       
         //2. Process parameters
         List<Object> params = JAXRSUtils

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Thu Mar 27 09:59:48 2008
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
+import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import javax.ws.rs.ProduceMime;
@@ -29,6 +30,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.jaxrs.JAXRSUtils;
@@ -41,6 +43,7 @@
 
 public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSOutInterceptor.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSOutInterceptor.class);
 
     public JAXRSOutInterceptor() {
         super(Phase.MARSHAL);
@@ -91,6 +94,14 @@
                 }
             }
             
+            if (writer == null) {
+                message.put(Message.RESPONSE_CODE, 406);
+                writeResponseErrorMessage(out, 
+                                          "NO_MSG_WRITER",
+                                          responseObj.getClass().getSimpleName());
+                return;
+            }
+            
             try {
                 LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
                 MediaType mt = computeFinalContentTypes(availableContentTypes, writer);
@@ -99,10 +110,26 @@
                 writer.writeTo(responseObj, mt, null, out);
             } catch (IOException e) {
                 e.printStackTrace();
+                message.put(Message.RESPONSE_CODE, 500);
+                writeResponseErrorMessage(out, "SERIALIZE_ERROR", 
+                                          responseObj.getClass().getSimpleName());
             }        
             
         }
 
+    }
+    
+    private void writeResponseErrorMessage(OutputStream out, String errorString, 
+                                           String parameter) {
+        try {
+            // TODO : make sure this message is picked up from a resource bundle
+            out.write(new org.apache.cxf.common.i18n.Message(errorString,
+                                                             BUNDLE,
+                                                             parameter
+                                                             ).toString().getBytes("UTF-8"));
+        } catch (IOException another) {
+            // ignore
+        }
     }
     
     private List<MediaType> computeAvailableContentTypes(Message message) {

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/Messages.properties?rev=641894&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/Messages.properties (added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/Messages.properties Thu Mar 27 09:59:48 2008
@@ -0,0 +1,25 @@
+#
+#
+#    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_OP_EXC =.No operation matching request path {0} is found, ContentType : {1}, Accept : {2}.
+SERIALIZE_ERROR =.Error serializing the response, please check the server logs, response class : {0}.
+NO_MSG_WRITER =.No message body writer found for response class : {0}.
+NO_MSG_READER =.No message body reader found for request class : {0}.
+

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

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

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

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java Thu Mar 27 09:59:48 2008
@@ -30,9 +30,12 @@
 import javax.ws.rs.core.MultivaluedMap;
 
 public final class URITemplate {
+    
+    public static final String TEMPLATE_PARAMETERS = "jaxrs.template.parameters";
+    
     public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
     public static final String UNLIMITED_REGEX_SUFFIX = "(/)?";
-    public static final String RIGHT_HAND_VALUE = "RIGHT_HAND_VALUE";
+    public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
     
     /**
      * The regular expression for matching URI templates and names.
@@ -125,17 +128,13 @@
         int i = 1;
         for (String name : templateVariables) {
             String value = m.group(i++);
-            if (templateVariableToValue.getFirst(name) != null) {
-                continue;
-            }
-
-            templateVariableToValue.putSingle(name, value);
+            templateVariableToValue.add(name, value);
         }
 
         // The right hand side value, might be used to further resolve sub-resources.
         if (regexSuffix != null) {
             String finalGroup = m.group(i);
-            templateVariableToValue.putSingle(RIGHT_HAND_VALUE, finalGroup == null ? "/" : finalGroup);
+            templateVariableToValue.putSingle(FINAL_MATCH_GROUP, finalGroup == null ? "/" : finalGroup);
         }
 
         return true;

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AcceptTypeQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AcceptTypeQueryHandler.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AcceptTypeQueryHandler.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AcceptTypeQueryHandler.java Thu Mar 27 09:59:48 2008
@@ -25,6 +25,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.message.Message;
 
 public class AcceptTypeQueryHandler implements SystemQueryHandler {
@@ -39,7 +40,9 @@
         // more to come
     }
     
-    public Response handleSystemQuery(Message m, MultivaluedMap<String, String> queries) {
+    public Response handleQuery(Message m,
+                                ClassResourceInfo rootResource,
+                                MultivaluedMap<String, String> queries) {
         
         String type = queries.getFirst(CONTENT_QUERY);
         if (type != null) {

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SecurityContextImpl.java Thu Mar 27 09:59:48 2008
@@ -48,9 +48,11 @@
         return sc == null ? null : sc.getUserPrincipal();
     }
 
-    //  TODO
+    
     public boolean isSecure() {
-        return false;
+        String value = m.getExchange().getDestination().getAddress()
+            .getAddress().getValue();
+        return value.startsWith("https://");
     }
 
     public boolean isUserInRole(String role) {

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SystemQueryHandler.java Thu Mar 27 09:59:48 2008
@@ -22,6 +22,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.message.Message;
 
 /**
@@ -32,7 +33,9 @@
     
 public interface SystemQueryHandler {
     
-    Response handleSystemQuery(Message m, MultivaluedMap<String, String> queries);
+    Response handleQuery(Message m, 
+                         ClassResourceInfo rootRespurce,
+                         MultivaluedMap<String, String> queries);
     boolean supports(MultivaluedMap<String, String> queries);
 
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriInfoImpl.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriInfoImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/UriInfoImpl.java Thu Mar 27 09:59:48 2008
@@ -21,6 +21,7 @@
 
 import java.net.URI;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
@@ -34,12 +35,12 @@
 
 public class UriInfoImpl implements UriInfo {
 
-    private URITemplate template; 
+    private MultivaluedMap<String, String> templateParams; 
     private Message message;
     
-    public UriInfoImpl(Message m, URITemplate template) {
+    public UriInfoImpl(Message m, MultivaluedMap<String, String> templateParams) {
         this.message = m;
-        this.template = template;
+        this.templateParams = templateParams;
     }
     
     public URI getAbsolutePath() {
@@ -108,7 +109,14 @@
     public MultivaluedMap<String, String> getTemplateParameters(boolean decode) {
         // this needs to be changed
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        template.match(getPath(decode), values);
+        for (Map.Entry<String, List<String>> entry : templateParams.entrySet()) {
+            if (entry.getKey().equals(URITemplate.FINAL_MATCH_GROUP)) {
+                continue;
+            }
+            values.add(entry.getKey(), 
+                       decode ? JAXRSUtils.uriDecode(entry.getValue().get(0)) 
+                              : entry.getValue().get(0));
+        }
         return values;
     }
 

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java Thu Mar 27 09:59:48 2008
@@ -34,6 +34,7 @@
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -42,11 +43,10 @@
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.provider.RequestImpl;
+import org.apache.cxf.jaxrs.provider.SecurityContextImpl;
 import org.apache.cxf.jaxrs.provider.UriInfoImpl;
 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.Ignore;
@@ -59,6 +59,7 @@
         @Context private UriInfo uriInfo;
         @Context private HttpHeaders headers;
         @Context private Request request;
+        @Context private SecurityContext sContext;
         
         public UriInfo getUriInfo() {
             return uriInfo;
@@ -72,6 +73,10 @@
             return request;
         }
         
+        public SecurityContext getSecurityContext() {
+            return sContext;
+        }
+        
         @ProduceMime("text/xml")
         @ConsumeMime("text/xml")
         public void test() {
@@ -109,6 +114,7 @@
         public void testParams(@Context UriInfo info,
                                @Context HttpHeaders hs,
                                @Context Request r,
+                               @Context SecurityContext s,
                                @HeaderParam("Foo") String h) {
             // complete
         }
@@ -192,21 +198,22 @@
              "GET", values, contentTypes, acceptContentTypes);       
         assertNotNull(ori);
         assertEquals("getBooks", ori.getMethod().getName());
-        assertEquals("Only the first {id} should've been picked up", 2, values.size());
-        assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
-        assertEquals("Only the first {id} should've been picked up", 1, 
-                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
-        assertEquals("Only the first {id} should've been picked up", "1", values.getFirst("id"));
+        assertEquals("Only id and final match groups should be there", 2, values.size());
+        assertEquals("2 {id} values should've been picked up", 2, values.get("id").size());
+        assertEquals("FINAL_MATCH_GROUP should've been picked up", 1, 
+                     values.get(URITemplate.FINAL_MATCH_GROUP).size());
+        assertEquals("First {id} is 1", "1", values.getFirst("id"));
+        assertEquals("Second id is 2", "2", values.get("id").get(1));
         
         values = new MetadataMap<String, String>();
         ori = JAXRSUtils.findTargetResourceClass(resources, "/2",
              "POST", values, contentTypes, acceptContentTypes);       
         assertNotNull(ori);
         assertEquals("updateBookStoreInfo", ori.getMethod().getName());
-        assertEquals("Only the first {id} should've been picked up", 2, values.size());
-        assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
-        assertEquals("Only the first {id} should've been picked up", 1, 
-                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
+        assertEquals("Only id and final match groups should be there", 2, values.size());
+        assertEquals("Only single {id} should've been picked up", 1, values.get("id").size());
+        assertEquals("FINAL_MATCH_GROUP should've been picked up", 1, 
+                     values.get(URITemplate.FINAL_MATCH_GROUP).size());
         assertEquals("Only the first {id} should've been picked up", "2", values.getFirst("id"));
         
         values = new MetadataMap<String, String>();
@@ -218,7 +225,7 @@
         assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
         assertEquals("Only the first {id} should've been picked up", 1, values.get("bookId").size());
         assertEquals("Only the first {id} should've been picked up", 1, 
-                     values.get(URITemplate.RIGHT_HAND_VALUE).size());
+                     values.get(URITemplate.FINAL_MATCH_GROUP).size());
         assertEquals("Only the first {id} should've been picked up", "3", values.getFirst("id"));
         assertEquals("Only the first {id} should've been picked up", "4", values.getFirst("bookId"));
     }
@@ -537,6 +544,7 @@
                                          new Class[]{UriInfo.class, 
                                                      HttpHeaders.class, 
                                                      Request.class,
+                                                     SecurityContext.class,
                                                      String.class}), 
                 cri);
         ori.setHttpMethod("GET");
@@ -549,12 +557,13 @@
         
         List<Object> params = 
             JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
-        assertEquals("4 parameters expected", 4, params.size());
+        assertEquals("5 parameters expected", 5, params.size());
         assertSame(UriInfoImpl.class, params.get(0).getClass());
         assertSame(HttpHeadersImpl.class, params.get(1).getClass());
         assertSame(RequestImpl.class, params.get(2).getClass());
-        assertSame(String.class, params.get(3).getClass());
-        assertEquals("Wrong header param", "bar,baz", params.get(3));
+        assertSame(SecurityContextImpl.class, params.get(3).getClass());
+        assertSame(String.class, params.get(4).getClass());
+        assertEquals("Wrong header param", "bar,baz", params.get(4));
     }
     
     @Test
@@ -565,16 +574,14 @@
         
         Customer c = new Customer();
         
-        IMocksControl control = EasyMock.createNiceControl();
-        Message m = control.createMock(Message.class);
-        m.get(Message.PROTOCOL_HEADERS);
-        EasyMock.expectLastCall().andReturn(new HashMap<String, List<String>>());
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
         
         JAXRSUtils.injectHttpContextValues(c, ori, m);
         assertSame(UriInfoImpl.class, c.getUriInfo().getClass());
         assertSame(HttpHeadersImpl.class, c.getHeaders().getClass());
         assertSame(RequestImpl.class, c.getRequest().getClass());
-        
+        assertSame(SecurityContextImpl.class, c.getSecurityContext().getClass());
         
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java Thu Mar 27 09:59:48 2008
@@ -81,7 +81,7 @@
         
         boolean match = uriTemplate.match("/customers/123", values);
         assertTrue(match);
-        String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE);
+        String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
         assertEquals("/123", subResourcePath);
     }
         
@@ -93,7 +93,7 @@
         
         boolean match = uriTemplate.match("/customers/name/john/dep/CS", values);
         assertTrue(match);
-        String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE);
+        String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
         assertEquals("/name/john/dep/CS", subResourcePath);
     }
         
@@ -108,7 +108,7 @@
         
         boolean match = uriTemplate.match("/books/123/chapter/1", values);
         assertTrue(match);
-        String subResourcePath = values.getFirst(URITemplate.RIGHT_HAND_VALUE);
+        String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
         assertEquals("/chapter/1", subResourcePath);
     }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/UriInfoImplTest.java Thu Mar 27 09:59:48 2008
@@ -22,6 +22,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.jaxrs.MetadataMap;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -93,25 +94,40 @@
     
     @Test
     public void testGetTemplateParameters() {
+       
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+        new URITemplate("/bar").match("/baz", values);
         
         UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
-                                        new URITemplate("/bar"));
+                                        values);
         assertEquals("unexpected templates", 0, u.getTemplateParameters().size());
         
+        values.clear();
+        new URITemplate("/{id}").match("/bar%201", values);
         u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"),
-                                        new URITemplate("/{id}"));
+                                        values);
         
         MultivaluedMap<String, String> tps = u.getTemplateParameters(false);
         assertEquals("Number of templates is wrong", 1, tps.size());
         assertEquals("Wrong template value", tps.getFirst("id"), "bar%201");
         
+        values.clear();
+        new URITemplate("/{id}/{baz}").match("/1%202/bar", values);
         u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/1%202/bar"),
-                            new URITemplate("/{id}/{baz}"));
+                            values);
 
         tps = u.getTemplateParameters();
         assertEquals("Number of templates is wrong", 2, tps.size());
         assertEquals("Wrong template value", tps.getFirst("id"), "1 2");
         assertEquals("Wrong template value", tps.getFirst("baz"), "bar");
+        
+        // with suffix
+        values.clear();
+        new URITemplate("/bar", URITemplate.UNLIMITED_REGEX_SUFFIX).match("/bar", values);
+        
+        u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
+                                        values);
+        assertEquals("unexpected templates", 0, u.getTemplateParameters().size());
     }
     
     @Test

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Chapter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Chapter.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Chapter.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/Chapter.java Thu Mar 27 09:59:48 2008
@@ -44,5 +44,5 @@
     public long getId() {
         return id;
     }
-
+    
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java Thu Mar 27 09:59:48 2008
@@ -60,7 +60,14 @@
         System.out.println("----invoking getChapter with chapterid: " + chapterid);
 
         return chapters.get(new Long(chapterid));
-    }   
+    } 
+    
+    @Path("chapters/sub/{chapterid}/")    
+    public Chapter getSubChapter(@PathParam("chapterid")int chapterid) {
+        System.out.println("----invoking getChapter with chapterid: " + chapterid);
+
+        return chapters.get(new Long(chapterid));
+    } 
     
     final void init() {
         Chapter c1 = new Chapter();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Thu Mar 27 09:59:48 2008
@@ -20,9 +20,12 @@
 package org.apache.cxf.systest.jaxrs;
 
 
+import java.util.Calendar;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -30,6 +33,7 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 import javax.xml.transform.dom.DOMSource;
 
@@ -49,6 +53,19 @@
         init();
         System.out.println("----books: " + books.size());
     }
+    
+    @GET
+    @Path("webappexception")
+    public Book throwException() {
+        Response response = Response.serverError().entity("This is a WebApplicationException").build();
+        throw new WebApplicationException(response);
+    }
+    
+    @GET
+    @Path("timetable")
+    public Calendar getTimetable() {
+        return new GregorianCalendar();
+    }
 
     @GET
     @Path("/books/{bookId}/")
@@ -113,6 +130,7 @@
     @POST
     @Path("/books")
     @ProduceMime("text/xml")
+    @ConsumeMime("application/xml")
     public Response addBook(Book book) {
         System.out.println("----invoking addBook, book name is: " + book.getName());
         book.setId(++bookId);
@@ -121,6 +139,14 @@
         return Response.ok(book).build();
     }
 
+    @POST
+    @Path("/binarybooks")
+    @ProduceMime("text/xml")
+    @ConsumeMime("application/octet-stream")
+    public Response addBinaryBook(long[] book) {
+        return Response.ok(book).build();
+    }
+    
     @PUT
     @Path("/books/")
     public Response updateBook(Book book) {
@@ -148,6 +174,7 @@
     
     @PUT
     @Path("/bookswithjson/")
+    @ConsumeMime("application/json")
     public Response updateBookJSON(Book book) {
         System.out.println("----invoking updateBook, book name is: " + book.getName());
         Book b = books.get(book.getId());

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Chapter.java Thu Mar 27 09:59:48 2008
@@ -19,6 +19,9 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.ProduceMime;
 import javax.xml.bind.annotation.XmlRootElement;
 
 
@@ -43,6 +46,13 @@
     }
     public long getId() {
         return id;
+    }
+    
+    @GET
+    @Path("/recurse")
+    @ProduceMime("application/xml")
+    public Chapter getItself() {
+        return this;
     }
 
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Thu Mar 27 09:59:48 2008
@@ -44,80 +44,131 @@
     }
     
     @Test
-    public void testGetBook123() throws Exception {
-        String endpointAddress =
-            "http://localhost:9080/bookstore/books/123"; 
-        URL url = new URL(endpointAddress);
-        URLConnection connect = url.openConnection();
-        connect.addRequestProperty("Accept", "application/xml");
-        InputStream in = connect.getInputStream();
-        assertNotNull(in);           
-
-        InputStream expected = getClass()
-            .getResourceAsStream("resources/expected_get_book123.txt");
-
-        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
-        
-        connect = url.openConnection();
-        connect.addRequestProperty("Accept", "application/xml,application/json");
-        in = connect.getInputStream();
-        assertNotNull(in);           
-
-        expected = getClass()
-            .getResourceAsStream("resources/expected_get_book123json.txt");
-
-        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
+    public void testWebApplicationException() throws Exception {
+        getAndCompare("http://localhost:9080/bookstore/webappexception",
+                      "This is a WebApplicationException",
+                      "application/xml", 500);
     }
     
     @Test
-    public void testGetChapter() throws Exception {
-        String endpointAddress =
-            "http://localhost:9080/bookstore/booksubresource/123/chapters/1"; 
-        URL url = new URL(endpointAddress);
-        URLConnection connect = url.openConnection();
-        connect.addRequestProperty("Accept", "application/xml");
-        InputStream in = connect.getInputStream();
-        assertNotNull(in);           
-
-        InputStream expected = getClass()
-            .getResourceAsStream("resources/expected_get_chapter1.txt");
-
-        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+    public void testAcceptTypeMismatch() throws Exception {
+        // TODO : more specific message is needed
+        String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
+            + " xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">.No operation matching request path "
+            + "/bookstore/booknames/123/ is found, ContentType : */*, Accept : foo/bar.</ns1:faultstring>"
+            + "</ns1:XMLFault>";
+        
+        getAndCompare("http://localhost:9080/bookstore/booknames/123",
+                      msg,
+                      "foo/bar", 500);
     }
     
     @Test
-    public void testGetBook123ReturnString() throws Exception {
+    public void testNoMessageWriterFound() throws Exception {
+        // TODO : more specific message is needed
+        String msg = ".No message body writer found for response class : GregorianCalendar.";
+        
+        getAndCompare("http://localhost:9080/bookstore/timetable",
+                      msg,
+                      "*/*", 406);
+    }
+    
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testNoMessageReaderFound() throws Exception {
+//      TODO : more specific message is needed
+        String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
+            + " xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">"
+            + "java.lang.RuntimeException: No message body reader found for target class long[], "
+            + "content type : application/octet-stream"
+            + "</ns1:faultstring>"
+            + "</ns1:XMLFault>";
+        
         String endpointAddress =
-            "http://localhost:9080/bookstore/booknames/123"; 
-        URL url = new URL(endpointAddress);
-        InputStream in = url.openStream();
-        assertNotNull(in);           
+            "http://localhost:9080/bookstore/binarybooks";
 
-        InputStream expected = getClass()
-            .getResourceAsStream("resources/expected_get_book123_returnstring.txt");
-
-        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestHeader("Content-Type", "application/octet-stream");
+        post.setRequestHeader("Accept", "text/xml");
+        post.setRequestBody("Bar");
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(500, result);
+            assertEquals(msg, post.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
     }
     
     @Test
-    public void testGetBookNotFound() throws Exception {
+    public void testConsumeTypeMismatch() throws Exception {
+        // TODO : more specific message is needed
+        String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
+            + " xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">.No operation matching request path "
+            + "/bookstore/books/ is found, ContentType : application/bar, Accept : text/xml."
+            + "</ns1:faultstring></ns1:XMLFault>";
+        
         String endpointAddress =
-            "http://localhost:9080/bookstore/books/126"; 
+            "http://localhost:9080/bookstore/books";
 
-        GetMethod get = new GetMethod(endpointAddress);
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestHeader("Content-Type", "application/bar");
+        post.setRequestHeader("Accept", "text/xml");
         HttpClient httpclient = new HttpClient();
         
         try {
-            int result = httpclient.executeMethod(get);
+            int result = httpclient.executeMethod(post);
             assertEquals(500, result);
-            
-            InputStream expected = getClass().getResourceAsStream("resources/expected_get_book_notfound.txt");
-            
-            assertEquals(getStringFromInputStream(expected), get.getResponseBodyAsString());
+            assertEquals(msg, post.getResponseBodyAsString());
         } finally {
             // Release current connection to the connection pool once you are done
-            get.releaseConnection();
-        }  
+            post.releaseConnection();
+        }
+    }
+    
+    @Test
+    public void testGetBook123() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+        
+        getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
+                               "resources/expected_get_book123json.txt",
+                               "application/xml,application/json", 200);
+    }
+    
+    @Test
+    public void testGetChapter() throws Exception {
+        
+        getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/1",
+                               "resources/expected_get_chapter1.txt",
+                               "application/xml", 200);
+    }
+    
+    @Test
+    public void testGetChapterChapter() throws Exception {
+        
+        getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/sub/1/recurse",
+                               "resources/expected_get_chapter1.txt",
+                               "application/xml", 200);
+    }
+    
+    @Test
+    public void testGetBook123ReturnString() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/booknames/123",
+                               "resources/expected_get_book123_returnstring.txt",
+                               "text/plain", 200);
+    }
+    
+    @Test
+    public void testGetBookNotFound() throws Exception {
+        
+        getAndCompareAsStrings("http://localhost:9080/bookstore/books/126",
+                               "resources/expected_get_book_notfound.txt",
+                               "application/xml", 500);
     }
     
     @Test
@@ -128,6 +179,7 @@
         String inputFile = getClass().getResource("resources/add_book.txt").getFile();         
         File input =  new File(inputFile);
         PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestHeader("Content-Type", "application/xml");
         RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
         post.setRequestEntity(entity);
         HttpClient httpclient = new HttpClient();
@@ -429,6 +481,37 @@
             get.releaseConnection();
         }  
     }
+    
+    private void getAndCompareAsStrings(String address, 
+                                        String resourcePath,
+                                        String acceptType,
+                                        int status) throws Exception {
+        String expected = getStringFromInputStream(
+                              getClass().getResourceAsStream(resourcePath));
+        getAndCompare(address,
+                      expected,
+                      acceptType,
+                      status);
+    }
+    
+    private void getAndCompare(String address, 
+                               String expectedValue,
+                               String acceptType,
+                               int expectedStatus) throws Exception {
+        GetMethod get = new GetMethod(address);
+        get.setRequestHeader("Accept", acceptType);
+        HttpClient httpClient = new HttpClient();
+        try {
+            int result = httpClient.executeMethod(get);
+            assertEquals(expectedStatus, result);
+            String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
+            assertEquals("Expected value is wrong", 
+                         expectedValue, jsonContent);
+        } finally {
+            get.releaseConnection();
+        }
+    }
+    
     
     private String getStringFromInputStream(InputStream in) throws Exception {        
         CachedOutputStream bos = new CachedOutputStream();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java?rev=641894&r1=641893&r2=641894&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedOutsideBookTest.java Thu Mar 27 09:59:48 2008
@@ -36,7 +36,8 @@
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(BookServerResourceCreatedOutside.class));
+        assertTrue("server did not launch correctly", 
+                   launchServer(BookServerResourceCreatedOutside.class, true));
     }
     
     @Test
@@ -70,7 +71,7 @@
         httpUrlConnection.setDoInput(true);   
         httpUrlConnection.setRequestMethod("POST");   
         httpUrlConnection.setRequestProperty("Accept",   "text/xml");   
-        httpUrlConnection.setRequestProperty("Content-type",   "text/html");   
+        httpUrlConnection.setRequestProperty("Content-type",   "application/xml");   
         httpUrlConnection.setRequestProperty("Connection",   "close");   
         //httpurlconnection.setRequestProperty("Content-Length",   String.valueOf(is.available()));   
 



Mime
View raw message