我从Mule开始,我尝试从他们的页面执行一些示例,但几乎总是我得到相同的错误:“消息有效负载的类型为:BufferInputStream ” ,所以我不知道我的流程是否有问题。这是我的XML
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:db="http://www.mulesoft.org/schema/mule/db" 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="CE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<db:template-query name="insert_into_current" doc:name="Template Query">
<db:parameterized-query><![CDATA[INSERT INTO current("name", "date", "bookvalue") VALUES(:name,:date,:bookvalue);]]></db:parameterized-query>
<db:in-param name="name" defaultValue="#[xpath('//Name').text]"/>
<db:in-param name="date" type="DATE" defaultValue="#[xpath('//LastTradeDate').text]"/>
<db:in-param name="bookvalue" defaultValue="#[xpath('//BookValue').text])"/>
</db:template-query>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="query.yahooapis.com" basePath="v1/public/yql" doc:name="HTTP Request Configuration" port="80"/>
<db:mysql-config name="MySQL_Configuration" host="xxxxxx" port="3306" user="" password="xxxx" database="xxxx" doc:name="MySQL Configuration"/>
<flow name="financeapiFlow1" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" followRedirects="true" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="q" value="#[message.inboundProperties.'http.query.params'.q]"/>
<http:query-param paramName="env" value="#[message.inboundProperties.'http.query.params'.env]"/>
<http:query-param paramName="format" value="#[message.inboundProperties.'http.query.params'.format]"/>
</http:request-builder>
</http:request>
<logger message=""### VALUES "+#[message.inboundProperties.'http.query.params'.q]+" - "+#[message.inboundProperties.'http.query.params'.env]+" - "+#[message.inboundProperties.'http.query.params'.format]" level="INFO" doc:name="Logger"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<db:insert config-ref="MySQL_Configuration" doc:name="Database">
<db:dynamic-query><![CDATA[INSERT INTO MULE("symbol", "lastTradeDate", "bookvalue") VALUES('#[message.payload.query.results.quote.symbol]','#[message.payload.query.results.quote.LastTradeDate]','#[message.payload.query.results.quote.BookValue]');]]></db:dynamic-query>
</db:insert>
</flow>
这是我的堆栈跟踪:
Exception stack is:
1. null (java.lang.NullPointerException)
org.mule.mvel2.optimizers.impl.refl.nodes.MapAccessor:42 (null)
2. cannot invoke getter: getInboundProperties (see trace) (java.lang.RuntimeException)
org.mule.mvel2.optimizers.impl.refl.nodes.GetterAccessor:70 (null)
3. Execution of the expression "message.inboundProperties.'http.query.params'.q" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.MVELExpressionLanguage:202 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
4. Execution of the expression "message.inboundProperties.'http.query.params'.q" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: BufferInputStream (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
at org.mule.mvel2.optimizers.impl.refl.nodes.MapAccessor.getValue(MapAccessor.java:42)
at org.mule.mvel2.optimizers.impl.refl.nodes.MapAccessor.getValue(MapAccessor.java:39)
at org.mule.mvel2.optimizers.impl.refl.nodes.GetterAccessor.getValue(GetterAccessor.java:40)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
谢谢!
答案 0 :(得分:1)
问题是,一旦到达request
,listener
的inboundProperties就会丢失,因此以下logger
上的表达式会失败。我建议将这些属性保存到变量或向上移动logger
,如果你想要的只是了解HTTP请求的样子。