cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ulhasbh...@apache.org
Subject svn commit: r570831 - in /incubator/cxf/trunk: rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/ rt/transports/jms/src/main/resources/schemas/wsdl/ rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/ systests/src/test/java/org/apa...
Date Wed, 29 Aug 2007 15:00:41 GMT
Author: ulhasbhole
Date: Wed Aug 29 08:00:40 2007
New Revision: 570831

URL: http://svn.apache.org/viewvc?rev=570831&view=rev
Log:
* Added support for handling ByteMessage in JMS conduit and destination.


Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
    incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConstants.java
    incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
    incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSTransportBase.java
    incubator/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd
    incubator/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/Server.java
    incubator/cxf/trunk/testutils/src/main/resources/wsdl/jms_test.wsdl

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
(original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
Wed Aug 29 08:00:40 2007
@@ -31,7 +31,6 @@
 import javax.jms.JMSException;
 import javax.jms.Queue;
 import javax.jms.QueueSender;
-import javax.jms.TextMessage;
 import javax.jms.Topic;
 import javax.jms.TopicPublisher;
 import javax.naming.NamingException;
@@ -158,9 +157,7 @@
         if (jmsMessage != null) {
             
             base.populateIncomingContext(jmsMessage, outMessage, JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
-            String messageType = jmsMessage instanceof TextMessage 
-                        ? JMSConstants.TEXT_MESSAGE_TYPE : JMSConstants.BINARY_MESSAGE_TYPE;
-            result = base.unmarshal(jmsMessage, messageType);
+            result = base.unmarshal(jmsMessage);
             return result;
         } else {
             String error = "JMSClientTransport.receive() timed out. No message available.";

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConstants.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConstants.java
(original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConstants.java
Wed Aug 29 08:00:40 2007
@@ -26,6 +26,7 @@
 
     public static final String TEXT_MESSAGE_TYPE = "text";
     public static final String BINARY_MESSAGE_TYPE = "binary";
+    public static final String BYTE_MESSAGE_TYPE = "byte";
 
     public static final String JMS_POOLEDSESSION = "jms.pooled.session";   
     public static final String JMS_SERVER_REQUEST_HEADERS = "org.apache.cxf.jms.server.request.headers";

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
Wed Aug 29 08:00:40 2007
@@ -34,6 +34,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.jms.BytesMessage;
 import javax.jms.JMSException;
 import javax.jms.Queue;
 import javax.jms.QueueSender;
@@ -171,19 +172,18 @@
     
     protected void incoming(javax.jms.Message message) throws IOException {
         try {
-            getLogger().log(Level.FINE, "server received request: ", message);          

-
-            String msgType = message instanceof TextMessage 
-                    ? JMSConstants.TEXT_MESSAGE_TYPE : JMSConstants.BINARY_MESSAGE_TYPE;
-            Object request = base.unmarshal(message, msgType);
+            getLogger().log(Level.FINE, "server received request: ", message);
+           
+            Object request = base.unmarshal(message);
             getLogger().log(Level.FINE, "The Request Message is [ " + request + "]");
             byte[] bytes = null;
 
-            if (JMSConstants.TEXT_MESSAGE_TYPE.equals(msgType)) {
+            if (message instanceof TextMessage) {
                 String requestString = (String)request;
                 getLogger().log(Level.FINE, "server received request: ", requestString);
                 bytes = requestString.getBytes();
             } else {
+                //Both ByteMessage and ObjectMessage would get unmarshalled to byte array.
                 bytes = (byte[])request;
             }
 
@@ -406,28 +406,34 @@
                     replySession = base.sessionFactory.get(false);
                     sender = (QueueSender)replySession.producer();
                     
-                    boolean textPayload = request instanceof TextMessage 
-                        ? true : false;
-                    if (textPayload) {
-                        
+                    if (request instanceof TextMessage) {
                         reply = base.marshal(currentStream.toString(), 
-                                            replySession.session(), 
-                                            null, 
-                                            JMSConstants.TEXT_MESSAGE_TYPE);
+                                             replySession.session(), 
+                                             null, 
+                                             JMSConstants.TEXT_MESSAGE_TYPE);
                         getLogger().log(Level.FINE,
-                                        "The response message is ["
-                                        + currentStream.toString() + "]");
+                                         "The response message is ["
+                                         + currentStream.toString() + "]");
+                    } else if (request instanceof BytesMessage) {
+                        reply = base.marshal(((ByteArrayOutputStream)currentStream).toByteArray(),
+                                             replySession.session(),
+                                             null, 
+                                             JMSConstants.BYTE_MESSAGE_TYPE);
+                        getLogger().log(Level.FINE, "The response message is [" 
+                                             + new String((
+                                                 (ByteArrayOutputStream)currentStream).toByteArray())

+                                             + "]");
                     } else {
                         reply = base.marshal(((ByteArrayOutputStream)currentStream).toByteArray(),
-                                           replySession.session(),
-                                           null, 
-                                          JMSConstants.BINARY_MESSAGE_TYPE);
+                                             replySession.session(),
+                                             null, 
+                                            JMSConstants.BINARY_MESSAGE_TYPE);
                         getLogger().log(Level.FINE, "The response message is [" 
-                                           + new String(((ByteArrayOutputStream)currentStream).toByteArray())

-                                           + "]");
-                    }     
-                     
-                    
+                                             + new String((
+                                                 (ByteArrayOutputStream)currentStream).toByteArray())

+                                             + "]");
+                    }
+                   
                     setReplyCorrelationID(request, reply);
                     
                     base.setMessageProperties(headers, reply);

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSTransportBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSTransportBase.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSTransportBase.java
(original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSTransportBase.java
Wed Aug 29 08:00:40 2007
@@ -22,6 +22,7 @@
 import java.util.Enumeration;
 import java.util.List;
 
+import javax.jms.BytesMessage;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -85,6 +86,10 @@
 
         if (JMSConstants.TEXT_MESSAGE_TYPE.equals(messageType)) {
             message = session.createTextMessage((String)payload);
+        } else if (JMSConstants.BYTE_MESSAGE_TYPE.equals(messageType)) {
+            message = session.createBytesMessage();
+            ((BytesMessage)message).writeBytes((byte[])payload);
+            
         } else {
             message = session.createObjectMessage();
             ((ObjectMessage)message).setObject((byte[])payload);
@@ -105,11 +110,15 @@
      * @return the unmarshalled message payload, either of type String or
      * byte[] depending on payload type
      */
-    protected Object unmarshal(Message message, String messageType) throws JMSException {
+    protected Object unmarshal(Message message) throws JMSException {
         Object ret = null;
 
-        if (JMSConstants.TEXT_MESSAGE_TYPE.equals(messageType)) {
+        if (message instanceof TextMessage) {
             ret = ((TextMessage)message).getText();
+        } else if (message instanceof BytesMessage) {
+            byte[] retBytes = new byte[(int) ((BytesMessage) message).getBodyLength()];
+            ((BytesMessage) message).readBytes(retBytes);
+            ret = retBytes;
         } else {
             ret = (byte[])((ObjectMessage)message).getObject();
         }

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd (original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/resources/schemas/wsdl/jms.xsd Wed Aug
29 08:00:40 2007
@@ -114,6 +114,7 @@
         <xs:restriction base="xs:string">
             <xs:enumeration value="text"/>
             <xs:enumeration value="binary"/>
+            <xs:enumeration value="byte"/>
         </xs:restriction>
     </xs:simpleType>
     

Modified: incubator/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
Wed Aug 29 08:00:40 2007
@@ -25,6 +25,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import javax.jms.BytesMessage;
+
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.message.Message;
@@ -126,7 +128,29 @@
                
     }
     
-    
-   
+    @Test
+    public void testJMSMessageMarshal() throws Exception {
+        setupServiceInfo("http://cxf.apache.org/hello_world_jms", 
+                         "/wsdl/jms_test.wsdl", 
+                         "HelloWorldServiceLoop", 
+                         "HelloWorldPortLoop");
 
+        String testMsg = "Test Message"; 
+        JMSConduit conduit = setupJMSConduit(true, false); 
+        Message msg = new MessageImpl();
+        conduit.prepare(msg);
+        PooledSession sess = conduit.base.sessionFactory.get(true);
+        byte [] b = testMsg.getBytes();
+        javax.jms.Message message = conduit.base.marshal(b, 
+                                                         sess.session(), 
+                                                         null, JMSConstants.BYTE_MESSAGE_TYPE);
+        
+        assertTrue("Message should have been of type BytesMessage ", 
+                   message instanceof BytesMessage);
+//        byte[] returnBytes = new byte[(int)((BytesMessage) message).getBodyLength()];
+//        ((BytesMessage) message).readBytes(returnBytes);
+//        assertTrue("Message marshalled was incorrect", 
+//                   testMsg.equals(new String(returnBytes)));
+    }
+    
 }

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java?rev=570831&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
Wed Aug 29 08:00:40 2007
@@ -0,0 +1,97 @@
+/**
+ * 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.jms;
+
+import javax.annotation.Resource;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.cxf.hello_world_jms.BadRecordLitFault;
+import org.apache.cxf.hello_world_jms.HelloWorldPortType;
+import org.apache.cxf.hello_world_jms.NoSuchCodeLitFault;
+import org.apache.cxf.hello_world_jms.types.BadRecordLit;
+import org.apache.cxf.hello_world_jms.types.ErrorCode;
+import org.apache.cxf.hello_world_jms.types.NoSuchCodeLit;
+import org.apache.cxf.hello_world_jms.types.TestRpcLitFaultResponse;
+import org.apache.cxf.transport.jms.JMSConstants;
+import org.apache.cxf.transport.jms.JMSMessageHeadersType;
+import org.apache.cxf.transport.jms.JMSPropertyType;
+
+
+
+@WebService(serviceName = "HWByteMsgService", 
+            portName = "HWSByteMsgPort",
+            endpointInterface = "org.apache.cxf.hello_world_jms.HelloWorldPortType",
+            targetNamespace = "http://cxf.apache.org/hello_world_jms",
+            wsdlLocation = "testutils/jms_test.wsdl")
+public class GreeterByteMessageImpl implements HelloWorldPortType {
+    @Resource
+    protected WebServiceContext wsContext;
+    public String greetMe(String me) {
+        MessageContext mc = wsContext.getMessageContext();
+        JMSMessageHeadersType headers =
+            (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_REQUEST_HEADERS);
+        System.out.println("get the message headers JMSCorrelationID" + headers.getJMSCorrelationID());
+        System.out.println("Reached here :" + me);
+        
+        // set reply header custom property
+        JMSPropertyType testProperty = new JMSPropertyType();
+        testProperty.setName("Test_Prop");
+        testProperty.setValue("some return value "  + me);
+        
+        System.out.println("found property in request headers at index: " 
+                           + headers.getProperty().indexOf(testProperty));
+        
+        JMSMessageHeadersType responseHeaders =
+            (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_RESPONSE_HEADERS);
+        responseHeaders.getProperty().add(testProperty);
+        
+        return "Hello " + me;
+    }
+
+    public String sayHi() {        
+        return "Bonjour";
+    }
+    
+    public void greetMeOneWay(String requestType) {
+        System.out.println("*********  greetMeOneWay: " + requestType);
+    }
+    
+    public TestRpcLitFaultResponse testRpcLitFault(String faultType) 
+        throws BadRecordLitFault, NoSuchCodeLitFault {
+        BadRecordLit badRecord = new BadRecordLit();
+        badRecord.setReason("BadRecordLitFault");
+        if (faultType.equals(BadRecordLitFault.class.getSimpleName())) {
+            throw new BadRecordLitFault("TestBadRecordLit", badRecord);
+        }
+        if (faultType.equals(NoSuchCodeLitFault.class.getSimpleName())) {
+            ErrorCode ec = new ErrorCode();
+            ec.setMajor((short)1);
+            ec.setMinor((short)1);
+            NoSuchCodeLit nscl = new NoSuchCodeLit();
+            nscl.setCode(ec);
+            throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
+        }
+        
+        return new TestRpcLitFaultResponse();
+    }
+    
+    
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/GreeterByteMessageImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/JMSClientServerTest.java
Wed Aug 29 08:00:40 2007
@@ -30,6 +30,7 @@
 
 
 import org.apache.cxf.hello_world_jms.BadRecordLitFault;
+import org.apache.cxf.hello_world_jms.HWByteMsgService;
 import org.apache.cxf.hello_world_jms.HelloWorldOneWayPort;
 import org.apache.cxf.hello_world_jms.HelloWorldOneWayQueueService;
 import org.apache.cxf.hello_world_jms.HelloWorldPortType;
@@ -160,6 +161,35 @@
                     assertNotNull(nslf.getFaultInfo());
                     assertNotNull(nslf.getFaultInfo().getCode());
                 } 
+            }
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+    
+    @Test
+    public void testByteMessage() throws Exception {
+        QName serviceName = getServiceName(new QName("http://cxf.apache.org/hello_world_jms",

+                                 "HWByteMsgService"));
+        URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
+        assertNotNull(wsdl);
+
+        HWByteMsgService service = new HWByteMsgService(wsdl, serviceName);
+        assertNotNull(service);
+
+        String response1 = new String("Hello Milestone-");
+        String response2 = new String("Bonjour");
+        try {
+            HelloWorldPortType greeter = service.getHWSByteMsgPort();
+            for (int idx = 0; idx < 2; idx++) {
+                String greeting = greeter.greetMe("Milestone-" + idx);
+                assertNotNull("no response received from service", greeting);
+                String exResponse = response1 + idx;
+                assertEquals(exResponse, greeting);
+
+                String reply = greeter.sayHi();
+                assertNotNull("no response received from service", reply);
+                assertEquals(response2, reply);
             }
         } catch (UndeclaredThrowableException ex) {
             throw (Exception)ex.getCause();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/Server.java?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/Server.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/Server.java Wed
Aug 29 08:00:40 2007
@@ -30,11 +30,13 @@
         Object impl2 =  new GreeterImplQueueOneWay();
         Object impl3  = new GreeterImplTopicOneWay();
         Object impleDoc = new GreeterImplDoc();
+        Object impl4 = new GreeterByteMessageImpl();
         Endpoint.publish(null, impleDoc);
         String address = "http://localhost:9000/SoapContext/SoapPort";
         Endpoint.publish(address, implementor);
         Endpoint.publish("http://testaddr.not.required/", impl2);
         Endpoint.publish("http://testaddr.not.required.topic/", impl3);
+        Endpoint.publish("http://testaddr.not.required.byte/", impl4);
     }
 
 

Modified: incubator/cxf/trunk/testutils/src/main/resources/wsdl/jms_test.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/wsdl/jms_test.wsdl?rev=570831&r1=570830&r2=570831&view=diff
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/wsdl/jms_test.wsdl (original)
+++ incubator/cxf/trunk/testutils/src/main/resources/wsdl/jms_test.wsdl Wed Aug 29 08:00:40
2007
@@ -378,6 +378,20 @@
             <jms:server durableSubscriberName="CXF_subscriber"/>
         </port>
     </service>
+    <service name="HWByteMsgService">
+        <port binding="tns:HelloWorldPortBinding" name="HWSByteMsgPort">
+            <jms:address
+                jndiConnectionFactoryName="ConnectionFactory" 
+                jndiDestinationName="dynamicQueues/test.jmstransport.binary"
+                jndiReplyDestinationName="dynamicQueues/test.jmstransport.binary.reply">
+                <jms:JMSNamingProperty name="java.naming.factory.initial" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/>
+                <jms:JMSNamingProperty name="java.naming.provider.url" value="tcp://localhost:61500"/>
+            </jms:address>
+            
+            <jms:client messageType="byte"/>
+            <jms:server durableSubscriberName="CXF_subscriber"/>
+        </port>
+    </service>
 
     <service name="HWStaticReplyQTextMsgService">
            <port binding="tns:HWStaticReplyQTextPortBinding" name="HWStaticReplyQTextPort">



Mime
View raw message