2013-06-24 70 views
1

问题也可能与我对这个概念的理解有关。
ActionClass正在调用代理bean,即AccountingInterface。代理bean接口使用AccountingUtil类实现。所以我期待AccountingUtil返回xml通过seda:accountingQueue,然后流出控制台。
的ApplicationContextApache Camel Proxy不起作用

<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) 

还有一个问题我可以拥有多个serviceURLproxyBean(interface)
我想用不同的方法调用不同的serviceURL,但只是单个接口的一部分。

回答

0

更新: 啊,刚刚明白你的问题。首先是位居第一。

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

不,不同的方法会调用相同的URL,但是..以及BeanInvocation中的不同方法。这当然可以通过在骆驼路由中路由请求来实现,例如首先将它发送到一个简单的direct:routeAccoutingRequest,然后查看调用的方法以找出它应该在选择结构中应该到达哪个端点。

你可以使用一个普通的对象与ProducerTemplates建立你自己的逻辑来实现诸如发送字符串,调用不同的方法等等。代理是用于代理bean调用。

+0

这应该不是我想的问题。对于一个简单的用例,普通代理bean正在工作。这种方法在骆驼行动中提到。 “代理接口方法的返回”会转到服务url吗? –

+0

阅读这个问题有点太快了。根本改变了答案 –

+0

我明白了每个代理bean都有onUR serviceURL的意思。无法理解我的流程为什么会出错。更新我的问题以解释代码流。 –