Search in sources :

Example 26 with DefaultExchange

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

the class XsltBuilderTest method testXsltTransformerFile.

public void testXsltTransformerFile() throws Exception {
    File styleSheet = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
    XsltBuilder builder = new XsltBuilder();
    builder.setTransformerFile(styleSheet);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    builder.process(exchange);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) File(java.io.File)

Example 27 with DefaultExchange

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

the class XsltBuilderTest method testXsltTransformerInputStream.

public void testXsltTransformerInputStream() throws Exception {
    File styleSheet = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
    XsltBuilder builder = new XsltBuilder();
    builder.setTransformerInputStream(new FileInputStream(styleSheet));
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    builder.process(exchange);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 28 with DefaultExchange

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

the class XsltBuilderTest method testXsltOutputFile.

public void testXsltOutputFile() throws Exception {
    URL styleSheet = getClass().getResource("example.xsl");
    XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile();
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml");
    builder.process(exchange);
    assertIsInstanceOf(File.class, exchange.getOut().getBody());
    File file = new File("target/xslt/xsltout.xml");
    assertTrue("Output file should exist", file.exists());
    String body = exchange.getOut().getBody(String.class);
    assertTrue(body.endsWith("<goodbye>world!</goodbye>"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) File(java.io.File) URL(java.net.URL)

Example 29 with DefaultExchange

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

the class XsltBuilderTest method testNotFailNullBody.

public void testNotFailNullBody() throws Exception {
    URL styleSheet = getClass().getResource("example.xsl");
    XsltBuilder builder = XsltBuilder.xslt(styleSheet);
    builder.setFailOnNullBody(false);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(null);
    builder.process(exchange);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye/>", exchange.getOut().getBody(String.class));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) URL(java.net.URL)

Example 30 with DefaultExchange

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

the class XsltBuilderTest method testXsltOutputFileDelete.

public void testXsltOutputFileDelete() throws Exception {
    URL styleSheet = getClass().getResource("example.xsl");
    XsltBuilder builder = XsltBuilder.xslt(styleSheet).outputFile().deleteOutputFile();
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    exchange.getIn().setHeader(Exchange.XSLT_FILE_NAME, "target/xslt/xsltout.xml");
    builder.process(exchange);
    assertIsInstanceOf(File.class, exchange.getOut().getBody());
    File file = new File("target/xslt/xsltout.xml");
    assertTrue("Output file should exist", file.exists());
    String body = exchange.getOut().getBody(String.class);
    assertTrue(body.endsWith("<goodbye>world!</goodbye>"));
    // now done the exchange
    List<Synchronization> onCompletions = exchange.handoverCompletions();
    UnitOfWorkHelper.doneSynchronizations(exchange, onCompletions, log);
    // the file should be deleted
    assertFalse("Output file should be deleted", file.exists());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Synchronization(org.apache.camel.spi.Synchronization) File(java.io.File) URL(java.net.URL)

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