Apache Camel Proxy无法正常工作

时间:2013-06-24 21:15:35

标签: java apache-camel

问题也可能与我对这个概念的理解有关。
ActionClass正在调用AccountingInterface的代理bean。代理bean接口使用AccountingUtil类实现。所以我希望xml返回的AccountingUtil能够通过seda:accountingQueue传递,然后在控制台上流式传输。
的ApplicationContext

    <bean id="accountingInterface" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
      <property name="serviceUrl" value="seda:accountingQueue"/>
      <property name="serviceInterface" value="acord.transaction.util.AccountingInterface"/>
    </bean>
    <route>
        <from uri="seda:accountingQueue"/>
        <setHeader headerName="nowInMillis">
           <groovy>new Date().getTime()</groovy>
         </setHeader>
         <to uri="stream:out"/>
    </route>

AccountingInterface

public interface AccountingInterface 
{
    void send(String xml);
    String accountingUpdate(EDITDate accountingProcessDate);
}

AccountingUtil

public class AccountingUtil implements AccountingInterface
{
  public String accountingUpdate(EDITDate accountingProcessDate)
     {
       //doSomething
      return xml;
    }

ActionClass

AccountingInterface accountingInterface = (AccountingInterface) AppContext.getBean("accountingInterface");
accountingInterface.accountingUpdate(accountingProcessDate);

但我得到例外:

No body available of type: java.lang.String but has value: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]] of type: org.apache.camel.component.bean.BeanInvocation on: Message: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]. Caused by: No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.lang.String with value BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]. Exchange[Message: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.lang.String with value BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]]
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)

还有一个问题我可以为单个serviceURL设置多个proxyBean(interface)吗?我想要不同的方法来调用不同的serviceURL,但只是单个界面的一部分。

1 个答案:

答案 0 :(得分:0)

<强>更新 啊,只是理解你的问题。首先是第一位。

进行代理时,Camel会将调用(以哪个方法/接口和哪些参数)转换为BeanInvocation对象。然后通过选择的Camel端点(在您的情况下为seda)进行处理。但是你试图将它打印到std out而不是调用AccountingInterface的bean实例(例如你的AccountingUpdateACORDUtil)。

不,不同的方法会调用同一个网址,但是BeanInvocation中有不同的方法。这当然可以通过在Camel路由中路由您的请求来实现,例如首先将其发送到简单的direct:routeAccoutingRequest然后查看调用的方法以确定它应该在选择构造中去哪个端点。

您可以使用带有ProducerTemplates的普通对象构建自己的逻辑,以实现发送字符串,调用不同方法等内容。代理用于代理bean调用。