use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class DeleteDomainCommandTest method setUp.
@Before
public void setUp() {
sdbClient = new AmazonSDBClientMock();
configuration = new SdbConfiguration();
configuration.setDomainName("DOMAIN1");
exchange = new DefaultExchange(new DefaultCamelContext());
command = new DeleteDomainCommand(sdbClient, configuration, exchange);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class DomainMetadataCommandTest method setUp.
@Before
public void setUp() {
sdbClient = new AmazonSDBClientMock();
configuration = new SdbConfiguration();
configuration.setDomainName("DOMAIN1");
exchange = new DefaultExchange(new DefaultCamelContext());
command = new DomainMetadataCommand(sdbClient, configuration, exchange);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ListDomainsCommandTest method setUp.
@Before
public void setUp() {
sdbClient = new AmazonSDBClientMock();
configuration = new SdbConfiguration();
configuration.setDomainName("DOMAIN1");
configuration.setMaxNumberOfDomains(new Integer(5));
exchange = new DefaultExchange(new DefaultCamelContext());
command = new ListDomainsCommand(sdbClient, configuration, exchange);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class PutAttributesCommandTest method setUp.
@Before
public void setUp() {
sdbClient = new AmazonSDBClientMock();
configuration = new SdbConfiguration();
configuration.setDomainName("DOMAIN1");
exchange = new DefaultExchange(new DefaultCamelContext());
command = new PutAttributesCommand(sdbClient, configuration, exchange);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ResourceHelper method resolveMandatoryResourceAsInputStream.
/**
* Resolves the mandatory resource.
* <p/>
* The resource uri can refer to the following systems to be loaded from
* <ul>
* <il>file:nameOfFile - to refer to the file system</il>
* <il>classpath:nameOfFile - to refer to the classpath (default)</il>
* <il>http:uri - to load the resource using HTTP</il>
* <il>ref:nameOfBean - to lookup the resource in the {@link org.apache.camel.spi.Registry}</il>
* <il>bean:nameOfBean.methodName - to lookup a bean in the {@link org.apache.camel.spi.Registry} and call the method</il>
* </ul>
* If no prefix has been given, then the resource is loaded from the classpath
* <p/>
* If possible recommended to use {@link #resolveMandatoryResourceAsUrl(org.apache.camel.spi.ClassResolver, String)}
*
* @param camelContext the Camel Context
* @param uri URI of the resource
* @return the resource as an {@link InputStream}. Remember to close this stream after usage.
* @throws java.io.IOException is thrown if the resource file could not be found or loaded as {@link InputStream}
*/
public static InputStream resolveMandatoryResourceAsInputStream(CamelContext camelContext, String uri) throws IOException {
if (uri.startsWith("ref:")) {
String ref = uri.substring(4);
String value = CamelContextHelper.mandatoryLookup(camelContext, ref, String.class);
return new ByteArrayInputStream(value.getBytes());
} else if (uri.startsWith("bean:")) {
String bean = uri.substring(5);
if (bean.contains(".")) {
String method = StringHelper.after(bean, ".");
bean = StringHelper.before(bean, ".") + "?method=" + method;
}
Exchange dummy = new DefaultExchange(camelContext);
Object out = camelContext.resolveLanguage("bean").createExpression(bean).evaluate(dummy, Object.class);
if (dummy.getException() != null) {
IOException io = new IOException("Cannot find resource: " + uri + " from calling the bean");
io.initCause(dummy.getException());
throw io;
}
if (out != null) {
InputStream is = camelContext.getTypeConverter().tryConvertTo(InputStream.class, dummy, out);
if (is == null) {
String text = camelContext.getTypeConverter().tryConvertTo(String.class, dummy, out);
if (text != null) {
return new ByteArrayInputStream(text.getBytes());
}
} else {
return is;
}
} else {
throw new IOException("Cannot find resource: " + uri + " from calling the bean");
}
}
InputStream is = resolveResourceAsInputStream(camelContext.getClassResolver(), uri);
if (is == null) {
String resolvedName = resolveUriPath(uri);
throw new FileNotFoundException("Cannot find resource: " + resolvedName + " in classpath for URI: " + uri);
} else {
return is;
}
}
Aggregations