Search in sources :

Example 6 with MessageReceiver

use of org.apache.axis2.engine.MessageReceiver in project pentaho-platform by pentaho.

the class AxisUtil method createService.

@SuppressWarnings("unchecked")
private static AxisService createService(String implClass, AxisConfiguration axisConfig, ClassLoader loader) throws AxisFault {
    try {
        HashMap messageReciverMap = new HashMap();
        // $NON-NLS-1$
        Class inOnlyMessageReceiver = Loader.loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
        MessageReceiver messageReceiver = (MessageReceiver) inOnlyMessageReceiver.newInstance();
        messageReciverMap.put(WSDL2Constants.MEP_URI_IN_ONLY, messageReceiver);
        // $NON-NLS-1$
        Class inoutMessageReceiver = Loader.loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
        MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver.newInstance();
        messageReciverMap.put(WSDL2Constants.MEP_URI_IN_OUT, inOutmessageReceiver);
        messageReciverMap.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY, inOutmessageReceiver);
        return AxisService.createService(implClass, axisConfig, messageReciverMap, null, null, loader);
    } catch (Exception e) {
        throw AxisFault.makeFault(e);
    }
}
Also used : HashMap(java.util.HashMap) MessageReceiver(org.apache.axis2.engine.MessageReceiver)

Example 7 with MessageReceiver

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

the class AxisAsyncEndpoint method receive.

void receive(MessageContext messageCtx) throws AxisFault {
    log.debug("MessageReceiver has been invoked");
    final AxisMessage messageData;
    try {
        Assert.assertTrue(messageCtx.isServerSide());
        TransportInDescription transportIn = messageCtx.getTransportIn();
        Assert.assertNotNull("transportIn not set on message context", transportIn);
        Assert.assertEquals(context.getTransportName(), transportIn.getName());
        Assert.assertEquals(context.getTransportName(), messageCtx.getIncomingTransportName());
        for (MessageContextValidator validator : validators) {
            validator.validate(messageCtx, false);
        }
        messageData = new AxisMessage(messageCtx);
    } catch (Throwable ex) {
        support.putException(ex);
        return;
    }
    support.putMessage(null, messageData);
}
Also used : TransportInDescription(org.apache.axis2.description.TransportInDescription) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage) MessageContextValidator(org.apache.axis2.transport.testkit.axis2.MessageContextValidator)

Example 8 with MessageReceiver

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

the class MinConcurrencyTest method runTest.

@Override
protected void runTest() throws Throwable {
    int endpointCount = channels.length;
    int expectedConcurrency = endpointCount * messages;
    final MessageReceiver messageReceiver = new MessageReceiver() {

        public void receive(MessageContext msgContext) throws AxisFault {
            synchronized (concurrencyReachedLock) {
                concurrencyReached++;
                concurrencyReachedLock.notifyAll();
            }
            try {
                synchronized (shutdownAwaitLock) {
                    shutdownAwaitLock.wait();
                }
            } catch (InterruptedException ex) {
            }
        }
    };
    TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
    TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
    try {
        for (int i = 0; i < endpointCount; i++) {
            TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
            AsyncChannel channel = channels[i];
            clientResourceSet.addResource(channel);
            AxisAsyncTestClient client = new AxisAsyncTestClient(false);
            clientResourceSet.addResource(client);
            clientResourceSet.setUp();
            clientResourceSets[i] = clientResourceSet;
            TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
            endpointResourceSet.addResource(new AxisTestEndpoint() {

                @Override
                protected AxisOperation createOperation() {
                    AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
                    operation.setMessageReceiver(messageReceiver);
                    return operation;
                }

                @Override
                protected void onTransportError(Throwable ex) {
                // TODO Auto-generated method stub
                }
            });
            if (!preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
            for (int j = 0; j < messages; j++) {
                ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
                AxisMessage message = new AxisMessage();
                message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
                SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
                SOAPEnvelope envelope = factory.getDefaultEnvelope();
                message.setEnvelope(envelope);
                client.sendMessage(options, new ContentType(message.getMessageType()), message);
            }
            if (preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
        }
        long startTime = System.currentTimeMillis();
        while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
            synchronized (concurrencyReachedLock) {
                concurrencyReachedLock.wait(5000);
            }
        }
        synchronized (shutdownAwaitLock) {
            shutdownAwaitLock.notifyAll();
        }
        if (concurrencyReached < expectedConcurrency) {
            fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
        }
    } finally {
        for (int i = 0; i < endpointCount; i++) {
            if (endpointResourceSets[i] != null) {
                endpointResourceSets[i].tearDown();
            }
            if (clientResourceSets[i] != null) {
                clientResourceSets[i].tearDown();
            }
        }
    }
}
Also used : ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) ContentType(javax.mail.internet.ContentType) QName(javax.xml.namespace.QName) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) MessageReceiver(org.apache.axis2.engine.MessageReceiver) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) MessageContext(org.apache.axis2.context.MessageContext) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage)

Example 9 with MessageReceiver

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

the class ClientHandler method markRequestCompletedWithError.

/**
 * Mark request to send failed with error
 *
 * @param axis2Request the Axis2HttpRequest to be marked as completed with an error
 * @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
 */
protected void markRequestCompletedWithError(final Axis2HttpRequest axis2Request, final int errorCode, final String errorMessage, final Exception exceptionToRaise) {
    axis2Request.setCompleted(true);
    if (errorCode == -1 && errorMessage == null && exceptionToRaise == null) {
        // no need to continue
        return;
    }
    final MessageContext mc = axis2Request.getMsgContext();
    // if the request message is a sandesha messag we ignore the
    // exception handling
    // we cannot use the declared sandesha2 constant since
    // nhttp transport shouldn't take a sandesha2 dependency
    String done = (String) mc.getProperty("Sandesha2AppProcessingDone");
    if (JavaUtils.isTrueExplicitly(done)) {
        return;
    }
    if (mc.getAxisOperation() != null && mc.getAxisOperation().getMessageReceiver() != null) {
        if (metrics != null) {
            if (metrics.getLevel() == MetricsCollector.LEVEL_FULL) {
                if (errorCode == NhttpConstants.CONNECTION_TIMEOUT) {
                    metrics.incrementTimeoutsReceiving(mc);
                } else {
                    metrics.incrementFaultsSending(errorCode, mc);
                }
            } else {
                if (errorCode == NhttpConstants.CONNECTION_TIMEOUT) {
                    metrics.incrementTimeoutsReceiving();
                } else {
                    metrics.incrementFaultsSending();
                }
            }
        }
        workerPool.execute(new Runnable() {

            public void run() {
                MessageReceiver mr = mc.getAxisOperation().getMessageReceiver();
                try {
                    // This AxisFault is created to create the fault message context
                    // noinspection ThrowableInstanceNeverThrown
                    AxisFault axisFault = exceptionToRaise != null ? new AxisFault(errorMessage, exceptionToRaise) : new AxisFault(errorMessage);
                    MessageContext nioFaultMessageContext = MessageContextBuilder.createFaultMessageContext(mc, axisFault);
                    SOAPEnvelope envelope = nioFaultMessageContext.getEnvelope();
                    if (log.isDebugEnabled()) {
                        log.debug("Sending Fault for Request with Message ID : " + mc.getMessageID());
                    }
                    nioFaultMessageContext.setProperty(NhttpConstants.SENDING_FAULT, Boolean.TRUE);
                    nioFaultMessageContext.setProperty(NhttpConstants.ERROR_MESSAGE, errorMessage);
                    if (errorCode != -1) {
                        nioFaultMessageContext.setProperty(NhttpConstants.ERROR_CODE, errorCode);
                    }
                    if (exceptionToRaise != null) {
                        nioFaultMessageContext.setProperty(NhttpConstants.ERROR_DETAIL, exceptionToRaise.toString());
                        nioFaultMessageContext.setProperty(NhttpConstants.ERROR_EXCEPTION, exceptionToRaise);
                        envelope.getBody().getFault().getDetail().setText(exceptionToRaise.toString());
                    } else {
                        nioFaultMessageContext.setProperty(NhttpConstants.ERROR_DETAIL, errorMessage);
                        envelope.getBody().getFault().getDetail().setText(errorMessage);
                    }
                    nioFaultMessageContext.setProperty(CLIENT_CONNECTION_DEBUG, mc.getProperty(CLIENT_CONNECTION_DEBUG));
                    mr.receive(nioFaultMessageContext);
                } 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) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 10 with MessageReceiver

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

the class ClientHandler method responseReceived.

/**
 * Process a response received for the request sent out
 *
 * @param conn the connection being processed
 */
public void responseReceived(final NHttpClientConnection conn) {
    setServerContextAttribute(NhttpConstants.RES_FROM_BACKEND_READ_START_TIME, System.currentTimeMillis(), conn);
    HttpContext context = conn.getContext();
    // set the current message size to zero
    if (isMessageSizeValidationEnabled) {
        context.setAttribute(NhttpConstants.MESSAGE_SIZE_VALIDATION_SUM, 0);
    }
    HttpResponse response = conn.getHttpResponse();
    ProxyTunnelHandler tunnelHandler = (ProxyTunnelHandler) context.getAttribute(TUNNEL_HANDLER);
    if (tunnelHandler != null && !tunnelHandler.isCompleted()) {
        context.removeAttribute(TUNNEL_HANDLER);
        tunnelHandler.handleResponse(response, conn);
        if (tunnelHandler.isSuccessful()) {
            log.debug(conn + ": Tunnel established");
            conn.resetInput();
            conn.requestOutput();
            return;
        } else {
            Axis2HttpRequest axis2Req = (Axis2HttpRequest) context.getAttribute(ATTACHMENT_KEY);
            context.setAttribute(AXIS2_HTTP_REQUEST, axis2Req);
            context.setAttribute(OUTGOING_MESSAGE_CONTEXT, axis2Req.getMsgContext());
            ContentOutputBuffer outputBuffer = new NhttpSharedOutputBuffer(bufferSize, conn, allocator, socketTimeout);
            axis2Req.setOutputBuffer(outputBuffer);
            context.setAttribute(REQUEST_SOURCE_BUFFER, outputBuffer);
            context.setAttribute(NhttpConstants.DISCARD_ON_COMPLETE, Boolean.TRUE);
        }
    }
    setServerContextAttribute(NhttpConstants.RES_HEADER_ARRIVAL_TIME, System.currentTimeMillis(), conn);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CONTINUE) {
        if (log.isDebugEnabled()) {
            log.debug(conn + ": Received a 100 Continue response");
        }
        // and wait for the response
        return;
    }
    ClientConnectionDebug ccd = (ClientConnectionDebug) conn.getContext().getAttribute(CLIENT_CONNECTION_DEBUG);
    if (ccd != null) {
        ccd.recordResponseStartTime(response.getStatusLine().toString());
    }
    // Have we sent out our request fully in the first place? if not, forget about it now..
    Axis2HttpRequest req = (Axis2HttpRequest) conn.getContext().getAttribute(AXIS2_HTTP_REQUEST);
    if (req != null) {
        req.setCompleted(true);
        if (log.isDebugEnabled()) {
            log.debug(conn + ": Response Received for Request : " + req);
        }
        if (!req.isSendingCompleted()) {
            req.getMsgContext().setProperty(NhttpConstants.ERROR_CODE, NhttpConstants.SEND_ABORT);
            NhttpSharedOutputBuffer outputBuffer = (NhttpSharedOutputBuffer) conn.getContext().getAttribute(REQUEST_SOURCE_BUFFER);
            if (outputBuffer != null) {
                outputBuffer.shutdown();
            }
            if (log.isDebugEnabled()) {
                log.debug(conn + ": Remote server aborted request being sent and replied : " + conn + " for request : " + conn.getContext().getAttribute(NhttpConstants.HTTP_REQ_METHOD));
            }
            context.setAttribute(NhttpConstants.DISCARD_ON_COMPLETE, Boolean.TRUE);
            if (metrics != null) {
                metrics.incrementFaultsSending(NhttpConstants.SEND_ABORT, req.getMsgContext());
            }
        }
    }
    switch(response.getStatusLine().getStatusCode()) {
        case HttpStatus.SC_ACCEPTED:
            {
                if (log.isDebugEnabled()) {
                    log.debug(conn + ": Received a 202 Accepted response");
                }
                // Process response body if Content-Type header is present in the response
                // If Content-Type header is null, We will ignore entity body
                Header contentType = response.getFirstHeader(HTTP.CONTENT_TYPE);
                if (contentType != null) {
                    processResponse(conn, context, response);
                    return;
                }
                // sometimes, some http clients sends an "\r\n" as the content body with a
                // HTTP 202 OK.. we will just get it into this temp buffer and ignore it..
                ContentInputBuffer inputBuffer = new SharedInputBuffer(8, conn, allocator);
                context.setAttribute(RESPONSE_SINK_BUFFER, inputBuffer);
                // create a dummy message with an empty SOAP envelope and a property
                // NhttpConstants.SC_ACCEPTED set to Boolean.TRUE to indicate this is a
                // placeholder message for the transport to send a HTTP 202 to the
                // client. Should / would be ignored by any transport other than
                // nhttp. For example, JMS would not send a reply message for one-way
                // operations.
                MessageContext outMsgCtx = (MessageContext) context.getAttribute(OUTGOING_MESSAGE_CONTEXT);
                MessageReceiver mr = outMsgCtx.getAxisOperation().getMessageReceiver();
                // 202 Accepted message
                if (!outMsgCtx.isPropertyTrue(NhttpConstants.IGNORE_SC_ACCEPTED)) {
                    try {
                        MessageContext responseMsgCtx = outMsgCtx.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
                        if (responseMsgCtx == null || outMsgCtx.getOptions().isUseSeparateListener() || outMsgCtx.getOperationContext().isComplete()) {
                            if (responseMsgCtx != null && responseMsgCtx.getProperty("synapse.send") == null) {
                                return;
                            }
                        } else if (responseMsgCtx == null || outMsgCtx.getOptions().isUseSeparateListener()) {
                            // Since we need to notify the SynapseCallback receiver to remove the
                            // call backs registered  we set a custom property
                            setHeaders(context, response, outMsgCtx, responseMsgCtx);
                            outMsgCtx.setProperty(NhttpConstants.HTTP_202_RECEIVED, "true");
                            mr.receive(outMsgCtx);
                            return;
                        }
                        if (responseMsgCtx == null) {
                            return;
                        }
                        setHeaders(context, response, outMsgCtx, responseMsgCtx);
                        responseMsgCtx.setServerSide(true);
                        responseMsgCtx.setDoingREST(outMsgCtx.isDoingREST());
                        responseMsgCtx.setProperty(MessageContext.TRANSPORT_IN, outMsgCtx.getProperty(MessageContext.TRANSPORT_IN));
                        responseMsgCtx.setTransportIn(outMsgCtx.getTransportIn());
                        responseMsgCtx.setTransportOut(outMsgCtx.getTransportOut());
                        responseMsgCtx.setAxisMessage(outMsgCtx.getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
                        responseMsgCtx.setOperationContext(outMsgCtx.getOperationContext());
                        responseMsgCtx.setConfigurationContext(outMsgCtx.getConfigurationContext());
                        responseMsgCtx.setTo(null);
                        if (!outMsgCtx.isDoingREST() && !outMsgCtx.isSOAP11()) {
                            responseMsgCtx.setEnvelope(new SOAP12Factory().getDefaultEnvelope());
                        } else {
                            responseMsgCtx.setEnvelope(new SOAP11Factory().getDefaultEnvelope());
                        }
                        responseMsgCtx.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
                        responseMsgCtx.setProperty(NhttpConstants.SC_ACCEPTED, Boolean.TRUE);
                        int statusCode = response.getStatusLine().getStatusCode();
                        responseMsgCtx.setProperty(NhttpConstants.HTTP_SC, statusCode);
                        mr.receive(responseMsgCtx);
                    } catch (org.apache.axis2.AxisFault af) {
                        log.debug(conn + ": Unable to report back " + "202 Accepted state to the message receiver");
                    }
                }
                return;
            }
        case HttpStatus.SC_OK:
            {
                processResponse(conn, context, response);
                return;
            }
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
            {
                if (warnOnHttp500(response)) {
                    log.warn(getErrorMessage("Received an internal server error : " + response.getStatusLine().getReasonPhrase(), conn));
                }
                processResponse(conn, context, response);
                return;
            }
        default:
            {
                if (log.isDebugEnabled()) {
                    log.debug(conn + ": " + getErrorMessage("HTTP status code received : " + response.getStatusLine().getStatusCode() + " :: " + response.getStatusLine().getReasonPhrase(), conn));
                }
                Header contentType = response.getFirstHeader(HTTP.CONTENT_TYPE);
                if (contentType != null) {
                    if ((contentType.getValue().indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0) || contentType.getValue().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0) {
                        if (log.isDebugEnabled()) {
                            log.debug(conn + ": Received an unexpected response with a SOAP payload");
                        }
                    } else if (contentType.getValue().indexOf("html") == -1) {
                        if (log.isDebugEnabled()) {
                            log.debug(conn + ": Received an unexpected response with a POX/REST payload");
                        }
                    } else {
                        log.warn(getErrorMessage("Received an unexpected response - " + "of content type : " + contentType.getValue() + " and status code : " + response.getStatusLine().getStatusCode() + " with reason : " + response.getStatusLine().getReasonPhrase(), conn));
                    }
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug(conn + ": " + getErrorMessage("Received a response - " + "without a content type with status code : " + response.getStatusLine().getStatusCode() + " and reason : " + response.getStatusLine().getReasonPhrase(), conn));
                    }
                }
                processResponse(conn, context, response);
            }
    }
}
Also used : SharedInputBuffer(org.apache.http.nio.util.SharedInputBuffer) AxisFault(org.apache.axis2.AxisFault) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) ClientConnectionDebug(org.apache.synapse.transport.nhttp.debug.ClientConnectionDebug) ContentOutputBuffer(org.apache.http.nio.util.ContentOutputBuffer) Header(org.apache.http.Header) MessageReceiver(org.apache.axis2.engine.MessageReceiver) SOAP12Factory(org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) ProxyTunnelHandler(org.apache.synapse.transport.http.conn.ProxyTunnelHandler) MessageContext(org.apache.axis2.context.MessageContext) ContentInputBuffer(org.apache.http.nio.util.ContentInputBuffer)

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