使用Anypoint Studio(MULE)在localhost上找不到资源

Pap*_*ter 2 esb http localhost mule mule-studio

我试着在MuleSoft的网站上建议教程.

我首先从这个例子开始:

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

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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.6.0"
    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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8084" doc:name="HTTP Listener Configuration"/>
    <flow name="basic_tutorialFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <expression-filter expression="#[payload != '/favicon.ico']" doc:name="Expression"/>
        <logger level="INFO" doc:name="Logger" message="Current payload is #[payload]"/>
        <set-payload doc:name="Set Payload" value="#['Hello, ' + message.inboundProperties.'http.request.path' + '. Today is ' + server.dateTime.format('dd/MM/yy') + '.' ]"/>
    </flow>
</mule>
Run Code Online (Sandbox Code Playgroud)

可在此处找到http://www.mulesoft.org/documentation/display/current/Basic+Studio+Tutorial

我使用拖放功能制作它,之后我在网站上复制了代码,以确保它不是我的错误.

当我输入没有有效负载的URL时,它运行良好.我收到了这个回复

你好, /.今天是2015年1月23日.

但是,当我在教程中添加有效负载时,它不起作用:

资源未找到.

我也尝试了其他例子,只要我不输入有效载荷就可以了.以下是控制台告诉我的内容:

INFO  2015-01-23 10:33:55,614 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Current payload is {NullPayload}
INFO  2015-01-23 10:34:32,794 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: No listener found for request: (GET)/asd
INFO  2015-01-23 10:34:32,796 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: Available listeners are: [(*)/]
INFO  2015-01-23 10:34:36,205 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: No listener found for request: (GET)/world
INFO  2015-01-23 10:34:36,205 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: Available listeners are: [(*)/]
Run Code Online (Sandbox Code Playgroud)

基本上问题是:

INFO  2015-01-23 10:34:36,205 [[basic_tutorial].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.listener.HttpListenerRegistry: No listener found for request: (GET)/world
Run Code Online (Sandbox Code Playgroud)

jus*_*iba 5

因此,对于3.6,HTTP连接器已经发生了巨大变化.以下是一些变化:

  • 以前,HTTP连接器会将路径的内容放在有效负载内.而且,现在您需要按原样调用路径.我的意思是,如今你的端点正在侦听http:// localhost:8084 /,那就是你需要发送请求的地方.在http:// localhost:8084/HelloWorld上发送请求将不匹配.

  • 现在发送GET请求会将您的有效负载设置为NullPayload,这是有道理的,因为HTTP GET没有HTTP主体.

我建议如下:让您的端点在路径上监听如下:

<http:listener config-ref="HTTP_Listener_Configuration" path="/{name}" doc:name="HTTP"/>
Run Code Online (Sandbox Code Playgroud)

请注意,我添加了一个名为"name"的占位符变量,您可以将其更改为您喜欢的任何内容.然后,您可以按如下方式访问此占位符:

#[message.inboundProperties['http.uri.params']['name']]
Run Code Online (Sandbox Code Playgroud)

您可以使用此表达式返回一些花​​哨的字符串,如上所述:

<flow name="basic_tutorialFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/{name}"   doc:name="HTTP"/>
    <set-variable variableName="name" value="#[message.inboundProperties['http.uri.params']['name']]" />
    <set-payload doc:name="Set Payload" value="#['Hello, ' + flowVars['name'] + '. Today is ' + server.dateTime.format('dd/MM/yy') + '.' ]"/>
</flow>
Run Code Online (Sandbox Code Playgroud)

干杯,JS