2016-03-14 2 views
1

У меня есть мул вид потока, как показано нижеОбработка Accept кодирование в ESB мул

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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" 
    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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd"> 
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8111" doc:name="HTTP Listener Configuration"/> 
    <http:request-config name="HTTP_Request_Configuration" host="api.bonanza.com" port="443" doc:name="HTTP Request Configuration" protocol="HTTPS"/> 
    <flow name="bonanza_fetchtoken_ceFlow"> 
     <http:listener config-ref="HTTP_Listener_Configuration" path="/add" allowedMethods="GET,POST" doc:name="HTTP" /> 
     <flow-ref name="bonanza_addfixedpriceitemSub_Flow" doc:name="bonanza_addfixedpriceitemSub_Flow"/> 
    </flow> 
    <sub-flow name="bonanza_addfixedpriceitemSub_Flow"> 
     <message-properties-transformer doc:name="Message Properties"> 
      <add-message-property key="X-BONANZLE-API-DEV-NAME" value="t******I"/> 
      <add-message-property key="X-BONANZLE-API-CERT-NAME" value="l*****F"/> 
     </message-properties-transformer> 
     <set-property propertyName="Content-Type" value="application/x-www-form-urlencoded" doc:name="Property"/> 
     <set-property propertyName="Accept" value="application/json" doc:name="Property"/> 
     <set-variable variableName="sim" value="{requesterCredentials:{bonanzleAuthToken:nWn1a9l3NT}}" doc:name="Variable"/> 
     <scripting:transformer returnClass="java.util.Map" doc:name="Groovy"> 
      <scripting:script engine="Groovy"><![CDATA[import groovy.json.JsonBuilder 
m = [addFixedPriceItemRequest:'{requesterCredentials:{bonanzleAuthToken:n*****T}}'] 
builder = new JsonBuilder() 
builder(m) 

]]></scripting:script> 
     </scripting:transformer> 

     <logger message="payload :#[payload]" level="INFO" doc:name="Logger"/> 
     <http:request config-ref="HTTP_Request_Configuration" path="/api_requests/secure_request" method="POST" followRedirects="true" parseResponse="false" doc:name="HTTP"> 
      <http:success-status-code-validator values="0..599"/> 
     </http:request> 
     <logger message="resp :#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/> 
    </sub-flow> 
</mule> 

Я могу получать успешный ответ от API с помощью почтальона инструмента. Я пытаюсь моделировать то же самое, используя выше поток ESB мула. Но API выдает мне ошибку, как показано ниже. Поэтому я использовал requestb.in для сравнения запросов, поступающих из esb mule и postman. Я обнаружил различия в HTTP-заголовках.

RAW тела от почтальона requestb.in -

addFixedPriceItemRequest={requesterCredentials:{bonanzleAuthToken:nW*****NT}} 

RAW тело от ESB мула к requestb.in

addFixedPriceItemRequest=%7BrequesterCredentials%3A%7BbonanzleAuthToken%3AnW****NT%7D%7D 

кажется, что я должен сериализовать содержимое JSon перед отправкой, как содержание type - application/x-www-form-urlencoded. Я нашел эту информацию в этом mule doc

Как я могу сериализовать полезную нагрузку json в groovy и отправлять в качестве полезной нагрузки карты?

Response API Error

{ 
    "ack": "Failure", 
    "version": "1.0beta", 
    "timestamp": "2016-03-15T07:18:11.000Z", 
    "errorMessage": { 
    "message": "Cannot determine what type of request you are making. Often this can be the result of data that has not been escaped before being passed to the API. If you are passing data with quotation marks or other special characters, you should translate it to JSON, then escape it, before sending it over the API." 
    } 
} 

Пожалуйста, дайте мне знать, для какой-либо дополнительной информации. Заранее спасибо!

+0

Трудно понять, в чем проблема, с которой вы столкнулись. Он отправляет исходящие запросы в «http: request» или формирует ответы на запросы, поступающие в «http: listener». –

+0

Когда вы принимаете кодировку 'gzip', почему вы извлекаете полезную нагрузку ответа как String? –

+0

@CharuKhurana Вы упоминаете о синтаксическом отклике в узле logger? я просто удалил его. Тот же ответ. – Simbu

ответ

1

Поток, обработанный добавлением пары ключевых значений в запросах parms в компоненте http. В переменной flowVariable requestpayload есть строка json. Итак, мой компонент http Mule выглядит ниже.

<http:request config-ref="HTTP_Request_Configuration" path="/api_requests/secure_request" method="POST" followRedirects="true" parseResponse="false" doc:name="HTTP"> 
      <http:request-builder> 
       <http:query-param paramName="addFixedPriceItemRequest" value="#[flowVars.requestpayload]"/> 
      </http:request-builder> 
      <http:success-status-code-validator values="0..599"/> 
     </http:request> 
Смежные вопросы