Package org.apache.camel

Examples of org.apache.camel.TypeConverter.convertTo()


        // try to find a suitable type converter
        TypeConverter converter = getOrFindTypeConverter(type, value);
        if (converter != null) {
            log.trace("Using converter: {} to convert {}", converter, key);
            Object rc = converter.convertTo(type, exchange, value);
            if (rc != null) {
                return rc;
            }
        }
View Full Code Here


public class CamelJaxbFallbackConverterTest extends CamelTestSupport {
   
    @Test
    public void testConvertor() throws Exception {
        TypeConverter converter = context.getTypeConverter();
        PersonType person = converter.convertTo(PersonType.class,
            "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>");
        assertNotNull("Person should not be null ", person);
        assertEquals("Get the wrong first name ", person.getFirstName(), "FOO");
        assertEquals("Get the wrong second name ", person.getLastName(), "BAR");
        Exchange exchange = new DefaultExchange(context);
View Full Code Here

        assertEquals("Get the wrong first name ", person.getFirstName(), "FOO");
        assertEquals("Get the wrong second name ", person.getLastName(), "BAR");
        Exchange exchange = new DefaultExchange(context);
        exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
      
        String value = converter.convertTo(String.class, exchange, person);
        assertTrue("Should get a right marshalled string", value.indexOf("<lastName>BAR</lastName>") > 0);
       
        try {
            byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR\u0008</lastName></Person>".getBytes("UTF-8");
            InputStream is = new ByteArrayInputStream(buffers);
View Full Code Here

        assertTrue("Should get a right marshalled string", value.indexOf("<lastName>BAR</lastName>") > 0);
       
        try {
            byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR\u0008</lastName></Person>".getBytes("UTF-8");
            InputStream is = new ByteArrayInputStream(buffers);
            person = converter.convertTo(PersonType.class, exchange, is);
            fail("expect the exception here");
        } catch (Exception ex) {
            assertTrue("The exception should be CamelExecutionException", ex instanceof org.apache.camel.CamelExecutionException);
        }
    }
View Full Code Here

        InputStream is = new ByteArrayInputStream(buffers);
        Exchange exchange = new DefaultExchange(context);
        exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
        exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, true);
        TypeConverter converter = context.getTypeConverter();
        PersonType person = converter.convertTo(PersonType.class, exchange, is);
        assertNotNull("Person should not be null ", person);
        assertEquals("Get the wrong first name ", person.getFirstName(), "FOO");
        assertEquals("Get the wrong second name ", person.getLastName(), "BAR ");
       
       
View Full Code Here

        assertEquals("Get the wrong first name ", person.getFirstName(), "FOO");
        assertEquals("Get the wrong second name ", person.getLastName(), "BAR ");
       
       
        person.setLastName("BAR\u0008\uD8FF");
        String value = converter.convertTo(String.class, exchange, person);
        assertTrue("Didn't filter the non-xml chars", value.indexOf("<lastName>BAR  </lastName>") > 0);
       
        exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, false);
       
        value = converter.convertTo(String.class, exchange, person);
View Full Code Here

        String value = converter.convertTo(String.class, exchange, person);
        assertTrue("Didn't filter the non-xml chars", value.indexOf("<lastName>BAR  </lastName>") > 0);
       
        exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, false);
       
        value = converter.convertTo(String.class, exchange, person);
        assertTrue("Should not filter the non-xml chars", value.indexOf("<lastName>BAR\uD8FF</lastName>") > 0);
   
    }

}
View Full Code Here

            // no then try to lookup a type converter
            TypeConverter tc = registry.lookup(type, from);
            if (tc != null) {
                Object body = file.getBody();
                return tc.convertTo(type, exchange, body);
            }
        }
       
        return null;
    }
View Full Code Here

            }

            // no then try to lookup a type converter
            TypeConverter tc = registry.lookup(type, from);
            if (tc != null) {
                return tc.convertTo(type, exchange, body);
            }
        }

        return null;
    }
View Full Code Here

            // lets first try converting the body itself first
            // as for some types like InputStream v Reader its more efficient to do the transformation
            // from the body itself as its got efficient implementations of them, before trying the
            // message
            T answer = converter.convertTo(type, getExchange(), body);
            if (answer != null) {
                return answer;
            }

            // fallback to the message itself (e.g. used in camel-http)
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.