发送内容类型application / x-www-form-urlencoded WSO2 ESB

时间:2016-05-19 18:14:00

标签: wso2esb wso2-emm

我一直在服务链中工作,在WSO2 EMM中使用Bearer Token回答我。 我在ESB中创建了一个代理,然后我转到了一个新的序列,进行下一个调用,但是这个序列接收了一个Content-Type application / x-www-form-urlencoded。我一直在寻找帮助,以便找到有趣的东西。

这是我的代理

<?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>

这是我的序列,它从我的代理

中的其他服务获取响应
<?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>

然后当我运行它时,我有一个错误的HTTP / 1.1 415不支持的媒体类型

请帮助

2 个答案:

答案 0 :(得分:2)

我明白这就是答案

<?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>

答案 1 :(得分:0)

我有同样的错误。这是我的解决方案,与之前的类似,但在Json中:

<property name="scope" scope="default" type="STRING" value="myScope"/>
<payloadFactory media-type="json">
    <format>{"grant_type":"password","username":"admin","password":"admin","scope":"$1"}</format>
    <args>
        <arg evaluator="xml" expression="get-property('scope')"/>
    </args>
</payloadFactory>
<!-- authorization header with consumer-key:consumer-secret in Base64 -->
<header name="Authorization" scope="transport" value="Basic RUVyY0VRejFfU..."/>
<header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
<call blocking="true">
    <endpoint key="GetToken"/>
</call>