2012-10-22 131 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),這是未來的證明。 –