Author: veithen
Date: Sun Nov 9 08:48:33 2008
New Revision: 712510
URL: http://svn.apache.org/viewvc?rev=712510&view=rev
Log:
SYNAPSE-424 (part 2): Allow specifying the message property for the content
type of outgoing message, using a message context property or an EPR parameter.
Added:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java
(with props)
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
webservices/commons/trunk/modules/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSChannel.java
webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java
Sun Nov 9 08:48:33 2008
@@ -56,6 +56,10 @@
* The Parameter name indicating the response JMS destination. i.e.
DESTINATION_TYPE_QUEUE, DESTINATION_TYPE_TOPIC
*/
public static final String REPLY_PARAM_TYPE =
"transport.jms.ReplyDestinationType";
+ /**
+ * The EPR parameter name indicating the message property to use to store
the content type.
+ */
+ public static final String CONTENT_TYPE_PROPERTY_PARAM =
"transport.jms.ContentTypeProperty";
/**
* Values used for DEST_PARAM_TYPE, REPLY_PARAM_TYPE
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
Sun Nov 9 08:48:33 2008
@@ -176,11 +176,6 @@
endpoint.setDestinationType(JMSConstants.DESTINATION_TYPE_QUEUE);
}
- // compute service EPR and keep for later use
- endpoint.setEndpointReference(JMSUtils.getEPR(cf,
endpoint.getDestinationType(),
- endpoint.getJndiDestinationName()));
- serviceNameToEndpointMap.put(service.getName(), endpoint);
-
Parameter contentTypeParam =
service.getParameter(JMSConstants.CONTENT_TYPE_PARAM);
if (contentTypeParam == null) {
ContentTypeRuleSet contentTypeRuleSet = new ContentTypeRuleSet();
@@ -192,6 +187,10 @@
endpoint.setContentTypeRuleSet(ContentTypeRuleFactory.parse(contentTypeParam));
}
+ // compute service EPR and keep for later use
+ endpoint.setEndpointReference(JMSUtils.getEPR(cf, endpoint));
+ serviceNameToEndpointMap.put(service.getName(), endpoint);
+
log.info("Starting to listen on destination : " +
endpoint.getJndiDestinationName() + " of type "
+ endpoint.getDestinationType() + " for service " +
service.getName());
cf.addDestination(endpoint);
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
Sun Nov 9 08:48:33 2008
@@ -21,6 +21,7 @@
import org.apache.axis2.transport.base.BaseUtils;
import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.base.MetricsCollector;
+import org.apache.axis2.transport.jms.ctype.ContentTypeInfo;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisOperation;
@@ -174,39 +175,38 @@
msgContext.setSoapAction("urn:" +
operation.getName().getLocalPart());
}
+ ContentTypeInfo contentTypeInfo =
+
endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
+ if (contentTypeInfo == null) {
+ throw new AxisFault("Unable to determine content type for
message " +
+ msgContext.getMessageID());
+ }
+
// set the message property OUT_TRANSPORT_INFO
// the reply is assumed to be over the JMSReplyTo destination,
using
// the same incoming connection factory, if a JMSReplyTo is
available
- if (message.getJMSReplyTo() != null) {
- msgContext.setProperty(
- Constants.OUT_TRANSPORT_INFO,
- new JMSOutTransportInfo(jmsConnectionFactory,
message.getJMSReplyTo()));
-
- } else if (service != null) {
+ Destination replyTo = message.getJMSReplyTo();
+ if (replyTo == null) {
// does the service specify a default reply destination ?
Parameter param =
service.getParameter(JMSConstants.REPLY_PARAM);
if (param != null && param.getValue() != null) {
- msgContext.setProperty(
- Constants.OUT_TRANSPORT_INFO,
- new JMSOutTransportInfo(
- jmsConnectionFactory,
- jmsConnectionFactory.getDestination((String)
param.getValue())));
+ replyTo = jmsConnectionFactory.getDestination((String)
param.getValue());
}
+
}
-
- String contentType =
endpoint.getContentTypeRuleSet().getContentType(message);
- if (contentType == null) {
- throw new AxisFault("Unable to determine content type for
message " +
- msgContext.getMessageID());
+ if (replyTo != null) {
+ msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
+ new JMSOutTransportInfo(jmsConnectionFactory,
replyTo,
+
contentTypeInfo.getPropertyName()));
}
-
- JMSUtils.setSOAPEnvelope(message, msgContext, contentType);
+
+ JMSUtils.setSOAPEnvelope(message, msgContext,
contentTypeInfo.getContentType());
jmsListener.handleIncomingMessage(
msgContext,
JMSUtils.getTransportHeaders(message),
soapAction,
- contentType
+ contentTypeInfo.getContentType()
);
metrics.incrementMessagesReceived();
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java
Sun Nov 9 08:48:33 2008
@@ -65,6 +65,9 @@
private Hashtable<String,String> properties = null;
/** the target EPR string where applicable */
private String targetEPR = null;
+ /** the message property name that stores the content type of the outgoing
message */
+ private String contentTypeProperty;
+
private String contentType = null;
/**
@@ -73,11 +76,13 @@
* @param jmsConnectionFactory the JMS connection factory
* @param dest the destination
*/
- JMSOutTransportInfo(JMSConnectionFactory jmsConnectionFactory, Destination
dest) {
+ JMSOutTransportInfo(JMSConnectionFactory jmsConnectionFactory, Destination
dest,
+ String contentTypeProperty) {
this.jmsConnectionFactory = jmsConnectionFactory;
this.destination = dest;
destinationType = dest instanceof Topic ?
JMSConstants.DESTINATION_TYPE_TOPIC
:
JMSConstants.DESTINATION_TYPE_QUEUE;
+ this.contentTypeProperty = contentTypeProperty;
}
/**
@@ -99,10 +104,8 @@
if(replyDestinationType != null) {
setReplyDestinationType(replyDestinationType);
}
- String replyDestinationName =
properties.get(JMSConstants.REPLY_PARAM);
- if(replyDestinationName != null) {
- setReplyDestinationName(replyDestinationName);
- }
+ replyDestinationName = properties.get(JMSConstants.REPLY_PARAM);
+ contentTypeProperty =
properties.get(JMSConstants.CONTENT_TYPE_PROPERTY_PARAM);
try {
context = new InitialContext(properties);
} catch (NamingException e) {
@@ -277,4 +280,12 @@
public void setReplyDestinationName(String replyDestinationName) {
this.replyDestinationName = replyDestinationName;
}
+
+ public String getContentTypeProperty() {
+ return contentTypeProperty;
+ }
+
+ public void setContentTypeProperty(String contentTypeProperty) {
+ this.contentTypeProperty = contentTypeProperty;
+ }
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
Sun Nov 9 08:48:33 2008
@@ -171,12 +171,22 @@
// defined JMS connection factory, we need to synchronize as
sessions are not
// thread safe
synchronized(session) {
+ // The message property to be used to send the content type is
determined by
+ // the out transport info, i.e. either from the EPR if we are
sending a request,
+ // or, if we are sending a response, from the configuration of
the service that
+ // received the request). The property name can be overridden
by a message
+ // context property.
+ String contentTypeProperty =
+
(String)msgCtx.getProperty(JMSConstants.CONTENT_TYPE_PROPERTY_PARAM);
+ if (contentTypeProperty == null) {
+ contentTypeProperty = jmsOut.getContentTypeProperty();
+ }
// convert the axis message context into a JMS Message that we
can send over JMS
Message message = null;
String correlationId = null;
try {
- message = createJMSMessage(msgCtx, session);
+ message = createJMSMessage(msgCtx, session,
contentTypeProperty);
} catch (JMSException e) {
handleException("Error creating a JMS message from the
axis message context", e);
}
@@ -238,8 +248,12 @@
try {
correlationId = message.getJMSMessageID();
} catch(JMSException ignore) {}
- waitForResponseAndProcess(session, replyDestination,
- jmsOut.getReplyDestinationType(), msgCtx,
correlationId);
+
+ // We assume here that the response uses the same message
property to
+ // specify the content type of the message.
+ waitForResponseAndProcess(session, replyDestination,
+ jmsOut.getReplyDestinationType(), msgCtx,
correlationId,
+ contentTypeProperty);
}
}
@@ -259,10 +273,13 @@
* @param session the session to use to listen for the response
* @param replyDestination the JMS reply Destination
* @param msgCtx the outgoing message for which we are expecting the
response
+ * @param contentTypeProperty the message property used to determine the
content type
+ * of the response message
* @throws AxisFault on error
*/
private void waitForResponseAndProcess(Session session, Destination
replyDestination,
- String replyDestinationType, MessageContext msgCtx, String
correlationId) throws AxisFault {
+ String replyDestinationType, MessageContext msgCtx, String
correlationId,
+ String contentTypeProperty) throws AxisFault {
try {
MessageConsumer consumer;
@@ -299,7 +316,7 @@
}
try {
- processSyncResponse(msgCtx, reply);
+ processSyncResponse(msgCtx, reply, contentTypeProperty);
metrics.incrementMessagesReceived();
} catch (AxisFault e) {
metrics.incrementFaultsReceiving();
@@ -326,12 +343,14 @@
*
* @param msgContext the MessageContext
* @param session the JMS session
+ * @param contentTypeProperty the message property to be used to store the
+ * content type
* @return a JMS message from the context and session
* @throws JMSException on exception
* @throws AxisFault on exception
*/
- private Message createJMSMessage(MessageContext msgContext, Session
session)
- throws JMSException, AxisFault {
+ private Message createJMSMessage(MessageContext msgContext, Session
session,
+ String contentTypeProperty) throws JMSException, AxisFault {
Message message = null;
String msgType = getProperty(msgContext,
JMSConstants.JMS_MESSAGE_TYPE);
@@ -388,7 +407,10 @@
txtMsg.setText(sw.toString());
message = txtMsg;
}
- message.setStringProperty(BaseConstants.CONTENT_TYPE, contentType);
+
+ if (contentTypeProperty != null) {
+ message.setStringProperty(contentTypeProperty, contentType);
+ }
} else if (JMSConstants.JMS_BYTE_MESSAGE.equals(jmsPayloadType)) {
message = session.createBytesMessage();
@@ -462,9 +484,12 @@
*
* @param outMsgCtx the outgoing message for which we are expecting the
response
* @param message the JMS response message received
+ * @param contentTypeProperty the message property used to determine the
content type
+ * of the response message
* @throws AxisFault on error
*/
- private void processSyncResponse(MessageContext outMsgCtx, Message
message) throws AxisFault {
+ private void processSyncResponse(MessageContext outMsgCtx, Message message,
+ String contentTypeProperty) throws AxisFault {
MessageContext responseMsgCtx =
createResponseMessageContext(outMsgCtx);
@@ -477,7 +502,9 @@
// workaround as Axis2 1.2 is about to be released and Synapse 1.0
responseMsgCtx.setServerSide(false);
- String contentType = JMSUtils.getProperty(message,
BaseConstants.CONTENT_TYPE);
+ String contentType =
+ contentTypeProperty == null ? null
+ : JMSUtils.getProperty(message, contentTypeProperty);
try {
JMSUtils.setSOAPEnvelope(message, responseMsgCtx, contentType);
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
Sun Nov 9 08:48:33 2008
@@ -137,13 +137,21 @@
* @return the EPR as a String
*/
// TODO: duplicate code (see JMSConnectionFactory#getEPRForDestination)
- static String getEPR(JMSConnectionFactory cf, String destinationType,
String destination) {
+ static String getEPR(JMSConnectionFactory cf, JMSEndpoint endpoint) {
StringBuffer sb = new StringBuffer();
- sb.append(JMSConstants.JMS_PREFIX).append(destination);
-
sb.append("?").append(JMSConstants.DEST_PARAM_TYPE).append("=").append(destinationType);
+
sb.append(JMSConstants.JMS_PREFIX).append(endpoint.getJndiDestinationName());
+ sb.append("?").append(JMSConstants.DEST_PARAM_TYPE);
+ sb.append("=").append(endpoint.getDestinationType());
for (Map.Entry<String,String> entry :
cf.getJndiProperties().entrySet()) {
sb.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
+ String contentTypeProperty =
endpoint.getContentTypeRuleSet().getDefaultContentTypeProperty();
+ if (contentTypeProperty != null) {
+ sb.append("&");
+ sb.append(JMSConstants.CONTENT_TYPE_PROPERTY_PARAM);
+ sb.append("=");
+ sb.append(contentTypeProperty);
+ }
return sb.toString();
}
Added:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java?rev=712510&view=auto
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java
(added)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java
Sun Nov 9 08:48:33 2008
@@ -0,0 +1,49 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.axis2.transport.jms.ctype;
+
+/**
+ * Class encapsulating the content type information for a given message.
+ */
+public class ContentTypeInfo {
+ private final String propertyName;
+ private final String contentType;
+
+ public ContentTypeInfo(String propertyName, String contentType) {
+ this.propertyName = propertyName;
+ this.contentType = contentType;
+ }
+
+ /**
+ * Get the name of the message property from which the content type
+ * has been extracted.
+ *
+ * @return the property name or null if the content type was not determined
+ * by extracting it from a message property
+ */
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ /**
+ * Get the content type of the message.
+ *
+ * @return The content type of the message. The return value is never null.
+ */
+ public String getContentType() {
+ return contentType;
+ }
+}
Propchange:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
Sun Nov 9 08:48:33 2008
@@ -26,8 +26,18 @@
* Attempt to determine the content type of the given JMS message.
*
* @param message the message
- * @return the content type of the message, or null if the rule doesn't
match
+ * @return If the rule matches, the return value encapsulates the content
type of the
+ * message and the message property name from which is was
extracted
+ * (if applicable). If the rule doesn't match, the method returns
null.
* @throws JMSException
*/
- String getContentType(Message message) throws JMSException;
+ ContentTypeInfo getContentType(Message message) throws JMSException;
+
+ /**
+ * Get the name of the message property used to extract the content type
from,
+ * if applicable.
+ *
+ * @return the property name or null if not applicable
+ */
+ String getExpectedContentTypeProperty();
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
Sun Nov 9 08:48:33 2008
@@ -26,6 +26,7 @@
*/
public class ContentTypeRuleSet {
private final List<ContentTypeRule> rules = new
ArrayList<ContentTypeRule>();
+ private String defaultContentTypeProperty;
/**
* Add a content type rule to this set.
@@ -34,6 +35,9 @@
*/
public void addRule(ContentTypeRule rule) {
rules.add(rule);
+ if (defaultContentTypeProperty == null) {
+ defaultContentTypeProperty = rule.getExpectedContentTypeProperty();
+ }
}
/**
@@ -41,16 +45,20 @@
* This method will try the registered rules in turn until the first rule
matches.
*
* @param message the message
- * @return the content type of the message or null if none of the rules
matches
+ * @return the content type information for the message or null if none of
the rules matches
* @throws JMSException
*/
- public String getContentType(Message message) throws JMSException {
+ public ContentTypeInfo getContentTypeInfo(Message message) throws
JMSException {
for (ContentTypeRule rule : rules) {
- String contentType = rule.getContentType(message);
- if (contentType != null) {
- return contentType;
+ ContentTypeInfo contentTypeInfo = rule.getContentType(message);
+ if (contentTypeInfo != null) {
+ return contentTypeInfo;
}
}
return null;
}
+
+ public String getDefaultContentTypeProperty() {
+ return defaultContentTypeProperty;
+ }
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
Sun Nov 9 08:48:33 2008
@@ -27,7 +27,11 @@
this.contentType = contentType;
}
- public String getContentType(Message message) {
- return contentType;
+ public ContentTypeInfo getContentType(Message message) {
+ return new ContentTypeInfo(null, contentType);
+ }
+
+ public String getExpectedContentTypeProperty() {
+ return null;
}
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
Sun Nov 9 08:48:33 2008
@@ -29,7 +29,11 @@
this.contentType = contentType;
}
- public String getContentType(Message message) {
- return messageType.isInstance(message) ? contentType : null;
+ public ContentTypeInfo getContentType(Message message) {
+ return messageType.isInstance(message) ? new ContentTypeInfo(null,
contentType) : null;
+ }
+
+ public String getExpectedContentTypeProperty() {
+ return null;
}
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
Sun Nov 9 08:48:33 2008
@@ -28,7 +28,12 @@
this.propertyName = propertyName;
}
- public String getContentType(Message message) throws JMSException {
- return message.getStringProperty(propertyName);
+ public ContentTypeInfo getContentType(Message message) throws JMSException
{
+ String value = message.getStringProperty(propertyName);
+ return value == null ? null : new ContentTypeInfo(propertyName, value);
+ }
+
+ public String getExpectedContentTypeProperty() {
+ return propertyName;
}
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
Sun Nov 9 08:48:33 2008
@@ -51,26 +51,34 @@
ruleSet = ContentTypeRuleFactory.parse(service.getParameter("test"));
}
+ private void assertContentTypeInfo(String propertyName, String
contentType, Message message)
+ throws Exception {
+
+ ContentTypeInfo contentTypeInfo = ruleSet.getContentTypeInfo(message);
+ assertEquals(propertyName, contentTypeInfo.getPropertyName());
+ assertEquals(contentType, contentTypeInfo.getContentType());
+ }
+
public void test1() throws Exception {
Message message = new BytesMessageImpl();
message.setStringProperty("contentType", "application/xml");
- assertEquals("application/xml", ruleSet.getContentType(message));
+ assertContentTypeInfo("contentType", "application/xml", message);
- assertEquals("text/plain", ruleSet.getContentType(new
TextMessageImpl()));
- assertEquals("application/octet-stream", ruleSet.getContentType(new
BytesMessageImpl()));
- assertEquals(null, ruleSet.getContentType(new ObjectMessageImpl()));
+ assertContentTypeInfo(null, "text/plain", new TextMessageImpl());
+ assertContentTypeInfo(null, "application/octet-stream", new
BytesMessageImpl());
+ assertEquals(null, ruleSet.getContentTypeInfo(new
ObjectMessageImpl()));
}
public void test2() throws Exception {
Message message = new BytesMessageImpl();
message.setStringProperty("contentType", "application/xml");
- assertEquals("application/xml", ruleSet.getContentType(message));
+ assertContentTypeInfo("contentType", "application/xml", message);
message = new TextMessageImpl();
message.setStringProperty("ctype", "application/xml");
- assertEquals("application/xml", ruleSet.getContentType(message));
+ assertContentTypeInfo("ctype", "application/xml", message);
- assertEquals("text/xml", ruleSet.getContentType(new
TextMessageImpl()));
- assertEquals("text/xml", ruleSet.getContentType(new
BytesMessageImpl()));
+ assertContentTypeInfo(null, "text/xml", new TextMessageImpl());
+ assertContentTypeInfo(null, "text/xml", new BytesMessageImpl());
}
}
Modified:
webservices/commons/trunk/modules/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSChannel.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSChannel.java?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSChannel.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSChannel.java
Sun Nov 9 08:48:33 2008
@@ -132,7 +132,8 @@
return new EndpointReference(
"jms:/" + jndiName + "?transport.jms.DestinationType=" +
destinationType +
"&java.naming.factory.initial=org.mockejb.jndi.MockContextFactory" +
- "&transport.jms.ConnectionFactoryJNDIName=" +
connectionFactoryJNDIName);
+ "&transport.jms.ConnectionFactoryJNDIName=" +
connectionFactoryJNDIName +
+ "&" + JMSConstants.CONTENT_TYPE_PROPERTY_PARAM +
"=Content-Type");
}
public void setupService(AxisService service, boolean isClientSide) throws
Exception {
Modified: webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml?rev=712510&r1=712509&r2=712510&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml (original)
+++ webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml Sun Nov
9 08:48:33 2008
@@ -169,6 +169,10 @@
<td></td>
</tr>
<tr>
+ <td>transport.jms.ContentTypeProperty</td>
+ <td>The name of the message property to store the content
type of messages sent to the endpoint.</td>
+ </tr>
+ <tr>
<td>java.naming.factory.initial</td>
<td></td>
</tr>
@@ -186,5 +190,22 @@
</tr>
</table>
</section>
+ <section name="Content type detection">
+ <dl>
+ <dt>Incoming requests</dt>
+ <dd>The content type of the message is determined according to
the settings specified in
+ the <tt>transport.jms.ContentType</tt> service parameter.</dd>
+ <dt>Outgoing responses</dt>
+ <dd>If the content type of the request was determined using
the value of a message property, the
+ content type of the response will stored in the same message
property.</dd>
+ <dt>Outgoing requests</dt>
+ <dd>The content type will be stored in the message property
specified by
+ the <tt>transport.jms.ContentTypeProperty</tt> message context
property or
+ the <tt>transport.jms.ContentTypeProperty</tt> parameter of
the endpoint reference.</dd>
+ <dt>Incoming responses</dt>
+ <dd>The content type will be extracted from the message
property that was used to
+ store the content type of the outgoing request.</dd>
+ </dl>
+ </section>
</body>
</document>
\ No newline at end of file