请求BODY在Apache-Camel上的Exchange期间返回NULL

时间:2014-10-30 18:30:17

标签: java cxf apache-camel

我有一个使用Apache-camel(版本2.9.1)的项目来检索一些信息。问题是当我调用方法时:

 final DecriptResponseHSMConnector responseData = camelTemplate
.requestBodyAndHeaders(CXFRS_BEAN_HSM_CONNECTOR_CLIENT,
  cardDataRequest, param,
  DecriptResponseHSMConnector.class); 

请求Body和Headers我得到例外:

Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: DecriptCardDataRequest [dataType=SOMEDATA, bdk=SOMEDATA, keySerialNumber=SOMEDATA, encryptedData=SOMEDATA]]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1237)
at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:509)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeaders(DefaultProducerTemplate.java:247)
at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:296)
at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:292)
at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:329)
at br.com.cielo.pp.hsm.CriptografarCartaoServiceImpl.obterCartaoDescriptografado(CriptografarCartaoServiceImpl.java:150)
at br.com.cielo.pp.hsm.CriptDescrypt.descritografaNumeroCartao(CriptDescrypt.java:20)
at servicesocket.Main.main(Main.java:23)
Caused by: java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.hash(Unknown Source)
at java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
at com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.get(ConcurrentLinkedHashMap.java:740)
at org.apache.camel.util.LRUCache.get(LRUCache.java:62)
at org.apache.camel.util.LRUSoftCache.get(LRUSoftCache.java:73)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer$ClientFactoryBeanCache.get(CxfRsProducer.java:355)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeProxyClient(CxfRsProducer.java:196)
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProducer.java:89)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63)
at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:352)
at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:324)
at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:223)
at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:324)
at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:186)
at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:115)
at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeaders(DefaultProducerTemplate.java:238)
... 6 more

NullPointerException 的确切点在于 ExchangeHelper.class类(来自apache-camel的内部类)的以下方法,此处:

public static Object extractResultBody(Exchange exchange, ExchangePattern pattern) {
    Object answer = null;
    if (exchange != null) {
        // rethrow if there was an exception during execution
        if (exchange.getException() != null) {
            throw ObjectHelper.wrapCamelExecutionException(exchange, exchange.getException());
        }

        // result could have a fault message
        if (hasFaultMessage(exchange)) {
            return exchange.getOut().getBody();
        }

        // okay no fault then return the response according to the pattern
        // try to honor pattern if provided
        boolean notOut = pattern != null && !pattern.isOutCapable();
        boolean hasOut = exchange.hasOut();
        if (hasOut && !notOut) {
            // we have a response in out and the pattern is out capable
            answer = exchange.getOut().getBody();
        } else if (!hasOut && exchange.getPattern() == ExchangePattern.InOptionalOut) {
            // special case where the result is InOptionalOut and with no OUT response
            // so we should return null to indicate this fact
            answer = null;
        } else {
            // use IN as the response
            answer = exchange.getIn().getBody();
        }
    }
    return answer;
}

我的applicationContext现在:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cxf="http://camel.apache.org/schema/cxf" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 
   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
   http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
   http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

<!-- Enable Spring Application Context -->
<context:spring-configured />

<!-- Enable @Required @Autowired @PreDestroy @PostConstruct @Resource -->
<context:annotation-config />
<context:spring-configured></context:spring-configured>

<!-- Scan context package for any eligible annotation configured beans. -->
<context:component-scan base-package="br.com.SOMEINFO.pp.hsm" />
<context:component-scan base-package="br.com.SOMEINFO.pp.cadastrocartoes" />

<camelContext xmlns="http://camel.apache.org/schema/spring" />

<bean
    class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />

<bean id="Customer" class="HelloWorldService.Customer">
</bean>



<!-- configuracao acesso weblogic -->
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            <prop key="java.naming.provider.url">SOMEINFO</prop>
            <prop key="java.naming.security.principal">SOMEINFO</prop>
            <prop key="java.naming.security.credentials">SOMEINFO</prop>
        </props>
    </property>
</bean>

<bean id="jndiFactoryBean" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="ConnectionFactory3" />
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="lookupOnStartup" value="false" />
    <property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="jndiDestinationResolver"
    class="org.springframework.jms.support.destination.JndiDestinationResolver">
    <property name="jndiTemplate" ref="jndiTemplate" />
</bean>
<bean id="jmsConfiguration" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="jndiFactoryBean" />
    <property name="destinationResolver" ref="jndiDestinationResolver" />
</bean>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="configuration" ref="jmsConfiguration" />
</bean>
<!-- configuracao JMS ppTransacional -->
<bean id="jndiTemplate2" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            <prop key="java.naming.provider.url">SOMEINFO</prop>
        </props>
    </property>
</bean>

<bean id="jndiTemplate3" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            <prop key="java.naming.provider.url">SOMEINFO</prop>
            <prop key="java.naming.security.principal">SOMEINFO</prop>
            <prop key="java.naming.security.credentials">SOMEINFO</prop>
        </props>
    </property>
</bean>

<bean id="helloWorldService" class="HelloWorldService.HelloWorldService">
    <property name="name" value="Spring 3.2.3" />
</bean>

<!-- HSM Connector -->

<cxf:rsClient id="hsmConnectorClient"
    address="http://SOMEINFO/HSMConnector-1.0/services/HSMConnector"
    serviceClass="br.com.prill.SOMEINFO.silicio.hsm.proxy.HSMConnectorProxy"
    loggingFeatureEnabled="true" />

有任何提示要纠正这个问题吗?

0 个答案:

没有答案