Search in sources :

Example 1 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project wso2-axis2-transports by wso2.

the class AxisAsyncEndpoint method createOperation.

@Override
protected InOnlyAxisOperation createOperation() {
    InOnlyAxisOperation operation = new InOnlyAxisOperation(new QName("default"));
    operation.setMessageReceiver(new MessageReceiver() {

        public void receive(MessageContext messageCtx) throws AxisFault {
            AxisAsyncEndpoint.this.receive(messageCtx);
        }
    });
    return operation;
}
Also used : InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisFault(org.apache.axis2.AxisFault) MessageReceiver(org.apache.axis2.engine.MessageReceiver) QName(javax.xml.namespace.QName) MessageContext(org.apache.axis2.context.MessageContext)

Example 2 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project wso2-synapse by wso2.

the class TargetHandler method handle202.

private boolean handle202(MessageContext requestMsgContext) throws AxisFault {
    if (requestMsgContext.isPropertyTrue(NhttpConstants.IGNORE_SC_ACCEPTED)) {
        // We should not further process this 202 response - Ignore it
        return true;
    }
    MessageReceiver mr = requestMsgContext.getAxisOperation().getMessageReceiver();
    MessageContext responseMsgCtx = requestMsgContext.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
    if (responseMsgCtx == null || requestMsgContext.getOptions().isUseSeparateListener()) {
        // Most probably a response from a dual channel invocation
        // Inject directly into the SynapseCallbackReceiver
        requestMsgContext.setProperty(NhttpConstants.HTTP_202_RECEIVED, "true");
        mr.receive(requestMsgContext);
        return true;
    }
    return false;
}
Also used : MessageReceiver(org.apache.axis2.engine.MessageReceiver) MessageContext(org.apache.axis2.context.MessageContext)

Example 3 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project wso2-synapse by wso2.

the class TargetErrorHandler method handleError.

/**
 * Mark request to send failed with error
 *
 * @param mc the failed message context
 * @param errorCode the error code to raise
 * @param errorMessage the text for an error message to be returned to the MR on failure
 * @param exceptionToRaise an Exception to be returned to the MR on failure
 * @param state state of the connection
 */
public void handleError(final MessageContext mc, final int errorCode, final String errorMessage, final Exception exceptionToRaise, final ProtocolState state) {
    if (errorCode == -1 && errorMessage == null && exceptionToRaise == null) {
        return;
    }
    if (mc.getAxisOperation() == null || mc.getAxisOperation().getMessageReceiver() == null) {
        return;
    }
    // if (mc.getOperationContext().isComplete()) {
    // return;
    // } ? why we ignoring this..
    updateFaultInfo(errorCode, mc, targetConfiguration.getMetrics());
    targetConfiguration.getWorkerPool().execute(new Runnable() {

        public void run() {
            MessageReceiver mr = mc.getAxisOperation().getMessageReceiver();
            // Remove Correlation-ID MDC thread local value that can be persisting from the previous usage of
            // this thread and add a new one if there is any
            ThreadContext.remove(CorrelationConstants.CORRELATION_MDC_PROPERTY);
            Object correlationId = mc.getProperty(CorrelationConstants.CORRELATION_ID);
            if (correlationId != null && correlationId instanceof String) {
                ThreadContext.put(CorrelationConstants.CORRELATION_MDC_PROPERTY, String.valueOf(correlationId));
            }
            try {
                AxisFault axisFault = (exceptionToRaise != null ? new AxisFault(errorMessage, exceptionToRaise) : new AxisFault(errorMessage));
                MessageContext faultMessageContext = MessageContextBuilder.createFaultMessageContext(mc, axisFault);
                SOAPEnvelope envelope = faultMessageContext.getEnvelope();
                if (log.isDebugEnabled()) {
                    log.debug("Sending Fault for Request with Message ID : " + mc.getMessageID());
                }
                faultMessageContext.setTo(null);
                faultMessageContext.removeProperty(PassThroughConstants.PASS_THROUGH_PIPE);
                // copy the important properties from the original message context
                faultMessageContext.setProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION, mc.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION));
                faultMessageContext.setProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONFIGURATION, mc.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONFIGURATION));
                faultMessageContext.setServerSide(true);
                faultMessageContext.setDoingREST(mc.isDoingREST());
                faultMessageContext.setProperty(MessageContext.TRANSPORT_IN, mc.getProperty(MessageContext.TRANSPORT_IN));
                faultMessageContext.setTransportIn(mc.getTransportIn());
                faultMessageContext.setTransportOut(mc.getTransportOut());
                if (!(mc.getOperationContext().getAxisOperation() instanceof OutOnlyAxisOperation)) {
                    faultMessageContext.setAxisMessage(mc.getOperationContext().getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
                }
                faultMessageContext.setOperationContext(mc.getOperationContext());
                faultMessageContext.setConfigurationContext(mc.getConfigurationContext());
                faultMessageContext.setTo(null);
                faultMessageContext.setProperty(PassThroughConstants.SENDING_FAULT, Boolean.TRUE);
                faultMessageContext.setProperty(PassThroughConstants.ERROR_MESSAGE, errorMessage);
                if (errorCode != -1) {
                    faultMessageContext.setProperty(PassThroughConstants.ERROR_CODE, getErrorCode(errorCode, state));
                }
                if (exceptionToRaise != null) {
                    faultMessageContext.setProperty(PassThroughConstants.ERROR_DETAIL, getStackTrace(exceptionToRaise));
                    faultMessageContext.setProperty(PassThroughConstants.ERROR_EXCEPTION, exceptionToRaise);
                    envelope.getBody().getFault().getDetail().setText(exceptionToRaise.toString());
                } else {
                    faultMessageContext.setProperty(PassThroughConstants.ERROR_DETAIL, errorMessage);
                    envelope.getBody().getFault().getDetail().setText(errorMessage);
                }
                faultMessageContext.setProperty(PassThroughConstants.NO_ENTITY_BODY, true);
                faultMessageContext.setProperty(CorrelationConstants.CORRELATION_ID, mc.getProperty(CorrelationConstants.CORRELATION_ID));
                faultMessageContext.setProperty(PassThroughConstants.INTERNAL_EXCEPTION_ORIGIN, mc.getProperty(PassThroughConstants.INTERNAL_EXCEPTION_ORIGIN));
                mr.receive(faultMessageContext);
            } catch (AxisFault af) {
                log.error("Unable to report back failure to the message receiver", af);
            }
        }
    });
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageReceiver(org.apache.axis2.engine.MessageReceiver) OutOnlyAxisOperation(org.apache.axis2.description.OutOnlyAxisOperation) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 4 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project wso2-synapse by wso2.

the class HttpTargetResponseWorker method handle202.

private boolean handle202(MessageContext requestMsgContext) throws AxisFault {
    if (requestMsgContext.isPropertyTrue(BridgeConstants.IGNORE_SC_ACCEPTED)) {
        // We should not further process this 202 response - Ignore it
        return true;
    }
    MessageReceiver mr = requestMsgContext.getAxisOperation().getMessageReceiver();
    MessageContext responseMsgContext = requestMsgCtx.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
    if (responseMsgContext == null || requestMsgContext.getOptions().isUseSeparateListener()) {
        // Most probably a response from a dual channel invocation
        // Inject directly into the SynapseCallbackReceiver
        requestMsgContext.setProperty(BridgeConstants.HTTP_202_RECEIVED, "true");
        mr.receive(requestMsgContext);
        return true;
    }
    return false;
}
Also used : MessageReceiver(org.apache.axis2.engine.MessageReceiver) MessageContext(org.apache.axis2.context.MessageContext)

Example 5 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project wso2-synapse by wso2.

the class SynapseCommodityServiceTest method setUp.

protected void setUp() throws java.lang.Exception {
    ServerConfigurationInformation information = new ServerConfigurationInformation();
    information.setCreateNewInstance(false);
    information.setSynapseHome(".");
    // Initializing Synapse repository
    information.setSynapseXMLLocation("./../../repository/conf/sample/resources/misc/synapse.xml");
    information.setAxis2Xml("./../../repository/conf/axis2.xml");
    findAndReplace(new File("./../../repository/conf/axis2_pt_server.xml"), new File("./target/test_repos/axis2.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    findAndReplace(new File("./../../repository/conf/axis2_be_server.xml"), new File("./target/test_repos/axis2_be_server.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    System.setProperty("jmx.agent.name", "synapse");
    ConfigurationContext synapseConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2.xml");
    TransportInDescription synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    synTrsIn.getParameter("port").setValue("10100");
    synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    synTrsIn.getParameter("port").setValue("12100");
    startServer(synapseConfigCtx);
    ServerContextInformation contextInformation = new ServerContextInformation(synapseConfigCtx, information);
    ServerManager serverManager = new ServerManager();
    serverManager.init(information, contextInformation);
    serverManager.start();
    // Initializing Business Endpoint
    // Set a different agent name to avoid collisions between the MBeans registered
    // by the two servers.
    System.setProperty("jmx.agent.name", "business");
    ConfigurationContext businessConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2_be_server.xml");
    HashMap messageReciverMap = new HashMap();
    Class inOnlyMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
    org.apache.axis2.engine.MessageReceiver messageReceiver = (org.apache.axis2.engine.MessageReceiver) inOnlyMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_ONLY, messageReceiver);
    Class inoutMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
    MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_OUT, inOutmessageReceiver);
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_ROBUST_IN_ONLY, inOutmessageReceiver);
    AxisService businessService = AxisService.createService(Services.class.getName(), businessConfigCtx.getAxisConfiguration(), messageReciverMap, "http://business.org", "http://business.org", Services.class.getClassLoader());
    businessConfigCtx.getAxisConfiguration().addService(businessService);
    TransportInDescription busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    busTrsIn.getParameter("port").setValue("10101");
    busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    busTrsIn.getParameter("port").setValue("12101");
    startServer(businessConfigCtx);
}
Also used : ServerManager(org.apache.synapse.ServerManager) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageReceiver(org.apache.axis2.engine.MessageReceiver) HashMap(java.util.HashMap) AxisService(org.apache.axis2.description.AxisService) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) TransportInDescription(org.apache.axis2.description.TransportInDescription) Services(org.apache.synapse.util.Services) ServerContextInformation(org.apache.synapse.ServerContextInformation) MessageReceiver(org.apache.axis2.engine.MessageReceiver)

Aggregations

MessageReceiver (org.apache.axis2.engine.MessageReceiver)9 MessageContext (org.apache.axis2.context.MessageContext)7 AxisFault (org.apache.axis2.AxisFault)4 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 HashMap (java.util.HashMap)2 QName (javax.xml.namespace.QName)2 InOnlyAxisOperation (org.apache.axis2.description.InOnlyAxisOperation)2 TransportInDescription (org.apache.axis2.description.TransportInDescription)2 AxisMessage (org.apache.axis2.transport.testkit.message.AxisMessage)2 ContentType (javax.mail.internet.ContentType)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 SOAP11Factory (org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory)1 SOAP12Factory (org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 AxisOperation (org.apache.axis2.description.AxisOperation)1 AxisService (org.apache.axis2.description.AxisService)1 OutOnlyAxisOperation (org.apache.axis2.description.OutOnlyAxisOperation)1 MessageContextValidator (org.apache.axis2.transport.testkit.axis2.MessageContextValidator)1 AxisAsyncTestClient (org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient)1 AxisTestEndpoint (org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint)1