cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r908451 - in /cxf/trunk: 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/apache/cxf/jaxrs/...
Date Wed, 10 Feb 2010 11:17:33 GMT
Author: sergeyb
Date: Wed Feb 10 11:17:32 2010
New Revision: 908451

URL: http://svn.apache.org/viewvc?rev=908451&view=rev
Log:
JAXRS : adding ProtocolHeaders and improving JMS test

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.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/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.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=908451&r1=908450&r2=908451&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 Wed Feb 10 11:17:32 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";

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java?rev=908451&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
Wed Feb 10 11:17:32 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.jaxrs.ext;
+
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+/**
+ * An injectable interface that provides access to protocol headers
+ *
+ */
+public interface ProtocolHeaders {
+    
+    /**
+     * Get the value of a request header.
+     * @param name the header name, case insensitive
+     * @return the header value
+     */
+    String getRequestHeaderValue(String name);
+    
+    /**
+     * Get the values of a request header.
+     * @param name the header name, case insensitive
+     * @return a read-only list of header values.
+     */
+    List<String> getRequestHeader(String name);
+    
+    /**
+     * Get the values of request headers. 
+     * @return a read-only map of header names and values.
+     */
+    MultivaluedMap<String, String> getRequestHeaders();
+    
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeaders.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java?rev=908451&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
Wed Feb 10 11:17:32 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.jaxrs.ext;
+
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.message.Message;
+
+public class ProtocolHeadersImpl implements ProtocolHeaders {
+
+    // TODO : introduce a common abstract class instead with
+    // ProtocolHeaderImpl and HttpHeadersImpl inheriting from it given that
+    // HttpHeadersImpl is just a wrapper around Message.PROTOCOL_HEADERS
+    private HttpHeadersImpl httpHeaders;
+    
+    public ProtocolHeadersImpl(Message m) {
+        httpHeaders = new HttpHeadersImpl(m);
+    }
+    
+    public List<String> getRequestHeader(String name) {
+        return httpHeaders.getRequestHeader(name);
+    }
+
+    public String getRequestHeaderValue(String name) {
+        List<String> values = getRequestHeader(name);
+        return values.size() > 0 ? values.get(0) : null;
+    }
+
+    public MultivaluedMap<String, String> getRequestHeaders() {
+        return httpHeaders.getRequestHeaders();
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ProtocolHeadersImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java?rev=908451&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
Wed Feb 10 11:17:32 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.jaxrs.impl.tl;
+
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
+
+public class ThreadLocalProtocolHeaders extends AbstractThreadLocalProxy<ProtocolHeaders>

+    implements ProtocolHeaders {
+
+
+    public MultivaluedMap<String, String> getRequestHeaders() {
+        return get().getRequestHeaders();
+    }
+
+    public List<String> getRequestHeader(String name) {
+        return get().getRequestHeader(name);
+    }
+    
+    public String getRequestHeaderValue(String name) {
+        return get().getRequestHeaderValue(name);
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProtocolHeaders.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=908451&r1=908450&r2=908451&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Feb 10 11:17:32 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/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=908451&r1=908450&r2=908451&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Feb 10 11:17:32 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;
@@ -699,6 +701,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/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=908451&r1=908450&r2=908451&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 Wed
Feb 10 11:17:32 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java?rev=908451&r1=908450&r2=908451&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
Wed Feb 10 11:17:32 2010
@@ -65,10 +65,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 {
@@ -84,28 +111,58 @@
             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();
-            JMSUtils.retrieveAndSetPayload(cxfMessage, jmsMessage, null);
-            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();
+        JMSUtils.retrieveAndSetPayload(cxfMessage, jmsMessage, null);
+        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,
@@ -115,6 +172,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);
@@ -122,7 +205,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 
@@ -135,7 +222,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();

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java?rev=908451&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
Wed Feb 10 11:17:32 2010
@@ -0,0 +1,163 @@
+/**
+ * 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.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+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;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.apache.cxf.jaxrs.ext.Oneway;
+import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
+import org.apache.cxf.transport.jms.JMSUtils;
+
+@Path("/bookstore")
+public class JMSBookStore {
+
+    @javax.ws.rs.core.Context
+    private ProtocolHeaders headers;
+    
+    private Map<Long, Book> books = new HashMap<Long, Book>();
+
+    
+    
+    public JMSBookStore() {
+        books.put(123L, new Book("CXF JMS Rocks", 123L));
+    }
+    
+
+    @GET
+    @Path("/books/{bookId}/")
+    @Produces("application/xml")
+    public Book getBook(@PathParam("bookId") String id) throws BookNotFoundFault {
+        return doGetBook(id);
+    }
+    
+    private Book doGetBook(String id) throws BookNotFoundFault {
+        Book book = books.get(Long.parseLong(id));
+        if (book != null) {
+            return book;
+        } else {
+            BookNotFoundDetails details = new BookNotFoundDetails();
+            details.setId(Long.parseLong(id));
+            throw new BookNotFoundFault(details);
+        }
+    }
+    
+    @POST
+    @Path("/books")
+    @Produces("text/xml")
+    @Consumes("application/xml")
+    public Response addBook(Book book) {
+        
+        String ct1 = headers.getRequestHeaderValue("Content-Type");
+        String ct2 = headers.getRequestHeader("Content-Type").get(0);
+        String ct3 = headers.getRequestHeaders().getFirst("Content-Type");
+        if (!("application/xml".equals(ct1) && ct1.equals(ct2) && ct1.equals(ct3)))
{
+            throw new RuntimeException("Unexpected content type");
+        }
+        if (!"custom.value".equals(headers.getRequestHeaderValue("custom.protocol.header")))
{
+            throw new RuntimeException("Custom header is not set");
+        }
+        
+        book.setId(124);
+        books.put(book.getId(), book);
+
+        return Response.ok(book).build();
+    }
+    
+    @PUT
+    @Path("/oneway")
+    @Consumes()
+    @Oneway
+    public void onewayRequest(Book book) throws Exception {
+        
+        Context ctx = getContext();
+        ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory");
+        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, replyToDestination, book);
+            session.close();
+        } finally {
+            try {
+                connection.stop();
+                connection.close();
+            } catch (JMSException ex) {
+                // ignore
+            }
+        }    
+    }
+    
+    private Context getContext() throws Exception {
+        Properties props = new Properties();
+        props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+                          "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
+        props.setProperty(Context.PROVIDER_URL, "tcp://localhost:61500");
+        return new InitialContext(props);
+        
+    }
+    
+    private void postOneWayBook(Session session, Destination destination, Book book) 
+        throws Exception {
+        MessageProducer producer = session.createProducer(destination);
+        
+        Message message = JMSUtils.createAndSetPayload(
+            writeBook(book), session, "text");
+                    
+        producer.send(message);
+        producer.close();
+    }
+    
+    private String writeBook(Book b) throws Exception {
+        JAXBContext c = JAXBContext.newInstance(new Class[]{Book.class});
+        Marshaller m = c.createMarshaller();
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        m.marshal(b, bos);
+        return bos.toString();
+    }
+}
+
+

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

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

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml?rev=908451&r1=908450&r2=908451&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/jms_server_config.xml
Wed Feb 10 11:17:32 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