使用Anypoint Studio(MULE)在localhost上找不到资源 [英] Resource not found on localhost using Anypoint Studio (MULE)
问题描述
我尝试在MuleSoft网站上建议的教程。
I tried to do the tutorials suggested on the MuleSoft's website.
我首先从这个例子开始:
I first started with this example:
<?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>
可以在这里找到 http://www.mulesoft.org/documentation/display/current/Basic+Studio+Tutorial
我是使用拖放功能制作的,之后我在网站上复制了代码,以确保这不是我的错误。
I made it using the drag and drop feature and after that I copied the code on the website just to be sure it wasn't my mistake.
当我输入没有有效负载的URL时,它运行良好。我得到了这个回复
When I enter the URL with no payload it works well. I get this response
你好,/。今天是2015年1月23日。
Hello, /. Today is 23/01/15.
但是当我在教程中添加有效负载时,它不起作用:
But when I add a payload like in the tutorial it doesn't work :
找不到资源。
我也尝试过其他例子,只要我不输入有效负载就可以了。以下是控制台告诉我的内容:
I have tried other examples as well, as long as I don't enter a payload it works. Here is what the console tells me :
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: [(*)/]
基本上问题是:
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
推荐答案
因此,使用3.6时,HTTP连接器发生了巨大变化。以下是一些更改:
So with 3.6, the HTTP connector has changed drastically. Here are some changes:
-
以前,HTTP连接器会将路径内容放在有效负载内。而且,现在您需要按原样调用路径。我的意思是,如今你的终端正在监听 http:// localhost:8084 / ,那就是你需要的地方发送请求。在 http:// localhost:8084 / HelloWorld 上发送请求将不匹配。
Previously, the HTTP connector would place the contents of the path inside your payload. Moreover, now you need to invoke paths as is. What I mean is that nowadays, if your endpoint is listening on http://localhost:8084/, that's where you need to send the request. Sending a request on http://localhost:8084/HelloWorld will NOT match.
现在发送GET请求会将您的有效负载设置为NullPayload,这是有道理的,因为HTTP GET没有HTTP正文。
Sending a GET request now will set your payload to NullPayload, which admittedly makes sense, since an HTTP GET does not have an HTTP body.
我建议如下:让你的终端在路径上监听如下:
What I suggest is the following: have your endpoint listening on a path as follows:
<http:listener config-ref="HTTP_Listener_Configuration" path="/{name}" doc:name="HTTP"/>
请注意,我添加了一个名为name的占位符变量,您可以将其更改为任何您喜欢。然后,您可以按如下方式访问此占位符:
Notice that I've added a placeholder variable called "name", you can change this to whatever you like. You can then access this placeholder as follows:
#[message.inboundProperties['http.uri.params']['name']]
您可以使用此表达式返回一些奇特的字符串,如上所述:
You can use this expression to return some fancy string, as you're doing above:
<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>
干杯,
JS
Cheers, JS
这篇关于使用Anypoint Studio(MULE)在localhost上找不到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!