cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r775241 - in /cxf/trunk: 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/test/java/org/apache/cxf/jaxrs/impl/ systests/src/test/java/org/apac...
Date Fri, 15 May 2009 17:16:22 GMT
Author: sergeyb
Date: Fri May 15 17:16:22 2009
New Revision: 775241

URL: http://svn.apache.org/viewvc?rev=775241&view=rev
Log:
JAX-RS : moving JAXRSInInterceptor to Phase.UNMARSHAL, support for relative URIs in ResponseBuilder.location

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamReaderInInterceptor.java
  (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamWriterOutInterceptor.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/AtomBookStore.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.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/XmlStreamReaderProvider.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
    cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Fri May 15 17:16:22 2009
@@ -33,9 +33,12 @@
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.core.Variant;
 
 import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public final class ResponseBuilderImpl extends ResponseBuilder {
     private int status = 200;
@@ -91,6 +94,13 @@
     }
 
     public ResponseBuilder location(URI location) {
+        if (!location.isAbsolute()) {
+            Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
+            if (currentMessage != null) {
+                UriInfo ui = new UriInfoImpl(currentMessage.getExchange().getInMessage(),
null);
+                location = ui.getBaseUriBuilder().path(location.toString()).build();
+            }
+        }
         return setHeader(HttpHeaders.LOCATION, location);
     }
 

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=775241&r1=775240&r2=775241&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
Fri May 15 17:16:22 2009
@@ -56,7 +56,7 @@
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSInInterceptor.class);
 
     public JAXRSInInterceptor() {
-        super(Phase.PRE_STREAM);
+        super(Phase.UNMARSHAL);
     }
 
     public void handleMessage(Message message) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Fri May 15 17:16:22 2009
@@ -39,7 +39,14 @@
 
 public class ResponseBuilderImplTest extends Assert {
 
-        
+     
+    @Test
+    public void testAbsoluteLocation() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.putSingle("Location", "http://localhost/rest");
+        checkBuild(Response.ok().location(URI.create("http://localhost/rest")).build(), 200,
null, m);
+    }
+    
     @Test
     public void testLanguage() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();

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=775241&r1=775240&r2=775241&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 Fri May
15 17:16:22 2009
@@ -121,8 +121,6 @@
             Book b = (Book)jc.createUnmarshaller().unmarshal(reader);
             books.put(b.getId(), b);
             
-            // this code is broken as Response does not
-            
             URI uri = 
                 uField.getBaseUriBuilder().path("books").path("entries") 
                                                 .path(Long.toString(b.getId())).build();
@@ -132,6 +130,25 @@
         }
     }
     
+    @POST
+    @Path("/books/feed/relative")
+    @Consumes("application/atom+xml")
+    public Response addBookAsEntryRelativeURI(Entry e) throws Exception {
+        try {
+            String text = e.getContentElement().getValue();
+            StringReader reader = new StringReader(text);
+            JAXBContext jc = JAXBContext.newInstance(Book.class);
+            Book b = (Book)jc.createUnmarshaller().unmarshal(reader);
+            books.put(b.getId(), b);
+            
+            URI uri = URI.create("books/entries/" + Long.toString(b.getId()));
+            return Response.created(uri).entity(e).build();
+        } catch (Exception ex) {
+            return Response.serverError().build();
+        }
+    }
+    
+    
     @GET
     @Path("/books/entries/{bookId}/")
     @Produces({"application/atom+xml", "application/json" })

Modified: 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=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Fri
May 15 17:16:22 2009
@@ -27,6 +27,7 @@
 import javax.ws.rs.GET;
 import javax.ws.rs.MatrixParam;
 import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -107,6 +108,14 @@
         return b;
     }
     
+    @PUT
+    @Path("books/convert2")
+    @Consumes({"application/xml", "application/json", "application/jettison" })
+    @Produces("application/xml")
+    public Book convertBook2(Book2 book) {
+        return convertBook(book);
+    }
+    
     @GET
     @Path("books/aegis")
     @Produces({"application/html;q=1.0", "application/xml;q=0.5", "application/json;q=0.5"
})

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java?rev=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAtomBookTest.java Fri
May 15 17:16:22 2009
@@ -71,32 +71,8 @@
                           + " application/xhtml+xml, image/png, image/jpeg, image/gif,"
                           + " image/x-xbitmap, */*;q=0.1");
         
-        Entry e = createBookEntry(256, "AtomBook");
-        StringWriter w = new StringWriter();
-        e.writeTo(w);
-        
-        PostMethod post = new PostMethod(endpointAddress);
-        post.setRequestEntity(
-             new StringRequestEntity(w.toString(), "application/atom+xml", null));
-        HttpClient httpclient = new HttpClient();
-        
-        String location = null;
-        try {
-            int result = httpclient.executeMethod(post);
-            assertEquals(201, result);
-            location = post.getResponseHeader("Location").getValue();
-            InputStream ins = post.getResponseBodyAsStream();
-            Document<Entry> entryDoc = abdera.getParser().parse(copyIn(ins));
-            assertEquals(entryDoc.getRoot().toString(), e.toString());
-        } finally {
-            post.releaseConnection();
-        }         
-        
-        Entry entry = getEntry(location, null);
-        assertEquals(location, entry.getBaseUri().toString());
-        assertEquals("AtomBook", entry.getTitle());
-                
-        
+        Entry entry = addEntry(endpointAddress);
+        entry = addEntry(endpointAddress + "/relative");
         
         endpointAddress =
             "http://localhost:9080/bookstore/bookstore/books/subresources/123"; 
@@ -124,6 +100,34 @@
         
     }
     
+    private Entry addEntry(String endpointAddress) throws Exception {
+        Entry e = createBookEntry(256, "AtomBook");
+        StringWriter w = new StringWriter();
+        e.writeTo(w);
+        
+        PostMethod post = new PostMethod(endpointAddress);
+        post.setRequestEntity(
+             new StringRequestEntity(w.toString(), "application/atom+xml", null));
+        HttpClient httpclient = new HttpClient();
+        
+        String location = null;
+        try {
+            int result = httpclient.executeMethod(post);
+            assertEquals(201, result);
+            location = post.getResponseHeader("Location").getValue();
+            InputStream ins = post.getResponseBodyAsStream();
+            Document<Entry> entryDoc = abdera.getParser().parse(copyIn(ins));
+            assertEquals(entryDoc.getRoot().toString(), e.toString());
+        } finally {
+            post.releaseConnection();
+        }         
+        
+        Entry entry = getEntry(location, null);
+        assertEquals(location, entry.getBaseUri().toString());
+        assertEquals("AtomBook", entry.getTitle());
+        return entry;
+    }
+    
     @Test
     public void testGetBooks2() throws Exception {
         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=775241&r1=775240&r2=775241&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
Fri May 15 17:16:22 2009
@@ -202,7 +202,22 @@
     }
     
     @Test
-    public void testGetBookReaderWriter() throws Exception {
+    public void testReaderWriterFromJaxrsFilters() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/the/thebooks5/bookstore/books/convert2";
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.type("application/xml").accept("application/xml");
+        Book2 b = new Book2();
+        b.setId(777L);
+        b.setName("CXF - 777");
+        Book2 b2 = wc.invoke("PUT", b, Book2.class);
+        assertNotSame(b, b2);
+        assertEquals(777, b2.getId());
+        assertEquals("CXF - 777", b2.getName());
+    }
+    
+    @Test
+    public void testReaderWriterFromInterceptors() throws Exception {
         String endpointAddress =
             "http://localhost:9080/the/thebooks5/bookstore/books/convert";
         WebClient wc = WebClient.create(endpointAddress);
@@ -210,7 +225,7 @@
         Book2 b = new Book2();
         b.setId(777L);
         b.setName("CXF - 777");
-        Book2 b2 = wc.post(b, Book2.class);
+        Book2 b2 = wc.invoke("POST", b, Book2.class);
         assertNotSame(b, b2);
         assertEquals(777, b2.getId());
         assertEquals("CXF - 777", b2.getName());

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamReaderInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamReaderInInterceptor.java?rev=775241&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamReaderInInterceptor.java
(added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamReaderInInterceptor.java
Fri May 15 17:16:22 2009
@@ -0,0 +1,46 @@
+/**
+ * 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.io.InputStream;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class XMLStreamReaderInInterceptor extends AbstractPhaseInterceptor<Message>
{
+
+    public XMLStreamReaderInInterceptor() {
+        super(Phase.POST_STREAM);
+    }
+    
+    public void handleMessage(Message m) throws Fault {
+        String method = m.get(Message.HTTP_REQUEST_METHOD).toString();
+        if ("POST".equals(method)) {
+            XMLStreamReader reader = 
+                StaxUtils.createXMLStreamReader(m.getContent(InputStream.class));
+            m.setContent(XMLStreamReader.class, new CustomXmlStreamReader(reader));
+        }
+    }
+
+}

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

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

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamWriterOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamWriterOutInterceptor.java?rev=775241&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamWriterOutInterceptor.java
(added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XMLStreamWriterOutInterceptor.java
Fri May 15 17:16:22 2009
@@ -0,0 +1,46 @@
+/**
+ * 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.io.OutputStream;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
+
+public class XMLStreamWriterOutInterceptor extends AbstractOutDatabindingInterceptor {
+
+    public XMLStreamWriterOutInterceptor() {
+        super(Phase.PRE_MARSHAL);
+    }
+    
+    public void handleMessage(Message m) throws Fault {
+        String method = m.getExchange().getInMessage().get(Message.HTTP_REQUEST_METHOD).toString();
+        if ("POST".equals(method)) {
+            XMLStreamWriter writer = 
+                StaxUtils.createXMLStreamWriter(m.getContent(OutputStream.class));
+            m.setContent(XMLStreamWriter.class, new CustomXmlStreamWriter(writer));
+        }
+    }
+
+}

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

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

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java?rev=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamReaderProvider.java
Fri May 15 17:16:22 2009
@@ -32,7 +32,7 @@
 
     public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
         String method = m.get(Message.HTTP_REQUEST_METHOD).toString();
-        if ("POST".equals(method)) {
+        if ("PUT".equals(method)) {
             XMLStreamReader reader = 
                 StaxUtils.createXMLStreamReader(m.getContent(InputStream.class));
             m.setContent(XMLStreamReader.class, new CustomXmlStreamReader(reader));

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java?rev=775241&r1=775240&r2=775241&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
Fri May 15 17:16:22 2009
@@ -32,7 +32,7 @@
 
     public Response handleResponse(Message m, OperationResourceInfo ori, Response response)
{
         String method = ori.getHttpMethod();
-        if ("POST".equals(method)) {
+        if ("PUT".equals(method)) {
             XMLStreamWriter writer = 
                 StaxUtils.createXMLStreamWriter(m.getContent(OutputStream.class));
             m.setContent(XMLStreamWriter.class, new CustomXmlStreamWriter(writer));

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=775241&r1=775240&r2=775241&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 Fri May 15 17:16:22 2009
@@ -101,6 +101,15 @@
        <bean class="org.apache.cxf.systest.jaxrs.XmlStreamReaderProvider"/>
        <bean class="org.apache.cxf.systest.jaxrs.XmlStreamWriterProvider"/>
     </jaxrs:providers> 
+    
+    <jaxrs:inInterceptors>
+       <bean class="org.apache.cxf.systest.jaxrs.XMLStreamReaderInInterceptor"/>
+    </jaxrs:inInterceptors>
+    
+    <jaxrs:outInterceptors>
+       <bean class="org.apache.cxf.systest.jaxrs.XMLStreamWriterOutInterceptor"/>
+    </jaxrs:outInterceptors>
+    
   </jaxrs:server> 
   
   <util:map id="outTemplates">



Mime
View raw message