当前位置: 首页>>代码示例>>Java>>正文


Java TypeConverterRegistry类代码示例

本文整理汇总了Java中org.apache.camel.spi.TypeConverterRegistry的典型用法代码示例。如果您正苦于以下问题:Java TypeConverterRegistry类的具体用法?Java TypeConverterRegistry怎么用?Java TypeConverterRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeConverterRegistry类属于org.apache.camel.spi包,在下文中一共展示了TypeConverterRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertTo

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
@FallbackConverter
public static <T> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) {

    try {
        if (value != null && value.getClass().equals(String.class)) {
            if (value.toString().startsWith("{") || value.toString().startsWith("[")) {
                T result = new UnirestJacksonObjectMapper().readValue(value.toString(), type);

                return result;
            }
        }
    }
    catch(Exception ex){
        return null;
    }
    return null;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:18,代码来源:CustomCamelConverters.java

示例2: convertToHttpRequest

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
/**
 * A fallback converter that allows us to easily call Java beans and use the raw Netty {@link HttpRequest} as parameter types.
 */
@FallbackConverter
public static Object convertToHttpRequest(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // if we want to covert to HttpRequest
    if (value != null && HttpRequest.class.isAssignableFrom(type)) {

        // okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
        // so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
        // HttpRequest from the NettyHttpMessage
        NettyHttpMessage msg;
        if (exchange.hasOut()) {
            msg = exchange.getOut(NettyHttpMessage.class);
        } else {
            msg = exchange.getIn(NettyHttpMessage.class);
        }
        if (msg != null && msg.getBody() == value) {
            // ensure the http request content is reset so we can read all the content out-of-the-box
            HttpRequest request = msg.getHttpRequest();
            request.getContent().resetReaderIndex();
            return request;
        }
    }

    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:NettyHttpConverter.java

示例3: convertToHttpResponse

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
/**
 * A fallback converter that allows us to easily call Java beans and use the raw Netty {@link HttpRequest} as parameter types.
 */
@FallbackConverter
public static Object convertToHttpResponse(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // if we want to covert to convertToHttpResponse
    if (value != null && HttpResponse.class.isAssignableFrom(type)) {

        // okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
        // so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
        // HttpRequest from the NettyHttpMessage
        NettyHttpMessage msg;
        if (exchange.hasOut()) {
            msg = exchange.getOut(NettyHttpMessage.class);
        } else {
            msg = exchange.getIn(NettyHttpMessage.class);
        }
        if (msg != null && msg.getBody() == value) {
            return msg.getHttpResponse();
        }
    }

    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:NettyHttpConverter.java

示例4: toInputStream

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
@Converter
public static InputStream toInputStream(Response response, Exchange exchange) {
    Object obj = response.getEntity();
    
    if (obj == null) {
        return null;
    }
    
    if (obj instanceof InputStream) {
        // short circuit the lookup
        return (InputStream)obj;
    }
    
    TypeConverterRegistry registry = exchange.getContext().getTypeConverterRegistry();
    TypeConverter tc = registry.lookup(InputStream.class, obj.getClass());
    
    if (tc != null) {
        return tc.convertTo(InputStream.class, exchange, obj);
    }
    
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CxfConverter.java

示例5: convertToHttpRequest

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
/**
 * A fallback converter that allows us to easily call Java beans and use the raw Netty {@link HttpRequest} as parameter types.
 */
@FallbackConverter
public static Object convertToHttpRequest(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // if we want to covert to HttpRequest
    if (value != null && HttpRequest.class.isAssignableFrom(type)) {

        // okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
        // so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
        // HttpRequest from the NettyHttpMessage
        NettyHttpMessage msg;
        if (exchange.hasOut()) {
            msg = exchange.getOut(NettyHttpMessage.class);
        } else {
            msg = exchange.getIn(NettyHttpMessage.class);
        }
        if (msg != null && msg.getBody() == value) {
            // ensure the http request content is reset so we can read all the content out-of-the-box
            FullHttpRequest request = msg.getHttpRequest();
            request.content().resetReaderIndex();
            return request;
        }
    }

    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:NettyHttpConverter.java

示例6: convertTo

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
@FallbackConverter
public static Object convertTo(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // use a fallback type converter so we can convert the embedded body if the value is GenericFile
    if (GenericFile.class.isAssignableFrom(value.getClass())) {
        GenericFile<?> file = (GenericFile<?>) value;
        Class<?> from = file.getBody().getClass();

        // maybe from is already the type we want
        if (from.isAssignableFrom(type)) {
            return file.getBody();
        }
        // no then try to lookup a type converter
        TypeConverter tc = registry.lookup(type, from);
        if (tc != null) {
            Object body = file.getBody();
            return tc.convertTo(type, exchange, body);
        }
    }
    
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MyOtherTypeConverter.java

示例7: convertTo

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
@FallbackConverter
@SuppressWarnings("unchecked")
public static <T extends Payload> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) throws IOException {
    Class<?> sourceType = value.getClass();
    if (GenericFile.class.isAssignableFrom(sourceType)) {
        GenericFile<?> genericFile = (GenericFile<?>) value;
        if (genericFile.getFile() != null) {
            Class<?> genericFileType = genericFile.getFile().getClass();
            TypeConverter converter = registry.lookup(Payload.class, genericFileType);
            if (converter != null) {
                return (T) converter.convertTo(Payload.class, genericFile.getFile());
            }
        }
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JcloudsPayloadConverter.java

示例8: convertToRequest

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
/**
 * A fallback converter that allows us to easily call Java beans and use the raw Spark {@link Request} as parameter types.
 */
@FallbackConverter
public static Object convertToRequest(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // if we want to covert to Request
    if (value != null && Request.class.isAssignableFrom(type)) {

        // okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
        // so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
        // HttpRequest from the NettyHttpMessage
        SparkMessage msg;
        if (exchange.hasOut()) {
            msg = exchange.getOut(SparkMessage.class);
        } else {
            msg = exchange.getIn(SparkMessage.class);
        }
        if (msg != null) {
            return msg.getRequest();
        }
    }

    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SparkConverter.java

示例9: convertToResponse

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
/**
 * A fallback converter that allows us to easily call Java beans and use the raw Spark {@link Response} as parameter types.
 */
@FallbackConverter
public static Object convertToResponse(Class<?> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    // if we want to covert to Response
    if (value != null && Response.class.isAssignableFrom(type)) {

        // okay we may need to cheat a bit when we want to grab the HttpRequest as its stored on the NettyHttpMessage
        // so if the message instance is a NettyHttpMessage and its body is the value, then we can grab the
        // HttpRequest from the NettyHttpMessage
        SparkMessage msg;
        if (exchange.hasOut()) {
            msg = exchange.getOut(SparkMessage.class);
        } else {
            msg = exchange.getIn(SparkMessage.class);
        }
        if (msg != null) {
            return msg.getResponse();
        }
    }

    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:SparkConverter.java

示例10: convertTo

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
@FallbackConverter
@SuppressWarnings("unchecked")
public static <T> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
    if (value != null) {
        // should not try to convert Request as its not possible
        if (Request.class.isAssignableFrom(value.getClass())) {
            return (T) Void.TYPE;
        }
    }

    return null;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:13,代码来源:JettyConverter.java

示例11: InstanceMethodTypeConverter

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
public InstanceMethodTypeConverter(CachingInjector<?> injector, Method method, TypeConverterRegistry registry, boolean allowNull) {
    this.injector = injector;
    this.method = method;
    this.useExchange = method.getParameterTypes().length == 2;
    this.registry = registry;
    this.allowNull = allowNull;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:InstanceMethodTypeConverter.java

示例12: handleHasConverterAnnotation

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
private CachingInjector<?> handleHasConverterAnnotation(TypeConverterRegistry registry, Class<?> type,
                                                        CachingInjector<?> injector, Method method, boolean allowNull) {
    if (isValidConverterMethod(method)) {
        int modifiers = method.getModifiers();
        if (isAbstract(modifiers) || !isPublic(modifiers)) {
            LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: " + method
                    + " as a converter method is not a public and concrete method");
        } else {
            Class<?> toType = method.getReturnType();
            if (toType.equals(Void.class)) {
                LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: "
                        + method + " as a converter method returns a void method");
            } else {
                Class<?> fromType = method.getParameterTypes()[0];
                if (isStatic(modifiers)) {
                    registerTypeConverter(registry, method, toType, fromType,
                            new StaticMethodTypeConverter(method, allowNull));
                } else {
                    if (injector == null) {
                        injector = new CachingInjector<Object>(registry, CastUtils.cast(type, Object.class));
                    }
                    registerTypeConverter(registry, method, toType, fromType,
                            new InstanceMethodTypeConverter(injector, method, registry, allowNull));
                }
            }
        }
    } else {
        LOG.warn("Ignoring bad converter on type: " + type.getCanonicalName() + " method: " + method
                + " as a converter method should have one parameter");
    }
    return injector;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:33,代码来源:AnnotationTypeConverterLoader.java

示例13: handleHasFallbackConverterAnnotation

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
private CachingInjector<?> handleHasFallbackConverterAnnotation(TypeConverterRegistry registry, Class<?> type,
                                                                CachingInjector<?> injector, Method method, boolean allowNull) {
    if (isValidFallbackConverterMethod(method)) {
        int modifiers = method.getModifiers();
        if (isAbstract(modifiers) || !isPublic(modifiers)) {
            LOG.warn("Ignoring bad fallback converter on type: " + type.getCanonicalName() + " method: " + method
                    + " as a fallback converter method is not a public and concrete method");
        } else {
            Class<?> toType = method.getReturnType();
            if (toType.equals(Void.class)) {
                LOG.warn("Ignoring bad fallback converter on type: " + type.getCanonicalName() + " method: "
                        + method + " as a fallback converter method returns a void method");
            } else {
                if (isStatic(modifiers)) {
                    registerFallbackTypeConverter(registry, new StaticMethodFallbackTypeConverter(method, registry, allowNull), method);
                } else {
                    if (injector == null) {
                        injector = new CachingInjector<Object>(registry, CastUtils.cast(type, Object.class));
                    }
                    registerFallbackTypeConverter(registry, new InstanceMethodFallbackTypeConverter(injector, method, registry, allowNull), method);
                }
            }
        }
    } else {
        LOG.warn("Ignoring bad fallback converter on type: " + type.getCanonicalName() + " method: " + method
                + " as a fallback converter method should have one parameter");
    }
    return injector;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:AnnotationTypeConverterLoader.java

示例14: registerFallbackTypeConverter

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
protected void registerFallbackTypeConverter(TypeConverterRegistry registry, TypeConverter typeConverter, Method method) {
    boolean canPromote = false;
    // check whether the annotation may indicate it can promote
    if (method.getAnnotation(FallbackConverter.class) != null) {
        canPromote = method.getAnnotation(FallbackConverter.class).canPromote();
    }
    registry.addFallbackTypeConverter(typeConverter, canPromote);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:AnnotationTypeConverterLoader.java

示例15: InstanceMethodFallbackTypeConverter

import org.apache.camel.spi.TypeConverterRegistry; //导入依赖的package包/类
public InstanceMethodFallbackTypeConverter(CachingInjector<?> injector, Method method, TypeConverterRegistry registry, boolean allowNull) {
    this.injector = injector;
    this.method = method;
    this.useExchange = method.getParameterTypes().length == 4;
    this.registry = registry;
    this.allowNull = allowNull;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:InstanceMethodFallbackTypeConverter.java


注:本文中的org.apache.camel.spi.TypeConverterRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。