Search in sources :

Example 91 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class StaticFallbackConverterTest method testStaticFallbackConverter.

public void testStaticFallbackConverter() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    TimeZone tz = TimeZone.getDefault();
    String money = context.getTypeConverter().convertTo(String.class, exchange, tz);
    assertEquals("Time talks", money);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) TimeZone(java.util.TimeZone)

Example 92 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class StaticFallbackConverterTest method testStaticFallbackMandatoryConverter.

public void testStaticFallbackMandatoryConverter() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    TimeZone tz = TimeZone.getDefault();
    String money = context.getTypeConverter().mandatoryConvertTo(String.class, exchange, tz);
    assertEquals("Time talks", money);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) TimeZone(java.util.TimeZone)

Example 93 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class StaticFallbackConverterTest method testStaticFallbackMandatoryFailed.

public void testStaticFallbackMandatoryFailed() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    try {
        context.getTypeConverter().mandatoryConvertTo(Date.class, exchange, new Timestamp(0));
        fail("Should have thrown an exception");
    } catch (NoTypeConversionAvailableException e) {
    // expected
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) Timestamp(java.sql.Timestamp)

Example 94 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class StAX2SAXSourceTest method testDefaultPrefixInRootElementWithCopyTransformer.

public void testDefaultPrefixInRootElementWithCopyTransformer() throws Exception {
    TransformerFactory trf = TransformerFactory.newInstance();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLStreamReader reader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, new StringReader(TEST_XML));
    // ensure UTF-8 encoding
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString());
    XMLStreamWriter writer = context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange, baos);
    StAX2SAXSource staxSource = new StAX2SAXSource(reader);
    StreamSource templateSource = new StreamSource(getClass().getResourceAsStream("/xslt/common/copy.xsl"));
    Transformer transformer = trf.newTransformer(templateSource);
    log.info("Used transformer: {}", transformer.getClass().getName());
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.transform(staxSource, new StreamResult(baos));
    writer.flush();
    baos.flush();
    assertThat(new String(baos.toByteArray()), equalTo(TEST_XML));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) TransformerFactory(javax.xml.transform.TransformerFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 95 with DefaultExchange

use of org.apache.camel.impl.DefaultExchange in project camel by apache.

the class IOConverterTest method testToInputStreamStringBufferAndBuilderExchange.

public void testToInputStreamStringBufferAndBuilderExchange() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.setProperty(Exchange.CHARSET_NAME, ObjectHelper.getDefaultCharacterSet());
    StringBuffer buffer = new StringBuffer();
    buffer.append("Hello World");
    InputStream is = IOConverter.toInputStream(buffer, exchange);
    assertNotNull(is);
    assertEquals("Hello World", IOConverter.toString(is, exchange));
    StringBuilder builder = new StringBuilder();
    builder.append("Hello World");
    is = IOConverter.toInputStream(builder, exchange);
    assertNotNull(is);
    assertEquals("Hello World", IOConverter.toString(is, exchange));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Exchange (org.apache.camel.Exchange)381 Test (org.junit.Test)254 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)127 CamelContext (org.apache.camel.CamelContext)54 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 HashMap (java.util.HashMap)33 Message (org.apache.camel.Message)32 Before (org.junit.Before)32 Tx (org.nhindirect.common.tx.model.Tx)31 ESMClass (org.jsmpp.bean.ESMClass)30 Processor (org.apache.camel.Processor)22 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)22 Expression (org.apache.camel.Expression)21 File (java.io.File)20 DefaultMessage (org.apache.camel.impl.DefaultMessage)20 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 URL (java.net.URL)16 Date (java.util.Date)16