本文整理汇总了Java中org.apache.camel.NoTypeConversionAvailableException类的典型用法代码示例。如果您正苦于以下问题:Java NoTypeConversionAvailableException类的具体用法?Java NoTypeConversionAvailableException怎么用?Java NoTypeConversionAvailableException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NoTypeConversionAvailableException类属于org.apache.camel包,在下文中一共展示了NoTypeConversionAvailableException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convert
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
private static Object convert(TypeConverter typeConverter, Class<?> type, Object value)
throws URISyntaxException, NoTypeConversionAvailableException {
if (typeConverter != null) {
return typeConverter.mandatoryConvertTo(type, value);
}
if (type == URI.class) {
return new URI(value.toString());
}
PropertyEditor editor = PropertyEditorManager.findEditor(type);
if (editor != null) {
// property editor is not thread safe, so we need to lock
Object answer;
synchronized (LOCK) {
editor.setAsText(value.toString());
answer = editor.getValue();
}
return answer;
}
return null;
}
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:IntrospectionSupport.java
示例2: genericFileToInputStream
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
@Converter
public static InputStream genericFileToInputStream(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException {
if (file.getFile() instanceof File) {
// prefer to use a file input stream if its a java.io.File
File f = (File) file.getFile();
// the file must exists
if (f.exists()) {
// read the file using the specified charset
String charset = file.getCharset();
if (charset != null) {
LOG.debug("Read file {} with charset {}", f, file.getCharset());
} else {
LOG.debug("Read file {} (no charset)", f);
}
return IOConverter.toInputStream(f, charset);
}
}
if (exchange != null) {
// otherwise ensure the body is loaded as we want the input stream of the body
file.getBinding().loadContent(exchange, file);
return exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
} else {
// should revert to fallback converter if we don't have an exchange
return null;
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:GenericFileConverter.java
示例3: genericFileToString
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
@Converter
public static String genericFileToString(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException {
// use reader first as it supports the file charset
BufferedReader reader = genericFileToReader(file, exchange);
if (reader != null) {
return IOConverter.toString(reader);
}
if (exchange != null) {
// otherwise ensure the body is loaded as we want the content of the body
file.getBinding().loadContent(exchange, file);
return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, file.getBody());
} else {
// should revert to fallback converter if we don't have an exchange
return null;
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:GenericFileConverter.java
示例4: genericFileToSerializable
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
@Converter
public static Serializable genericFileToSerializable(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException {
if (exchange != null) {
// load the file using input stream
InputStream is = genericFileToInputStream(file, exchange);
if (is != null) {
// need to double convert to convert correctly
byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, is);
if (data != null) {
return exchange.getContext().getTypeConverter().convertTo(Serializable.class, exchange, data);
}
}
}
// should revert to fallback converter if we don't have an exchange
return null;
}
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:GenericFileConverter.java
示例5: genericFileToReader
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
private static BufferedReader genericFileToReader(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException {
if (file.getFile() instanceof File) {
// prefer to use a file input stream if its a java.io.File
File f = (File) file.getFile();
// the file must exists
if (!f.exists()) {
return null;
}
// and use the charset if the file was explicit configured with a charset
String charset = file.getCharset();
if (charset != null) {
LOG.debug("Read file {} with charset {}", f, file.getCharset());
return IOConverter.toReader(f, charset);
} else {
LOG.debug("Read file {} (no charset)", f);
return IOConverter.toReader(f, exchange);
}
}
return null;
}
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:GenericFileConverter.java
示例6: testMultipleNodeList
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
/**
* Regression test to ensure that a NodeList of length > 1 is not processed by the new converters.
* @throws Exception
*/
@Test
public void testMultipleNodeList() throws Exception {
getMockEndpoint("mock:found").expectedMessageCount(0);
getMockEndpoint("mock:found").setResultWaitTime(500);
getMockEndpoint("mock:notfound").expectedMessageCount(0);
getMockEndpoint("mock:notfound").setResultWaitTime(500);
try {
template.requestBody("direct:doTest", XML_INPUT_MULTIPLE, String.class);
fail("NoTypeConversionAvailableException expected");
} catch (CamelExecutionException ex) {
assertEquals(RuntimeCamelException.class, ex.getCause().getClass());
assertEquals(NoTypeConversionAvailableException.class, ex.getCause().getCause().getClass());
}
assertMockEndpointsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:XPathLanguageSingleNodeListTest.java
示例7: testBeanNoTypeConvertionPossibleFail
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void testBeanNoTypeConvertionPossibleFail() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
// we send in a Date object which cannot be converted to XML so it should fail
try {
template.requestBody("direct:start", new Date());
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
NoTypeConversionAvailableException ntae = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
assertEquals(Date.class, ntae.getFromType());
assertEquals(Document.class, ntae.getToType());
assertNotNull(ntae.getValue());
assertNotNull(ntae.getMessage());
}
assertMockEndpointsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:BeanNoTypeConvertionPossibleTest.java
示例8: testBeanHeaderNoTypeConvertionPossibleFail
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void testBeanHeaderNoTypeConvertionPossibleFail() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
// we send in a bar string as header which cannot be converted to a number so it should fail
try {
template.requestBodyAndHeader("direct:start", "Hello World", "foo", 555);
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
ParameterBindingException pbe = assertIsInstanceOf(ParameterBindingException.class, e.getCause());
assertEquals(1, pbe.getIndex());
assertTrue(pbe.getMethod().getName().contains("hello"));
assertEquals(555, pbe.getParameterValue());
NoTypeConversionAvailableException ntae = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
assertEquals(Integer.class, ntae.getFromType());
assertEquals(Document.class, ntae.getToType());
assertEquals(555, ntae.getValue());
assertNotNull(ntae.getMessage());
}
assertMockEndpointsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:BeanNoTypeConvertionPossibleWhenHeaderTest.java
示例9: testCannotBindToParameter
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void testCannotBindToParameter() throws Exception {
// Create hashmap for testing purpose
users.put("charles", new User("Charles", "43"));
users.put("claus", new User("Claus", "33"));
Exchange out = template.send("direct:in", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setProperty("p1", "abc");
exchange.setProperty("p2", 123);
Message in = exchange.getIn();
in.setHeader("users", users); // add users hashmap
in.setBody("TheBody");
}
});
assertTrue("Should fail", out.isFailed());
assertIsInstanceOf(RuntimeCamelException.class, out.getException());
assertIsInstanceOf(NoTypeConversionAvailableException.class, out.getException().getCause());
}
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:BeanWithHeadersAndBodyInject2Test.java
示例10: testOrderNoFQNUnknown
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void testOrderNoFQNUnknown() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.bean(MyBean.class, "order(Unknown)")
.to("mock:result");
}
});
context.start();
try {
template.sendBody("direct:start", new MyOrder());
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
assertEquals("Unknown", cause.getValue());
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:BeanOverloadedMethodFQNTest.java
示例11: testOrderFQNUnknown
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void testOrderFQNUnknown() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.bean(MyBean.class, "order(org.apache.camel.component.bean.BeanOverloadedMethodFQNTest$Unknown)")
.to("mock:result");
}
});
context.start();
try {
template.sendBody("direct:start", new MyOrder());
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class, e.getCause().getCause());
assertEquals("org.apache.camel.component.bean.BeanOverloadedMethodFQNTest$Unknown", cause.getValue());
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:BeanOverloadedMethodFQNTest.java
示例12: writeRow
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
/**
* Writes the given row.
*
* @param exchange exchange to use (for type conversion)
* @param row row to write
* @param writer uniVocity writer to use
* @throws NoTypeConversionAvailableException when it's not possible to convert the row as map.
*/
private void writeRow(Exchange exchange, Object row, W writer) throws NoTypeConversionAvailableException {
Map<?, ?> map = convertToMandatoryType(exchange, Map.class, row);
if (adaptHeaders) {
for (Object key : map.keySet()) {
headers.add(convertToMandatoryType(exchange, String.class, key));
}
}
Object[] values = new Object[headers.size()];
int index = 0;
for (String header : headers) {
values[index++] = map.get(header);
}
writer.writeRow(values);
}
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:Marshaller.java
示例13: getTextlineBody
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
/**
* Gets the string body to be used when sending with the textline codec.
*
* @param body the current body
* @param exchange the exchange
* @param delimiter the textline delimiter
* @param autoAppendDelimiter whether absent delimiter should be auto appended
* @return the string body to send
* @throws NoTypeConversionAvailableException is thrown if the current body could not be converted to a String type
*/
public static String getTextlineBody(Object body, Exchange exchange, TextLineDelimiter delimiter, boolean autoAppendDelimiter) throws NoTypeConversionAvailableException {
String s = exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, exchange, body);
// auto append delimiter if missing?
if (autoAppendDelimiter) {
if (TextLineDelimiter.LINE.equals(delimiter)) {
// line delimiter so ensure it ends with newline
if (!s.endsWith("\n")) {
LOG.trace("Auto appending missing newline delimiter to body");
s = s + "\n";
}
} else {
// null delimiter so ensure it ends with null
if (!s.endsWith("\u0000")) {
LOG.trace("Auto appending missing null delimiter to body");
s = s + "\u0000";
}
}
}
return s;
}
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:NettyHelper.java
示例14: extractOffset
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
private static long extractOffset(String now, TypeConverter typeConverter) throws NoTypeConversionAvailableException {
Matcher matcher = NOW_PATTERN.matcher(now);
if (matcher.matches()) {
String op = matcher.group(1);
String remainder = matcher.group(2);
// convert remainder to a time millis (eg we have a String -> long converter that supports
// syntax with hours, days, minutes: eg 5h30m for 5 hours and 30 minutes).
long offset = typeConverter.mandatoryConvertTo(long.class, remainder);
if ("+".equals(op)) {
return offset;
} else {
return -1 * offset;
}
}
return 0;
}
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:MailConverters.java
示例15: publish
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
public void publish() throws IOException {
AMQP.BasicProperties properties;
byte[] body;
try {
// To maintain backwards compatibility try the TypeConverter (The DefaultTypeConverter seems to only work on Strings)
body = camelExchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, camelExchange, message.getBody());
properties = endpoint.getMessageConverter().buildProperties(camelExchange).build();
} catch (NoTypeConversionAvailableException | TypeConversionException e) {
if (message.getBody() instanceof Serializable) {
// Add the header so the reply processor knows to de-serialize it
message.getHeaders().put(RabbitMQEndpoint.SERIALIZE_HEADER, true);
properties = endpoint.getMessageConverter().buildProperties(camelExchange).build();
body = serializeBodyFrom(message);
} else if (message.getBody() == null) {
properties = endpoint.getMessageConverter().buildProperties(camelExchange).build();
body = null;
} else {
LOG.warn("Could not convert {} to byte[]", message.getBody());
throw new RuntimeCamelException(e);
}
}
publishToRabbitMQ(properties, body);
}
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:RabbitMQMessagePublisher.java
示例16: marshall
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
protected <T> T marshall(Class<T> type, ComplexDataObject dataObject, Exchange exchange) throws IOException {
if (parentTypeConverter != null) {
// TODO allow configuration to determine the sink from the Exchange
Sink sink = getSink(dataObject, exchange);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
sink.setOutputStream(buffer);
sink.writeObject(dataObject);
byte[] data = buffer.toByteArray();
try {
return parentTypeConverter.mandatoryConvertTo(type, data);
} catch (NoTypeConversionAvailableException e) {
return null;
}
}
return null;
}
开发者ID:jboss-fuse,项目名称:camel-c24io,代码行数:22,代码来源:FallbackTypeConverter.java
示例17: asBeanParameter
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
private String asBeanParameter(TypeConverter converter, Map.Entry<String, Object> entry) {
try {
return "bean." + entry.getKey() + "=" + converter.mandatoryConvertTo(String.class, entry.getValue());
} catch (NoTypeConversionAvailableException e) {
throw new IllegalStateException(e);
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:8,代码来源:FunctionHandler.java
示例18: consumeOption
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
private <T> void consumeOption(String name, Class<T> type, Consumer<T> consumer) throws NoTypeConversionAvailableException {
final TypeConverter converter = getCamelContext().getTypeConverter();
final Object val = getOptions().get(name);
final T result = converter.mandatoryConvertTo(type, val);
consumer.accept(result);
LOGGER.debug("Consume option {}", name);
getOptions().remove(name);
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:11,代码来源:SqlStartConnectorComponent.java
示例19: buildEndpointOptions
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
/**
* Gather all options to use when building the delegate uri.
*/
private Map<String, String> buildEndpointOptions(String remaining, Map<String, Object> parameters) throws URISyntaxException, NoTypeConversionAvailableException {
final TypeConverter converter = getCamelContext().getTypeConverter();
final Map<String, String> endpointOptions = new LinkedHashMap<>();
// Extract options from options that are supposed to be set at the endpoint
// level, those options can be overridden and extended using by the query
// parameters.
Collection<String> endpointProperties = definition.getEndpointProperties().keySet();
for (String key : endpointProperties) {
Object val = this.options.get(key);
if (val != null) {
doAddOption(endpointOptions, key, converter.mandatoryConvertTo(String.class, val));
}
}
// options from query parameters
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
if (entry.getValue() != null) {
doAddOption(endpointOptions, entry.getKey(), converter.mandatoryConvertTo(String.class, entry.getValue()));
}
}
// add extra options from remaining (context-path)
if (remaining != null) {
String targetUri = componentScheme + ":" + remaining;
Map<String, String> extra = catalog.endpointProperties(targetUri);
if (extra != null && !extra.isEmpty()) {
extra.forEach((key, value) -> doAddOption(endpointOptions, key, value));
}
}
return endpointOptions;
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:37,代码来源:ComponentProxyComponent.java
示例20: markMessagesRead
import org.apache.camel.NoTypeConversionAvailableException; //导入依赖的package包/类
/**
* Mark all messages read for given accountovmId
*
* @param login isds login
* @param password isds password
* @throws NoTypeConversionAvailableException
*/
public void markMessagesRead(String login, String password) throws NoTypeConversionAvailableException {
Authentication auth = new BasicAuthentication(TEST_CONFIG, login, password);
DataBoxManager manager = new DataBoxManager(TEST_CONFIG, auth);
log.info("Marking meessages as downloaded for login {}", login);
List<MessageEnvelope> envs = manager.getDataBoxMessagesService()
.getListOfReceivedMessages(
new Date(0L), new Date(Long.MAX_VALUE),
context().getTypeConverter().mandatoryConvertTo(EnumSet.class, "!read"),
1, Integer.MAX_VALUE);
envs.stream().forEach(env -> manager.getDataBoxMessagesService().markMessageAsDownloaded(env));
}
开发者ID:czgov,项目名称:camel-isds,代码行数:20,代码来源:ISDSTestBase.java
注:本文中的org.apache.camel.NoTypeConversionAvailableException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论