Skip to content
Permalink
Browse files
CXF-5543 Removing dependency jms dependency from jaxrs systests. Some…
… other cleanup and fixes

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1565154 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cschneider committed Feb 6, 2014
1 parent 3fae604 commit b235b11b7a207d47ae00f84b4ba7b6902e699981
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 142 deletions.
@@ -40,7 +40,7 @@
import org.springframework.jms.listener.DefaultMessageListenerContainer;

/**
* Factory to create JmsTemplates and JmsListeners from configuration and context information
* Factory to create jms helper objects from configuration and context information
*/
public final class JMSFactory {
static final String MESSAGE_ENDPOINT_FACTORY = "MessageEndpointFactory";
@@ -55,7 +55,10 @@
import org.apache.cxf.transport.jms.util.JMSMessageConverter;
import org.apache.cxf.transport.jms.util.JMSUtil;

public final class JMSMessageUtils {
/**
* Static util methods for converting cxf to jms messages and vice a versa
*/
final class JMSMessageUtils {
private static final Logger LOG = LogUtils.getL7dLogger(JMSMessageUtils.class);

private JMSMessageUtils() {
@@ -28,7 +28,7 @@
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;

public final class MessageStreamUtil {
final class MessageStreamUtil {

private MessageStreamUtil() {
}
@@ -25,6 +25,7 @@
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.StreamMessage;
import javax.jms.TextMessage;

/**
@@ -67,6 +68,9 @@ public Object fromMessage(Message message) throws JMSException {
return bytes;
} else if (message instanceof ObjectMessage) {
return ((ObjectMessage)message).getObject();
} else if (message instanceof StreamMessage) {
StreamMessage streamMessage = (StreamMessage)message;
return streamMessage.readObject();
} else {
throw new IllegalArgumentException("Unsupported message type " + nullSafeClassName(message));
}
@@ -43,7 +43,7 @@ public static Message receive(Session session,
boolean pubSubNoLocal) {
ResourceCloser closer = new ResourceCloser();
try {
final String messageSelector = "JMSCorrelationID = '" + correlationId + "'";
String messageSelector = correlationId == null ? null : "JMSCorrelationID = '" + correlationId + "'";
MessageConsumer consumer = closer.register(session.createConsumer(replyToDestination, messageSelector,
pubSubNoLocal));
javax.jms.Message replyMessage = consumer.receive(receiveTimeout);
@@ -63,8 +63,8 @@ public static RuntimeException convertJmsException(JMSException e) {
return new RuntimeException(e.getMessage(), e);
}

public static String createCorrelationId(final String prefix, long i) {
String index = Long.toHexString(i);
public static String createCorrelationId(final String prefix, long sequenceNUm) {
String index = Long.toHexString(sequenceNUm);
StringBuilder id = new StringBuilder(prefix);
id.append(CORRELATTION_ID_PADDING, 0, 16 - index.length());
id.append(index);
@@ -0,0 +1,44 @@
/**
* 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.transport.jms;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.junit.Assert;
import org.junit.Test;

public class JMSMessageUtilTest extends Assert {

@Test
public void testGetEncoding() throws IOException {
assertEquals("Get the wrong encoding", JMSMessageUtils.getEncoding("text/xml; charset=utf-8"), "UTF-8");
assertEquals("Get the wrong encoding", JMSMessageUtils.getEncoding("text/xml"), "UTF-8");
assertEquals("Get the wrong encoding", JMSMessageUtils.getEncoding("text/xml; charset=GBK"), "GBK");
try {
JMSMessageUtils.getEncoding("text/xml; charset=asci");
fail("Expect the exception here");
} catch (Exception ex) {
assertTrue("we should get the UnsupportedEncodingException here",
ex instanceof UnsupportedEncodingException);
}
}

}

This file was deleted.

@@ -40,7 +40,6 @@ public class MessageIdAsCorrelationIdJMSConduitTest {
private static final String SERVICE_QUEUE = "test";
private static final String BROKER_URI = "vm://localhost?broker.persistent=false";
private ConnectionFactory connectionFactory;
//private String requestMessageId;

@Test
public void testSendReceiveWithTempReplyQueue() throws Exception {
@@ -159,11 +159,6 @@
<artifactId>cxf-rt-transports-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-jms</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-clustering</artifactId>
@@ -19,12 +19,14 @@

package org.apache.cxf.systest.jaxrs;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
@@ -44,8 +46,6 @@
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.JMSMessageUtils;
import org.apache.cxf.transport.jms.util.JMSUtil;
import org.junit.BeforeClass;
import org.junit.Test;

@@ -241,10 +241,11 @@ public void testOneWayBook() throws Exception {
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();
JMSMessageUtils.retrieveAndSetPayload(cxfMessage, jmsMessage);
Book b = readBook(cxfMessage.getContent(InputStream.class));
BytesMessage jmsMessage = (BytesMessage)consumer.receive(300000);
byte[] bytes = new byte[(int)jmsMessage.getBodyLength()];
jmsMessage.readBytes(bytes);
InputStream is = new ByteArrayInputStream(bytes);
Book b = readBook(is);
assertEquals(bookId, b.getId());
assertEquals(bookName, b.getName());
}
@@ -274,8 +275,9 @@ private void postOneWayBook(Session session, Destination destination)
throws Exception {
MessageProducer producer = session.createProducer(destination);

Message message = JMSUtil.createAndSetPayload(
writeBook(new Book("JMS OneWay", 125L)), session, "byte");
byte[] payload = writeBook(new Book("JMS OneWay", 125L));
BytesMessage message = session.createBytesMessage();
message.writeBytes(payload);
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");
@@ -287,8 +289,9 @@ private void postOneWayBook(Session session, Destination destination)
private void postBook(Session session, Destination destination, Destination replyTo)
throws Exception {
MessageProducer producer = session.createProducer(destination);

Message message = JMSUtil.createAndSetPayload(writeBook(new Book("JMS", 3L)), session, "byte");
byte[] payload = writeBook(new Book("JMS", 3L));
BytesMessage message = session.createBytesMessage();
message.writeBytes(payload);
message.setJMSReplyTo(replyTo);
// or, if oneway,
// message.setStringProperty("OnewayRequest", "true");
@@ -328,5 +331,4 @@ private byte[] writeBook(Book b) throws Exception {
return bos.toByteArray();
}


}
@@ -25,11 +25,11 @@
import java.util.Map;
import java.util.Properties;

import javax.jms.BytesMessage;
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;
@@ -50,7 +50,6 @@
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.util.JMSUtil;

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

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

BytesMessage message = session.createBytesMessage();
message.writeBytes(writeBook(book));
producer.send(message);
producer.close();
}
@@ -643,14 +643,10 @@ public void twoWayTestWithCreateMessage(final TestCaseType testcase) throws Exce
ResourceCloser closer = new ResourceCloser();
try {
Session session = JMSFactory.createJmsSessionFactory(jmsConfig, closer).createSession();

final Destination replyToDestination = jmsConfig.getReplyToDestination(session, null);
Message jmsMessage = JMSTestUtil.buildJMSMessageFromTestCase(testcase, session, replyToDestination);
Destination targetDest = jmsConfig.getTargetDestination(session);
Destination replyToDestination = jmsConfig.getReplyToDestination(session, null);
JMSSender sender = JMSFactory.createJmsSender(jmsConfig, null);
Destination targetDest =
jmsConfig.getDestinationResolver().resolveDestinationName(session,
jmsConfig.getTargetDestination(),
jmsConfig.isReplyPubSubDomain());
Message jmsMessage = JMSTestUtil.buildJMSMessageFromTestCase(testcase, session, replyToDestination);
sender.sendMessage(closer, session, targetDest, jmsMessage);
Message replyMessage = JMSUtil.receive(session, replyToDestination,
jmsMessage.getJMSMessageID(), 10000, true);
@@ -350,8 +350,7 @@
<targetService/>
<contentType>text/xml; charset=UTF-8</contentType>
<soapAction/>
<requestURI>jms:jndi:dynamicQueues/testqueue1002
</requestURI>
<requestURI>jms:jndi:dynamicQueues/testqueue1002</requestURI>
<messageBody/>
</requestMessage>
<responseMessage>
@@ -65,6 +65,7 @@ public static Bus createStaticBus(String config) throws Exception {
BusFactory.setDefaultBus(staticBus);
return staticBus;
}

public static Bus createStaticBus() throws Exception {
return createStaticBus(null);
}

0 comments on commit b235b11

Please sign in to comment.