【问题标题】:Resource not found on localhost using Anypoint Studio (MULE)使用 Anypoint Studio (MULE) 在 localhost 上找不到资源
【发布时间】:2015-03-22 16:41:48
【问题描述】:

我尝试按照 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>

可以在这里找到http://www.mulesoft.org/documentation/display/current/Basic+Studio+Tutorial

我使用拖放功能完成了它,然后我在网站上复制了代码以确保这不是我的错误。

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

你好,/。今天是 23/01/15。

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

找不到资源。

我也尝试过其他示例,只要我不输入有效负载即可。这是控制台告诉我的:

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

【问题讨论】:

    标签: http localhost mule esb mule-studio


    【解决方案1】:

    如前所述,从 3.6 版开始,HTTP 连接器发生了很大变化。

    现在,连接器只监听您明确定义的特定路径。

    我的问题是我什至无法通过可恶的http://localhost:8080/soap?wsdl 获得 WSDL。

    因此,我发现解决此问题的最简单解决方案是允许连接器通过以通配符“*”结束路径来接受所有子路径。

    如下所示更改您的 project.xml:

    <http:listener config-ref="HTTP_Listener_Configuration" path="/*" doc:name="HTTP"/>
    

    所有子路径都会被处理。

    【讨论】:

      【解决方案2】:

      因此,在 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"/>
      

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

      #[message.inboundProperties['http.uri.params']['name']]
      

      你可以使用这个表达式返回一些花​​哨的字符串,就像你在上面做的那样:

      <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

      【讨论】:

      • 感谢 JS,这真的很有帮助。我有点困惑。如果我还想拥有 localhost:8084 返回 Hello, /。今天是 23/01/15。 (因为现在它返回 Resource note found)我需要在我的流程中添加一个选择块吗?
      • 对此有任何答案吗?我复制了贾斯汀的解决方案。我收到了与 Paperbag 类似的回复:“你好,null。今天是 09/02/15。”发送“localhost:8081/test?name=name”时
      • 嗨,戴夫。您可以使用“http.query.params”入站属性访问查询参数。 @PaperbagWriter 使用的是 URI 参数。
      猜你喜欢
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 2015-08-21
      • 2018-08-20
      • 1970-01-01
      • 2018-05-07
      • 2016-07-29
      • 1970-01-01
      相关资源
      最近更新 更多