use of java.io.IOException in project camel by apache.
the class FailOverLoadBalanceMultipleExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start").loadBalance().failover(IllegalArgumentException.class, IOException.class, CamelException.class).to("direct:x", "direct:y", "direct:z");
from("direct:x").to("mock:x").process(new Processor() {
public void process(Exchange exchange) throws Exception {
throw new CamelExchangeException("Forced", exchange);
}
});
from("direct:y").to("mock:y").process(new Processor() {
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
});
from("direct:z").to("mock:z");
}
};
}
use of java.io.IOException in project camel by apache.
the class XMLTokenExpressionIteratorInvalidXMLTest method invokeAndVerify.
private void invokeAndVerify(Iterator<?> tokenizer, boolean error) throws IOException, XMLStreamException {
Exception exp = null;
try {
tokenizer.next();
tokenizer.next();
} catch (Exception e) {
exp = e;
} finally {
((Closeable) tokenizer).close();
}
if (error) {
assertNotNull("the error expected", exp);
} else {
assertNull("no error expected", exp);
}
}
use of java.io.IOException in project camel by apache.
the class OnExceptionRouteTest method testErrorWhileHandlingException.
public void testErrorWhileHandlingException() throws Exception {
// DLC does not handle the exception as we failed during processing in onException
MockEndpoint error = getMockEndpoint("mock:error");
error.expectedMessageCount(0);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.sendBody("direct:start", "<order><type>myType</type><user>FuncError</user></order>");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
// the myOwnHandlerBean throw exception while handling an exception
IOException cause = assertIsInstanceOf(IOException.class, e.getCause());
assertEquals("Damn something did not work", cause.getMessage());
}
assertMockEndpointsSatisfied();
// should not handle it
assertNull(myOwnHandlerBean.getPayload());
}
use of java.io.IOException in project camel by apache.
the class WebsocketRouteTest method readAll.
private static byte[] readAll(InputStream is) {
ByteArrayOutputStream bytebuf = new ByteArrayOutputStream();
try {
byte[] buf = new byte[4024];
int n;
while ((n = is.read(buf, 0, buf.length)) > 0) {
bytebuf.write(buf, 0, n);
}
} catch (IOException e) {
// ignore
} finally {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
return bytebuf.toByteArray();
}
use of java.io.IOException in project camel by apache.
the class DefaultPackageScanClassResolver method find.
protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes) {
if (log.isTraceEnabled()) {
log.trace("Searching for: {} in package: {} using classloader: {}", new Object[] { test, packageName, loader.getClass().getName() });
}
Enumeration<URL> urls;
try {
urls = getResources(loader, packageName);
if (!urls.hasMoreElements()) {
log.trace("No URLs returned by classloader");
}
} catch (IOException ioe) {
log.warn("Cannot read package: " + packageName, ioe);
return;
}
while (urls.hasMoreElements()) {
URL url = null;
try {
url = urls.nextElement();
log.trace("URL from classloader: {}", url);
url = customResourceLocator(url);
String urlPath = url.getFile();
urlPath = URLDecoder.decode(urlPath, "UTF-8");
if (log.isTraceEnabled()) {
log.trace("Decoded urlPath: {} with protocol: {}", urlPath, url.getProtocol());
}
// If it's a file in a directory, trim the stupid file: spec
if (urlPath.startsWith("file:")) {
// to remedy this then create new path without using the URLDecoder
try {
urlPath = new URI(url.getFile()).getPath();
} catch (URISyntaxException e) {
// fallback to use as it was given from the URLDecoder
// this allows us to work on Windows if users have spaces in paths
}
if (urlPath.startsWith("file:")) {
urlPath = urlPath.substring(5);
}
}
// osgi bundles should be skipped
if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:")) {
log.trace("Skipping OSGi bundle: {}", url);
continue;
}
// bundle resource should be skipped
if (url.toString().startsWith("bundleresource:") || urlPath.startsWith("bundleresource:")) {
log.trace("Skipping bundleresource: {}", url);
continue;
}
// Else it's in a JAR, grab the path to the jar
if (urlPath.indexOf('!') > 0) {
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
}
log.trace("Scanning for classes in: {} matching criteria: {}", urlPath, test);
File file = new File(urlPath);
if (file.isDirectory()) {
log.trace("Loading from directory using file: {}", file);
loadImplementationsInDirectory(test, packageName, file, classes);
} else {
InputStream stream;
if (urlPath.startsWith("http:") || urlPath.startsWith("https:") || urlPath.startsWith("sonicfs:") || isAcceptableScheme(urlPath)) {
// load resources using http/https, sonicfs and other acceptable scheme
// sonic ESB requires to be loaded using a regular URLConnection
log.trace("Loading from jar using url: {}", urlPath);
URL urlStream = new URL(urlPath);
URLConnection con = urlStream.openConnection();
// disable cache mainly to avoid jar file locking on Windows
con.setUseCaches(false);
stream = con.getInputStream();
} else {
log.trace("Loading from jar using file: {}", file);
stream = new FileInputStream(file);
}
loadImplementationsInJar(test, packageName, stream, urlPath, classes, jarCache);
}
} catch (IOException e) {
// use debug logging to avoid being to noisy in logs
log.debug("Cannot read entries in url: " + url, e);
}
}
}
Aggregations