Jim Archer
Jim Archer

Reputation: 1417

Mulesoft HTTP Connector configuration

When I connect to:

http://legacy.cafebonappetit.com/api/2/menus?cafe=261

I get back JSON as I should. However, I'm unable to do this with the Mulesoft HTTP Connector. When I try, I get back 500. Here is my XML:

    <flow name="GetDiningInfo">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
    <http:request config-ref="HTTP_Request_Configuration" path="/api/2/menus" method="GET" doc:name="GET announcement from dining server" followRedirects="true" host="legacy.cafebonappetit.com" port="80">
        <http:request-builder>
            <http:query-param paramName="cafe" value="261"/>
        </http:request-builder>
    </http:request>
    <logger level="INFO" doc:name="Logger"/>
</flow>

The connector global config is:

    <http:request-config name="HTTPReqConfigforCafeBonAppetit.com" host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP Request Configuration"/>

What am I doing wrong?

Thanks...

UPDATE: Still no joy. I'm still getting back a 500 internal server failure through Mule.

Here is the latest code that does not duplicate the path:

<http:request-config name="HTTPReqConfigforCafeBonAppetit" host="legacy.cafebonappetit.com" port="80" basePath="/api/2/" doc:name="HTTP Request Configuration" usePersistentConnections="false"/>

<flow name="GetDiningInfo">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
    <http:request config-ref="HTTPReqConfigforCafeBonAppetit" path="menus" method="GET" doc:name="GET menu" followRedirects="true" parseResponse="false">
        <http:request-builder>
            <http:query-param paramName="cafe" value="261"/>
        </http:request-builder>
    </http:request>
    <logger level="INFO" doc:name="Logger"/>
</flow>

Upvotes: 1

Views: 4155

Answers (10)

LINI MOL
LINI MOL

Reputation: 1

http:request-builder

try to add a header

Upvotes: 0

Pakalavenkatreddy
Pakalavenkatreddy

Reputation: 1

Use this below code for your issue...

<http:request config-ref="HTTP_Request_Configuration" path="/menus" method="GET" doc:name="HTTP">
    <http:request-builder>
        <http:query-param paramName="cafe" value="261"/>
        <http:header headerName="Host" value="the_host"/>
    </http:request-builder>
    <http:success-status-code-validator values="100..599"/>
</http:request>

Upvotes: 0

Anil Agrawal
Anil Agrawal

Reputation: 11

you can use the code like this

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" 
port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" 
host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP 
Request Configuration"/>
<flow name="so-testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" 
doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="menus" 
method="GET" doc:name="HTTP">
<http:request-builder>
        <http:query-param paramName="cafe" value="261"/>
        <http:header headerName="Host" value="legacy.cafebonappetit.com"/>
    </http:request-builder>
    <http:success-status-code-validator values="100..599"/>
</http:request>
</flow>

Upvotes: 0

KranthiKumar
KranthiKumar

Reputation: 1

The server for legacy.cafebonappetit.com cannot handle the header Host including the port (which is valid). The HTTP connector sends Host: legacy.cafebonappetit.com:80 by default causing the server to reject the request, so you need to explicitly add the Host header, as in the example below. enter image description here

Upvotes: 0

Raj Mevada
Raj Mevada

Reputation: 21

You have to delete base path from global configuration of delete path in your xml because it generates url like : http://legacy.cafebonappetit.com/api/2/api/2/menus?cafe=261

here in url api/2/api/2 generated twice so thats why error occured

Upvotes: 0

ravi
ravi

Reputation: 21

The only way to resolve this issue is to make the server process the request. Add this line in the xml,

<http:header headerName="Host" value="the_host"/>

Upvotes: 0

Well the trouble here is when you send a request to the server by the 80 port. The server rejects the request immediately. To resolve this you got to add the header, so this way the server understand and process the request.

To do that just add the following line: $<http:header headerName="Host" value="the_host"/>.

The following XML got the solution:

<http:listener-config name="localhost" port="8085" doc:name="HTTP Listener Configuration" host="0.0.0.0"/>
<http:request-config name="HTTP_Request_Configuration" host="legacy.cafebonappetit.com" port="80"  doc:name="HTTP Request Configuration" basePath="/api/2"/>
<flow name="GetDiningInfo">
    <http:listener config-ref="localhost" path="/dining" doc:name="HTTP"/>
    <http:request config-ref="HTTP_Request_Configuration" path="/menus" method="GET" doc:name="HTTP">
        <http:request-builder>
            <http:query-param paramName="cafe" value="261"/>
            <http:header headerName="Host" value="legacy.cafebonappetit.com"/>
        </http:request-builder>
        <http:success-status-code-validator values="100..599"/>
    </http:request>    
     <logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow> 

Upvotes: 0

afelisatti
afelisatti

Reputation: 2835

The server for legacy.cafebonappetit.com cannot handle the header Host including the port (which is valid). The HTTP connector sends Host: legacy.cafebonappetit.com:80 by default causing the server to reject the request, so you need to explicitly add the Host header, as in the example below.

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="legacy.cafebonappetit.com" port="80" basePath="/api/2" doc:name="HTTP Request Configuration"/>
<flow name="so-testFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
    <http:request config-ref="HTTP_Request_Configuration" path="menus" method="GET" doc:name="HTTP">
        <http:request-builder>
            <http:query-param paramName="cafe" value="261"/>
            <http:header headerName="Host" value="legacy.cafebonappetit.com"/>
        </http:request-builder>
        <http:success-status-code-validator values="100..599"/>
    </http:request>
</flow>

The example also includes a status code validator for all codes which allows you to see the exact error the server sends when the explicit Host header is removed.

Upvotes: 0

Naveen Raj
Naveen Raj

Reputation: 801

The below code seems to work.

<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8084" doc:name="HTTP Listener Configuration"/>

<http:endpoint exchange-pattern="request-response" method="POST" name="HTTP" address="http://legacy.cafebonappetit.com/api/2/menus?cafe=261" doc:name="HTTP"/>
<flow name="GetDiningInfo">
<http:listener config-ref="HTTP_Listener_Configuration" path="/dining" doc:name="HTTP"/>
 <logger level="INFO" doc:name="Logger"/>


Upvotes: -1

sulthony h
sulthony h

Reputation: 1277

Have you evaluated the URL request result? By referring that configuration it should be http://legacy.cafebonappetit.com/api/2/api/2/menus?cafe=261

That's why you unable to get the expected result. Therefore replace the path of http:request with /menus, without the base path /api/2. Because it's already defined in http:request-config

Upvotes: 2

Related Questions