Mule file download with HTTP Endpoint

后端 未结 1 1857
有刺的猬
有刺的猬 2021-01-07 11:17

My HTTP Endpoint responsible for downloading the file at the end of the flow is erroring out. It keeps trying to communicate with http://:80/ instead of the URL

相关标签:
1条回答
  • 2021-01-07 11:55

    I can't spot the error: your flow looks good (except a problem I'll detail below) so, alternatively to using an http:outbound-endpoint, which can be finicky at times, you could use the http:rest-service-component.

    Your next problem will be in the outputPattern of the file endpoint: remember at this point message.payload will be the response from the HTTP endpoint not the (partial) URL anymore. You need to pre-compute the file name and store it in a flow variable, then use it.

    This would give:

    <configuration>
      <expression-language>
        <import class="org.mule.util.StringUtils" />
      </expression-language>
    </configuration>
    
    <flow name="BingFlow1" doc:name="BingFlow1">
        <http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/>
        <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;WebFileType=%27PDF%27&amp;$top=50&amp;$format=Json" user="*****" password="*****" doc:name="Bing"/>
        <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
        <expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
        <collection-splitter doc:name="Collection Splitter"/>
        <set-variable variableName="fileName" value="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://').replace('/','.')]" />
        <http:rest-service-component serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&amp;':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]" httpMethod="GET">
            <http:error-filter>
                <expression-filter expression="#[Integer.valueOf(message.inboundProperties['http.status']) &gt;= 400]" />
            </http:error-filter>
        </http:rest-service-component>
        <file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/user/Documents/output" mimeType="application/pdf"/>
    </flow>
    
    0 讨论(0)
提交回复
热议问题