2012-10-22 77 views
1

我试图从通过Mule的表达式语言(MEL)导入的Java.lang.string中使用.length来查找长度并在选择运算符中使用它。我认为这个问题是一种类型不匹配,但不知道如何隐藏我所拥有的所以我能够找到长度。在Mule中使用导入的Java语言表达式语言

我正在公开一个Web服务,并尝试在选择的端点上使用POJO中的ID。基本我想payload.bookID.length> 10.因此,如果ID大于10,我可以给一个服务(谷歌),否则路线UPC

航线

目前我得到

Execution of the expression "payload.bookid.length > 10" failed.(org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: BookLookupService$Book
Caused by: [Error: could not access: length; in class: java.lang.String] [Near : {... Unknown ....}]

第一包括配置文件的一部分和相关的java文件。我对流程有进一步的问题,但不知道如何发布数据映射器以便人们可以使用它们。如果有人也有提示。

谢谢!

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" 
    xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" 
    xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 
    xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" 
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" 
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.3.1" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd 
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd "> 
    <mulexml:namespace-manager 
     includeConfigNamespaces="true"> 
     <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
     <mulexml:namespace prefix="cas" uri="http://case2.com/"/> 
     <mulexml:namespace prefix="cas1" uri="http://case2.com/"/> 
    </mulexml:namespace-manager> 
    <data-mapper:config name="json_to_pojo" 
     transformationGraphPath="json_to_pojo.grf" doc:name="DataMapper" /> 
    <data-mapper:config name="google_out_to_pojo" transformationGraphPath="google_out_to_pojo.grf" doc:name="google_out_to_pojo"/> 
    <data-mapper:config name="google_out" transformationGraphPath="google_out.grf" doc:name="google_out"/> 

    <flow name="case2Flow1" doc:name="case2Flow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" 
      address="http://localhost:8081/Case2" doc:name="HTTP"></http:inbound-endpoint> 
     <cxf:simple-service serviceClass="com.case2.BookLookupService" 
      doc:name="SOAP" /> 
     <component class="com.case2.BookLookupServiceImpl" doc:name="Java" /> 
     <logger 
      message="Incoming payload is: #[payload] 
Book ID is : #[payload.bookid]" 
      level="INFO" doc:name="Logger" /> 
     <choice doc:name="Choice"> 
      <when expression="payload.bookid.length > 10"> 
       <flow-ref name="googleISBNFlow2" doc:name="Google" /> 
      </when> 
     </choice> 
    </flow> 

</mule> 

的Java

package com.case2; 

public interface BookLookupService 
{ 
public static class BookLookup 
{ 
    private String bookid; 

    public String getBookid() 
    { 
     return bookid; 
    } 

    public void setBookid(final String bookid) 
    { 
     this.bookid = bookid; 
    } 
} 

public static class Book 
{ 
    private String bookid, name, imageurl; 

    public String getBookid() 
    { 
     return bookid; 
    } 

    public void setBookid(final String bookid) 
    { 
     this.bookid = bookid; 
    } 

    public String getName() 
    { 
     return name; 
    } 

    public void setName(final String name) 
    { 
     this.name = name; 
    } 


    public String getImageURL() 
    { 
     return imageurl; 
    } 

    public void setImageURL(final String imageurl) 
    { 
     this.imageurl = imageurl; 
    } 

} 

Book lookup(final BookLookup bookLookup); 
} 



package com.case2; 

public class BookLookupServiceImpl implements BookLookupService 
{ 
    public Book lookup(final BookLookup bookLookup) 
    { 
     final Book book = new Book(); 
     book.setName("LOTR"); 
     book.setBookid(bookLookup.getBookid()); 
     return book; 
    } 
} 

回答

2

您所遇到的问题似乎涉及您如何写的时候表达。

它应该是这样的:

<when expression="#[payload.bookid.length() > 10]"> 

由于每DataMapper的问题是一个EE的功能,我建议您联系MuleSoft直接

4

genjosanzo是正确的这两个方面(错误访问getBookid()和DataMapper EE支持)除了正确的MEL表达式是:

<when expression="#[message.payload.bookid.length() > 10]"> 
+0

大卫关心解释为什么你应该指定message.payload当genjosanzo的作品。它可以访问另一个有效载荷吗? – bbotz

+1

如果直接使用'payload',则使用隐式向后兼容模式,可能永久保留在MEL中,也可能不会永久保存。如果使用'message.payload',则使用规范的MEL(请参阅http://www.mulesoft.org/documentation/display/MULE3USER/Mule+Expression+Language#MuleExpressionLanguage-Message),这是未来的证明。 –