Author: veithen
Date: Sun Sep 14 13:35:41 2008
New Revision: 695282
URL: http://svn.apache.org/viewvc?rev=695282&view=rev
Log:
JMS transport tests: Added non Axis test client for request/response.
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSAsyncClient.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSBytesMessageFactory.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSMessageFactory.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSRequestResponseClient.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTextMessageFactory.java
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSClient.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTransportTest.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuiteBuilder.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/MessageDecoder.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/XMLMessage.java
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSAsyncClient.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSAsyncClient.java?rev=695282&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSAsyncClient.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSAsyncClient.java
Sun Sep 14 13:35:41 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.synapse.transport.jms;
+
+import javax.mail.internet.ContentType;
+
+import org.apache.synapse.transport.testkit.client.AsyncTestClient;
+import org.apache.synapse.transport.testkit.client.ClientOptions;
+
+public class JMSAsyncClient<T> extends JMSClient<T> implements
AsyncTestClient<T> {
+ public JMSAsyncClient(JMSMessageFactory<T> jmsMessageFactory) {
+ super(jmsMessageFactory);
+ }
+
+ public void sendMessage(ClientOptions options, ContentType contentType, T
message) throws Exception {
+ doSendMessage(options, contentType, message);
+ }
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSBytesMessageFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSBytesMessageFactory.java?rev=695282&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSBytesMessageFactory.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSBytesMessageFactory.java
Sun Sep 14 13:35:41 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.synapse.transport.jms;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.synapse.transport.testkit.name.Name;
+
[EMAIL PROTECTED]("bytes")
+public class JMSBytesMessageFactory implements JMSMessageFactory<byte[]> {
+ public static final JMSBytesMessageFactory INSTANCE = new
JMSBytesMessageFactory();
+
+ private JMSBytesMessageFactory() {}
+
+ public Message createMessage(Session session, byte[] data) throws
JMSException {
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(data);
+ return message;
+ }
+
+ public byte[] parseMessage(Message message) throws JMSException {
+ BytesMessage bytesMessage = (BytesMessage)message;
+ byte[] data = new byte[(int)bytesMessage.getBodyLength()];
+ bytesMessage.readBytes(data);
+ return data;
+ }
+}
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSClient.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSClient.java?rev=695282&r1=695281&r2=695282&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSClient.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSClient.java
Sun Sep 14 13:35:41 2008
@@ -22,21 +22,37 @@
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
+import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.mail.internet.ContentType;
+import org.apache.synapse.transport.base.BaseConstants;
import org.apache.synapse.transport.testkit.client.ClientOptions;
import org.apache.synapse.transport.testkit.client.TestClient;
+import org.apache.synapse.transport.testkit.name.Name;
+import org.apache.synapse.transport.testkit.name.Named;
-public class JMSClient implements TestClient {
- protected Connection connection;
- protected Session session;
- protected MessageProducer producer;
- protected ContentTypeMode contentTypeMode;
[EMAIL PROTECTED]("jms")
+public class JMSClient<T> implements TestClient {
+ protected final JMSMessageFactory<T> jmsMessageFactory;
+ private Connection connection;
+ private Session session;
+ private MessageProducer producer;
+ private ContentTypeMode contentTypeMode;
+
+ public JMSClient(JMSMessageFactory<T> jmsMessageFactory) {
+ this.jmsMessageFactory = jmsMessageFactory;
+ }
+
+ @Named
+ public JMSMessageFactory<T> getJmsMessageFactory() {
+ return jmsMessageFactory;
+ }
+
@SuppressWarnings("unused")
- private void setUp(JMSTestEnvironment env, JMSAsyncChannel channel) throws
Exception {
+ private void setUp(JMSTestEnvironment env, JMSChannel channel) throws
Exception {
Destination destination = channel.getDestination();
ConnectionFactory connectionFactory =
env.getConnectionFactory(destination);
connection = connectionFactory.createConnection();
@@ -45,6 +61,15 @@
contentTypeMode = channel.getContentTypeMode();
}
+ protected String doSendMessage(ClientOptions options, ContentType
contentType, T message) throws Exception {
+ Message jmsMessage = jmsMessageFactory.createMessage(session, message);
+ if (contentTypeMode == ContentTypeMode.TRANSPORT) {
+ jmsMessage.setStringProperty(BaseConstants.CONTENT_TYPE,
contentType.toString());
+ }
+ producer.send(jmsMessage);
+ return jmsMessage.getJMSMessageID();
+ }
+
@SuppressWarnings("unused")
private void tearDown() throws Exception {
producer.close();
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSMessageFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSMessageFactory.java?rev=695282&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSMessageFactory.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSMessageFactory.java
Sun Sep 14 13:35:41 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.synapse.transport.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+
+import org.apache.synapse.transport.testkit.name.Key;
+
[EMAIL PROTECTED]("jmsType")
+public interface JMSMessageFactory<T> {
+ Message createMessage(Session session, T data) throws JMSException;
+ T parseMessage(Message message) throws JMSException;
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSRequestResponseClient.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSRequestResponseClient.java?rev=695282&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSRequestResponseClient.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSRequestResponseClient.java
Sun Sep 14 13:35:41 2008
@@ -0,0 +1,69 @@
+/*
+ * 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.synapse.transport.jms;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.mail.internet.ContentType;
+
+import org.apache.synapse.transport.testkit.client.ClientOptions;
+import org.apache.synapse.transport.testkit.client.RequestResponseTestClient;
+import org.apache.synapse.transport.testkit.message.IncomingMessage;
+
+public class JMSRequestResponseClient<T> extends JMSClient<T> implements
RequestResponseTestClient<T,T> {
+ private Destination replyDestination;
+ private Connection replyConnection;
+ private Session replySession;
+
+ public JMSRequestResponseClient(JMSMessageFactory<T> jmsMessageFactory) {
+ super(jmsMessageFactory);
+ }
+
+ @SuppressWarnings("unused")
+ private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel
channel) throws Exception {
+ replyDestination = channel.getReplyDestination();
+ ConnectionFactory connectionFactory =
env.getConnectionFactory(replyDestination);
+ replyConnection = connectionFactory.createConnection();
+ replyConnection.start();
+ replySession = replyConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ }
+
+ public IncomingMessage<T> sendMessage(ClientOptions options, ContentType
contentType, T message) throws Exception {
+ String correlationId = doSendMessage(options, contentType, message);
+ MessageConsumer consumer =
replySession.createConsumer(replyDestination, "JMSCorrelationID = '" +
correlationId + "'");
+ try {
+ Message replyMessage = consumer.receive(8000);
+ return new IncomingMessage<T>(new
ContentType(replyMessage.getStringProperty("Content-Type")),
+
jmsMessageFactory.parseMessage(replyMessage));
+ } finally {
+ consumer.close();
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private void tearDown() throws Exception {
+ replySession.close();
+ replyConnection.close();
+ }
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTextMessageFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTextMessageFactory.java?rev=695282&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTextMessageFactory.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTextMessageFactory.java
Sun Sep 14 13:35:41 2008
@@ -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.synapse.transport.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.synapse.transport.testkit.name.Name;
+
[EMAIL PROTECTED]("text")
+public class JMSTextMessageFactory implements JMSMessageFactory<String> {
+ public static final JMSTextMessageFactory INSTANCE = new
JMSTextMessageFactory();
+
+ private JMSTextMessageFactory() {}
+
+ public Message createMessage(Session session, String data) throws
JMSException {
+ TextMessage message = session.createTextMessage();
+ message.setText(data);
+ return message;
+ }
+
+ public String parseMessage(Message message) throws JMSException {
+ return ((TextMessage)message).getText();
+ }
+}
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTransportTest.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTransportTest.java?rev=695282&r1=695281&r2=695282&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTransportTest.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/jms/JMSTransportTest.java
Sun Sep 14 13:35:41 2008
@@ -41,9 +41,9 @@
TransportTestSuite suite = new
TransportTestSuite(JMSTransportTest.class);
// SwA doesn't make sense with text messages
- suite.addExclude("(&(test=AsyncSwA)(client=TextMessage))");
+ suite.addExclude("(&(test=AsyncSwA)(client=jms)(jmsType=text))");
// SYNAPSE-304:
- suite.addExclude("(&(test=AsyncTextPlain)(client=BytesMessage))");
+
suite.addExclude("(&(test=AsyncTextPlain)(client=jms)(jmsType=bytes))");
// SYNAPSE-436:
suite.addExclude("(&(test=EchoXML)(replyDestType=topic)(endpoint=axis))");
@@ -62,8 +62,8 @@
builder.addAxisAsyncTestClient(new AxisAsyncTestClient());
builder.addAxisAsyncTestClient(new AxisAsyncTestClient(), new
JMSAxisTestClientSetup(JMSConstants.JMS_BYTE_MESSAGE));
builder.addAxisAsyncTestClient(new AxisAsyncTestClient(), new
JMSAxisTestClientSetup(JMSConstants.JMS_TEXT_MESSAGE));
- builder.addByteArrayAsyncTestClient(new JMSBytesMessageClient());
- builder.addStringAsyncTestClient(new JMSTextMessageClient());
+ builder.addByteArrayAsyncTestClient(new
JMSAsyncClient<byte[]>(JMSBytesMessageFactory.INSTANCE));
+ builder.addStringAsyncTestClient(new
JMSAsyncClient<String>(JMSTextMessageFactory.INSTANCE));
builder.addAxisAsyncEndpoint(new AxisAsyncEndpoint());
@@ -77,6 +77,7 @@
};
builder.addAxisRequestResponseTestClient(new
AxisRequestResponseTestClient(), timeoutSetup);
+ builder.addStringRequestResponseTestClient(new
JMSRequestResponseClient<String>(JMSTextMessageFactory.INSTANCE));
builder.addEchoEndpoint(new MockEchoEndpoint());
builder.addEchoEndpoint(new AxisEchoEndpoint());
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuiteBuilder.java?rev=695282&r1=695281&r2=695282&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuiteBuilder.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuiteBuilder.java
Sun Sep 14 13:35:41 2008
@@ -163,6 +163,10 @@
xmlRequestResponseClients.add(adapt(client,
MessageEncoder.XML_TO_BYTE, MessageDecoder.BYTE_TO_XML), relatedResources);
}
+ public void
addStringRequestResponseTestClient(RequestResponseTestClient<String,String>
client, Object... relatedResources) {
+ xmlRequestResponseClients.add(adapt(client,
MessageEncoder.XML_TO_STRING, MessageDecoder.STRING_TO_XML), relatedResources);
+ }
+
public void addEchoEndpoint(Endpoint endpoint, Object... relatedResources)
{
echoEndpoints.add(endpoint, relatedResources);
}
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/MessageDecoder.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/MessageDecoder.java?rev=695282&r1=695281&r2=695282&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/MessageDecoder.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/MessageDecoder.java
Sun Sep 14 13:35:41 2008
@@ -21,6 +21,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -113,18 +114,11 @@
new MessageDecoder<byte[],XMLMessage>() {
public XMLMessage decode(ContentType contentType, byte[] message)
throws Exception {
- String baseType = contentType.getBaseType();
- ByteArrayInputStream in = new ByteArrayInputStream(message);
- XMLMessage.Type type = null;
- for (XMLMessage.Type candidate : XMLMessage.Type.values()) {
- if (candidate.getContentType().getBaseType().equals(baseType))
{
- type = candidate;
- break;
- }
- }
+ XMLMessage.Type type =
XMLMessage.getTypeFromContentType(contentType);
if (type == null) {
- throw new Exception("Unrecognized content type " + baseType);
+ throw new Exception("Unrecognized content type " +
contentType);
}
+ ByteArrayInputStream in = new ByteArrayInputStream(message);
if (type == XMLMessage.Type.SWA) {
Attachments attachments = new Attachments(in,
contentType.toString());
XMLStreamReader reader =
StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream());
@@ -142,6 +136,25 @@
}
}
};
+
+ MessageDecoder<String,XMLMessage> STRING_TO_XML =
+ new MessageDecoder<String,XMLMessage>() {
+
+ public XMLMessage decode(ContentType contentType, String message)
throws Exception {
+ XMLMessage.Type type =
XMLMessage.getTypeFromContentType(contentType);
+ if (type == null) {
+ throw new Exception("Unrecognized content type " +
contentType);
+ }
+ XMLStreamReader reader = StAXUtils.createXMLStreamReader(new
StringReader(message));
+ OMElement payload;
+ if (type == XMLMessage.Type.POX) {
+ payload = new StAXOMBuilder(reader).getDocumentElement();
+ } else {
+ payload = new
StAXSOAPModelBuilder(reader).getSOAPEnvelope().getBody().getFirstElement();
+ }
+ return new XMLMessage(payload, type);
+ }
+ };
MessageDecoder<byte[],String> BYTE_TO_STRING =
new MessageDecoder<byte[],String>() {
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/XMLMessage.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/XMLMessage.java?rev=695282&r1=695281&r2=695282&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/XMLMessage.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/message/XMLMessage.java
Sun Sep 14 13:35:41 2008
@@ -94,4 +94,16 @@
public Attachments getAttachments() {
return attachments;
}
+
+ public static Type getTypeFromContentType(ContentType contentType) {
+ String baseType = contentType.getBaseType();
+ Type type = null;
+ for (Type candidate : Type.values()) {
+ if (candidate.getContentType().getBaseType().equals(baseType)) {
+ type = candidate;
+ break;
+ }
+ }
+ return type;
+ }
}