title: Mule file download with HTTP Endpoint
body: <p>My HTTP Endpoint responsible for downloading the file at the end of the flow is erroring out. It keeps trying to communicate with <code>http://:80/</code> instead of the URL passed in. What am I doing wrong here?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:https="http://www.mulesoft.org/schema/mule/https" 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="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
  http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
  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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd "&gt;
      &lt;flow name="BingFlow1" doc:name="BingFlow1"&gt;
          &lt;http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/&gt;
          &lt;https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&amp;amp;WebFileType=%27PDF%27&amp;amp;$top=50&amp;amp;$format=Json" user="*****" password="*****" doc:name="Bing"/&gt;
          &lt;json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/&gt;
          &lt;expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/&gt;
          &lt;collection-splitter doc:name="Collection Splitter"/&gt;
          &lt;expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/&gt;
          &lt;logger message="Payload is: #[message.payload]" level="INFO" doc:name="Logger"/&gt;
          &lt;http:outbound-endpoint exchange-pattern="request-response" host="#[org.mule.util.StringUtils.substringBefore(message.payload, '/')]" port="80" method="GET" doc:name="HTTP" contentType="application/pdf" mimeType="application/pdf" path="#[org.mule.util.StringUtils.substringAfter(message.payload, '/')]"/&gt;
          &lt;file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[org.mule.util.StringUtils.replace(message.payload, '/','.')]" path="/home/user/Documents/output" mimeType="application/pdf"/&gt;
      &lt;/flow&gt;
  &lt;/mule&gt;
  </code></pre>
  
  <p>When changed to match the first answer, I get this exception:</p>
  
  <pre><code>********************************************************************************
  Message               : Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHas
  hMap
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
  1. Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHashMap (org.mule.transp
  ort.http.components.RestServiceException)
    org.mule.transport.http.components.RestServiceWrapper:219 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/http/components/RestServiceException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  org.mule.transport.http.components.RestServiceException: Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Mess
  age payload is of type: LinkedHashMap
      at org.mule.transport.http.components.RestServiceWrapper.doInvoke(RestServiceWrapper.java:219)
      at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:126)
      at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:61)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  </code></pre>
  
  <p><strong>--- SOLVED ---</strong></p>
  
  <p>Big thanks to David. This is my final solution:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:file="http://www.mulesoft.org/schema/mule/file"
      xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json"
      xmlns:https="http://www.mulesoft.org/schema/mule/https" 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="CE-3.3.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
  http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
  http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.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/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
  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 "&gt;
  
      &lt;configuration doc:name="Configuration"&gt;
          &lt;expression-language&gt;
              &lt;import class="org.mule.util.StringUtils" /&gt;
          &lt;/expression-language&gt;
      &lt;/configuration&gt;
      &lt;flow name="BingQuery" doc:name="BingQuery"&gt;
          &lt;http:inbound-endpoint exchange-pattern="one-way"
              host="localhost" port="8082" doc:name="HTTP" /&gt;
          &lt;https:outbound-endpoint exchange-pattern="request-response"
              host="api.datamarket.azure.com" port="443"
              path="Data.ashx/Bing/Search/v1/Web?Query=%27california%20school%20district%20contract%27&amp;amp;WebFileType=%27PDF%27&amp;amp;$top=10&amp;amp;$format=Json"
              user="*****" password="*****"
              doc:name="Bing" /&gt;
          &lt;json:json-to-object-transformer
              returnClass="java.util.Map" doc:name="JSON to Object" /&gt;
          &lt;expression-transformer expression="#[message.payload.d.results]"
              doc:name="Expression" /&gt;
          &lt;collection-splitter doc:name="Collection Splitter" /&gt;
          &lt;vm:outbound-endpoint exchange-pattern="one-way"
              doc:name="VM" path="fileWriter" /&gt;
      &lt;/flow&gt;
      &lt;flow name="RestProcessor" doc:name="RestProcessor"&gt;
          &lt;vm:inbound-endpoint exchange-pattern="one-way"
              doc:name="VM" path="fileWriter" /&gt;
          &lt;set-variable variableName="fileName" value="#[message.payload.ID].pdf"
              doc:name="Variable" /&gt;
          &lt;http:rest-service-component
              serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&amp;amp;':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]"
              httpMethod="GET"&gt;
              &lt;http:error-filter&gt;
                  &lt;expression-filter
                      expression="#[Integer.valueOf(message.inboundProperties['http.status']) &amp;gt;= 400]"&gt;&lt;/expression-filter&gt;
              &lt;/http:error-filter&gt;
          &lt;/http:rest-service-component&gt;
          &lt;file:outbound-endpoint responseTimeout="10000"
              doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/ken/Documents/output"
              mimeType="application/pdf" /&gt;
      &lt;/flow&gt;
  &lt;/mule&gt;
  </code></pre>