Resource not found on localhost using Anypoint Studio (MULE)

烈酒焚心 提交于 2019-12-14 02:13:15

问题


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>

Which can be found here 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.

When I enter the URL with no payload it works well. I get this response

Hello, /. Today is 23/01/15.

But when I add a payload like in the tutorial it doesn't work :

Resource not found.

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: [(*)/]

So basically the problem is :

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

回答1:


So with 3.6, the HTTP connector has changed drastically. Here are some changes:

  • 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.

  • 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"/>

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>

Cheers, JS




回答2:


As told before, the HTTP Connector is deeply changed from version 3.6 onward.

Now, the connector only listen to the specific path you explicitly define.

My issue was that I wasn't even able to get the WSDL by the obious http://localhost:8080/soap?wsdl.

So, the easiest solution I found to solve this issue was to allow the connector to accept all subpaths by ending the path with the wildcard '*'.

Change your project.xml as I show here:

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

and all subpaths will be processed.



来源:https://stackoverflow.com/questions/28113353/resource-not-found-on-localhost-using-anypoint-studio-mule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!