Resource not found on localhost using Anypoint Studio (MULE)

Paperbag Writer picture Paperbag Writer · Jan 23, 2015 · Viewed 7.2k times · Source

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

Answer

justin.saliba picture justin.saliba · Jan 23, 2015

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