Java 类org.apache.camel.component.cxf.CxfSpringEndpoint 实例源码

项目:Camel    文件:CxfEndpointBeanDefinitionParser.java   
@Override
protected Class<?> getBeanClass(Element arg0) {
    return CxfSpringEndpoint.class;
}
项目:fuse-bxms-integ    文件:KiePolicy.java   
public void process(Exchange exchange) throws Exception {
    // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
    // I need to copy the body of the exachange because for some reason
    // the getContext().getEndpoint() erase the content/or loose the reference
    String body = exchange.getIn().getBody(String.class);
    if (ke == null) {

        this.ke = exchange.getContext().getEndpoint(this.kieUri, KieEndpoint.class);
    }

    if (ke == null) {
        throw new RuntimeException("Could not find DroolsEndPoint for uri=" + this.kieUri);
    }

    ClassLoader originalClassLoader = null;
    try {
        originalClassLoader = Thread.currentThread().getContextClassLoader();

        CommandExecutor exec = ke.getExecutor();
        if (exec == null) {
            String lookup = exchange.getIn().getHeader(KieComponent.KIE_LOOKUP, String.class);
            if (StringUtils.isEmpty(lookup)) {
                // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
                lookup = ke.getLookup(body);
                // lookup = ke.getLookup( exchange.getIn().getBody( String.class ) );
            }

            if (StringUtils.isEmpty(lookup)) {
                throw new RuntimeException("No Executor defined and no lookup information available for uri " + this.ke.getEndpointUri());
            }
            exec = ke.getCommandExecutor(lookup);
        }

        if (exec == null) {
            throw new RuntimeException("CommandExecutor cannot be found for uri " + this.ke.getEndpointUri());
        }
        ClassLoader localClassLoader = ke.getClassLoader(exec);
        if (localClassLoader == null) {
            throw new RuntimeException("CommandExecutor Classloader cannot be null for uri " + this.ke.getEndpointUri());
        }

        // Set the classloader to the one used by the CommandExecutor
        // Have to set it in both places, as not all places yet use the camel ApplicationContextClassLoader (like xstream dataformats)
        Thread.currentThread().setContextClassLoader(localClassLoader);
        exchange.getContext().setApplicationContextClassLoader(localClassLoader);

        ExecutionNodePipelineContextImpl context = new ExecutionNodePipelineContextImpl(localClassLoader);
        context.setCommandExecutor(exec);

        exchange.setProperty("kie-context", context);
        // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
        // I need to re set the Body because the exchange loose the content at
        // the begining of the method
        exchange.getIn().setBody(new ByteArrayInputStream(body.getBytes("UTF-8")));

        boolean soap = false;
        if (!augmented && exchange.getFromEndpoint() instanceof CxfSpringEndpoint) {
            new PreCxfTransportSoapProcessor().process(exchange);
            soap = true;
        }
        processor.process(exchange);
        if (soap) {
            new PostCxfTransportSoapProcessor().process(exchange);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
        exchange.getContext().setApplicationContextClassLoader(originalClassLoader);
    }
}