Package org.mule.api

Examples of org.mule.api.MuleEvent


                        logger.info("Message not accepted with filter: " + endpoint.getFilter());
                    }
                    return;
                }

                MuleEvent event = new DefaultMuleEvent(msg, endpoint.getExchangePattern(), session);
                endpoint.process(event);
            }
            catch (Exception e1)
            {
                // TODO MULE-863: If this is an error, do something better than this
View Full Code Here


    public void testSendEvent() throws Exception
    {
        getService().initialise();
        getService().start();
        ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
        MuleEvent event = getTestEvent("Message");

        try
        {
            service.sendEvent(event);
            fail("Exception expected, JcaService does not support sendEvent()");
View Full Code Here

    public void testDispatchEvent() throws Exception
    {
        getService().initialise();
        getService().start();
        ImmutableEndpoint endpoint = getTestInboundEndpoint("jcaInFlowEndpoint");
        MuleEvent event = getTestEvent("Message");

        getService().dispatchEvent(event);
        assertEquals(1, workManager.getScheduledWorkList().size());
        assertEquals(0, workManager.getStartWorkList().size());
        assertEquals(0, workManager.getDoWorkList().size());
View Full Code Here

    private boolean threadSafeEvent;

    public void testSetExceptionPayloadAcrossThreads() throws InterruptedException
    {
        threadSafeEvent = true;
        MuleEvent event = new DummyEvent();
        runThread(event, false);
        runThread(event, true);
    }
View Full Code Here

        else if (event != null && !syncNullPayload)
        {
            if (!(service.getOutboundMessageProcessor() instanceof OutboundRouterCollection)
                || (service.getOutboundMessageProcessor() instanceof OutboundRouterCollection && ((OutboundRouterCollection) service.getOutboundMessageProcessor()).hasEndpoints()))
            {
                MuleEvent outboundEvent;
                if (event.getExchangePattern().hasResponse())
                {
                    // Copy of the inbound event for outbound phase
                    outboundEvent = new DefaultMuleEvent(new DefaultMuleMessage(event.getMessage()
                        .getPayload(), event.getMessage(), event.getMuleContext()), event);
                }
                else
                {
                    outboundEvent = event;
                }

                MuleEvent outboundResult = processNext(outboundEvent);

                if (outboundResult != null)
                {
                    event = outboundResult;
                }
View Full Code Here

    }

    public void testFailureWithoutThreadSafeEvent() throws InterruptedException
    {
        threadSafeEvent = false;
        MuleEvent event = new DummyEvent();
        runThread(event, false);
        runThread(event, true);
    }
View Full Code Here

     * We do all this together here rather than chaining them in order to conserve
     * 2.x exception handling behaviour
     */
    public MuleEvent process(MuleEvent event) throws MuleException
    {
        MuleEvent resultEvent;
        try
        {
            Object replyTo = event.getMessage().getReplyTo();
            ReplyToHandler replyToHandler = getReplyToHandler(event.getMessage(), event.getEndpoint());
            // Do not propagate REPLY_TO beyond the inbound endpoint
            event.getMessage().setReplyTo(null);

            resultEvent = service.getComponent().process(event);
            resultEvent = processNext(resultEvent);

            // Allow components to stop processing of the ReplyTo property (e.g.
            // CXF)
            if (resultEvent != null)
            {
                String replyToStop = resultEvent.getMessage().getInvocationProperty(MuleProperties.MULE_REPLY_TO_STOP_PROPERTY);
                if (!event.getExchangePattern().hasResponse() || !BooleanUtils.toBoolean(replyToStop))
                {
                    processReplyTo(event, resultEvent, replyToHandler, replyTo);
                }
            }
View Full Code Here

        //TODO MULE-4952 what is the strategy here for proxy components?
        endpointBuilder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);

        OutboundEndpoint endpoint = endpointBuilder.buildOutboundEndpoint();

        MuleEvent responseEvent = endpoint.process(event);

        if (responseEvent != null)
        {
            return responseEvent.getMessage();
        }
        else
        {
            return null;
        }
View Full Code Here

            {
                throw new IllegalArgumentException("Property org.mule.MuleContext not set on Axis MessageContext");
            }
       
            // Get the event stored in call if a request call is made there will be no event
            MuleEvent event = (MuleEvent)call.getProperty(MuleProperties.MULE_EVENT_PROPERTY);
       
            if (Boolean.TRUE.equals(call.getProperty("axis.one.way")))
            {
                sync = false;
            }
       
            // Get the dispatch endpoint
            String uri = msgContext.getStrProp(MessageContext.TRANS_URL);
            ImmutableEndpoint requestEndpoint = (ImmutableEndpoint)call
                .getProperty(MuleProperties.MULE_ENDPOINT_PROPERTY);
           
            OutboundEndpoint endpoint;
       
            // put username and password in URI if they are set on the current event
            if (msgContext.getUsername() != null)
            {
                String[] tempEndpoint = uri.split("//");
                String credentialString = msgContext.getUsername() + ":"
                                          + msgContext.getPassword();
                uri = tempEndpoint[0] + "//" + credentialString + "@" + tempEndpoint[1];
                endpoint = lookupEndpoint(uri);
            }
            else
            {
                endpoint = lookupEndpoint(uri);
            }

            if (requestEndpoint.getConnector() instanceof AxisConnector)
            {
                msgContext.setTypeMappingRegistry(((AxisConnector)requestEndpoint.getConnector())
                    .getAxis().getTypeMappingRegistry());
            }
           
            Map<String, Object> props = new HashMap<String, Object>();
            Object payload;
            int contentLength = 0;
            String contentType = null;
            if (msgContext.getRequestMessage().countAttachments() > 0)
            {
                File temp = File.createTempFile("soap", ".tmp");
                temp.deleteOnExit(); // TODO cleanup files earlier (IOUtils has a
                // file tracker)
                FileOutputStream fos = new FileOutputStream(temp);
                msgContext.getRequestMessage().writeTo(fos);
                fos.close();
                contentLength = (int)temp.length();
                payload = new FileInputStream(temp);
                contentType = "multipart/related";
            }
            else
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
                msgContext.getRequestMessage().writeTo(baos);
                baos.close();
                payload = baos.toByteArray();
            }

            // props.putAll(event.getProperties());
            for (Iterator iterator = msgContext.getPropertyNames(); iterator.hasNext();)
            {
                String name = (String)iterator.next();
                if (!name.equals("call_object") && !name.equals("wsdl.service"))
                {
                    props.put(name, msgContext.getProperty(name));
                }
            }

            // add all custom headers, filter out all mule headers (such as
            // MULE_SESSION) except
            // for MULE_USER header. Filter out other headers like "soapMethods" and
            // MuleProperties.MULE_METHOD_PROPERTY and "soapAction"
            // and also filter out any http related header
            if ((RequestContext.getEvent() != null)
                && (RequestContext.getEvent().getMessage() != null))
            {
                props = AxisCleanAndAddProperties.cleanAndAdd(RequestContext.getEventContext());
            }
           
            // with jms and vm the default SOAPAction will result in the name of the endpoint, which we may not necessarily want. This should be set manually on the endpoint
            String scheme = requestEndpoint.getEndpointURI().getScheme();
            if (!("vm".equalsIgnoreCase(scheme) || "jms".equalsIgnoreCase(scheme)))
            {
                if (call.useSOAPAction())
                {
                    uri = call.getSOAPActionURI();
                }
                props.put(SoapConstants.SOAP_ACTION_PROPERTY_CAPS, uri);
            }
            if (contentLength > 0)
            {
                props.put(HttpConstants.HEADER_CONTENT_LENGTH, Integer.toString(contentLength)); // necessary
                // for
                // supporting
                // httpclient
            }

           
            if (props.get(HttpConstants.HEADER_CONTENT_TYPE) == null)
            {
                if (contentType == null)
                {
                    contentType = "text/xml";
                }
               
                props.put(HttpConstants.HEADER_CONTENT_TYPE, contentType);
            }
            MuleMessage message = new DefaultMuleMessage(payload, props, muleContext);
            MuleSession session;

            if(event != null)
            {
                session = event.getSession();
            }
            else
            {
                session = new DefaultMuleSession(muleContext);
            }

            logger.info("Making Axis soap request on: " + uri);
            if (logger.isDebugEnabled())
            {
                logger.debug("Soap request is:\n" + new String((payload instanceof byte[] ? (byte[])payload : payload.toString().getBytes())));
            }

            if (sync)
            {
                EndpointBuilder builder = new EndpointURIEndpointBuilder(endpoint);
                builder.setExchangePattern(MessageExchangePattern.REQUEST_RESPONSE);
                OutboundEndpoint syncEndpoint = muleContext.getRegistry()
                    .lookupEndpointFactory()
                    .getOutboundEndpoint(builder);
                MuleEvent dispatchEvent = new DefaultMuleEvent(message,
                    MessageExchangePattern.REQUEST_RESPONSE, session);
                MuleMessage result = null;
                MuleEvent resultEvent = syncEndpoint.process(dispatchEvent);
                if (resultEvent != null)
                {
                    result = resultEvent.getMessage();
                }

                if (result != null)
                {
                    byte[] response = result.getPayloadAsBytes();
                    Message responseMessage = new Message(response);
                    msgContext.setResponseMessage(responseMessage);

                }
                else
                {
                    logger
                        .warn("No response message was returned from synchronous call to: " + uri);
                }
                // remove temp file created for streaming
                if (payload instanceof File)
                {
                    ((File)payload).delete();
                }
            }
            else
            {
                MuleEvent dispatchEvent = new DefaultMuleEvent(message, MessageExchangePattern.ONE_WAY,
                    session);
                endpoint.process(dispatchEvent);
            }
        }
        catch (Exception e)
View Full Code Here

        props.put("bar", "mar");

        MuleMessage message = new DefaultMuleMessage(new FruitBowl(new Apple(), new Banana()), props,
            muleContext);

        MuleEvent resultEvent = flow.process(new DefaultMuleEvent(message, getTestInboundEndpoint(""),
            getTestSession(getTestService(), muleContext)));
        assertNotNull(resultEvent);
        assertNotNull(resultEvent.getMessage().getPayload());
        Object payload = resultEvent.getMessage().getPayload();
        assertFalse(payload.getClass().isArray());
        assertTrue(payload instanceof List<?>);
        List<?> list = (List<?>) payload;
        assertTrue(list.contains("moo"));
        assertTrue(list.contains("mar"));
View Full Code Here

TOP

Related Classes of org.mule.api.MuleEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.