2012-10-19 2 views
1

플로우가 끝날 때 파일 다운로드를 담당하는 HTTP 엔드 포인트가 오류입니다. 전달 된 URL 대신 http://:80/과 계속 통신을 시도합니다. 여기서 내가 뭘 잘못하고 있니? --- 다윗HTTP 엔드 포인트로 뮬 파일 다운로드

큰 감사를

******************************************************************************** 
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) 
******************************************************************************** 

---이 해결 : 첫 번째 대답을 일치하도록 변경하면

<?xml version="1.0" encoding="UTF-8"?> 

<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 "> 
    <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"/> 
     <expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/> 
     <logger message="Payload is: #[message.payload]" level="INFO" doc:name="Logger"/> 
     <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, '/')]"/> 
     <file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[org.mule.util.StringUtils.replace(message.payload, '/','.')]" path="/home/user/Documents/output" mimeType="application/pdf"/> 
    </flow> 
</mule> 

, 나는이 예외를 얻을. 내가 오류를 발견 할 수

<?xml version="1.0" encoding="UTF-8"?> 
<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 "> 

    <configuration doc:name="Configuration"> 
     <expression-language> 
      <import class="org.mule.util.StringUtils" /> 
     </expression-language> 
    </configuration> 
    <flow name="BingQuery" doc:name="BingQuery"> 
     <http:inbound-endpoint exchange-pattern="one-way" 
      host="localhost" port="8082" 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=%27california%20school%20district%20contract%27&amp;WebFileType=%27PDF%27&amp;$top=10&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" /> 
     <vm:outbound-endpoint exchange-pattern="one-way" 
      doc:name="VM" path="fileWriter" /> 
    </flow> 
    <flow name="RestProcessor" doc:name="RestProcessor"> 
     <vm:inbound-endpoint exchange-pattern="one-way" 
      doc:name="VM" path="fileWriter" /> 
     <set-variable variableName="fileName" value="#[message.payload.ID].pdf" 
      doc:name="Variable" /> 
     <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]"></expression-filter> 
      </http:error-filter> 
     </http:rest-service-component> 
     <file:outbound-endpoint responseTimeout="10000" 
      doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/ken/Documents/output" 
      mimeType="application/pdf" /> 
    </flow> 
</mule> 
+0

: "페이로드는"? –

+0

URL에서 'http : //'를 뺀 – Thaneofife

답변

4

: 이것은 내 마지막 솔루션입니다 귀하의 흐름이 교대 시간에 몹시 신경을 쓰는 수있는 http:outbound-endpoint를 사용하여, 그래서 (나는 아래에서 자세히거야 문제는 제외) 좋아 보인다, http:rest-service-component을 사용할 수 있습니다.

다음 문제는 파일 끝점의 outputPattern에 있습니다.이 시점에서 message.payload은 (부분) URL이 아닌 HTTP 끝점의 응답이됩니다. 파일 이름을 미리 계산하여 플로우 변수에 저장 한 다음 사용해야합니다.

이 줄 것이다 : 이후에 기록됩니다 무엇

<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

굉장한 솔루션이지만 rest-service-component가 followRedirects를 수행하지 않습니까? 나는 .pdf로 끝나지 않는 것을 걸러 내기 위해 노력할 것입니다. pdf 로의 리다이렉트이기 때문에 3 번째 결과로 죽어 가고있다. – Thaneofife

+0

오, 문제 없어요.'rest-service-component'는 기본적으로 20x가 아닌 것을 거부하도록 구성되어 있습니다. 리디렉션을 따르도록 config를 찾을 수 있는지 보도록하겠습니다. –

+1

확인 확인 리디렉션에 대한 내 대답을 검토했습니다. 참고 문법을 좀 더 밝게하기 위해 MEL에'org.mule.util.StringUtils'을 전역 적으로 가져 왔습니다. –

관련 문제