I have been working in a service chaining that answers me with a Bearer Token using in WSO2 EMM. I made a proxy in ESB and then I passed to a new sequence that makes the next call but this one receives a Content-Type application/x-www-form-urlencoded. I have been looking for some help so that I can find anything interesting.
This is my proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="TokenService" startOnLoad="true" statistics="enable"
trace="enable" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<!--Aggregate incoming responses -->
<log level="full">
<property name="sequence" value="Paso 1 - request for client register"/>
</log>
<property description="Content-Type" name="ContentType"
scope="default" type="STRING" value="application/json"/>
<header name="Accept" scope="transport" value="application/json"/>
<payloadFactory description="Payload" media-type="json">
<format>{
"owner": "admin",
"clientName": "admin_emm",
"grantType":
"refresh_token password client_credentials",
"tokenScope": "prod"
}</format>
<args/>
</payloadFactory>
<send receive="Mensaje"/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>
This is my sequence that gets the response from the other service in my proxy
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="Mensaje" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<log level="custom">
<property expression="json-eval($.client_secret)"
name="client_secret" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<log level="custom">
<property expression="json-eval($.client_id)" name="client_id" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<log level="custom">
<property
expression="fn:concat('Basic ', base64Encode('client_id:client_secret'))"
name="Authorization" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<property name="grant_type" value="password"/>
<property name="username" value="admin"/>
<property name="password" value="admin"/>
<property name="scope" value="default"/>
<header name="Accept" scope="transport" value="application/json"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root xmlns="">
<grant_type>$1</grant_type>
<username>$2</username>
<password>$3</password>
<scope>$4</scope>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:grant_type" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:username" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:password" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:scope" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<property name="ContentType" value="application/x-www-form-urlencoded"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint name="Token">
<http method="POST" uri-template="https://localhost:9443/oauth2/token"/>
</endpoint>
</call>
<respond/>
</sequence>
Then when i run it i have an error of HTTP/1.1 415 Unsupported Media Type
Please, help
I got it this is the answer
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="Mensaje" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<property expression="json-eval($.client_secret)"
name="client_secret" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="json-eval($.client_id)" name="client_id" xmlns:ns="http://org.apache.synapse/xsd"/>
<property
expression="fn:concat(get-property('client_id'),':',get-property('client_secret'))"
name="Concatenados" xmlns:ns="http://org.apache.synapse/xsd"/>
<property expression="base64Encode(get-property('Concatenados'))"
name="Codificados" xmlns:ns="http://org.apache.synapse/xsd"/>
<property
expression="fn:concat('Basic ', get-property('Codificados'))"
name="Autorizacion" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="grant_type" value="password"/>
<property name="username" value="admin"/>
<property name="password" value="admin"/>
<property name="scope" value="default"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root xmlns="">
<grant_type>$1</grant_type>
<username>$2</username>
<password>$3</password>
<scope>$4</scope>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$ctx:grant_type" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:username" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:password" xmlns:ns="http://org.apache.synapse/xsd"/>
<arg evaluator="xml" expression="$ctx:scope" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
<header expression="get-property('Autorizacion')"
name="Authorization" scope="transport" xmlns:ns="http://org.apache.synapse/xsd"/>
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<call>
<endpoint name="Token">
<http method="POST" uri-template="https://localhost:9443/oauth2/token"/>
</endpoint>
</call>
<respond/>
</sequence>
来源:https://stackoverflow.com/questions/37331115/sending-content-type-application-x-www-form-urlencoded-wso2-esb