Search in sources :

Example 31 with URL

use of java.net.URL 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 32 with URL

use of java.net.URL 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 33 with URL

use of java.net.URL 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)

Example 34 with URL

use of java.net.URL in project camel by apache.

the class CamelContextAddRouteDefinitionsFromXmlTest method parseUri.

protected Object parseUri(String uri) throws JAXBException {
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    URL resource = getClass().getResource(uri);
    assertNotNull("Cannot find resource on the classpath: " + uri, resource);
    Object value = unmarshaller.unmarshal(resource);
    return value;
}
Also used : Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL)

Example 35 with URL

use of java.net.URL in project camel by apache.

the class DefaultClassResolverTest method testLoadResourceAsUri.

public void testLoadResourceAsUri() {
    DefaultClassResolver resolver = new DefaultClassResolver();
    URL url = resolver.loadResourceAsURL("log4j2.properties");
    assertNotNull(url);
}
Also used : URL(java.net.URL)

Aggregations

URL (java.net.URL)8112 IOException (java.io.IOException)2006 Test (org.junit.Test)1653 File (java.io.File)1638 MalformedURLException (java.net.MalformedURLException)1165 HttpURLConnection (java.net.HttpURLConnection)1030 InputStream (java.io.InputStream)1028 ArrayList (java.util.ArrayList)633 URLConnection (java.net.URLConnection)515 InputStreamReader (java.io.InputStreamReader)473 URLClassLoader (java.net.URLClassLoader)451 BufferedReader (java.io.BufferedReader)390 HashMap (java.util.HashMap)361 URISyntaxException (java.net.URISyntaxException)286 URI (java.net.URI)269 Map (java.util.Map)259 FileInputStream (java.io.FileInputStream)227 List (java.util.List)205 FileOutputStream (java.io.FileOutputStream)194 OutputStream (java.io.OutputStream)194