cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r591739 - in /incubator/cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ systests/src/test/java/org/apache/cxf/systest/jaxrs/ systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/
Date Sun, 04 Nov 2007 08:01:09 GMT
Author: jliu
Date: Sun Nov  4 01:01:08 2007
New Revision: 591739

URL: http://svn.apache.org/viewvc?rev=591739&view=rev
Log:
Handle checked exceptions in JAX-RS. Note this is still a very much experimental stuff, more
work needs to do on a).handle unchecked exceptions and exceptions thrown from cxf runtime
b).how to handle exceptions for different media types c). compatible with JSR-311 

Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundDetails.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundFault.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt
  (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.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/JAXRSClientServerBookTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java?rev=591739&r1=591738&r2=591739&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSBindingFactory.java
Sun Nov  4 01:01:08 2007
@@ -23,6 +23,8 @@
 import org.apache.cxf.binding.Binding;
 
 import org.apache.cxf.binding.xml.XMLBinding;
+import org.apache.cxf.binding.xml.interceptor.XMLFaultOutInterceptor;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.jaxrs.interceptor.JAXRSDispatchInterceptor;
 import org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor;
 import org.apache.cxf.service.Service;
@@ -41,13 +43,14 @@
         binding.getInInterceptors().add(new JAXRSDispatchInterceptor());
         binding.getOutInterceptors().add(new JAXRSOutInterceptor());
         
-        //TODO: Add fault interceptors
+        binding.getOutFaultInterceptors().add(new XMLFaultOutInterceptor());
+        binding.getOutFaultInterceptors().add(new StaxOutInterceptor());
 
         return binding;
     }
 
     /*
-     * The concept of Binding is not used in this JAX-RS impl. Here we use
+     * The concept of Binding can not be applied to JAX-RS. Here we use
      * Binding merely to make this JAX-RS impl compatible with CXF framework
      */
     public BindingInfo createBindingInfo(Service service, String namespace, Object obj) {

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundDetails.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundDetails.java?rev=591739&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundDetails.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundDetails.java
Sun Nov  4 01:01:08 2007
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class BookNotFoundDetails {
+    private long id;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+}

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

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

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundFault.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundFault.java?rev=591739&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundFault.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookNotFoundFault.java
Sun Nov  4 01:01:08 2007
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.jaxrs;
+
+import javax.xml.ws.WebFault;
+
+@WebFault
+public class BookNotFoundFault extends Exception {
+    private BookNotFoundDetails details;
+
+    public BookNotFoundFault(BookNotFoundDetails details) {
+        super();
+        this.details = details;
+    }
+
+    public BookNotFoundDetails getFaultInfo() {
+        return details;
+    }
+}

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

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

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=591739&r1=591738&r2=591739&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
Sun Nov  4 01:01:08 2007
@@ -30,6 +30,9 @@
 import javax.ws.rs.UriTemplate;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.customer.book.BookNotFoundDetails;
+import org.apache.cxf.customer.book.BookNotFoundFault;
+
 @UriTemplate("/bookstore/")
 public class BookStore {
 
@@ -53,9 +56,16 @@
 
     @HttpMethod("GET")
     @UriTemplate("/books/{bookId}/")
-    public Book getBook(@UriParam("bookId") String id) {
+    public Book getBook(@UriParam("bookId") String id) throws BookNotFoundFault {
         System.out.println("----invoking getBook with id: " + id);
-        return books.get(Long.parseLong(id));
+        Book book = books.get(Long.parseLong(id));
+        if (book != null) {
+            return book;
+        } else {
+            BookNotFoundDetails details = new BookNotFoundDetails();
+            details.setId(Long.parseLong(id));
+            throw new BookNotFoundFault(details);
+        }
     }
 
     @HttpMethod("POST")

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=591739&r1=591738&r2=591739&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
Sun Nov  4 01:01:08 2007
@@ -25,6 +25,7 @@
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.PutMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
@@ -54,6 +55,30 @@
 
         //System.out.println("---" + getStringFromInputStream(in));
         assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+    }
+    
+    @Test
+    public void testGetBookNotFound() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/bookstore/books/126"; 
+
+        GetMethod get = new GetMethod(endpointAddress);
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(get);
+            assertEquals(500, result);
+            //System.out.println("Response status code: " + result);
+            //System.out.println("Response body: ");
+            //System.out.println(get.getResponseBodyAsString());
+            
+            InputStream expected = getClass().getResourceAsStream("resources/expected_get_book_notfound.txt");
+            
+            assertEquals(getStringFromInputStream(expected), get.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are done
+            get.releaseConnection();
+        }  
     }
     
     @Test

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt?rev=591739&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt
Sun Nov  4 01:01:08 2007
@@ -0,0 +1 @@
+<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring
xmlns:ns1="http://cxf.apache.org/bindings/xformat">org.apache.cxf.customer.book.BookNotFoundFault</ns1:faultstring></ns1:XMLFault>
\ No newline at end of file

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

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/expected_get_book_notfound.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message