org.apache.camel.util.FileUtil Java Examples
The following examples show how to use
org.apache.camel.util.FileUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileRollback.java From camelinaction2 with Apache License 2.0 | 7 votes |
public void onFailure(Exchange exchange) { // this method is executed when the Exchange failed. // the cause Exception is stored on the Exchange which you can obtain using getException // delete the file String name = exchange.getIn().getHeader(Exchange.FILE_NAME_PRODUCED, String.class); LOG.warn("Failure occurred so deleting backup file: " + name); FileUtil.deleteFile(new File(name)); }
Example #2
Source File: QuarkusPlatformHttpConsumer.java From camel-quarkus with Apache License 2.0 | 5 votes |
void populateAttachments(Set<FileUpload> uploads, Message message) { for (FileUpload upload : uploads) { final String name = upload.name(); final String fileName = upload.fileName(); LOG.tracef("HTTP attachment %s = %s", name, fileName); // is the file name accepted boolean accepted = true; if (fileNameExtWhitelist != null) { String ext = FileUtil.onlyExt(fileName); if (ext != null) { ext = ext.toLowerCase(Locale.US); if (!fileNameExtWhitelist.equals("*") && !fileNameExtWhitelist.contains(ext)) { accepted = false; } } } if (accepted) { final File localFile = new File(upload.uploadedFileName()); uploadAttacher.attachUpload(localFile, fileName, message); } else { LOG.debugf( "Cannot add file as attachment: %s because the file is not accepted according to fileNameExtWhitelist: %s", fileName, fileNameExtWhitelist); } } }
Example #3
Source File: FileRollback.java From camelinaction with Apache License 2.0 | 5 votes |
public void onFailure(Exchange exchange) { // this method is executed when the Exchange failed. // the cause Exception is stored on the Exchange which you can obtain using getException // delete the file String name = exchange.getIn().getHeader(Exchange.FILE_NAME_PRODUCED, String.class); LOG.warn("Failure occurred so deleting backup file: " + name); FileUtil.deleteFile(new File(name)); }
Example #4
Source File: AppIntegrationTest.java From tutorials with MIT License | 5 votes |
private void deleteFile(String path) { try { FileUtil.removeDir(new File(path)); } catch (Exception e) { e.printStackTrace(); } }
Example #5
Source File: JsonValidatorIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testValidMessage() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("file:target/validator?noop=true") .to("json-validator:jsonvalidator/schema.json") .to("mock:valid"); } }); MockEndpoint mockValid = camelctx.getEndpoint("mock:valid", MockEndpoint.class); mockValid.expectedMessageCount(1); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("file:target/validator", "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }", Exchange.FILE_NAME, "valid.json"); mockValid.assertIsSatisfied(); Assert.assertTrue("Can delete the file", FileUtil.deleteFile(new File("target/validator/valid.json"))); } finally { camelctx.close(); } }
Example #6
Source File: JsonValidatorIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testInvalidMessage() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("file:target/validator?noop=true") .doTry() .to("json-validator:jsonvalidator/schema.json") .doCatch(ValidationException.class) .to("mock:invalid") .end(); } }); MockEndpoint mockInvalid = camelctx.getEndpoint("mock:invalid", MockEndpoint.class); mockInvalid.expectedMessageCount(1); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("file:target/validator", "{ \"name\": \"Joe Doe\", \"id\": \"AA1\", \"price\": 12.5 }", Exchange.FILE_NAME, "invalid.json"); mockInvalid.assertIsSatisfied(); Assert.assertTrue("Can delete the file", FileUtil.deleteFile(new File("target/validator/invalid.json"))); } finally { camelctx.close(); } }
Example #7
Source File: BuildTimeUriResolver.java From camel-quarkus with Apache License 2.0 | 4 votes |
private String toTransletName(final String compacted) { final String fileName = FileUtil.stripPath(compacted); final String name = FileUtil.stripExt(fileName, true); return StringHelper.capitalize(name, true); }
Example #8
Source File: BuildTimeUriResolver.java From camel-quarkus with Apache License 2.0 | 4 votes |
private static String compact(String href, String scheme) { final String afterScheme = scheme != null ? StringHelper.after(href, scheme) : href; final String compacted = FileUtil.compactPath(afterScheme, '/'); return compacted; }
Example #9
Source File: WildFlyClassResolver.java From wildfly-camel with Apache License 2.0 | 4 votes |
public InputStream loadResourceAsStream(String uri) { IllegalArgumentAssertion.assertNotNull(uri, "uri"); String resolvedName = FileUtil.compactPath(uri, '/'); return classLoader.getResourceAsStream(resolvedName); }
Example #10
Source File: WildFlyClassResolver.java From wildfly-camel with Apache License 2.0 | 4 votes |
public URL loadResourceAsURL(String uri) { IllegalArgumentAssertion.assertNotNull(uri, "uri"); String resolvedName = FileUtil.compactPath(uri, '/'); return classLoader.getResource(resolvedName); }