cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r909430 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/message/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ rt/frontend/jaxrs/src/main/java/org...
Date Fri, 12 Feb 2010 14:38:45 GMT
Author: sergeyb
Date: Fri Feb 12 14:38:44 2010
New Revision: 909430

URL: http://svn.apache.org/viewvc?rev=909430&view=rev
Log:
Merged revisions 908451 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r908451 | sergeyb | 2010-02-10 11:17:32 +0000 (Wed, 10 Feb 2010) | 1 line
  
  JAXRS : adding ProtocolHeaders and improving JMS test
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
      - copied unchanged from r908451, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
      - copied unchanged from r908451, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
      - copied unchanged from r908451, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
      - copied unchanged from r908451, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:908451

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/message/Message.java Fri Feb
12 14:38:44 2010
@@ -68,13 +68,15 @@
     String DECOUPLED_CHANNEL_MESSAGE = "decoupled.channel.message";
     String PARTIAL_RESPONSE_MESSAGE = "org.apache.cxf.partial.response";
     String ONE_WAY_REQUEST = "OnewayRequest";
+
+    
+    String HTTP_REQUEST_METHOD = "org.apache.cxf.request.method";
+    String REQUEST_URI = "org.apache.cxf.request.uri";
     
     String PROTOCOL_HEADERS = Message.class.getName() + ".PROTOCOL_HEADERS";
     String RESPONSE_CODE = Message.class.getName() + ".RESPONSE_CODE";
     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 PROPOGATE_EXCEPTION = Message.class.getName() + ".PROPOGATE_EXCEPTION";

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Fri Feb 12 14:38:44 2010
@@ -75,6 +75,7 @@
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.Description;
+import org.apache.cxf.jaxrs.ext.Oneway;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.ext.xml.XMLName;
 import org.apache.cxf.jaxrs.ext.xml.XMLSource;
@@ -272,7 +273,8 @@
         sb.append("<response");
         boolean isVoid = void.class == ori.getMethodToInvoke().getReturnType();
         if (isVoid) {
-            sb.append(" status=\"204\"");
+            boolean oneway = ori.getMethodToInvoke().getAnnotation(Oneway.class) != null;
+            sb.append(" status=\"" + (oneway ? 202 : 204) + "\"");
         }
         sb.append(">");
         if (void.class != ori.getMethodToInvoke().getReturnType()) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Fri Feb 12 14:38:44 2010
@@ -68,6 +68,7 @@
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.ParameterHandler;
+import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalContextResolver;
@@ -75,6 +76,7 @@
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletResponse;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageContext;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProtocolHeaders;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest;
@@ -697,6 +699,8 @@
             proxy = new ThreadLocalUriInfo();
         } else if (HttpHeaders.class.isAssignableFrom(type)) {
             proxy = new ThreadLocalHttpHeaders();
+        } else if (ProtocolHeaders.class.isAssignableFrom(type)) {
+            proxy = new ThreadLocalProtocolHeaders();
         } else if (SecurityContext.class.isAssignableFrom(type)) {
             proxy = new ThreadLocalSecurityContext();
         } else if (ContextResolver.class.isAssignableFrom(type)) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Fri Feb 12 14:38:44 2010
@@ -72,6 +72,8 @@
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
+import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
+import org.apache.cxf.jaxrs.ext.ProtocolHeadersImpl;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
@@ -769,8 +771,9 @@
         Object o = null;
         if (UriInfo.class.isAssignableFrom(clazz)) {
             o = createUriInfo(contextMessage);
-        } else if (HttpHeaders.class.isAssignableFrom(clazz)) {
-            o = createHttpHeaders(contextMessage);
+        } else if (HttpHeaders.class.isAssignableFrom(clazz)
+            || ProtocolHeaders.class.isAssignableFrom(clazz)) {
+            o = createHttpHeaders(contextMessage, clazz);
         } else if (Request.class.isAssignableFrom(clazz)) {
             o = new RequestImpl(contextMessage);
         } else if (SecurityContext.class.isAssignableFrom(clazz)) {
@@ -797,11 +800,12 @@
         return new UriInfoImpl(m, templateParams);
     }
     
-    private static HttpHeaders createHttpHeaders(Message m) {
+    private static Object createHttpHeaders(Message m, Class<?> ctxClass) {
         if (MessageUtils.isRequestor(m)) {
             m = m.getExchange() != null ? m.getExchange().getOutMessage() : m;
         }
-        return new HttpHeadersImpl(m);
+        return HttpHeaders.class.isAssignableFrom(ctxClass) ? new HttpHeadersImpl(m)
+            : new ProtocolHeadersImpl(m);
     }
     
     public static ContextResolver<?> createContextResolver(Type genericType, Message
m) {

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
Fri Feb 12 14:38:44 2010
@@ -66,10 +66,37 @@
         assertTrue("server did not launch correctly", 
                    launchServer(EmbeddedJMSBrokerLauncher.class, props, null));
         assertTrue("server did not launch correctly",
-                   launchServer(JMSServer.class, false));
+                   launchServer(JMSServer.class));
         serversStarted = true;
     }
     
+    @Test
+    public void testGetBook() throws Exception {
+        Context ctx = getContext();
+        ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory");
+        
+        Destination destination = (Destination)ctx.lookup("dynamicQueues/test.jmstransport.text");
+        Destination replyToDestination = (Destination)ctx.lookup("dynamicQueues/test.jmstransport.response");
+                
+        Connection connection = null;
+        try {
+            connection = factory.createConnection();
+            connection.start();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            postGetMessage(session, destination, replyToDestination);
+            checkBookInResponse(session, replyToDestination, 123L, "CXF JMS Rocks");
+            session.close();
+        } finally {
+            try {
+                connection.stop();
+                connection.close();
+            } catch (JMSException ex) {
+                // ignore
+            }
+        }
+        
+    }
+    
     
     @Test
     public void testAddGetBook() throws Exception {
@@ -85,29 +112,59 @@
             connection.start();
             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
             postBook(session, destination, replyToDestination);
-            MessageConsumer consumer = session.createConsumer(replyToDestination);
-            Message jmsMessage = consumer.receive(3000);
-            org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
-            byte[] bytes = JMSUtils.retrievePayload(jmsMessage, null);
-            cxfMessage.setContent(InputStream.class, new ByteArrayInputStream(bytes));
-            Book b = readBook(cxfMessage.getContent(InputStream.class));
-            assertEquals(124L, b.getId());
-            assertEquals("JMS", b.getName());
+            checkBookInResponse(session, replyToDestination, 124L, "JMS");
             session.close();
         } finally {
-            if (connection != null) {
-                try {
-                    connection.stop();
-                    connection.close();
-                } catch (JMSException ex) {
-                    // ignore
-                }
+            try {
+                connection.stop();
+                connection.close();
+            } catch (JMSException ex) {
+                // ignore
+            }
+        }
+        
+    }
+    
+    @Test
+    public void testOneWayBook() throws Exception {
+        Context ctx = getContext();
+        ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory");
+
+        Destination destination = (Destination)ctx.lookup("dynamicQueues/test.jmstransport.text");
+        Destination replyToDestination = (Destination)ctx.lookup("dynamicQueues/test.jmstransport.response");
                 
+        Connection connection = null;
+        try {
+            connection = factory.createConnection();
+            connection.start();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            postOneWayBook(session, destination);
+            checkBookInResponse(session, replyToDestination, 125L, "JMS OneWay");
+            session.close();
+        } finally {
+            try {
+                connection.stop();
+                connection.close();
+            } catch (JMSException ex) {
+                // ignore
             }
         }
         
     }
     
+    
+    private void checkBookInResponse(Session session, Destination replyToDestination,
+                                     long bookId, String bookName) throws Exception {
+        MessageConsumer consumer = session.createConsumer(replyToDestination);
+        Message jmsMessage = consumer.receive(300000);
+        org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
+        byte[] bytes = JMSUtils.retrievePayload(jmsMessage, null);
+        cxfMessage.setContent(InputStream.class, new ByteArrayInputStream(bytes));
+        Book b = readBook(cxfMessage.getContent(InputStream.class));
+        assertEquals(bookId, b.getId());
+        assertEquals(bookName, b.getName());
+    }
+    
     private Context getContext() throws Exception {
         Properties props = new Properties();
         props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
@@ -117,6 +174,32 @@
         
     }
     
+    private void postGetMessage(Session session, Destination destination, Destination replyTo)

+        throws Exception {
+        MessageProducer producer = session.createProducer(destination);
+        Message message = session.createMessage();
+        message.setJMSReplyTo(replyTo);
+        message.setStringProperty("Accept", "application/xml");
+        message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books/123");
+        message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "GET");
+        producer.send(message);
+        producer.close();
+    }
+    
+    private void postOneWayBook(Session session, Destination destination) 
+        throws Exception {
+        MessageProducer producer = session.createProducer(destination);
+        
+        Message message = JMSUtils.createAndSetPayload(
+            writeBook(new Book("JMS OneWay", 125L)), session, "text");
+        message.setStringProperty("Content-Type", "application/xml");
+        message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway");
+        message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "PUT");
+                    
+        producer.send(message);
+        producer.close();
+    }
+    
     private void postBook(Session session, Destination destination, Destination replyTo)

         throws Exception {
         MessageProducer producer = session.createProducer(destination);
@@ -124,7 +207,11 @@
         Message message = JMSUtils.createAndSetPayload(writeBook(new Book("JMS", 3L)), session,
"text");
         message.setJMSReplyTo(replyTo);
         // or, if oneway,
-        // message.setStringProperty("OnewayMessage", "true");
+        // message.setStringProperty("OnewayRequest", "true");
+        // we could've set this header in JMSDestination if no replyTo were set
+        // but in CXF one could also provide the replyTo in the configuration
+        // so it is just simpler to set this header if needed to avoid some
+        // complex logic on the server side
         
         // all these properties are optional
         // CXF JAXRS and JMS Transport will default to 
@@ -137,7 +224,7 @@
         message.setStringProperty("Accept", "text/xml");
         message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books");
         message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "POST");
-            
+        message.setStringProperty("custom.protocol.header", "custom.value");    
                     
         producer.send(message);
         producer.close();

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml?rev=909430&r1=909429&r2=909430&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
Fri Feb 12 14:38:44 2010
@@ -63,7 +63,7 @@
                 transportId="http://cxf.apache.org/transports/jms"
 		        address="/">
     <jaxrs:serviceBeans>
-      <bean class="org.apache.cxf.systest.jaxrs.BookStore" />
+      <bean class="org.apache.cxf.systest.jaxrs.JMSBookStore" />
     </jaxrs:serviceBeans>		
   </jaxrs:server>
 



Mime
View raw message