Author: ruwan Date: Tue Jan 13 13:01:32 2009 New Revision: 28729 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=28729
Log: Synapse as a handler to axis2 service in-progress Modified: branches/synapse/1.2.wso2v1/modules/handler/src/main/java/org/apache/synapse/handler/util/HandlerUtil.java Modified: branches/synapse/1.2.wso2v1/modules/handler/src/main/java/org/apache/synapse/handler/util/HandlerUtil.java URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/handler/src/main/java/org/apache/synapse/handler/util/HandlerUtil.java?rev=28729&r1=28728&r2=28729&view=diff ============================================================================== --- branches/synapse/1.2.wso2v1/modules/handler/src/main/java/org/apache/synapse/handler/util/HandlerUtil.java (original) +++ branches/synapse/1.2.wso2v1/modules/handler/src/main/java/org/apache/synapse/handler/util/HandlerUtil.java Tue Jan 13 13:01:32 2009 @@ -19,8 +19,13 @@ package org.apache.synapse.handler.util; -import org.apache.commons.logging.Log; +import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.commons.logging.Log; +import org.apache.synapse.Mediator; +import org.apache.synapse.handler.HandlerConstants; /** * This is a helper class to get the loggin done in both in and out handlers @@ -51,4 +56,70 @@ log.debug("Body : \n" + messageContext.getEnvelope()); } } + + public static boolean mediateInMessage(Log log, MessageContext messageContext, + org.apache.synapse.MessageContext synCtx) throws AxisFault { + + AxisService service = messageContext.getAxisService(); + if (service != null) { + Parameter inMediationParam = service.getParameter(HandlerConstants.IN_SEQUENCE_PARAM_NAME); + if (inMediationParam != null && inMediationParam.getValue() != null) { + if (inMediationParam.getValue() instanceof Mediator) { + Mediator inMessageSequence = (Mediator) inMediationParam.getValue(); + return inMessageSequence.mediate(synCtx); + } else if (inMediationParam.getValue() instanceof String) { + Mediator inMessageSequence = synCtx.getConfiguration().getSequence( + (String) inMediationParam.getValue()); + return inMessageSequence.mediate(synCtx); + } else { + if (log.isDebugEnabled()) { + log.debug("The provided in message mediation sequence is not a proper mediator"); + } + } + } else { + if (log.isDebugEnabled()) { + log.debug("Couldn't find the incoming mediation for the service " + service.getName()); + } + } + } else { + String message = "Couldn't find the Service for the associated message with id " + + messageContext.getMessageID(); + log.error(message); + throw new AxisFault(message); + } + return true; + } + + public static boolean mediateOutMessage(Log log, MessageContext messageContext, + org.apache.synapse.MessageContext synCtx) throws AxisFault { + + AxisService service = messageContext.getAxisService(); + if (service != null) { + Parameter inMediationParam = service.getParameter(HandlerConstants.OUT_SEQUENCE_PARAM_NAME); + if (inMediationParam != null && inMediationParam.getValue() != null) { + if (inMediationParam.getValue() instanceof Mediator) { + Mediator inMessageSequence = (Mediator) inMediationParam.getValue(); + return inMessageSequence.mediate(synCtx); + } else if (inMediationParam.getValue() instanceof String) { + Mediator inMessageSequence = synCtx.getConfiguration().getSequence( + (String) inMediationParam.getValue()); + return inMessageSequence.mediate(synCtx); + } else { + if (log.isDebugEnabled()) { + log.debug("The provided out message mediation sequence is not a proper mediator"); + } + } + } else { + if (log.isDebugEnabled()) { + log.debug("Couldn't find the outgoing mediation for the service " + service.getName()); + } + } + } else { + String message = "Couldn't find the Service for the associated message with id " + + messageContext.getMessageID(); + log.error(message); + throw new AxisFault(message); + } + return true; + } } _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
