Package org.mule.api

Examples of org.mule.api.MuleContext


            throws MuleArtifactFactoryException
    {
        String flowName = "flow-" + Integer.toString(element.hashCode());
        InputStream xmlConfig = IOUtils.toInputStream(getArtifactMuleConfig(flowName, element, callback, embedInFlow));

        MuleContext muleContext = null;
        SpringXmlConfigurationBuilder builder = null;
        Map<String, String> environmentProperties = callback.getEnvironmentProperties();
        Properties systemProperties = System.getProperties();
        Map<Object, Object> originalSystemProperties = new HashMap<Object, Object>(systemProperties);

        try
        {
            ConfigResource config = new ConfigResource("embedded-datasense.xml", xmlConfig);
            // This configuration overrides the default-mule-config one to replace beans that are not required
            ConfigResource defaultConfigOverride = new ConfigResource(getClass().getClassLoader().getResource("default-mule-config-override.xml").toURI().toURL());

            if (environmentProperties != null)
            {
                systemProperties.putAll(environmentProperties);
            }
            MuleContextFactory factory = new DefaultMuleContextFactory();

            builder = new SpringXmlConfigurationBuilder(new ConfigResource[] {config, defaultConfigOverride});
            muleContext = factory.createMuleContext(builder);
            muleContext.start();

            MuleArtifact artifact = null;
            if (embedInFlow)
            {
                Pipeline pipeline = muleContext.getRegistry().lookupObject(flowName);
                if (pipeline.getMessageSource() == null)
                {
                    if (pipeline.getMessageProcessors() != null && pipeline.getMessageProcessors().size() > 0)
                    {
                        artifact = new DefaultMuleArtifact(pipeline.getMessageProcessors().get(0));
                    }
                    else
                    {
                        throw new IllegalArgumentException("artifact is null");
                    }
                }
                else
                {
                    artifact = new DefaultMuleArtifact(pipeline.getMessageSource());
                }
            }
            else
            {
                artifact = new DefaultMuleArtifact(muleContext.getRegistry().lookupObject(element.getAttribute("name")));
            }

            builders.put(artifact, builder);
            contexts.put(artifact, muleContext);
            return artifact;
View Full Code Here


    @Override
    public void returnArtifact(MuleArtifact artifact)
    {
        SpringXmlConfigurationBuilder builder = builders.remove(artifact);
        MuleContext context = contexts.remove(artifact);
        dispose(builder, context);
    }
View Full Code Here

        before.setValid(false);
        before.setSecurityContext(createTestAuthentication());
        before.setProperty("foo", "bar");

        // Create mock muleContext
        MuleContext muleContext = Mockito.mock(MuleContext.class);
        MuleRegistry registry = Mockito.mock(MuleRegistry.class);
        Mockito.when(muleContext.getRegistry()).thenReturn(registry);
        Mockito.when(muleContext.getExecutionClassLoader()).thenReturn(getClass().getClassLoader());
        Mockito.when(registry.lookupFlowConstruct("flow")).thenReturn(flow);

        // Serialize and then deserialize
        DefaultMuleSession after = (DefaultMuleSession) SerializationUtils.deserialize(
                SerializationUtils.serialize(before), muleContext);
View Full Code Here

    @Before
    public void setUp() throws Exception
    {
        expressionManager = mock(ExpressionManager.class);
        MuleContext context = mock(MuleContext.class);
        when(context.getExpressionManager()).thenReturn(expressionManager);

        message = mock(MuleMessage.class);

        event = mock(MuleEvent.class);
        when(event.getMessage()).thenReturn(message);
View Full Code Here

        return resolvedUri;
    }

    private String resolveAddress(MuleEvent event) throws URISyntaxException, UnsupportedEncodingException
    {
        MuleContext muleContext = templateUriBuilder.getMuleContext();
        String resolvedAddress = templateUriBuilder.getEncodedConstructor();

        if (muleContext.getExpressionManager().isExpression(resolvedAddress))
        {
            resolvedAddress = muleContext.getExpressionManager().parse(resolvedAddress, event, true);
        }

        return resolvedAddress;
    }
View Full Code Here

    protected MuleContext doCreateMuleContext(MuleContextBuilder muleContextBuilder, ContextConfigurator configurator)
            throws InitialisationException, ConfigurationException
    {
        // Create muleContext instance and set it in MuleServer
        MuleContext muleContext = buildMuleContext(muleContextBuilder);

        notifyMuleContextCreation(muleContext);

        // Initialiase MuleContext
        muleContext.initialise();

        notifyMuleContextInitialization(muleContext);

        try
        {
            configurator.configure(muleContext);
        }
        catch (ConfigurationException e)
        {
            if (muleContext != null && !muleContext.isDisposed())
            {
                try
                {
                    muleContext.dispose();
                }
                catch (Exception e1)
                {
                    logger.warn("Can not dispose context. " + ExceptionUtils.getMessage(e1));
                    if (logger.isDebugEnabled())
View Full Code Here

        MuleMessageToHttpResponse transformer = getMuleMessageToHttpResponse();
        final String contentType = "text/xml";
        final String wrongContentType = "text/json";
        Map<String, Object> outboundProperties =  new HashMap<String, Object>();
        outboundProperties.put(HttpConstants.HEADER_CONTENT_TYPE, wrongContentType);
        MuleContext muleContext = mock(MuleContext.class);
        MuleMessage msg = new DefaultMuleMessage(null,outboundProperties, muleContext);
        //Making sure that the outbound property overrides both invocation and inbound
        msg.setInvocationProperty(HttpConstants.HEADER_CONTENT_TYPE, wrongContentType);
        msg.setProperty(HttpConstants.HEADER_CONTENT_TYPE, wrongContentType, PropertyScope.INBOUND);
       
View Full Code Here

            catch (RuntimeException e)
            {
                // expected
            }

            MuleContext ctx = ctxBuilder.buildMuleContext();
            assertFalse(ctx.isInitialised());
            assertFalse(ctx.isInitialising());
            assertFalse(ctx.isStarted());
            assertFalse(ctx.isDisposed());
            assertFalse(ctx.isDisposing());

            ctx.initialise();
        }
        finally
        {
            System.setProperty("java.version", javaVersion);
        }
View Full Code Here

            setCurrentPhase(phase);
        }
        // In the case of a connection exception, trigger the reconnection strategy.
        catch (ConnectException ce)
        {
            MuleContext muleContext = ((AbstractConnector) ce.getFailed()).getMuleContext();
            muleContext.getExceptionListener().handleException(ce);
        }
        catch (LifecycleException le)
        {
            throw le;
        }
View Full Code Here

    }

    protected MuleContext createMuleContext() throws Exception
    {
        // Should we set up the manager for every method?
        MuleContext context;
        if (isDisposeContextPerClass() && muleContext != null)
        {
            context = muleContext;
        }
        else
        {
            MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
            List<ConfigurationBuilder> builders = new ArrayList<ConfigurationBuilder>();
            builders.add(new SimpleConfigurationBuilder(getStartUpProperties()));
            //If the annotations module is on the classpath, add the annotations config builder to the list
            //This will enable annotations config for this instance
            if (ClassUtils.isClassOnPath(CLASSNAME_ANNOTATIONS_CONFIG_BUILDER, getClass()))
            {
                builders.add((ConfigurationBuilder) ClassUtils.instanciateClass(CLASSNAME_ANNOTATIONS_CONFIG_BUILDER,
                                                                                ClassUtils.NO_ARGS, getClass()));
            }
            builders.add(getBuilder());
            addBuilders(builders);
            MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
            DefaultMuleConfiguration muleConfiguration = new DefaultMuleConfiguration();
            String workingDirectory = this.workingDirectory.getRoot().getAbsolutePath();
            logger.info("Using working directory for test: " + workingDirectory);
            muleConfiguration.setWorkingDirectory(workingDirectory);
            contextBuilder.setMuleConfiguration(muleConfiguration);
            configureMuleContext(contextBuilder);
            context = muleContextFactory.createMuleContext(builders, contextBuilder);
            if (!isGracefulShutdown())
            {
                ((DefaultMuleConfiguration) context.getConfiguration()).setShutdownTimeout(0);
            }
        }
        return context;
    }
View Full Code Here

TOP

Related Classes of org.mule.api.MuleContext

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.