org.apache.camel.NoTypeConversionAvailableException Java Examples

The following examples show how to use org.apache.camel.NoTypeConversionAvailableException. 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: KnativeHttpConsumer.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
private Buffer computeResponseBody(Message message) throws NoTypeConversionAvailableException {
    Object body = message.getBody();
    Exception exception = message.getExchange().getException();

    if (exception != null) {
        // we failed due an exception so print it as plain text
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        exception.printStackTrace(pw);

        // the body should then be the stacktrace
        body = sw.toString().getBytes(StandardCharsets.UTF_8);
        // force content type to be text/plain as that is what the stacktrace is
        message.setHeader(Exchange.CONTENT_TYPE, "text/plain");

        // and mark the exception as failure handled, as we handled it by returning
        // it as the response
        ExchangeHelper.setFailureHandled(message.getExchange());
    }

    return body != null
        ? Buffer.buffer(message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(byte[].class, body))
        : null;
}
 
Example #2
Source File: SimpleFunctionConverter.java    From container with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T mandatoryConvertTo(Class<T> type, Object value) throws TypeConversionException,
    NoTypeConversionAvailableException {
    if (value == null && !allowNull) {
        throw new NoTypeConversionAvailableException(value, type);
    }
    if (!fromType.isAssignableFrom(value.getClass())) {
        throw new NoTypeConversionAvailableException(value, type);
    }
    O result = conversion.apply(fromType.cast(value));
    if (type.isAssignableFrom(toType)) {
        return type.cast(result);
    }
    throw new NoTypeConversionAvailableException(value, type);
}
 
Example #3
Source File: CamelCloudServiceDiscoveryAutoConfiguration.java    From camel-spring-boot with Apache License 2.0 4 votes vote down vote up
@Lazy
@Bean(name = "service-discovery")
public CamelCloudServiceDiscovery serviceDiscovery(List<ServiceDiscovery> serviceDiscoveryList) throws NoTypeConversionAvailableException {
    return new CamelCloudServiceDiscovery(serviceDiscoveryList);
}
 
Example #4
Source File: SimpleFunctionConverter.java    From container with Apache License 2.0 4 votes vote down vote up
@Override
public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException,
    NoTypeConversionAvailableException {
    return mandatoryConvertTo(type, value);
}