1
votes

I'm trying to use .length from Java.lang.string imported through Mule's Expression Language (MEL) to find the length and use it in a choice operator. The issue I believe is a type mismatch, but don't know how to covert what I have so I'm able to find the length.

I'm exposing a web service and trying to use the ID from the POJO on the endpoint in the choice. Essential I want payload.bookID.length > 10. So if the ID is greater than 10 I can route to one service (google) otherwise route to UPC

Currently I'm getting

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 ....}]

The first part of the configuration File, and associated java files are included. I have questions further about flow, but don't know how to post data mappers so people could use them. If someone has tips on that also.

Thanks!

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

2 Answers

2
votes

The problem you are experiencing seems to be related to how you wrote the when expression.

It should look like this:

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

As per the datamapper question being a EE feature I'd recommend you to contact MuleSoft directly

4
votes

genjosanzo is right on both counts (wrong access to getBookid() and DataMapper EE support) except the correct MEL expression is:

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