cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r720159 - in /cxf/branches/2.1.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/src...
Date Mon, 24 Nov 2008 10:48:13 GMT
Author: sergeyb
Date: Mon Nov 24 02:48:12 2008
New Revision: 720159

URL: http://svn.apache.org/viewvc?rev=720159&view=rev
Log:
Merged revisions 719305 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r719305 | sergeyb | 2008-11-20 17:48:33 +0000 (Thu, 20 Nov 2008) | 1 line
  
  JAXRS : adding system schema validation test, improving handling of exception mappers 
........

Added:
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/Messages.properties
      - copied unchanged from r719305, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/Messages.properties
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
      - copied unchanged from r719305, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
      - copied unchanged from r719305, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/book.xsd
      - copied unchanged from r719305, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/book.xsd
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/add_book2.txt
      - copied unchanged from r719305, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/add_book2.txt
Modified:
    cxf/branches/2.1.x-fixes/   (props changed)
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
    cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs/WEB-INF/beans.xml

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 24 02:48:12 2008
@@ -1 +1 @@
-/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281,718439,718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222,719273,719327,719354,719362,719368,719382,719649,719680,720119
+/cxf/trunk:686333-686363,686764,686820,687096,687194,687363,687387,687463,687543,687722,687798,687814,687817,687891,687910,687914,688086,688102,688133,688596,688735,688870,689572,689596,689855,689924,690067,690289,691246,691271,691295,691338,691355,691488,691602,691646,691706,691728,692116,692157,692310,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694795,694869,694981,694987,694993,695041,695096,695396,695484,695537,695552,695561,695619,695684,695835,695840,695868,695935,695977,696016,696094,696433,696720,697085,697868,698128,699289,700261,700507,700602,700981,701316,701783,701830,701862,702187,702205-702248,702267,702547,702561,702580,702602,702609,702616,702653,702656,702957,703191,703239,703309,703501,703513,703548,704584,704937,704997,705150,705235,705274,705340,705446,705548,705614,705692,705708,706482,706631,706675,706900,706909,707034,707089,707100,707902,708035,708044,708074,708410,708417,708550,708554,709353-709354,709425,710076,710150,71015
 4,711193,711388,711410,711490,711635,711975,712194,712198,712238,712272,712299,712312,712670,712893,713082,713095-713096,713099,713584,713597,713737,713804,713899,714167-714168,714245,714255,717937-717961,718281,718439,718448,718565,718620,718640,718665,718970,719017,719210,719215-719218,719222,719273,719305,719327,719354,719362,719368,719382,719649,719680,720119

Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
Mon Nov 24 02:48:12 2008
@@ -19,15 +19,47 @@
 
 package org.apache.cxf.jaxrs.impl;
 
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
+
 public class WebApplicationExceptionMapper 
     implements ExceptionMapper<WebApplicationException> {
 
+    private static final Logger LOG = LogUtils.getL7dLogger(WebApplicationExceptionMapper.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WebApplicationExceptionMapper.class);
+    
     public Response toResponse(WebApplicationException ex) {
-        return ex.getResponse();
+        if (LOG.isLoggable(Level.FINE)) {
+            org.apache.cxf.common.i18n.Message errorMsg = 
+                new org.apache.cxf.common.i18n.Message("WEB_APP_EXCEPTION", 
+                    BUNDLE, ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage());
+            LOG.fine(errorMsg.toString());
+        }
+         
+        Response r = ex.getResponse();
+        if (r == null) {
+            String message = null;
+            if (ex.getCause() == null) {
+                message = new org.apache.cxf.common.i18n.Message("DEFAULT_EXCEPTION_MESSAGE",

+                                                                 BUNDLE).toString();
+            } else {
+                message = ex.getCause().getMessage();
+                if (message == null) {
+                    message = ex.getCause().getClass().getName();
+                }
+            }
+            r = Response.status(500).type(MediaType.TEXT_PLAIN).entity(message).build();
+        }
+        return r;
     }
 
 }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Mon Nov 24 02:48:12 2008
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.ResourceBundle;
 import java.util.WeakHashMap;
 import java.util.logging.Logger;
 
@@ -52,6 +53,7 @@
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 
+import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -60,6 +62,8 @@
 public abstract class AbstractJAXBProvider 
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
     
+    protected static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractJAXBProvider.class);
+       
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractJAXBProvider.class);
 
     private static final String CHARSET_PARAMETER = "charset"; 
@@ -67,7 +71,7 @@
         
     private static Map<String, JAXBContext> packageContexts = new WeakHashMap<String,
JAXBContext>();
     private static Map<Class<?>, JAXBContext> classContexts = new WeakHashMap<Class<?>,
JAXBContext>();
-    
+        
     @Context protected ContextResolver<JAXBContext> resolver;
     private Schema schema;
     

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Mon Nov 24 02:48:12 2008
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.jaxrs.provider;
 
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -29,9 +28,12 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.ProduceMime;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -39,6 +41,8 @@
 import javax.xml.bind.Unmarshaller;
 import javax.xml.transform.stream.StreamSource;
 
+@ProduceMime({"application/xml", "text/xml" })
+@ConsumeMime({"application/xml", "text/xml" })
 @Provider
 public class JAXBElementProvider extends AbstractJAXBProvider  {
     
@@ -70,6 +74,15 @@
             }
             
         } catch (JAXBException e) {
+            // TODO : refactor it such that thsi caode can be used by across the board
+            String message = new org.apache.cxf.common.i18n.Message("JAXB_EXCEPTION", 
+                                 BUNDLE,
+                                 e.getLinkedException() != null 
+                                 ? e.getLinkedException().getMessage() : e.getMessage()).toString();
+            Response r = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+                .type(MediaType.TEXT_PLAIN).entity(message).build();
+            throw new WebApplicationException(r);
+        } catch (Exception e) {
             throw new WebApplicationException(e);        
         }
     }

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Mon Nov 24 02:48:12 2008
@@ -86,6 +86,8 @@
             throw new WebApplicationException(e);         
         } catch (XMLStreamException e) {
             throw new WebApplicationException(e);
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
         } 
     }
 

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Mon Nov 24 02:48:12 2008
@@ -60,6 +60,8 @@
         new ArrayList<ProviderInfo<MessageBodyWriter>>();
     private List<ProviderInfo<ContextResolver>> userContextResolvers = 
         new ArrayList<ProviderInfo<ContextResolver>>();
+    private List<ProviderInfo<ExceptionMapper>> defaultExceptionMappers = 
+        new ArrayList<ProviderInfo<ExceptionMapper>>();
     private List<ProviderInfo<ExceptionMapper>> userExceptionMappers = 
         new ArrayList<ProviderInfo<ExceptionMapper>>();
     private List<ProviderInfo<RequestHandler>> requestHandlers = 
@@ -76,7 +78,7 @@
                      userContextResolvers,
                      requestHandlers,
                      responseHandlers,
-                     userExceptionMappers,
+                     defaultExceptionMappers,
                      new JAXBElementProvider(),
                      new JSONProvider(),
                      new BinaryDataProvider(),
@@ -113,9 +115,24 @@
         return null;
     }
     
-    @SuppressWarnings("unchecked")
     public <T> ExceptionMapper<T> createExceptionMapper(Class<?> exceptionType,
Message m) {
-        for (ProviderInfo<ExceptionMapper> em : userExceptionMappers) {
+        
+        ExceptionMapper<T> mapper = doCreateExceptionMapper(userExceptionMappers,
+                                                            exceptionType,
+                                                            m);
+        if (mapper != null) {
+            return mapper;
+        }
+        
+        return doCreateExceptionMapper(defaultExceptionMappers,
+                                       exceptionType,
+                                       m);
+    }
+    
+    @SuppressWarnings("unchecked")
+    private static <T> ExceptionMapper<T> doCreateExceptionMapper(
+        List<ProviderInfo<ExceptionMapper>> mappers, Class<?> exceptionType,
Message m) {
+        for (ProviderInfo<ExceptionMapper> em : mappers) {
             Type[] types = em.getProvider().getClass().getGenericInterfaces();
             for (Type t : types) {
                 if (t instanceof ParameterizedType) {

Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Mon Nov 24 02:48:12 2008
@@ -31,9 +31,11 @@
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.xml.bind.JAXBContext;
@@ -44,8 +46,10 @@
 import org.apache.abdera.model.Feed;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.JAXBContextProvider;
+import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.MessageImpl;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -59,6 +63,21 @@
     }
     
     @Test
+    public void testExceptionMappers() throws Exception {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        ExceptionMapper<?> mapper = 
+            pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
+        assertNotNull(mapper);
+        WebApplicationExceptionMapper m = new WebApplicationExceptionMapper(); 
+        pf.registerUserProvider(m);
+        ExceptionMapper<?> mapper2 = 
+            pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
+        assertNotSame(mapper, mapper2);
+        assertSame(m, mapper2);
+        
+    }
+    
+    @Test
     public void testSortEntityProviders() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserProvider(new TestStringProvider());

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
Mon Nov 24 02:48:12 2008
@@ -24,10 +24,14 @@
 import java.util.Map;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
 
 @Path("/bookstore")
 @ProduceMime("application/json")
@@ -35,7 +39,9 @@
 
     private Map<Long, Book> books = new HashMap<Long, Book>();
     private Long mainId = 123L;
-        
+    @Context
+    private UriInfo ui;    
+    
     public BookStoreSpring() {
         init();
         System.out.println("----books: " + books.size());
@@ -48,6 +54,14 @@
     }
     
     @GET
+    @Path("/bookinfo")
+    public Book getBookByUriInfo() throws Exception {
+        MultivaluedMap<String, String> params = ui.getQueryParameters();
+        String id = params.getFirst("param1") + params.getFirst("param2");
+        return books.get(Long.valueOf(id));
+    }
+    
+    @GET
     @Path("/booksquery")
     public Book getBookByQuery(@QueryParam("id") String id) {
         
@@ -72,6 +86,16 @@
         return books.get(mainId);
     }  
 
+    @POST
+    @Path("books/convert")
+    @ProduceMime("application/xml")
+    public Book convertBook(Book2 book) {
+        // how to have Book2 populated ?
+        Book b = new Book();
+        b.setId(book.getId());
+        b.setName(book.getName());
+        return b;
+    }
     
     final void init() {
         Book book = new Book();

Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
(original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
Mon Nov 24 02:48:12 2008
@@ -19,10 +19,15 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -33,7 +38,16 @@
 
     @BeforeClass
     public static void startServers() throws Exception {
-        assertTrue("server did not launch correctly", launchServer(BookServerSpring.class));
+        assertTrue("server did not launch correctly", 
+                   launchServer(BookServerSpring.class));
+    }
+    
+    @Test
+    public void testGetBookByUriInfo() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/bookstore/bookinfo?"
+                               + "param1=12&param2=3"; 
+        getBook(endpointAddress);
     }
     
     @Test
@@ -76,6 +90,57 @@
         assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
     }
     
+    @Test
+    public void testAddInvalidBook() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/bookstore/books/convert";
+        
+        File input = new File(getClass().getResource("resources/add_book.txt").toURI());
        
+        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();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(500, result);
+            assertTrue(post.getResponseBodyAsString().contains("JAXBException"));
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
+                
+    }
+    
+    @Test
+    public void testAddValidBook() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/bookstore/books/convert";
+        
+        File input = new File(getClass().getResource("resources/add_book2.txt").toURI());
        
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestHeader("Content-Type", "application/xml");
+        RequestEntity entity = new FileRequestEntity(input, "text/xml");
+        post.setRequestEntity(entity);
+        HttpClient httpclient = new HttpClient();
+        
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(200, result);
+            
+            InputStream expected = getClass().getResourceAsStream("resources/expected_get_book123.txt");
+            
+            assertEquals(getStringFromInputStream(expected), post.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
+                
+    }
+    
     private String getStringFromInputStream(InputStream in) throws Exception {        
         CachedOutputStream bos = new CachedOutputStream();
         IOUtils.copy(in, bos);

Modified: cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=720159&r1=720158&r2=720159&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/resources/jaxrs/WEB-INF/beans.xml Mon Nov 24
02:48:12 2008
@@ -42,7 +42,19 @@
     <jaxrs:serviceBeans>
       <bean class="org.apache.cxf.systest.jaxrs.BookStoreSpring" />
     </jaxrs:serviceBeans>		   
+    <jaxrs:providers>
+       <ref bean="jaxbProvider"/>
+       
+    </jaxrs:providers>
+    
   </jaxrs:server>
 
+  <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
+      <property name="schemas">
+        <list>
+           <value>classpath:/org/apache/cxf/systest/jaxrs/book.xsd</value>
+        </list>
+      </property>
+  </bean>
 </beans>
 <!-- END SNIPPET: beans -->



Mime
View raw message