Search in sources :

Example 1 with ResponseMessageBuilder

use of org.apache.synapse.eventing.builders.ResponseMessageBuilder in project wso2-synapse by wso2.

the class SynapseEventSource method receive.

/**
 * Override the Message receiver method to accept subscriptions and events
 *
 * @param mc message context
 * @throws AxisFault
 */
public void receive(MessageContext mc) throws AxisFault {
    // Create synapse message context from the axis2 message context
    SynapseConfiguration synCfg = (SynapseConfiguration) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG).getValue();
    SynapseEnvironment synEnv = (SynapseEnvironment) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV).getValue();
    org.apache.synapse.MessageContext smc = new Axis2MessageContext(mc, synCfg, synEnv);
    // initialize the response message builder using the message context
    ResponseMessageBuilder messageBuilder = new ResponseMessageBuilder(mc);
    try {
        if (EventingConstants.WSE_SUBSCRIBE.equals(mc.getWSAAction())) {
            // add new subscription to the SynapseSubscription store through subscription manager
            processSubscriptionRequest(mc, messageBuilder);
        } else if (EventingConstants.WSE_UNSUBSCRIBE.equals(mc.getWSAAction())) {
            // Unsubscribe the matching subscription
            processUnSubscribeRequest(mc, messageBuilder);
        } else if (EventingConstants.WSE_GET_STATUS.equals(mc.getWSAAction())) {
            // Response with the status of the subscription
            processGetStatusRequest(mc, messageBuilder);
        } else if (EventingConstants.WSE_RENEW.equals(mc.getWSAAction())) {
            // Renew subscription
            processReNewRequest(mc, messageBuilder);
        } else {
            // Treat as an Event
            if (log.isDebugEnabled()) {
                log.debug("Event received");
            }
            dispatchEvents(smc);
        }
    } catch (EventException e) {
        handleException("Subscription manager processing error", e);
    }
}
Also used : EventException(org.wso2.eventing.exceptions.EventException) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ResponseMessageBuilder(org.apache.synapse.eventing.builders.ResponseMessageBuilder) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 ResponseMessageBuilder (org.apache.synapse.eventing.builders.ResponseMessageBuilder)1 EventException (org.wso2.eventing.exceptions.EventException)1