You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2008/07/01 20:41:29 UTC

svn commit: r673167 [5/6] - in /cxf/trunk: parent/ rt/frontend/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend...

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomEntryProviderTest.java Tue Jul  1 11:41:24 2008
@@ -46,7 +46,7 @@
     @Test
     public void testReadFrom() throws Exception {
         InputStream is = getClass().getResourceAsStream("atomEntry.xml");
-        Entry simple = afd.readFrom(Entry.class, null, null, is);
+        Entry simple = afd.readFrom(Entry.class, null, null, null, null, is);
         assertEquals("Wrong entry title", 
                      "Atom-Powered Robots Run Amok", simple.getTitle());
         
@@ -55,13 +55,14 @@
     @Test
     public void testWriteTo() throws Exception {
         InputStream is = getClass().getResourceAsStream("atomEntry.xml");
-        Entry simple = afd.readFrom(Entry.class, 
-                                    MediaType.parse("application/atom+xml;type=entry"), null, is);
+        Entry simple = afd.readFrom(Entry.class, null, 
+            null, MediaType.valueOf("application/atom+xml;type=entry"), null, is);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        afd.writeTo(simple, MediaType.parse("application/atom+xml;type=entry"), null, bos);
+        afd.writeTo(simple, null, null, null, 
+            MediaType.valueOf("application/atom+xml;type=entry"), null, bos);
         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
-        Entry simpleCopy = afd.readFrom(Entry.class, 
-                                        MediaType.parse("application/atom+xml"), null, bis);
+        Entry simpleCopy = afd.readFrom(Entry.class, null, 
+            null, MediaType.valueOf("application/atom+xml"), null, bis);
         assertEquals("Wrong entry title", 
                      "Atom-Powered Robots Run Amok", simpleCopy.getTitle());
         assertEquals("Wrong entry title", 
@@ -70,16 +71,16 @@
     
     @Test
     public void testWriteable() {
-        assertTrue(afd.isWriteable(Entry.class));
-        assertTrue(afd.isWriteable(FOMEntry.class));
-        assertFalse(afd.isWriteable(Feed.class));
+        assertTrue(afd.isWriteable(Entry.class, null, null));
+        assertTrue(afd.isWriteable(FOMEntry.class, null, null));
+        assertFalse(afd.isWriteable(Feed.class, null, null));
     }
     
     @Test
     public void testReadable() {
-        assertTrue(afd.isReadable(Entry.class));
-        assertTrue(afd.isReadable(FOMEntry.class));
-        assertFalse(afd.isReadable(Feed.class));
+        assertTrue(afd.isReadable(Entry.class, null, null));
+        assertTrue(afd.isReadable(FOMEntry.class, null, null));
+        assertFalse(afd.isReadable(Feed.class, null, null));
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AtomFeedProviderTest.java Tue Jul  1 11:41:24 2008
@@ -45,18 +45,18 @@
     @Test
     public void testReadFrom() throws Exception {
         InputStream is = getClass().getResourceAsStream("atomFeed.xml");
-        Feed simple = afd.readFrom(Feed.class, null, null, is);
+        Feed simple = afd.readFrom(Feed.class, null, null, null, null, is);
         assertEquals("Wrong feed title", "Example Feed", simple.getTitle());
         
     }
     
     public void testWriteTo() throws Exception {
         InputStream is = getClass().getResourceAsStream("atomFeed.xml");
-        Feed simple = afd.readFrom(Feed.class, null, null, is);
+        Feed simple = afd.readFrom(Feed.class, null, null, null, null, is);
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        afd.writeTo(simple, null, null, bos);
+        afd.writeTo(simple, null, null, null, null, null, bos);
         ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
-        Feed simpleCopy = afd.readFrom(Feed.class, null, null, bis);
+        Feed simpleCopy = afd.readFrom(Feed.class, null, null, null, null, bis);
         assertEquals("Wrong entry title", 
                      "Example Feed", simpleCopy.getTitle());
         assertEquals("Wrong entry title", 
@@ -65,16 +65,16 @@
     
     @Test
     public void testWriteable() {
-        assertTrue(afd.isWriteable(Feed.class));
-        assertTrue(afd.isWriteable(FOMFeed.class));
-        assertFalse(afd.isWriteable(Entry.class));
+        assertTrue(afd.isWriteable(Feed.class, null, null));
+        assertTrue(afd.isWriteable(FOMFeed.class, null, null));
+        assertFalse(afd.isWriteable(Entry.class, null, null));
     }
     
     @Test
     public void testReadable() {
-        assertTrue(afd.isReadable(Feed.class));
-        assertTrue(afd.isReadable(FOMFeed.class));
-        assertFalse(afd.isReadable(Entry.class));
+        assertTrue(afd.isReadable(Feed.class, null, null));
+        assertTrue(afd.isReadable(FOMFeed.class, null, null));
+        assertFalse(afd.isReadable(Entry.class, null, null));
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java Tue Jul  1 11:41:24 2008
@@ -22,9 +22,15 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.Arrays;
 
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
@@ -37,19 +43,19 @@
     @Test
     public void testIsWriteable() {
         MessageBodyWriter<Object> p = new BinaryDataProvider();
-        assertTrue(p.isWriteable(byte[].class)
-                   && p.isWriteable(InputStream.class)
-                   && p.isWriteable(File.class)
-                   && !p.isWriteable(int[].class));
+        assertTrue(p.isWriteable(byte[].class, null, null)
+                   && p.isWriteable(InputStream.class, null, null)
+                   && p.isWriteable(File.class, null, null)
+                   && !p.isWriteable(int[].class, null, null));
     }
     
     @Test
     public void testIsReadable() {
         MessageBodyReader<Object> p = new BinaryDataProvider();
-        assertTrue(p.isReadable(byte[].class)
-                   && p.isReadable(InputStream.class)
-                   && !p.isReadable(File.class)
-                   && !p.isReadable(int[].class));
+        assertTrue(p.isReadable(byte[].class, null, null)
+                   && p.isReadable(InputStream.class, null, null)
+                   && !p.isReadable(File.class, null, null)
+                   && !p.isReadable(int[].class, null, null));
     }
     
     @SuppressWarnings("unchecked")
@@ -57,13 +63,17 @@
     public void testReadFrom() throws Exception {
         MessageBodyReader p = new BinaryDataProvider();
         byte[] bytes = (byte[])p.readFrom(byte[].class, null, null, 
-                                          new ByteArrayInputStream("hi".getBytes()));
+                                          null, null, new ByteArrayInputStream("hi".getBytes()));
         assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
         
-        InputStream is = (InputStream)p.readFrom(InputStream.class, null, null, 
-                                          new ByteArrayInputStream("hi".getBytes()));
+        InputStream is = (InputStream)p.readFrom(InputStream.class, null, null, null, null, 
+            new ByteArrayInputStream("hi".getBytes()));
         bytes = IOUtils.readBytesFromStream(is);
         assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
+        
+        Reader r = (Reader)p.readFrom(Reader.class, null, null, 
+                       MediaType.valueOf("text/xml"), null, new ByteArrayInputStream("hi".getBytes()));
+        assertEquals(IOUtils.toString(r), "hi");
     }
     
     @SuppressWarnings("unchecked")
@@ -71,12 +81,30 @@
     public void testWriteTo() throws Exception {
         MessageBodyWriter p = new BinaryDataProvider();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        p.writeTo(new byte[]{'h', 'i'}, null, null, os);
+        p.writeTo(new byte[]{'h', 'i'}, null, null, null, null, null, os);
         assertTrue(Arrays.equals(new String("hi").getBytes(), os.toByteArray()));
         ByteArrayInputStream is = new ByteArrayInputStream("hi".getBytes());
         os = new ByteArrayOutputStream();
-        p.writeTo(is, null, null, os);
+        p.writeTo(is, null, null, null, null, null, os);
+        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
+        
+        Reader r = new StringReader("hi");
+        os = new ByteArrayOutputStream();
+        p.writeTo(r, null, null, null, MediaType.valueOf("text/xml"), null, os);
+        assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
+        
+        os = new ByteArrayOutputStream();
+        p.writeTo(new StreamingOutputImpl(), null, null, null, 
+                  MediaType.valueOf("text/xml"), null, os);
         assertTrue(Arrays.equals(os.toByteArray(), new String("hi").getBytes()));
     }
 
+    
+    private static class StreamingOutputImpl implements StreamingOutput {
+
+        public void write(OutputStream output) throws IOException {
+            output.write("hi".getBytes());
+        }
+        
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProviderTest.java Tue Jul  1 11:41:24 2008
@@ -41,7 +41,8 @@
     @Test
     public void testReadFrom() throws Exception {
         InputStream is = getClass().getResourceAsStream("singleValPostBody.txt");
-        MultivaluedMap<String, String> mvMap = ferp.readFrom(Object.class, null, null, is);
+        MultivaluedMap<String, String> mvMap = 
+            ferp.readFrom(Object.class, null, null, null, null, is);
         assertEquals("Wrong entry for foo", "bar", mvMap.getFirst("foo"));
         assertEquals("Wrong entry for boo", "far", mvMap.getFirst("boo"));
 
@@ -50,7 +51,8 @@
     @Test
     public void testReadFromMultiples() throws Exception {
         InputStream is = getClass().getResourceAsStream("multiValPostBody.txt");
-        MultivaluedMap<String, String> mvMap = ferp.readFrom(Object.class, null, null, is);
+        MultivaluedMap<String, String> mvMap = 
+            ferp.readFrom(Object.class, null, null, null, null, is);
         List<String> vals = mvMap.get("foo");
 
         assertEquals("Wrong size for foo params", 2, vals.size());
@@ -63,7 +65,7 @@
 
     @Test
     public void testReadable() {
-        assertTrue(ferp.isReadable(MultivaluedMap.class));
+        assertTrue(ferp.isReadable(MultivaluedMap.class, null, null));
     }
 
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java Tue Jul  1 11:41:24 2008
@@ -23,20 +23,27 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
 import java.util.List;
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
+import javax.xml.bind.JAXBContext;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
 import org.apache.cxf.helpers.IOUtils;
-import org.apache.cxf.jaxrs.JAXRSUtils;
+import org.apache.cxf.jaxrs.JAXBContextProvider;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -46,21 +53,21 @@
     
     @Before
     public void setUp() {
-        ProviderFactory.getInstance().clearUserMessageProviders();
+        ProviderFactory.getInstance().clearProviders();
     }
     
     @Test
     public void testSortEntityProviders() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new TestStringProvider());
-        pf.registerUserEntityProvider(new StringProvider());
+        pf.registerUserProvider(new TestStringProvider());
+        pf.registerUserProvider(new StringProvider());
         
-        List<MessageBodyReader> readers = pf.getUserMessageReaders();
+        List<ProviderInfo<MessageBodyReader>> readers = pf.getUserMessageReaders();
 
         assertTrue(indexOf(readers, TestStringProvider.class) 
                    < indexOf(readers, StringProvider.class));
         
-        List<MessageBodyWriter> writers = pf.getUserMessageWriters();
+        List<ProviderInfo<MessageBodyWriter>> writers = pf.getUserMessageWriters();
 
         assertTrue(indexOf(writers, TestStringProvider.class) 
                    < indexOf(writers, StringProvider.class));
@@ -79,7 +86,7 @@
         verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
         verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
         MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(File.class, JAXRSUtils.ALL_TYPES);
+            .createMessageBodyWriter(File.class, null, null, JAXRSUtils.ALL_TYPES, null);
         assertTrue(BinaryDataProvider.class == writer.getClass());
     }
     
@@ -87,14 +94,14 @@
                                 String errorMessage) 
         throws Exception {
         
-        MediaType mType = MediaType.parse(mediaType);
+        MediaType mType = MediaType.valueOf(mediaType);
         
         MessageBodyReader reader = ProviderFactory.getInstance()
-            .createMessageBodyReader(type, mType);
+            .createMessageBodyReader(type, null, null, mType, null);
         assertSame(errorMessage, provider, reader.getClass());
     
         MessageBodyWriter writer = ProviderFactory.getInstance()
-            .createMessageBodyWriter(type, mType);
+            .createMessageBodyWriter(type, null, null, mType, null);
         assertTrue(errorMessage, provider == writer.getClass());
     }
     
@@ -112,6 +119,9 @@
     
     @Test
     public void testGetAtomProvider() throws Exception {
+        ProviderFactory.getInstance().setUserProviders(
+             Arrays.asList(
+                  new Object[]{new AtomEntryProvider(), new AtomFeedProvider()}));
         verifyProvider(Entry.class, AtomEntryProvider.class, "application/atom+xml");
         verifyProvider(Feed.class, AtomFeedProvider.class, "application/atom+xml");
     }
@@ -119,7 +129,7 @@
     @Test
     public void testGetStringProviderUsingProviderDeclaration() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new TestStringProvider());
+        pf.registerUserProvider(new TestStringProvider());
         verifyProvider(String.class, TestStringProvider.class, "text/html");
     }    
     
@@ -132,23 +142,35 @@
     @Test
     public void testRegisterCustomJSONEntityProvider() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new CustomJSONProvider());
+        pf.registerUserProvider(new CustomJSONProvider());
         verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class, 
                        "application/json", "User-registered provider was not returned first");
     }
     
+    
+    @Test
+    public void testRegisterCustomResolver() throws Exception {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        pf.registerUserProvider(new JAXBContextProvider());
+        ContextResolver<JAXBContext> cr = pf.createContextResolver(JAXBContext.class, null);
+        assertTrue("JAXBContext ContextProvider can not be found", 
+                   cr instanceof JAXBContextProvider);
+        
+    }
+    
     @Test
     public void testRegisterCustomEntityProvider() throws Exception {
         ProviderFactory pf = (ProviderFactory)ProviderFactory.getInstance();
-        pf.registerUserEntityProvider(new CustomWidgetProvider());
+        pf.registerUserProvider(new CustomWidgetProvider());
         
         verifyProvider(org.apache.cxf.jaxrs.resources.Book.class, CustomWidgetProvider.class, 
                        "application/widget", "User-registered provider was not returned first");
     }
     
-    private int indexOf(List<? extends Object> providers, Class providerType) {
+    private int indexOf(List<? extends Object> providerInfos, Class providerType) {
         int index = 0;
-        for (Object p : providers) {
+        for (Object pi : providerInfos) {
+            Object p = ((ProviderInfo)pi).getProvider();
             if (p.getClass().isAssignableFrom(providerType)) {
                 break;
             }
@@ -162,11 +184,11 @@
     private final class TestStringProvider 
         implements MessageBodyReader<String>, MessageBodyWriter<String>  {
 
-        public boolean isReadable(Class<?> type) {
+        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type == String.class;
         }
         
-        public boolean isWriteable(Class<?> type) {
+        public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type == String.class;
         }
         
@@ -174,8 +196,8 @@
             return s.length();
         }
 
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {
+        public String readFrom(Class<String> clazz, Type genericType, Annotation[] annotations, 
+                               MediaType m, MultivaluedMap<String, String> headers, InputStream is) {
             try {
                 return IOUtils.toString(is);
             } catch (IOException e) {
@@ -184,8 +206,8 @@
             return null;
         }
 
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
+        public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[] annotations,  
+            MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
             try {
                 os.write(obj.getBytes());
             } catch (IOException e) {
@@ -200,11 +222,11 @@
     private final class CustomJSONProvider 
         implements MessageBodyReader<String>, MessageBodyWriter<String>  {
 
-        public boolean isReadable(Class<?> type) {
+        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
-        public boolean isWriteable(Class<?> type) {
+        public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
@@ -212,14 +234,14 @@
             return s.length();
         }
 
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {    
+        public String readFrom(Class<String> clazz, Type genericType, Annotation[] annotations, 
+                               MediaType m, MultivaluedMap<String, String> headers, InputStream is) {    
             //Dummy
             return null;
         }
 
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
+        public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[] annotations,  
+            MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
             //Dummy
         }
 
@@ -230,11 +252,11 @@
     private final class CustomWidgetProvider
         implements MessageBodyReader<String>, MessageBodyWriter<String>  {
 
-        public boolean isReadable(Class<?> type) {
+        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
-        public boolean isWriteable(Class<?> type) {
+        public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations) {
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
@@ -243,16 +265,17 @@
         }
 
 
-        public String readFrom(Class<String> type, MediaType m, MultivaluedMap<String, String> headers,
-                               InputStream is) {    
+        public String readFrom(Class<String> clazz, Type genericType, Annotation[] annotations, 
+                               MediaType m, MultivaluedMap<String, String> headers, InputStream is) {    
             //Dummy
             return null;
         }
 
-        public void writeTo(String obj, MediaType m, MultivaluedMap<String, Object> headers, 
-                            OutputStream os) {
+        public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[] annotations,  
+            MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
             //Dummy
         }
 
     }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java Tue Jul  1 11:41:24 2008
@@ -38,17 +38,17 @@
     @Test
     public void testIsWriteable() {
         SourceProvider p = new SourceProvider();
-        assertTrue(p.isWriteable(StreamSource.class)
-                   && p.isWriteable(DOMSource.class)
-                   && p.isWriteable(Source.class));
+        assertTrue(p.isWriteable(StreamSource.class, null, null)
+                   && p.isWriteable(DOMSource.class, null, null)
+                   && p.isWriteable(Source.class, null, null));
     }
     
     @Test
     public void testIsReadable() {
         SourceProvider p = new SourceProvider();
-        assertTrue(p.isReadable(StreamSource.class)
-                   && p.isReadable(DOMSource.class)
-                   && p.isReadable(Source.class));
+        assertTrue(p.isReadable(StreamSource.class, null, null)
+                   && p.isReadable(DOMSource.class, null, null)
+                   && p.isReadable(Source.class, null, null));
     }
 
     @Test
@@ -64,17 +64,17 @@
         SourceProvider p = new SourceProvider();
         StreamSource s = new StreamSource(new ByteArrayInputStream("<test/>".getBytes()));
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        p.writeTo(s, null, null, os);
+        p.writeTo(s, null, null, null, null, null, os);
         assertTrue(os.toString().contains("<test/>"));
         os = new ByteArrayOutputStream();
-        p.writeTo(createDomSource(), null, null, os);
+        p.writeTo(createDomSource(), null, null, null, null, null, os);
         assertTrue(os.toString().contains("<test/>"));
     }
     
     @SuppressWarnings("unchecked")
     private <T> Object verifyRead(MessageBodyReader p, Class<T> type) throws Exception {
         return p.readFrom(type,
-                   null, null, 
+                   null, null, null, null,
                    new ByteArrayInputStream("<test/>".getBytes()));
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookInterface.java Tue Jul  1 11:41:24 2008
@@ -22,6 +22,7 @@
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 
 public interface BookInterface {
@@ -31,4 +32,7 @@
     @ProduceMime("text/bar2")
     @ConsumeMime("text/foo2")
     String getAuthor();
+    
+    @Path("/books/{bookId}/")
+    Book getBook(@PathParam("bookId") String id);
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStore.java Tue Jul  1 11:41:24 2008
@@ -33,10 +33,16 @@
     public BookStore() {
     }
 
-    @Path("/books/{bookId}/")
-    public Book getBook(@PathParam("bookId") String id) {
+    public Book getBook(String id) {
+        return null;
+    }
+    
+    @Override
+    public Book getNewBook(String id, Boolean isNew) {
         return null;
     }
+    
+    
 
     @POST
     @Path("/books")

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookStoreNoSubResource.java Tue Jul  1 11:41:24 2008
@@ -30,7 +30,7 @@
 import javax.ws.rs.core.Response;
 
 @ProduceMime("text/plain")
-@Path("/bookstore/")
+@Path("/bookstore/{id}")
 public class BookStoreNoSubResource {
 
     public BookStoreNoSubResource() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/BookSuperClass.java Tue Jul  1 11:41:24 2008
@@ -22,6 +22,7 @@
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 
 
@@ -32,4 +33,8 @@
     @ProduceMime("text/bar")
     @ConsumeMime("text/foo")
     public abstract String getDescription();
+    
+    @Path("/books/{bookId}/{new}")
+    public abstract  Book getNewBook(@PathParam("bookId") String id,
+                                     @PathParam("new") Boolean isNew);
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java?rev=673167&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java Tue Jul  1 11:41:24 2008
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.cxf.jaxrs.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("/{a}/{b}/{c}/d")
+public class TestResource {
+
+    public TestResource() {
+    }
+    
+    @GET
+    @Path("/")
+    public String listMethod() {
+        return "This is a list method";
+    }
+
+    @GET
+    @Path("/{e}")
+    public String readMethod() {
+        return "This is a list method";
+    }
+}
+
+

Copied: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (from r651969, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?p2=cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java&p1=cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java&r1=651969&r2=673167&rev=673167&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Jul  1 11:41:24 2008
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.jaxrs;
+package org.apache.cxf.jaxrs.utils;
 
 
 import java.lang.reflect.Method;
@@ -25,18 +25,9 @@
 import java.util.HashMap;
 import java.util.List;
 
-import javax.annotation.Resource;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.ConsumeMime;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-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.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -44,122 +35,66 @@
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
-
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.MessageBodyWorkers;
+import javax.xml.bind.JAXBContext;
+
+import org.apache.cxf.jaxrs.Customer;
+import org.apache.cxf.jaxrs.JAXBContextProvider;
+import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
+import org.apache.cxf.jaxrs.SimpleFactory;
+import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.MessageBodyWorkersImpl;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
+import org.apache.cxf.jaxrs.impl.RequestImpl;
+import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
+import org.apache.cxf.jaxrs.impl.UriInfoImpl;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
+import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.MethodDispatcher;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.provider.HttpHeadersImpl;
-import org.apache.cxf.jaxrs.provider.PathSegmentImpl;
-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.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSUtilsTest extends Assert {
     
-    public class Customer {
-        
-        @Context private UriInfo uriInfo;
-        @Context private HttpHeaders headers;
-        @Context private Request request;
-        @Context private SecurityContext sContext;
-        @Resource private HttpServletRequest servletRequest;
-        @Resource private HttpServletResponse servletResponse;
-        @Resource private ServletContext servletContext;
-        
-               
-        public UriInfo getUriInfo() {
-            return uriInfo;
-        }
-        
-        public HttpHeaders getHeaders() {
-            return headers;
-        }
-        
-        public Request getRequest() {
-            return request;
-        }
-        
-        public SecurityContext getSecurityContext() {
-            return sContext;
-        }
-        
-        public HttpServletRequest getServletRequest() {
-            return servletRequest;
-        }
-        
-        public HttpServletResponse getServletResponse() {
-            return servletResponse;
-        }
-        
-        public ServletContext getServletContext() {
-            return servletContext;
-        }
-
-        @ProduceMime("text/xml")
-        @ConsumeMime("text/xml")
-        public void test() {
-            // complete
-        }
-        
-        @ProduceMime("text/xml")   
-        public void getItAsXML() {
-            // complete
-        }
-        @ProduceMime("text/plain")   
-        public void getItPlain() {
-            // complete
-        }
-        
-        @ProduceMime("text/xml")   
-        public void testQuery(@QueryParam("query") String queryString, 
-                              @QueryParam("query") int queryInt) {
-            // complete
-        }
-        
-        @ProduceMime("text/xml")   
-        public void testMultipleQuery(@QueryParam("query")  String queryString, 
-                                      @QueryParam("query2") String queryString2,
-                                      @QueryParam("query3") Long queryString3,
-                                      @QueryParam("query4") boolean queryBoolean4,
-                                      @QueryParam("query5") String queryString4) {
-            // complete
-        }
-        
-        @ProduceMime("text/xml")   
-        public void testMatrixParam(@MatrixParam("p1")  String queryString, 
-                                    @MatrixParam("p2") String queryString2) {
-            // complete
-        }
-        
-        public void testParams(@Context UriInfo info,
-                               @Context HttpHeaders hs,
-                               @Context Request r,
-                               @Context SecurityContext s,
-                               @HeaderParam("Foo") String h) {
-            // complete
-        }
-        
-        @Path("{id1}/{id2}")
-        public void testConversion(@PathParam("id1") PathSegmentImpl id1,
-                                   @PathParam("id2") SimpleFactory f) {
-            // complete
-        }
-    };
-    
     @Before
     public void setUp() {
     }
 
     @Test
+    public void testSelectBetweenMultipleResourceClasses() throws Exception {
+        JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class,
+                              org.apache.cxf.jaxrs.resources.BookStore.class);
+        sf.create();        
+        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
+        MultivaluedMap<String, String> map = new MetadataMap<String, String>();
+        ClassResourceInfo bStore = JAXRSUtils.selectResourceClass(resources, "/bookstore", map);
+        assertEquals(bStore.getResourceClass(), org.apache.cxf.jaxrs.resources.BookStore.class);
+        
+        bStore = JAXRSUtils.selectResourceClass(resources, "/bookstore/", map);
+        assertEquals(bStore.getResourceClass(), 
+                     org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class);
+        
+        bStore = JAXRSUtils.selectResourceClass(resources, "/bookstore/bar", map);
+        assertEquals(bStore.getResourceClass(), 
+                     org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class);
+    }
+    
+    @Test
     public void testFindTargetResourceClass() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class);
@@ -167,55 +102,57 @@
         List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
 
         String contentTypes = "*/*";
-        String acceptContentTypes = "*/*";
-
+        
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
-        OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123/",
-             "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);       
+        OperationResourceInfo ori = findTargetResourceClass(resources, null, 
+             "/bookstore/1/books/123/", "GET", new MetadataMap<String, String>(), contentTypes, 
+             getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("getBookJSON", ori.getMethod().getName());
+        assertEquals("getBookJSON", ori.getMethodToInvoke().getName());
         
         //test
-        acceptContentTypes = "application/json";
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-             "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+             "GET", new MetadataMap<String, String>(), contentTypes, getTypes("application/json"));        
         assertNotNull(ori);
-        assertEquals("getBookJSON", ori.getMethod().getName());
+        assertEquals("getBookJSON", ori.getMethodToInvoke().getName());
         
         //test 
-        acceptContentTypes = "application/xml";
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-              "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+              "GET", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));        
         assertNotNull(ori);
-        assertEquals("getBook", ori.getMethod().getName());
+        assertEquals("getBook", ori.getMethodToInvoke().getName());
         
         //test 
-        acceptContentTypes = "application/xml";
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                      "GET", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+                      "GET", new MetadataMap<String, String>(), contentTypes, 
+                      getTypes("application/xml"));        
         assertNotNull(ori);
-        assertEquals("getBooks", ori.getMethod().getName());
+        assertEquals("getBooks", ori.getMethodToInvoke().getName());
         
         //test find POST
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-                 "POST", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);       
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+                 "POST", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));       
         assertNotNull(ori);
-        assertEquals("addBook", ori.getMethod().getName());
+        assertEquals("addBook", ori.getMethodToInvoke().getName());
         
         //test find PUT
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-            "PUT", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);  
-        assertEquals("updateBook", ori.getMethod().getName());
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+            "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));  
+        assertEquals("updateBook", ori.getMethodToInvoke().getName());
         
         //test find DELETE
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-             "DELETE", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+             "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));        
         assertNotNull(ori);
-        assertEquals("deleteBook", ori.getMethod().getName());     
+        assertEquals("deleteBook", ori.getMethodToInvoke().getName());     
         
     }
     
+    private List<MediaType> getTypes(String types) {
+        return JAXRSUtils.parseMediaTypes(types);
+    }
+    
     @Test
     public void testFindTargetResourceClassWithTemplates() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
@@ -224,15 +161,14 @@
         List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
 
         String contentTypes = "*/*";
-        String acceptContentTypes = "*/*";
-
+        
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources, "/1/2/",
-             "GET", values, contentTypes, acceptContentTypes);       
+        OperationResourceInfo ori = findTargetResourceClass(resources, null, "/1/2/",
+             "GET", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("getBooks", ori.getMethod().getName());
+        assertEquals("getBooks", ori.getMethodToInvoke().getName());
         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, 
@@ -241,10 +177,10 @@
         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);       
+        ori = findTargetResourceClass(resources, null, "/2",
+             "POST", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("updateBookStoreInfo", ori.getMethod().getName());
+        assertEquals("updateBookStoreInfo", ori.getMethodToInvoke().getName());
         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, 
@@ -252,10 +188,10 @@
         assertEquals("Only the first {id} should've been picked up", "2", values.getFirst("id"));
         
         values = new MetadataMap<String, String>();
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/3/4",
-             "PUT", values, contentTypes, acceptContentTypes);       
+        ori = findTargetResourceClass(resources, null, "/3/4",
+             "PUT", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("updateBook", ori.getMethod().getName());
+        assertEquals("updateBook", ori.getMethodToInvoke().getName());
         assertEquals("Only the first {id} should've been picked up", 3, 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("bookId").size());
@@ -266,7 +202,6 @@
     }
     
     @Test
-    @Ignore
     public void testFindTargetResourceClassWithSubResource() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
         sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
@@ -274,28 +209,33 @@
         List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
 
         String contentTypes = "*/*";
-        String acceptContentTypes = "*/*";
-
-        OperationResourceInfo ori = JAXRSUtils.findTargetResourceClass(resources,
-            "/bookstore/books/123/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes,
-                                                                       acceptContentTypes);       
+        
+        OperationResourceInfo ori = findTargetResourceClass(resources,
+               null, "/bookstore/books/123", "GET", new MetadataMap<String, String>(), contentTypes,
+               getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("getBook", ori.getMethod().getName());
+        assertEquals("getBook", ori.getMethodToInvoke().getName());
         
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-            "POST", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);      
+        ori = findTargetResourceClass(resources, null, 
+            "/bookstore/books/123/true/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes,
+            getTypes("*/*"));       
         assertNotNull(ori);
-        assertEquals("addBook", ori.getMethod().getName());
+        assertEquals("getNewBook", ori.getMethodToInvoke().getName());
         
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books",
-             "PUT", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/books",
+            "POST", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));      
         assertNotNull(ori);
-        assertEquals("updateBook", ori.getMethod().getName());
+        assertEquals("addBook", ori.getMethodToInvoke().getName());
         
-        ori = JAXRSUtils.findTargetResourceClass(resources, "/bookstore/books/123",
-            "DELETE", new MetadataMap<String, String>(), contentTypes, acceptContentTypes);        
+        ori = findTargetResourceClass(resources, null, "/bookstore/books",
+             "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));        
         assertNotNull(ori);
-        assertEquals("deleteBook", ori.getMethod().getName());
+        assertEquals("updateBook", ori.getMethodToInvoke().getName());
+        
+        ori = findTargetResourceClass(resources, null, "/bookstore/books/123",
+            "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));        
+        assertNotNull(ori);
+        assertEquals("deleteBook", ori.getMethodToInvoke().getName());
     }
 
     @Test
@@ -304,9 +244,9 @@
         List<MediaType> methodMimeTypes = new ArrayList<MediaType>(
              JAXRSUtils.parseMediaTypes("application/mytype,application/xml,application/json"));
         
-        MediaType acceptContentType = MediaType.parse("application/json");
+        MediaType acceptContentType = MediaType.valueOf("application/json");
         List <MediaType> candidateList = JAXRSUtils.intersectMimeTypes(methodMimeTypes, 
-                                                 MediaType.parse("application/json"));  
+                                                 MediaType.valueOf("application/json"));  
 
         assertEquals(1, candidateList.size());
         assertTrue(candidateList.get(0).toString().equals("application/json"));
@@ -315,7 +255,7 @@
         methodMimeTypes = JAXRSUtils.parseMediaTypes(
             "application/mytype, application/json, application/xml");
         candidateList = JAXRSUtils.intersectMimeTypes(methodMimeTypes, 
-                                                      MediaType.parse("application/json"));  
+                                                      MediaType.valueOf("application/json"));  
 
         assertEquals(1, candidateList.size());
         assertTrue(candidateList.get(0).toString().equals("application/json"));
@@ -328,7 +268,7 @@
         
         //test accept wild card application/*       
         methodMimeTypes = JAXRSUtils.parseMediaTypes("text/html,text/xml,application/xml");
-        acceptContentType = MediaType.parse("text/*");
+        acceptContentType = MediaType.valueOf("text/*");
         candidateList = JAXRSUtils.intersectMimeTypes(methodMimeTypes, acceptContentType);  
 
         assertEquals(2, candidateList.size());
@@ -390,7 +330,7 @@
         acceptedMimeTypes = JAXRSUtils.parseMediaTypes("application/mytype,application/xml");
         
         candidateList = JAXRSUtils.intersectMimeTypes(acceptedMimeTypes, 
-                                                      MediaType.parse("application/json"));
+                                                      MediaType.valueOf("application/json"));
 
         assertEquals(0, candidateList.size());
     }
@@ -424,8 +364,8 @@
     
     @Test
     public void testCompareMediaTypes() throws Exception {
-        MediaType m1 = MediaType.parse("text/xml");
-        MediaType m2 = MediaType.parse("text/*");
+        MediaType m1 = MediaType.valueOf("text/xml");
+        MediaType m2 = MediaType.valueOf("text/*");
         assertTrue("text/xml is more specific than text/*", 
                    JAXRSUtils.compareMediaTypes(m1, m2) < 0);
         assertTrue("text/* is less specific than text/*", 
@@ -436,9 +376,9 @@
                    JAXRSUtils.compareMediaTypes(m2, new MediaType("text", "*")) == 0);
         
         assertTrue("text/plain is alphabetically earlier than text/xml", 
-                   JAXRSUtils.compareMediaTypes(MediaType.parse("text/plain"), m1) < 0);
+                   JAXRSUtils.compareMediaTypes(MediaType.valueOf("text/plain"), m1) < 0);
         assertTrue("text/xml is alphabetically later than text/plain", 
-                   JAXRSUtils.compareMediaTypes(m1, MediaType.parse("text/plain")) > 0);
+                   JAXRSUtils.compareMediaTypes(m1, MediaType.valueOf("text/plain")) > 0);
         assertTrue("*/* is less specific than text/xml", 
                    JAXRSUtils.compareMediaTypes(JAXRSUtils.ALL_TYPES, m1) > 0);
         assertTrue("*/* is less specific than text/xml", 
@@ -448,10 +388,10 @@
         assertTrue("*/* is less specific than text/*", 
                    JAXRSUtils.compareMediaTypes(m2, JAXRSUtils.ALL_TYPES) < 0);
         
-        MediaType m3 = MediaType.parse("text/xml;q=0.2");
+        MediaType m3 = MediaType.valueOf("text/xml;q=0.2");
         assertTrue("text/xml should be more preferred than than text/xml;q=0.2", 
                    JAXRSUtils.compareMediaTypes(m1, m3) < 0);
-        MediaType m4 = MediaType.parse("text/xml;q=.3");
+        MediaType m4 = MediaType.valueOf("text/xml;q=.3");
         assertTrue("text/xml;q=.3 should be more preferred than than text/xml;q=0.2", 
                    JAXRSUtils.compareMediaTypes(m4, m3) < 0);
     }
@@ -498,6 +438,44 @@
     }
     
     @Test
+    public void testQueryParametersBean() throws Exception {
+        Class[] argType = {Customer.CustomerBean.class};
+        Method m = Customer.class.getMethod("testQueryBean", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        
+        messageImpl.put(Message.QUERY_STRING, "a=aValue&b=123");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+                                                           null, 
+                                                           messageImpl);
+        assertEquals("Bean should be created", 1, params.size());
+        Customer.CustomerBean cb = (Customer.CustomerBean)params.get(0);
+        assertNotNull(cb);
+        
+        assertEquals("aValue", cb.getA());
+        assertEquals(new Long(123), cb.getB());
+    }
+    
+    @Test
+    public void testPathParametersBean() throws Exception {
+        Class[] argType = {Customer.CustomerBean.class};
+        Method m = Customer.class.getMethod("testPathBean", argType);
+        MessageImpl messageImpl = new MessageImpl();
+        
+        MultivaluedMap<String, String> pathTamplates = new MetadataMap<String, String>();
+        pathTamplates.add("a", "aValue");
+        pathTamplates.add("b", "123");
+        List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null),
+                                                           pathTamplates, 
+                                                           messageImpl);
+        assertEquals("Bean should be created", 1, params.size());
+        Customer.CustomerBean cb = (Customer.CustomerBean)params.get(0);
+        assertNotNull(cb);
+        
+        assertEquals("aValue", cb.getA());
+        assertEquals(new Long(123), cb.getB());
+    }
+    
+    @Test
     public void testMultipleQueryParameters() throws Exception {
         Class[] argType = {String.class, String.class, Long.class, 
                            Boolean.TYPE, String.class};
@@ -556,21 +534,21 @@
         cri.setMethodDispatcher(md);
         
         OperationResourceInfo ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", 
-                                              new MetadataMap<String, String>(), "*/*", "text/plain");
+              new MetadataMap<String, String>(), "*/*", getTypes("text/plain"));
         
         assertSame(ori, ori2);
         
         ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
-                                              "*/*", "text/xml");
+                                              "*/*", getTypes("text/xml"));
                          
         assertSame(ori, ori1);
         
         ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
-                                          "*/*", "*,text/plain,text/xml");
+                                          "*/*", getTypes("*,text/plain,text/xml"));
                      
         assertSame(ori, ori2);
         ori = JAXRSUtils.findTargetMethod(cri, "/", "GET", new MetadataMap<String, String>(), 
-                                          "*/*", "*,x/y,text/xml,text/plain");
+                                          "*/*", getTypes("*,x/y,text/xml,text/plain"));
                      
         assertSame(ori, ori2);
     }
@@ -586,6 +564,7 @@
                                                      HttpHeaders.class, 
                                                      Request.class,
                                                      SecurityContext.class,
+                                                     MessageBodyWorkers.class,
                                                      String.class}), 
                 cri);
         ori.setHttpMethod("GET");
@@ -598,19 +577,54 @@
         
         List<Object> params = 
             JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
-        assertEquals("5 parameters expected", 5, params.size());
+        assertEquals("6 parameters expected", 6, params.size());
         assertSame(UriInfoImpl.class, params.get(0).getClass());
         assertSame(HttpHeadersImpl.class, params.get(1).getClass());
         assertSame(RequestImpl.class, params.get(2).getClass());
         assertSame(SecurityContextImpl.class, params.get(3).getClass());
-        assertSame(String.class, params.get(4).getClass());
-        assertEquals("Wrong header param", "bar,baz", params.get(4));
+        assertSame(MessageBodyWorkersImpl.class, params.get(4).getClass());
+        assertSame(String.class, params.get(5).getClass());
+        assertEquals("Wrong header param", "bar,baz", params.get(5));
     }
     
     @Test
-    public void testHttpContextFields() throws Exception {
+    public void testServletContextParameters() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        OperationResourceInfo ori = 
+            new OperationResourceInfo(
+                Customer.class.getMethod("testServletParams", 
+                                         new Class[]{HttpServletRequest.class, 
+                                                     HttpServletResponse.class, 
+                                                     ServletContext.class}), 
+                cri);
+        ori.setHttpMethod("GET");
+        HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
+        HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
+        ServletContext context = EasyMock.createMock(ServletContext.class);
+        EasyMock.replay(request);
+        EasyMock.replay(response);
+        EasyMock.replay(context);
+        
+        Message m = new MessageImpl();
+        m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
+        m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
+        m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
+        
+        List<Object> params = 
+            JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
+        assertEquals("3 parameters expected", 3, params.size());
+        assertSame(request.getClass(), params.get(0).getClass());
+        assertSame(response.getClass(), params.get(1).getClass());
+        assertSame(context.getClass(), params.get(2).getClass());
+        
+    }
+    
+    @Test
+    public void testPerRequestHttpContextFields() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
         OperationResourceInfo ori = new OperationResourceInfo(null, cri);
         
         Customer c = new Customer();
@@ -618,18 +632,124 @@
         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());
+        InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
+        assertSame(UriInfoImpl.class, c.getUriInfo2().getClass());
         assertSame(HttpHeadersImpl.class, c.getHeaders().getClass());
         assertSame(RequestImpl.class, c.getRequest().getClass());
         assertSame(SecurityContextImpl.class, c.getSecurityContext().getClass());
+        assertSame(MessageBodyWorkersImpl.class, c.getBodyWorkers().getClass());
+        
+    }
+    
+    @Test
+    public void testSingletonHttpContextFields() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        cri.setResourceProvider(new SingletonResourceProvider(c));
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        
+        Message m = new MessageImpl();
+        m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
+        
+        InjectionUtils.injectContextFields(c, cri, m);
+        assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
+        assertSame(UriInfoImpl.class, 
+                   ((ThreadLocalProxy)c.getUriInfo2()).get().getClass());
+        assertSame(HttpHeadersImpl.class, 
+                   ((ThreadLocalProxy)c.getHeaders()).get().getClass());
+        assertSame(RequestImpl.class, 
+                   ((ThreadLocalProxy)c.getRequest()).get().getClass());
+        assertSame(SecurityContextImpl.class, 
+                   ((ThreadLocalProxy)c.getSecurityContext()).get().getClass());
+        assertSame(MessageBodyWorkersImpl.class, 
+                   ((ThreadLocalProxy)c.getBodyWorkers()).get().getClass());
         
     }
+    
+    @Test
+    public void testContextAnnotationOnMethod() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        cri.setResourceProvider(new SingletonResourceProvider(c));
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        
+        JAXRSUtils.handleSetters(cri, c, new MessageImpl());
+        assertNotNull(c.getUriInfo());
+        assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
+        assertSame(UriInfoImpl.class, 
+                   ((ThreadLocalProxy)c.getUriInfo()).get().getClass());
+    }
+    
+    @Test
+    public void testParamAnnotationOnMethod() throws Exception {
 
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        Message m = new MessageImpl();
+        m.put(Message.QUERY_STRING, "a=aValue&query2=b");
+        JAXRSUtils.handleSetters(cri, c, m);
+        assertEquals("aValue", c.getQueryParam());
+        
+    }
+    
+    @Test
+    public void testParamAnnotationOnField() throws Exception {
+
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        Message m = new MessageImpl();
+        m.put(Message.QUERY_STRING, "b=bValue");
+        JAXRSUtils.handleSetters(cri, c, m);
+        assertEquals("bValue", c.getB());
+        
+    }
+
+    @Test
+    public void testContextResolverParam() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        OperationResourceInfo ori = 
+            new OperationResourceInfo(
+                Customer.class.getMethod("testContextResolvers", 
+                                         new Class[]{ContextResolver.class}), 
+                                         cri);
+        ori.setHttpMethod("GET");
+        
+        ContextResolver<JAXBContext> cr = new JAXBContextProvider();
+        ProviderFactory.getInstance().registerUserProvider(cr);
+        
+        Message m = new MessageImpl();
+            
+        List<Object> params = 
+            JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
+        assertEquals("1 parameters expected", 1, params.size());
+        assertSame(cr.getClass(), params.get(0).getClass());
+    }
+    
+    @Test
+    public void testContextResolverFields() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
+        OperationResourceInfo ori = new OperationResourceInfo(null, cri);
+        
+        Customer c = new Customer();
+        ContextResolver<JAXBContext> cr = new JAXBContextProvider();
+        ProviderFactory.getInstance().registerUserProvider(cr);
+        
+        Message m = new MessageImpl();
+            
+        InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
+        assertSame(cr.getClass(), c.getContextResolver().getClass());
+    }
+    
     @Test
     public void testServletResourceFields() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
         OperationResourceInfo ori = new OperationResourceInfo(null, cri);
         
         Customer c = new Customer();
@@ -647,11 +767,22 @@
         m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
         m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
         
-        JAXRSUtils.injectServletResourceValues(c, ori, m);
+        InjectionUtils.injectResourceFields(c, ori.getClassResourceInfo(), m);
+        assertSame(request.getClass(), c.getServletRequestResource().getClass());
+        assertSame(response.getClass(), c.getServletResponseResource().getClass());
+        assertSame(context.getClass(), c.getServletContextResource().getClass());
+        assertNull(c.getServletRequest());
+        assertNull(c.getServletResponse());
+        assertNull(c.getServletContext());
+        
+        c = new Customer();
+        InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
+        assertNull(c.getServletRequestResource());
+        assertNull(c.getServletResponseResource());
+        assertNull(c.getServletContextResource());
         assertSame(request.getClass(), c.getServletRequest().getClass());
         assertSame(response.getClass(), c.getServletResponse().getClass());
         assertSame(context.getClass(), c.getServletContext().getClass());
-        
     }
     
     @Test
@@ -680,4 +811,26 @@
         SimpleFactory sf = (SimpleFactory)params.get(1);
         assertEquals(2, sf.getId());
     }
+    
+    private static OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources,
+                                                                Message message,
+                                                                String path, 
+                                                                String httpMethod,
+                                                                MultivaluedMap<String, String> values,
+                                                                String requestContentType, 
+                                                                List<MediaType> acceptContentTypes) {
+        
+        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, path, values);
+        
+        if (resource != null) {
+            String subResourcePath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+            OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource, subResourcePath, httpMethod, 
+                                                   values, requestContentType, acceptContentTypes);
+            if (ori != null) {
+                return ori;
+            }
+        }
+        
+        return null;
+    }
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookServer.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookServer.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookServer.java Tue Jul  1 11:41:24 2008
@@ -19,22 +19,61 @@
 
 package org.apache.cxf.systest.jaxrs;
 
-import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import java.net.URISyntaxException;
+
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.handler.DefaultHandler;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
     
 public class AtomBookServer extends AbstractBusTestServerBase {
 
+    private org.mortbay.jetty.Server server;
+    
     protected void run() {
-        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        sf.setResourceClasses(AtomBookStore.class);
-        //default lifecycle is per-request, change it to singleton
-        sf.setResourceProvider(AtomBookStore.class, 
-                               new SingletonResourceProvider(new AtomBookStore()));
-        sf.setAddress("http://localhost:9080/");
+        System.out.println("Starting Server");
+
+        server = new org.mortbay.jetty.Server();
+
+        SelectChannelConnector connector = new SelectChannelConnector();
+        connector.setPort(9080);
+        server.setConnectors(new Connector[] {connector});
+
+        WebAppContext webappcontext = new WebAppContext();
+        String contextPath = null;
+        try {
+            contextPath = getClass().getResource("/jaxrs_atom").toURI().getPath();
+        } catch (URISyntaxException e1) {
+            e1.printStackTrace();
+        }
+        webappcontext.setContextPath("/");
+
+        webappcontext.setWar(contextPath);
+
+        HandlerCollection handlers = new HandlerCollection();
+        handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()});
 
-        sf.create();        
+        server.setHandler(handlers);
+        try {
+            server.start();
+                       
+        } catch (Exception e) {
+            e.printStackTrace();
+        }     
+        
     }
+    
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (server != null) {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }   
 
     public static void main(String[] args) {
         try {

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java Tue Jul  1 11:41:24 2008
@@ -32,7 +32,10 @@
 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.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.JAXBContext;
@@ -48,6 +51,7 @@
 public class AtomBookStore {
 
     @Context private UriInfo uField;
+    private HttpHeaders headers;
     private Map<Long, Book> books = new HashMap<Long, Book>();
     private Map<Long, CD> cds = new HashMap<Long, CD>();
     private long bookId = 123;
@@ -58,10 +62,23 @@
         System.out.println("----books: " + books.size());
     }
     
+    @Context
+    public void setHttpHeaders(HttpHeaders theHeaders) {
+        headers = theHeaders;
+    }
+    
     @GET
     @Path("/books/feed")
-    @ProduceMime({"application/atom+xml", "application/json" })
+    @ProduceMime({"application/json", "application/atom+xml" })
     public Feed getBooksAsFeed(@Context UriInfo uParam) {
+        
+        MediaType mt = headers.getMediaType();
+        if (!mt.equals(MediaType.valueOf(MediaType.MEDIA_TYPE_WILDCARD))
+            && !mt.equals(MediaType.APPLICATION_JSON_TYPE) 
+            && !mt.equals(MediaType.APPLICATION_ATOM_XML_TYPE)) {
+            throw new WebApplicationException();
+        }
+        
         Factory factory = Abdera.getNewFactory();
         Feed f = factory.newFeed();
         f.setBaseUri(uParam.getAbsolutePath().toString());

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomClientBookTest.java Tue Jul  1 11:41:24 2008
@@ -37,8 +37,8 @@
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.codehaus.jettison.json.JSONObject;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class AtomClientBookTest extends AbstractBusClientServerTestBase {
@@ -52,21 +52,17 @@
     }
     
     @Test
-    @Ignore("this test fails on different JDK's due to the"
-            + "maps abdera uses not being ordered so the"
-            + "strict string compares fail")
     public void testGetBooks() throws Exception {
         String endpointAddress =
             "http://localhost:9080/bookstore/books/feed"; 
         Feed feed = getFeed(endpointAddress, null);
-        assertEquals(endpointAddress, feed.getBaseUri().toString());
+        assertEquals("/bookstore/books/feed", feed.getBaseUri().toString());
         assertEquals("Collection of Books", feed.getTitle());
         
-        getAndCompareAsStrings("http://localhost:9080/bookstore/books/feed",
+        getAndCompareJson("http://localhost:9080/bookstore/books/feed",
                                "resources/expected_atom_books_json.txt",
                                "application/json");
         
-        // add new book
         Entry e = createBookEntry(256, "AtomBook");
         StringWriter w = new StringWriter();
         e.writeTo(w);
@@ -84,44 +80,46 @@
             Document<Entry> entryDoc = abdera.getParser().parse(post.getResponseBodyAsStream());
             assertEquals(entryDoc.getRoot().toString(), e.toString());
         } finally {
-            // Release current connection to the connection pool once you are done
             post.releaseConnection();
         }         
         
-        Entry entry = getEntry(location, null);
+        Entry entry = getEntry("http://localhost:9080" + location, null);
         assertEquals(location, entry.getBaseUri().toString());
         assertEquals("AtomBook", entry.getTitle());
                 
-        // get existing book
+        
         
         endpointAddress =
             "http://localhost:9080/bookstore/books/subresources/123"; 
         entry = getEntry(endpointAddress, null);
         assertEquals("CXF in Action", entry.getTitle());
         
-        // now json
-        getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123",
+        getAndCompareJson("http://localhost:9080/bookstore/books/entries/123",
                                "resources/expected_atom_book_json.txt",
                                "application/json");
         
-        // do the same using a system query
-        getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123?_contentType="
+        getAndCompareJson("http://localhost:9080/bookstore/books/entries/123?_type="
                                + "application/json",
                                "resources/expected_atom_book_json.txt",
                                "*/*");
-//      do the same using a system query shortcut
-        getAndCompareAsStrings("http://localhost:9080/bookstore/books/entries/123?_contentType="
+        getAndCompareJson("http://localhost:9080/bookstore/books/entries/123?_type="
                                + "json",
                                "resources/expected_atom_book_json.txt",
                                "*/*");
         
+        // do the same using extension mappings
+        getAndCompareJson("http://localhost:9080/bookstore/books/entries/123.json",
+                               "resources/expected_atom_book_json.txt",
+                               "*/*");
+        
         
     }
     
-    private void getAndCompareAsStrings(String address, 
-                                        String resourcePath,
-                                        String type) throws Exception {
+    private void getAndCompareJson(String address, 
+                                   String resourcePath,
+                                   String type) throws Exception {
         GetMethod get = new GetMethod(address);
+        get.setRequestHeader("Content-Type", "*/*");
         get.setRequestHeader("Accept", type);
         HttpClient httpClient = new HttpClient();
         try {
@@ -129,7 +127,12 @@
             String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
             String expected = getStringFromInputStream(
                   getClass().getResourceAsStream(resourcePath));
-            assertEquals("Atom entry should've been formatted as json", expected, jsonContent);
+            
+            JSONObject obj1 = new JSONObject(jsonContent);
+            JSONObject obj2 = new JSONObject(expected);
+            
+            assertEquals("Atom entry should've been formatted as json", 
+                         obj1.toString(), obj2.toString());
         } finally {
             get.releaseConnection();
         }
@@ -162,6 +165,7 @@
     
     private Feed getFeed(String endpointAddress, String acceptType) throws Exception {
         GetMethod get = new GetMethod(endpointAddress);
+        get.setRequestHeader("Content-Type", "*/*");
         if (acceptType != null) {
             get.setRequestHeader("Accept", acceptType);
         }
@@ -177,6 +181,7 @@
     
     private Entry getEntry(String endpointAddress, String acceptType) throws Exception {
         GetMethod get = new GetMethod(endpointAddress);
+        get.setRequestHeader("Content-Type", "*/*");
         if (acceptType != null) {
             get.setRequestHeader("Accept", acceptType);
         }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BadgerFishProvider.java Tue Jul  1 11:41:24 2008
@@ -22,11 +22,15 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.Map;
 import java.util.WeakHashMap;
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -51,13 +55,16 @@
 public final class BadgerFishProvider 
     implements MessageBodyReader<Object>, MessageBodyWriter<Object>  {
 
-    static Map<Class, JAXBContext> jaxbContexts = new WeakHashMap<Class, JAXBContext>();
-
-    public boolean isReadable(Class<?> type) {
+    
+    private static Map<Class, JAXBContext> jaxbContexts = new WeakHashMap<Class, JAXBContext>();
+    @Context
+    private HttpHeaders requestHeaders;  
+    
+    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations) {
         return type.getAnnotation(XmlRootElement.class) != null;
     }
     
-    public boolean isWriteable(Class<?> type) {
+    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations) {
         return type.getAnnotation(XmlRootElement.class) != null;
     }
 
@@ -65,8 +72,8 @@
         return -1;
     }
     
-    public Object readFrom(Class<Object> type, MediaType m, MultivaluedMap<String, String> headers,
-                           InputStream is) {
+    public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, 
+                           MediaType m, MultivaluedMap<String, String> headers, InputStream is) {
         try {
             JAXBContext context = getJAXBContext(type);
             Unmarshaller unmarshaller = context.createUnmarshaller();
@@ -85,14 +92,16 @@
         return null;
     }
 
-    public void writeTo(Object obj, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
+    public void writeTo(Object obj, Class<?> clazz, Type genericType, Annotation[] annotations,  
+        MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
         try {
+            if (!"badger-fish-language".equals(requestHeaders.getLanguage())) {
+                throw new RuntimeException();
+            }
+            
             JAXBContext context = getJAXBContext(obj.getClass());
             Marshaller marshaller = context.createMarshaller();
-            //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
-
-            // Set up the JSON StAX implementation
-            
+                        
             XMLOutputFactory factory = new BadgerFishXMLOutputFactory();
             XMLStreamWriter xsw = factory.createXMLStreamWriter(os);            
             marshaller.marshal(obj, xsw);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/Book.java Tue Jul  1 11:41:24 2008
@@ -25,6 +25,7 @@
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.ProduceMime;
 import javax.xml.bind.annotation.XmlRootElement;
 
 
@@ -39,6 +40,11 @@
         System.out.println("----chapters: " + chapters.size());
     }
     
+    public Book(String name, long id) {
+        this.name = name;
+        this.id = id;
+    }
+    
     public void setName(String n) {
         name = n;
     }
@@ -56,6 +62,7 @@
     
     @GET
     @Path("chapters/{chapterid}/")    
+    @ProduceMime("application/xml;charset=ISO-8859-1")
     public Chapter getChapter(@PathParam("chapterid")int chapterid) {
         System.out.println("----invoking getChapter with chapterid: " + chapterid);
 

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java?rev=673167&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java Tue Jul  1 11:41:24 2008
@@ -0,0 +1,40 @@
+/**
+ * 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.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+public class BookExceptionMapper implements ExceptionMapper<BookNotFoundFault> {
+
+    private boolean toHandle;
+    
+    public Response toResponse(BookNotFoundFault ex) {
+        // status is 200 just to simplify the test client code
+        if (toHandle) {
+            return Response.status(200)     
+                      .entity("No book found at all : " + ex.getFaultInfo().getId()).build();
+        }
+        return null;
+    }
+
+    public void setToHandle(Boolean toHandle) {
+        this.toHandle = toHandle;
+    }
+}

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java?rev=673167&r1=673166&r2=673167&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookInterface.java Tue Jul  1 11:41:24 2008
@@ -21,14 +21,13 @@
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.ProduceMime;
 
-import org.apache.cxf.customer.book.BookNotFoundFault;
-
 public interface BookInterface {
 
     @GET
     @Path("/thosebooks/{bookId}/")
     @ProduceMime("application/xml")
-    Book getThatBook(Long id) throws BookNotFoundFault;
+    Book getThatBook(@PathParam("bookId") Long id) throws BookNotFoundFault;
 }