cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r706592 - in /cxf/trunk: api/src/main/java/org/apache/cxf/message/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/j...
Date Tue, 21 Oct 2008 12:21:09 GMT
Author: sergeyb
Date: Tue Oct 21 05:21:09 2008
New Revision: 706592

URL: http://svn.apache.org/viewvc?rev=706592&view=rev
Log:
JAX-RS : Fix for CXF-1820

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java   (with
props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
    cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java Tue Oct 21 05:21:09 2008
@@ -46,6 +46,7 @@
     String ENDPOINT_ADDRESS = Message.class.getName() + ".ENDPOINT_ADDRESS";
     String HTTP_REQUEST_METHOD = Message.class.getName() + ".HTTP_REQUEST_METHOD";
     String PATH_INFO = Message.class.getName() + ".PATH_INFO";
+    String REQUEST_URI = Message.class.getName() + ".REQUEST_URI";
     String QUERY_STRING = Message.class.getName() + ".QUERY_STRING";
     String MTOM_ENABLED = "mtom-enabled";
     String MTOM_THRESHOLD = "mtom-threshold";

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Tue Oct 21 05:21:09 2008
@@ -89,7 +89,7 @@
     
     private void updatePath(Message m, String path, String suffix) {
         String newPath = path.substring(0, path.length() - (suffix.length() + 1));
-        m.put(Message.PATH_INFO, newPath);
+        m.put(Message.REQUEST_URI, newPath);
     }
     
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Tue
Oct 21 05:21:09 2008
@@ -69,7 +69,7 @@
 
     public String getPath(boolean decode) {
         
-        String path = (String)message.get(Message.PATH_INFO);
+        String path = (String)message.get(Message.REQUEST_URI);
         return decode ? JAXRSUtils.uriDecode(path) : path;
     }
 
@@ -95,7 +95,7 @@
     public URI getRequestUri() {
         String queries = (String)message.get(Message.QUERY_STRING);
         return URI.create(getEndpointAddress() 
-                          + message.get(Message.PATH_INFO)
+                          + message.get(Message.REQUEST_URI)
                           + (queries == null ? "" : "?" + queries));
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Tue Oct 21 05:21:09 2008
@@ -83,9 +83,6 @@
             }
         }
 
-        if (!path.endsWith("/")) {
-            path = path + "/";
-        }
         return path;
     }
     
@@ -96,8 +93,9 @@
             rp.preprocess(message, new UriInfoImpl(message, null));
         }
         
-        String path = (String)message.get(Message.PATH_INFO);
+        String path = (String)message.get(Message.REQUEST_URI);
         String address = (String)message.get(Message.BASE_PATH);
+        
         String httpMethod = (String)message.get(Message.HTTP_REQUEST_METHOD);
         String requestContentType = (String)message.get(Message.CONTENT_TYPE);
         if (requestContentType == null) {

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=706592&r1=706591&r2=706592&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 Tue
Oct 21 05:21:09 2008
@@ -423,7 +423,7 @@
                                              String defaultValue,
                                              boolean decode) {
         List<PathSegment> segments = JAXRSUtils.getPathSegments(
-                                      (String)m.get(Message.PATH_INFO), decode);
+                                      (String)m.get(Message.REQUEST_URI), decode);
         if (segments.size() > 0) {
             MultivaluedMap<String, String> params = 
                 segments.get(segments.size() - 1).getMatrixParameters();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriInfoImplTest.java
Tue Oct 21 05:21:09 2008
@@ -181,7 +181,7 @@
         epr.getAddress().setValue(baseAddress);
         d.getAddress();
         EasyMock.expectLastCall().andReturn(epr);
-        m.get(Message.PATH_INFO);
+        m.get(Message.REQUEST_URI);
         EasyMock.expectLastCall().andReturn(pathInfo);
         m.get(Message.QUERY_STRING);
         EasyMock.expectLastCall().andReturn(query);

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Oct 21 05:21:09 2008
@@ -528,7 +528,7 @@
         Method m = Customer.class.getMethod("testMatrixParam", argType);
         MessageImpl messageImpl = new MessageImpl();
         
-        messageImpl.put(Message.PATH_INFO, "/foo/bar;p1=1;p2");
+        messageImpl.put(Message.REQUEST_URI, "/foo/bar;p1=1;p2");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
null), 
                                                            null, messageImpl);
         assertEquals("2 Matrix params should've been identified", 2, params.size());

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Tue Oct 21 05:21:09 2008
@@ -251,6 +251,7 @@
         inMessage.put(HTTP_RESPONSE, resp);
         inMessage.put(HTTP_CONTEXT, context);
         inMessage.put(Message.HTTP_REQUEST_METHOD, req.getMethod());
+        inMessage.put(Message.REQUEST_URI, req.getRequestURI());
         String contextPath = req.getContextPath();
         if (contextPath == null) {
             contextPath = "";

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Oct 21
05:21:09 2008
@@ -91,6 +91,14 @@
         String url2 = new URL(urlValue).toString();
         int index = url2.lastIndexOf('/');
         return doGetBook(url2.substring(index + 1));
+    }
+    
+    @GET
+    @Path("/bookquery")
+    public Book getBookByURLQuery(@QueryParam("urlid") String urlValue) throws Exception
{
+        String url2 = new URL(urlValue).toString();
+        int index = url2.lastIndexOf('/');
+        return doGetBook(url2.substring(index + 1));
     } 
 
     @GET

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=706592&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Tue
Oct 21 05:21:09 2008
@@ -0,0 +1,64 @@
+/**
+ * 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.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.ProduceMime;
+
+@Path("/bookstore")
+@ProduceMime("application/json")
+public class BookStoreSpring {
+
+    private Map<Long, Book> books = new HashMap<Long, Book>();
+    private Long mainId = 123L;
+        
+    public BookStoreSpring() {
+        init();
+        System.out.println("----books: " + books.size());
+    }
+    
+    @GET
+    @Path("/books/{id}")
+    public Book getBookById(@PathParam("id") Long id) {
+        return books.get(id);
+    }
+     
+    @GET
+    public Book getDefaultBook() {
+        return books.get(mainId);
+    }  
+
+    
+    final void init() {
+        Book book = new Book();
+        book.setId(mainId);
+        book.setName("CXF in Action");
+        books.put(book.getId(), book);
+    }
+    
+}
+
+

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

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

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Oct 21 05:21:09 2008
@@ -34,7 +34,6 @@
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
@@ -53,14 +52,20 @@
     }
     
     @Test
-    @Ignore
     public void testGetBookByURL() throws Exception {
         getAndCompareAsStrings("http://localhost:9080/bookstore/bookurl/http%3A%2F%2Ftest.com%2Frss%2F123",
                                "resources/expected_get_book123.txt",
                                "application/xml", 200);
     }
     
-    
+    @Test
+    public void testGetBookByEncodedQuery() throws Exception {
+        getAndCompareAsStrings("http://localhost:9080/bookstore/bookquery?"
+                               + "urlid=http%3A%2F%2Ftest.com%2Frss%2F123",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+    }
+        
     @Test
     public void testNoRootResourceException() throws Exception {
         getAndCompare("http://localhost:9080/nobookstore/webappexception",
@@ -74,7 +79,7 @@
         // TODO : more specific message is needed
         String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
             + " xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">.No operation matching
request path "
-            + "/bookstore/booknames/123/ is found, ContentType : */*, Accept : foo/bar.</ns1:faultstring>"
+            + "/bookstore/booknames/123 is found, ContentType : */*, Accept : foo/bar.</ns1:faultstring>"
             + "</ns1:XMLFault>";
         
         getAndCompare("http://localhost:9080/bookstore/booknames/123",
@@ -128,7 +133,7 @@
         // TODO : more specific message is needed
         String msg = "<ns1:XMLFault xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\"><ns1:faultstring"
             + " xmlns:ns1=\"http://cxf.apache.org/bindings/xformat\">.No operation matching
request path "
-            + "/bookstore/books/ is found, ContentType : application/bar, Accept : text/xml."
+            + "/bookstore/books is found, ContentType : application/bar, Accept : text/xml."
             + "</ns1:faultstring></ns1:XMLFault>";
         
         String endpointAddress =

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
Tue Oct 21 05:21:09 2008
@@ -40,6 +40,17 @@
     public void testGetBook123() throws Exception {
         String endpointAddress =
             "http://localhost:9080/bookstore/books/123"; 
+        getBook(endpointAddress); 
+    }
+    
+    @Test
+    public void testGetDefaultBook() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/bookstore"; 
+        getBook(endpointAddress); 
+    }
+
+    private void getBook(String endpointAddress) throws Exception {
         URL url = new URL(endpointAddress);
         URLConnection connect = url.openConnection();
         connect.addRequestProperty("Accept", "application/json");
@@ -48,16 +59,14 @@
         InputStream expected = getClass()
             .getResourceAsStream("resources/expected_get_book123json.txt");
 
-        //System.out.println("---" + getStringFromInputStream(in));
-        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
     }
-
+    
     private String getStringFromInputStream(InputStream in) throws Exception {        
         CachedOutputStream bos = new CachedOutputStream();
         IOUtils.copy(in, bos);
         in.close();
         bos.close();
-        //System.out.println(bos.getOut().toString());        
         return bos.getOut().toString();        
     }
 

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JaxRsJaxWsBookTest.java
Tue Oct 21 05:21:09 2008
@@ -41,17 +41,12 @@
     
     @Test
     public void testGetBook123() throws Exception {
-        String endpointAddress =
-            "http://localhost:9092/rest/bookstore/123"; 
-        URL url = new URL(endpointAddress);
-        URLConnection connect = url.openConnection();
-        connect.addRequestProperty("Accept", "application/xml");
-        InputStream in = connect.getInputStream();           
-
-        InputStream expected = getClass()
-            .getResourceAsStream("resources/expected_get_book123.txt");
-
+        
+        InputStream in = getRestInputStream("http://localhost:9092/rest/bookstore/123");
+        
+        InputStream expected = getClass().getResourceAsStream("resources/expected_get_book123.txt");
         assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in));
+                
     }
     
     @Test
@@ -72,8 +67,23 @@
         IOUtils.copy(in, bos);
         in.close();
         bos.close();
-        //System.out.println(bos.getOut().toString());        
         return bos.getOut().toString();        
     }
 
+    private InputStream getRestInputStream(String endpointAddress) throws Exception {
+        URL url = new URL(endpointAddress);
+        
+        for (int count = 0; count < 25; count++) {
+            URLConnection connect = url.openConnection();
+            connect.addRequestProperty("Accept", "application/xml");
+            try {
+                return connect.getInputStream();
+            } catch (Exception ex) {
+                // continue;
+            }
+        }
+        fail("REST endpoint can not be accessed");
+        // unreachable
+        return null;
+    }
 }

Modified: cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=706592&r1=706591&r2=706592&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml Tue Oct 21 05:21:09 2008
@@ -40,7 +40,7 @@
   <jaxrs:server id="bookservice"
 		        address="/">
     <jaxrs:serviceBeans>
-      <bean class="org.apache.cxf.systest.jaxrs.BookStore" />
+      <bean class="org.apache.cxf.systest.jaxrs.BookStoreSpring" />
     </jaxrs:serviceBeans>		   
   </jaxrs:server>
 



Mime
View raw message