Package org.mule.api.transformer

Examples of org.mule.api.transformer.Transformer.transform()


                //If the return type does not match, lets attempt to transform it before throwing an error
                try
                {
                    Transformer t = muleContext.getRegistry().lookupTransformer(
                        DataTypeFactory.createFromObject(result), DataTypeFactory.create(getReturnClass()));
                    result = t.transform(result);
                }
                catch (TransformerException e)
                {
                    throw new ExpressionRuntimeException(CoreMessages.transformUnexpectedType(result.getClass(),
                    getReturnClass()), e);
View Full Code Here


        {
            throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, resultType));
        }

        // Pass in the message itself
        Object result = transformer.transform(this, encoding);

        // Unless we disallow Object.class as a valid return type we need to do this extra check
        if (!resultType.getType().isAssignableFrom(result.getClass()))
        {
            throw new TransformerException(CoreMessages.transformOnObjectNotOfSpecifiedType(resultType, result));
View Full Code Here

                        Transformer transformer = muleContext.getRegistry().lookupTransformer(source, DataType.BYTE_ARRAY_DATA_TYPE);
                        if (transformer == null)
                        {
                            throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, DataType.BYTE_ARRAY_DATA_TYPE));
                        }
                        contents = transformer.transform(theContent);
                    }
                    catch(TransformerException ex)
                    {
                        String message = String.format(
                                "Unable to serialize the attachment %s, which is of type %s with contents of type %s",
View Full Code Here

        Transformer decompressorTransformer = getRoundTripTransformer();

        // Compress the test data.
        Object compressedData = compressorTransformer.transform(getTestData());
        // Decompress the test data.
        Object decompressedData = decompressorTransformer.transform(compressedData);

        assertTrue(String.format("Compress and decompress process failed. Expected '%s', but got '%s'", getTestData(), decompressedData),
                   compareResults(getTestData(), decompressedData));
    }
}
View Full Code Here

    @Test
    public void testTransform() throws Exception
    {
        Transformer trans = this.getTransformer();
        Object result = trans.transform(getTestData());
        assertNotNull("The result of the transform shouldn't be null", result);

        Object expectedResult = this.getResultData();
        assertNotNull("The expected result data must not be null", expectedResult);
View Full Code Here

    {
        Transformer roundTripTransformer = this.getRoundTripTransformer();
        //If null this is just a one way test
        if (roundTripTransformer != null)
        {
            Object result = roundTripTransformer.transform(this.getResultData());
            assertNotNull("The result of the roundtrip transform shouldn't be null", result);

            final boolean match = this.compareRoundtripResults(this.getTestData(), result);

            if (!match)
View Full Code Here

        // Hack to set the default charset used by the javax.mail API to perform the mail subject encoding as iso-8859-1.
        System.setProperty("mail.mime.charset", "iso-8859-1");

        // Transform.
        Object result = roundTripTransformer.transform(message, "iso-2022-jp");

        assertNotNull("The result of the roundtrip transform shouldn't be null", result);
        assertTrue(result instanceof MimeMessage);
        // Assert that the mail subject has been correctly encoded in iso-2022-jp.
        assertEquals(((MimeMessage) result).getSubject(), testSubject);
View Full Code Here

                {
                    DataType sourceType = DataTypeFactory.createFromObject(header.getObject());
                    transformer = muleContext.getRegistry().lookupTransformer(sourceType, DataType.STRING_DATA_TYPE);

                    String key = WSConsumer.SOAP_HEADERS_PROPERTY_PREFIX + header.getName().getLocalPart();
                    String value = (String) transformer.transform(header.getObject());

                    event.getMessage().setProperty(key, value, PropertyScope.INBOUND);
                }
                catch (TransformerException e)
                {
View Full Code Here

                                                             outboundProperty), event, transformer, e.getCause()));
                }

                try
                {
                    Document document = (Document) transformer.transform(value);

                    // This QName is required by the SoapHeader but it is not used.
                    QName qname = new QName(null, document.getDocumentElement().getTagName());

                    message.getHeaders().add(new SoapHeader(qname, document.getDocumentElement()));
View Full Code Here

    {
        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

TOP
Copyright © 2018 www.massapi.com. 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.