Author: ruwan
Date: Sun May 9 17:38:50 2010
New Revision: 942568
URL: http://svn.apache.org/viewvc?rev=942568&view=rev
Log:
Adding logging and making it more re-usable by adding synchronous mediation
behaviors
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java?rev=942568&r1=942567&r2=942568&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/Target.java
Sun May 9 17:38:50 2010
@@ -19,7 +19,10 @@
package org.apache.synapse.mediators.eip;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.axis2.addressing.EndpointReference;
@@ -36,31 +39,49 @@ public class Target {
/** An optional Action to be set on the message when handing over to the
target */
private String soapAction = null;
- /** The inlined target sequence definition */
+ /** The in-lined target sequence definition */
private SequenceMediator sequence = null;
/** The target sequence reference key */
private String sequenceRef = null;
- /** The inlined target endpoint definition */
+ /** The in-lined target endpoint definition */
private Endpoint endpoint = null;
/** The target endpoint reference key */
private String endpointRef = null;
+ private boolean asynchronous = true;
+
+ private static final Log log = LogFactory.getLog(Target.class);
+
/**
* process the message through this target (may be to mediate
* using the target sequence, send message to the target endpoint or both)
*
* @param synCtx - MessageContext to be mediated
+ * @return <code>false</code> if the target is mediated as synchronous and
the sequence
+ * mediation returns <code>false</code>, <code>true</code> otherwise
*/
- public void mediate(MessageContext synCtx) {
+ public boolean mediate(MessageContext synCtx) {
+
+ boolean returnValue = true;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Target mediation : START");
+ }
if (soapAction != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the SOAPAction as : " + soapAction);
+ }
synCtx.setSoapAction(soapAction);
}
if (toAddress != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the To header as : " + toAddress);
+ }
if (synCtx.getTo() != null) {
synCtx.getTo().setAddress(toAddress);
} else {
@@ -71,20 +92,63 @@ public class Target {
// since we are injecting the new messages asynchronously, we cannot
process a message
// through a sequence and then again with an endpoint
if (sequence != null) {
- synCtx.getEnvironment().injectAsync(synCtx, sequence);
+ if (asynchronous) {
+ if (log.isDebugEnabled()) {
+ log.debug("Asynchronously mediating using the in-lined
anonymous sequence");
+ }
+ synCtx.getEnvironment().injectAsync(synCtx, sequence);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Synchronously mediating using the in-lined
anonymous sequence");
+ }
+ returnValue = sequence.mediate(synCtx);
+ }
} else if (sequenceRef != null) {
SequenceMediator refSequence = (SequenceMediator)
synCtx.getSequence(sequenceRef);
if (refSequence != null) {
- synCtx.getEnvironment().injectAsync(synCtx, refSequence);
+ if (asynchronous) {
+ if (log.isDebugEnabled()) {
+ log.debug("Asynchronously mediating using the sequence
" +
+ "named : " + sequenceRef);
+ }
+ synCtx.getEnvironment().injectAsync(synCtx, refSequence);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Synchronously mediating using the sequence
" +
+ "named : " + sequenceRef);
+ }
+ returnValue = refSequence.mediate(synCtx);
+ }
+ } else {
+ handleException("Couldn't find the sequence named : " +
sequenceRef);
}
} else if (endpoint != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Sending using the in-lined anonymous endpoint");
+ }
endpoint.send(synCtx);
} else if (endpointRef != null) {
Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
if (epr != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Sending using the endpoint named : " +
endpointRef);
+ }
epr.send(synCtx);
+ } else {
+ handleException("Couldn't find the endpoint named : " +
endpointRef);
}
}
+
+ if (log.isDebugEnabled()) {
+ log.debug("Target mediation : END");
+ }
+
+ return returnValue;
+ }
+
+ private void handleException(String message) {
+ log.error(message);
+ throw new SynapseException(message);
}
///////////////////////////////////////////////////////////////////////////////////////
@@ -138,4 +202,8 @@ public class Target {
public void setEndpointRef(String endpointRef) {
this.endpointRef = endpointRef;
}
+
+ public void setAsynchronous(boolean asynchronous) {
+ this.asynchronous = asynchronous;
+ }
}
\ No newline at end of file