我正在尝试使用通过 Mule 的表达式语言 (MEL) 导入的 Java.lang.string 中的 .length 来查找长度并在选择运算符中使用它。我认为的问题是类型不匹配,但不知道如何隐藏我所拥有的,所以我能够找到长度。
我正在公开一个 Web 服务并尝试在选择的端点上使用 POJO 中的 ID。基本我想要 payload.bookID.length > 10。所以如果 ID 大于 10,我可以路由到一项服务(谷歌),否则路由到 UPC
目前我得到
执行表达式“payload.bookid.length > 10”失败。(org.mule.api.expression.ExpressionRuntimeException)。消息负载类型:BookLookupService$Book
原因:[错误:无法访问:长度;在课堂上: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>
爪哇
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;
}
}