Skip to content
Permalink
Browse files
CXF-5543 Fix for compile error in jaxrs systests
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1565125 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cschneider committed Feb 6, 2014
1 parent 35aa26c commit 3fae604e2ab638a5fbce479078245c75675b5e72
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
@@ -37,7 +37,6 @@
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
@@ -54,6 +53,7 @@
import org.apache.cxf.transport.jms.uri.JMSEndpoint;
import org.apache.cxf.transport.jms.uri.JMSEndpointParser;
import org.apache.cxf.transport.jms.util.JMSMessageConverter;
import org.apache.cxf.transport.jms.util.JMSUtil;

public final class JMSMessageUtils {
private static final Logger LOG = LogUtils.getL7dLogger(JMSMessageUtils.class);
@@ -62,30 +62,6 @@ private JMSMessageUtils() {

}

/**
* Create a JMS of the appropriate type populated with the given payload.
*
* @param payload the message payload, expected to be either of type String or byte[] depending on payload
* type
* @param session the JMS session
* @param replyTo the ReplyTo destination if any
* @return a JMS of the appropriate type populated with the given payload
*/
static Message createAndSetPayload(Object payload, Session session, String messageType)
throws JMSException {
Message message = null;
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);
}
return message;
}

public static org.apache.cxf.message.Message asCXFMessage(Message message, String headerType)
throws UnsupportedEncodingException, JMSException {

@@ -103,7 +79,7 @@ public static org.apache.cxf.message.Message asCXFMessage(Message message, Strin
* @throws UnsupportedEncodingException
* @throws JMSException
*/
private static void retrieveAndSetPayload(org.apache.cxf.message.Message inMessage, Message message)
public static void retrieveAndSetPayload(org.apache.cxf.message.Message inMessage, Message message)
throws UnsupportedEncodingException, JMSException {
String messageType = null;
Object converted = new JMSMessageConverter().fromMessage(message);
@@ -360,7 +336,7 @@ public static Message asJMSMessage(JMSConfiguration jmsConfig,
String headerType)
throws JMSException {

Message jmsMessage = JMSMessageUtils.createAndSetPayload(payload, session, messageType);
Message jmsMessage = JMSUtil.createAndSetPayload(payload, session, messageType);
JMSMessageHeadersType messageProperties = getOrCreateHeader(outMessage, headerType);
JMSMessageUtils.prepareJMSMessageHeaderProperties(messageProperties, outMessage, jmsConfig);
JMSMessageUtils.prepareJMSMessageProperties(messageProperties, outMessage,
@@ -18,12 +18,16 @@
*/
package org.apache.cxf.transport.jms.util;

import javax.jms.BytesMessage;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.apache.cxf.transport.jms.JMSConstants;

public final class JMSUtil {
private static final char[] CORRELATTION_ID_PADDING = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'
@@ -66,6 +70,30 @@ public static String createCorrelationId(final String prefix, long i) {
id.append(index);
return id.toString();
}

/**
* Create a JMS of the appropriate type populated with the given payload.
*
* @param payload the message payload, expected to be either of type String or byte[] depending on payload
* type
* @param session the JMS session
* @param replyTo the ReplyTo destination if any
* @return a JMS of the appropriate type populated with the given payload
*/
public static Message createAndSetPayload(Object payload, Session session, String messageType)
throws JMSException {
Message message = null;
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);
}
return message;
}


}
@@ -39,6 +39,7 @@
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.jms.util.JMSUtil;
import org.apache.cxf.transport.jms.util.ResourceCloser;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -146,7 +147,7 @@ public void testJMSMessageMarshal() throws IOException, JMSException {
try {
Session session = JMSFactory.createJmsSessionFactory(jmsConfig, closer).createSession();
javax.jms.Message jmsMessage =
JMSMessageUtils.createAndSetPayload(testBytes, session, JMSConstants.BYTE_MESSAGE_TYPE);
JMSUtil.createAndSetPayload(testBytes, session, JMSConstants.BYTE_MESSAGE_TYPE);
assertTrue("Message should have been of type BytesMessage ", jmsMessage instanceof BytesMessage);
} finally {
closer.close();
@@ -44,8 +44,8 @@
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.cxf.testutil.common.EmbeddedJMSBrokerLauncher;
import org.apache.cxf.transport.jms.JMSUtils;

import org.apache.cxf.transport.jms.JMSMessageUtils;
import org.apache.cxf.transport.jms.util.JMSUtil;
import org.junit.BeforeClass;
import org.junit.Test;

@@ -243,7 +243,7 @@ private void checkBookInResponse(Session session, Destination replyToDestination
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);
JMSMessageUtils.retrieveAndSetPayload(cxfMessage, jmsMessage);
Book b = readBook(cxfMessage.getContent(InputStream.class));
assertEquals(bookId, b.getId());
assertEquals(bookName, b.getName());
@@ -274,7 +274,7 @@ private void postOneWayBook(Session session, Destination destination)
throws Exception {
MessageProducer producer = session.createProducer(destination);

Message message = JMSUtils.createAndSetPayload(
Message message = JMSUtil.createAndSetPayload(
writeBook(new Book("JMS OneWay", 125L)), session, "byte");
message.setStringProperty("Content-Type", "application/xml");
message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway");
@@ -288,7 +288,7 @@ private void postBook(Session session, Destination destination, Destination repl
throws Exception {
MessageProducer producer = session.createProducer(destination);

Message message = JMSUtils.createAndSetPayload(writeBook(new Book("JMS", 3L)), session, "byte");
Message message = JMSUtil.createAndSetPayload(writeBook(new Book("JMS", 3L)), session, "byte");
message.setJMSReplyTo(replyTo);
// or, if oneway,
// message.setStringProperty("OnewayRequest", "true");
@@ -50,7 +50,7 @@
import org.apache.cxf.jaxrs.ext.Oneway;
import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
import org.apache.cxf.testutil.common.EmbeddedJMSBrokerLauncher;
import org.apache.cxf.transport.jms.JMSUtils;
import org.apache.cxf.transport.jms.util.JMSUtil;

@Path("/bookstore")
public class JMSBookStore {
@@ -162,8 +162,7 @@ private void postOneWayBook(Session session, Destination destination, Book book)
throws Exception {
MessageProducer producer = session.createProducer(destination);

Message message = JMSUtils.createAndSetPayload(
writeBook(book), session, "byte");
Message message = JMSUtil.createAndSetPayload(writeBook(book), session, "byte");

producer.send(message);
producer.close();

0 comments on commit 3fae604

Please sign in to comment.