cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r803460 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 12 Aug 2009 11:46:32 GMT
Author: sergeyb
Date: Wed Aug 12 11:46:32 2009
New Revision: 803460

URL: http://svn.apache.org/viewvc?rev=803460&view=rev
Log:
CXF-2389 : applying a patch (with additional tests) on behalf of Philippe Merle

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=803460&r1=803459&r2=803460&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Wed Aug 12 11:46:32 2009
@@ -27,7 +27,6 @@
 import java.net.URI;
 import java.net.URL;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -256,24 +255,6 @@
     }
 
     
-    protected List<MediaType> getAccept() {
-        List<String> headers = requestHeaders.get(HttpHeaders.ACCEPT);
-        if (headers == null || headers.size() == 0) {
-            return null;
-        }
-        List<MediaType> types = new ArrayList<MediaType>();
-        for (String s : headers) {
-            types.add(MediaType.valueOf(s));
-        }
-        return types;
-    }
-
-    
-    protected MediaType getType() {
-        String type = requestHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
-        return type == null ? null : MediaType.valueOf(type);
-    }
-
     protected UriBuilder getCurrentBuilder() {
         return currentBuilder;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=803460&r1=803459&r2=803460&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Aug 12 11:46:32 2009
@@ -25,6 +25,7 @@
 import java.lang.reflect.Method;
 import java.net.HttpURLConnection;
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -268,12 +269,12 @@
             }
         }
         
-        List<MediaType> accepts = getAccept();
+        List<MediaType> accepts = getAccept(headers);
         if (accepts == null) {
             accepts = InjectionUtils.isPrimitive(responseClass) 
                 ? Collections.singletonList(MediaType.TEXT_PLAIN_TYPE)
                 : ori.getProduceTypes().size() == 0 
-                || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD_TYPE) 
+                || ori.getProduceTypes().get(0).equals(MediaType.WILDCARD_TYPE) 
                 ? Collections.singletonList(MediaType.APPLICATION_XML_TYPE) : ori.getProduceTypes();
             for (MediaType mt : accepts) {
                 headers.add(HttpHeaders.ACCEPT, mt.toString());
@@ -283,6 +284,18 @@
         return headers;
     }
     
+    private List<MediaType> getAccept(MultivaluedMap<String, String> allHeaders)
{
+        List<String> headers = allHeaders.get(HttpHeaders.ACCEPT);
+        if (headers == null || headers.size() == 0) {
+            return null;
+        }
+        List<MediaType> types = new ArrayList<MediaType>();
+        for (String s : headers) {
+            types.add(MediaType.valueOf(s));
+        }
+        return types;
+    }
+    
     private List<Object> getPathParamValues(MultivaluedMap<ParameterType, Parameter>
map,
                                             Object[] params,
                                             OperationResourceInfo ori) {
@@ -358,7 +371,7 @@
         List<Parameter> fm = getParameters(map, ParameterType.FORM);
         for (Parameter p : fm) {
             if (params[p.getIndex()] != null) {
-                FormUtils.addPropertyToForm(form, p.getName(), params[p.getIndex()]);
+                FormUtils.addPropertyToForm(form, p.getName(), params[p.getIndex()].toString());
             }
         }
         
@@ -401,10 +414,11 @@
             m.put(URITemplate.TEMPLATE_PARAMETERS, templatesMap);
         }
         
-        if (bodyIndex != -1 || types.containsKey(ParameterType.FORM)) {
+        boolean isForm = types.containsKey(ParameterType.FORM);
+        if (bodyIndex != -1 || isForm) {
             m.setContent(OperationResourceInfo.class, ori);
             m.put("BODY_INDEX", bodyIndex);
-            Object body = bodyIndex != -1 ? params[bodyIndex] : handleForm(types, params);

+            Object body = isForm ? handleForm(types, params) : params[bodyIndex];
             MessageContentsList contents = new MessageContentsList(new Object[]{body});
             m.setContent(List.class, contents);
             m.getInterceptorChain().add(new BodyWriter());

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java?rev=803460&r1=803459&r2=803460&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresource.java Wed
Aug 12 11:46:32 2009
@@ -38,6 +38,10 @@
     @Produces("application/xml")
     Book getTheBook() throws BookNotFoundFault;
     
+    @GET
+    @Path("/subresource/noproduces")
+    Book getTheBookNoProduces() throws BookNotFoundFault;
+    
     @POST
     @Path("/subresource2/{n1:.*}")
     @Consumes("text/plain")
@@ -53,7 +57,8 @@
     @POST
     @Path("/subresource3")
     Book getTheBook3(@FormParam("id") String id,
-                     @FormParam("name") String name) throws BookNotFoundFault;
+                     @FormParam("name") String name,
+                     @FormParam("nameid") Integer nameid) throws BookNotFoundFault;
     
     @GET
     @Path("/subresource4/{id}/{name}")

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java?rev=803460&r1=803459&r2=803460&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookSubresourceImpl.java
Wed Aug 12 11:46:32 2009
@@ -53,11 +53,11 @@
         return b;
     }
     
-    public Book getTheBook3(String sid, String name) throws BookNotFoundFault {
+    public Book getTheBook3(String sid, String name, Integer nameid) throws BookNotFoundFault
{
         Book b = new Book();
         
         b.setId(Long.valueOf(sid)); 
-        b.setName(name);
+        b.setName(name + nameid.toString());
         return b;
     }
     
@@ -80,4 +80,8 @@
         return bookPath;
     }
 
+    public Book getTheBookNoProduces() throws BookNotFoundFault {
+        return getTheBook();
+    }
+
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=803460&r1=803459&r2=803460&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Wed
Aug 12 11:46:32 2009
@@ -203,6 +203,18 @@
     }
     
     @Test
+    public void testGetBookSubresourceClientNoProduces() throws Exception {
+        
+        String baseAddress = "http://localhost:9092/test/services/rest";
+        BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
+                                                                  BookStoreJaxrsJaxws.class);
+        BookSubresource bs = proxy.getBookSubresource("125");
+        Book b = bs.getTheBookNoProduces();
+        assertEquals(125, b.getId());
+        assertEquals("CXF in Action", b.getName());
+    }
+    
+    @Test
     public void testGetBookSubresourceParamExtensions() throws Exception {
         
         String baseAddress = "http://localhost:9092/test/services/rest";
@@ -295,7 +307,8 @@
         WebClient wc = WebClient.create(baseAddress);
         MultivaluedMap<String, Object> map = new MetadataMap<String, Object>();
         map.putSingle("id", "679");
-        map.putSingle("name", "CXF in Action - 679");
+        map.putSingle("name", "CXF in Action - ");
+        map.putSingle("nameid", "679");
         Book b = readBook((InputStream)wc.accept("application/xml")
                           .form((Map<String, List<Object>>)map).getEntity());
         assertEquals(679, b.getId());
@@ -308,7 +321,8 @@
         String baseAddress = "http://localhost:9092/test/services/rest/bookstore/books/679/subresource3";
         WebClient wc = WebClient.create(baseAddress);
         Form f = new Form();
-        f.set("id", "679").set("name", "CXF in Action - 679");
+        f.set("id", "679").set("name", "CXF in Action - ")
+            .set("nameid", "679");
         Book b = readBook((InputStream)wc.accept("application/xml")
                           .form(f).getEntity());
         assertEquals(679, b.getId());
@@ -322,7 +336,7 @@
         BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
                                                                   BookStoreJaxrsJaxws.class);
         BookSubresource bs = proxy.getBookSubresource("679");
-        Book b = bs.getTheBook3("679", "CXF in Action - 679");
+        Book b = bs.getTheBook3("679", "CXF in Action - ", new Integer(679));
         assertEquals(679, b.getId());
         assertEquals("CXF in Action - 679", b.getName());
     }



Mime
View raw message