cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1498353 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 01 Jul 2013 10:24:09 GMT
Author: sergeyb
Date: Mon Jul  1 10:24:09 2013
New Revision: 1498353

URL: http://svn.apache.org/r1498353
Log:
[CXF-5093] Updates to JAX-RS related code

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/pom.xml
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Mon Jul  1 10:24:09 2013
@@ -92,6 +92,9 @@ public class MessageContextImpl implemen
                 if (inMessage != null && inMessage != m) {
                     value = inMessage.get(key);
                 }
+                if (value == null) {
+                    value = m.getExchange().get(key);
+                }
             }
         } 
         return value;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
Jul  1 10:24:09 2013
@@ -168,6 +168,7 @@ public final class JAXRSUtils {
     public static final String MEDIA_TYPE_Q_PARAM = "q";
     public static final String MEDIA_TYPE_QS_PARAM = "qs";
     private static final String MEDIA_TYPE_DISTANCE_PARAM = "d";
+    private static final String DEFAULT_CONTENT_TYPE = "default.content.type";
     
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
@@ -827,7 +828,8 @@ public final class JAXRSUtils {
             String contentType = (String)message.get(Message.CONTENT_TYPE);
 
             if (contentType == null) {
-                contentType = MediaType.APPLICATION_OCTET_STREAM;
+                String defaultCt = (String)message.getContextualProperty(DEFAULT_CONTENT_TYPE);
+                contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
             }
 
             return readFromMessageBody(parameterClass,
@@ -1304,17 +1306,15 @@ public final class JAXRSUtils {
                 } catch (Exception ex) {
                     throw new Fault(ex);
                 }
-            } else {
-                String errorMessage = new org.apache.cxf.common.i18n.Message("NO_MSG_READER",
-                                                       BUNDLE,
-                                                       targetTypeClass.getSimpleName(),
-                                                       mediaTypeToString(contentType)).toString();
-                LOG.warning(errorMessage);
-                throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
             }
         }
 
-        return null;
+        String errorMessage = new org.apache.cxf.common.i18n.Message("NO_MSG_READER",
+                                                                     BUNDLE,
+                                                                     targetTypeClass.getSimpleName(),
+                                                                     mediaTypeToString(contentType)).toString();
+        LOG.warning(errorMessage);
+        throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
     }
     
     @SuppressWarnings("unchecked")

Modified: cxf/trunk/systests/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/pom.xml?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/pom.xml (original)
+++ cxf/trunk/systests/jaxrs/pom.xml Mon Jul  1 10:24:09 2013
@@ -203,6 +203,14 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http-hc</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
           <groupId>javax.annotation</groupId>
           <artifactId>jsr250-api</artifactId>

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Mon
Jul  1 10:24:09 2013
@@ -31,6 +31,7 @@ import javax.ws.rs.ext.ExceptionMapper;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.ext.search.QueryContextProvider;
 import org.apache.cxf.jaxrs.ext.search.SearchBean;
@@ -54,7 +55,7 @@ public class BookServer extends Abstract
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
         sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class);
-        
+        sf.getInInterceptors().add(new LoggingInInterceptor());
         List<Object> providers = new ArrayList<Object>();
         
         //default lifecycle is per-request, change it to singleton
@@ -88,6 +89,7 @@ public class BookServer extends Abstract
         sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
         sf.getProperties().put("search.visitor", new SQLPrinterVisitor<SearchBean>("books"));
         sf.getProperties().put("org.apache.cxf.http.header.split", true);
+        sf.getProperties().put("default.content.type", "*/*");
         server = sf.create();
         BusFactory.setDefaultBus(null);
         BusFactory.setThreadDefaultBus(null);

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java?rev=1498353&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java
Mon Jul  1 10:24:09 2013
@@ -0,0 +1,66 @@
+/**
+ * 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 org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+    
+public class BookServerAsyncClient extends AbstractBusTestServerBase {
+    public static final String PORT = allocatePort(BookServerAsyncClient.class);
+ 
+    org.apache.cxf.endpoint.Server server; 
+    
+    protected void run() {
+        Bus bus = BusFactory.getDefaultBus();
+        setBus(bus);
+        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+        sf.setBus(bus);
+        sf.setResourceClasses(BookStore.class);
+        sf.setResourceProvider(BookStore.class,
+                               new SingletonResourceProvider(new BookStore(), true));
+        sf.setAddress("http://localhost:" + PORT + "/");
+
+        sf.getProperties(true).put("default.content.type", "*/*");
+        server = sf.create();
+        BusFactory.setDefaultBus(null);
+        BusFactory.setThreadDefaultBus(null);
+    }
+    
+    public void tearDown() throws Exception {
+        server.stop();
+        server.destroy();
+        server = null;
+    }
+
+    public static void main(String[] args) {
+        try {
+            BookServerAsyncClient s = new BookServerAsyncClient();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

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

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

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Mon
Jul  1 10:24:09 2013
@@ -151,6 +151,14 @@ public class BookStore {
         return doGetBook("123");
     }
     
+    @RETRIEVE
+    @Path("/retrieve")
+    @Produces("application/xml")
+    @Consumes("application/xml")
+    public Book retrieveBook(Book book) {
+        return book;
+    }
+    
     @POST
     @Path("/emptyform")
     @Produces("text/plain")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1498353&r1=1498352&r2=1498353&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Mon Jul  1 10:24:09 2013
@@ -48,7 +48,6 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase {
@@ -91,35 +90,19 @@ public class JAXRS20ClientServerBookTest
     @Test
     public void testGetBook() {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
-        doTestGetBook(address);
+        doTestGetBook(address, false);
     }
     
     @Test
-    public void testGetBookAsync() throws Exception {
+    public void testGetBookSyncWithAsync() {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
-        doTestGetBookAsync(address, false);
-    }
-    
-    @Test
-    @Ignore
-    public void testGetBookAsync404() throws Exception {
-        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
-        WebClient wc = createWebClient(address);
-        Future<Book> future = wc.async().get(Book.class);
-        Book book = future.get();
-        assertEquals(124L, book.getId());
+        doTestGetBook(address, true);
     }
     
     @Test
-    @Ignore
-    public void testGetBookAsync404Callback() throws Exception {
-        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
-        WebClient wc = createWebClient(address);
-        final Holder<Book> holder = new Holder<Book>();
-        InvocationCallback<Book> callback = createCallback(holder);
-        Future<Book> future = wc.async().get(callback);
-        Book book = future.get();
-        assertEquals(124L, book.getId());
+    public void testGetBookAsync() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        doTestGetBookAsync(address, false);
     }
     
     @Test
@@ -180,7 +163,7 @@ public class JAXRS20ClientServerBookTest
     @Test
     public void testGetBookWrongPath() {
         String address = "http://localhost:" + PORT + "/wrongpath";
-        doTestGetBook(address);
+        doTestGetBook(address, false);
     }
     @Test
     public void testGetBookWrongPathAsync() throws Exception {
@@ -341,8 +324,11 @@ public class JAXRS20ClientServerBookTest
         
     }
     
-    private void doTestGetBook(String address) {
+    private void doTestGetBook(String address, boolean useAsync) {
         WebClient wc = createWebClient(address);
+        if (useAsync) {
+            WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
+        }
         Book book = wc.get(Book.class);
         assertEquals(124L, book.getId());
         validateResponse(wc);

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java?rev=1498353&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
Mon Jul  1 10:24:09 2013
@@ -0,0 +1,109 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Future;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.InvocationCallback;
+import javax.xml.ws.Holder;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase {
+    public static final String PORT = BookServerAsyncClient.PORT;
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly",
+                   launchServer(BookServerAsyncClient.class, true));
+        createStaticBus();
+    }
+    
+    @Test
+    public void testRetrieveBookCustomMethodAsyncSync() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/retrieve";
+        WebClient wc = WebClient.create(address);
+        wc.type("application/xml").accept("application/xml");
+        WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", true);
+        Book book = wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class);
+        assertEquals("Retrieve", book.getName());
+    }
+    
+    @Test
+    public void testRetrieveBookCustomMethodAsync() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/retrieve";
+        WebClient wc = WebClient.create(address);
+        wc.accept("application/xml");
+        Future<Book> book = wc.async().method("RETRIEVE", Entity.xml(new Book("Retrieve",
123L)), 
+                                              Book.class);
+        assertEquals("Retrieve", book.get().getName());
+    }
+    
+    @Test
+    @Ignore
+    public void testGetBookAsync404() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
+        WebClient wc = createWebClient(address);
+        Future<Book> future = wc.async().get(Book.class);
+        Book book = future.get();
+        assertEquals(124L, book.getId());
+    }
+    
+    @Test
+    @Ignore
+    public void testGetBookAsync404Callback() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
+        WebClient wc = createWebClient(address);
+        final Holder<Book> holder = new Holder<Book>();
+        InvocationCallback<Book> callback = createCallback(holder);
+        Future<Book> future = wc.async().get(callback);
+        Book book = future.get();
+        assertEquals(124L, book.getId());
+    }
+    
+    private WebClient createWebClient(String address) {
+        List<Object> providers = new ArrayList<Object>();
+        WebClient wc = WebClient.create(address, providers);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
+        return wc;
+    }
+    
+    private InvocationCallback<Book> createCallback(final Holder<Book> holder)
{
+        return new InvocationCallback<Book>() {
+            public void completed(Book response) {
+                holder.value = response;
+            }
+            public void failed(Throwable error) {
+                error.printStackTrace();
+            }
+        };
+    }
+    
+}

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

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



Mime
View raw message