Package org.mule.api.transformer

Examples of org.mule.api.transformer.Transformer


    }

    @Override
    public Transformer getTransformer() throws Exception
    {
        Transformer trans = super.getTransformer();
        trans.setReturnDataType(new SimpleDataType<byte[]>(byte[].class));
        EndpointBuilder builder = new EndpointURIEndpointBuilder("test://test", muleContext);
        builder.setEncoding(ENCODING);
        ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint(
            builder);
        trans.setEndpoint(endpoint);
        return trans;
    }
View Full Code Here


        //MULE-4879 field ordering is not guaranteed by the JVM so we cannot compare result strings
        if(expected instanceof String)
        {
            try
            {
                Transformer toObject = getRoundTripTransformer();
                expected = toObject.transform(expected);
                result = toObject.transform(result);
            }
            catch (Exception e)
            {
                fail(e.getMessage());
                return false;
View Full Code Here

        }
    }

    public Transformer resolve(DataType source, DataType result) throws ResolverException
    {
        Transformer transformer = exactTransformerCache.get(source.toString() + result.toString());
        if (transformer != null)
        {
            return transformer;
        }

        List<Transformer> trans = muleContext.getRegistry().lookupTransformers(source, result);

        transformer = getNearestTransformerMatch(trans, source.getType(), result.getType());
        //If an exact mach is not found, we have a 'second pass' transformer that can be used to converting to String or
        //byte[]
        Transformer secondPass;

        if (transformer == null)
        {
            //If no transformers were found but the outputType type is String or byte[] we can perform a more general search
            // using Object.class and then convert to String or byte[] using the second pass transformer
View Full Code Here

    public void testReturnType() throws Exception
    {
        try
        {
            muleContext.start();
            Transformer trans = muleContext.getRegistry().lookupTransformer("testTransformer");
            fail("config should fail with bad content type");
        }
        catch (Exception ex)
        {
            System.err.println("Caught " + ex.getClass() + " (as expected)");
View Full Code Here

        return "org/mule/module/xml/xml-namespace-test.xml";
    }

    public void testTransformWithParameter() throws Exception
    {
        Transformer trans = muleContext.getRegistry().lookupTransformer("test1");
        assertNotNull(trans);
        MuleMessage message = new DefaultMuleMessage("<testing/>", muleContext);
        message.setOutboundProperty("Welcome", "hello");
        Object result = trans.transform(message);
        assertNotNull(result);
        XMLUnit.setIgnoreWhitespace(true);
        XMLAssert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><echo-value xmlns=\"http://test.com\">hello</echo-value>", result);
    }
View Full Code Here

    }

    public void testArrayReturnType() throws Exception
    {

        Transformer trans = muleContext.getRegistry().lookupTransformer("testTrans");

        assertNotNull(trans);
        assertEquals(Orange[].class, trans.getReturnClass());
    }
View Full Code Here

     * {@inheritDoc}
     */
    public Transformer lookupTransformer(DataType source, DataType result) throws TransformerException
    {
        final String dataTypePairHash = getDataTypeSourceResultPairHash(source, result);
        Transformer cachedTransformer = (Transformer) exactTransformerCache.get(dataTypePairHash);
        if (cachedTransformer != null)
        {
            return cachedTransformer;
        }

        Transformer trans = resolveTransformer(source, result);

        if (trans != null)
        {
            Transformer concurrentlyAddedTransformer = (Transformer) exactTransformerCache.putIfAbsent(
                dataTypePairHash, trans);
            if (concurrentlyAddedTransformer != null)
            {
                return concurrentlyAddedTransformer;
            }
View Full Code Here

        for (TransformerResolver resolver : resolvers)
        {
            try
            {
                Transformer trans = resolver.resolve(source, result);
                if (trans != null)
                {
                    return trans;
                }
            }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void unregisterTransformer(String transformerName) throws MuleException
    {
        Transformer transformer = lookupTransformer(transformerName);
        notifyTransformerResolvers(transformer, TransformerResolver.RegistryAction.REMOVED);
        registry.unregisterObject(transformerName, Transformer.class);

    }
View Full Code Here

public class TransformerCachingTestCase extends AbstractMuleTestCase
{
    public void testCacheUpdate() throws Exception
    {
        SimpleDataType<?> sourceType = new SimpleDataType<FilterInputStream>(FilterInputStream.class);
        Transformer trans = muleContext.getRegistry().lookupTransformer(sourceType, DataTypeFactory.BYTE_ARRAY);
        assertNotNull(trans);
        assertTrue(trans instanceof ObjectToByteArray);

        Transformer trans2 = new FilterInputStreamToByteArray();
        muleContext.getRegistry().registerTransformer(trans2);

        trans = muleContext.getRegistry().lookupTransformer(sourceType, DataTypeFactory.BYTE_ARRAY);
        assertNotNull(trans);
        assertTrue(trans instanceof FilterInputStreamToByteArray);

        trans = muleContext.getRegistry().lookupTransformer(DataTypeFactory.INPUT_STREAM, DataTypeFactory.BYTE_ARRAY);
        assertNotNull(trans);
        assertTrue(trans instanceof ObjectToByteArray);

        muleContext.getRegistry().unregisterTransformer(trans2.getName());

        trans = muleContext.getRegistry().lookupTransformer(sourceType, DataTypeFactory.BYTE_ARRAY);
        assertNotNull(trans);
        assertTrue(trans instanceof ObjectToByteArray);
View Full Code Here

TOP

Related Classes of org.mule.api.transformer.Transformer

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.