我一直在研究服务链,该服务链在WSO2 EMM中使用承载令牌来回答我。
我在ESB中创建了一个代理,然后传递到一个新序列,该序列进行下一个调用,但是此序列接收到Content-Type应用程序/ 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不支持的媒体类型的错误

请帮忙

最佳答案

我明白了,这就是答案

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

09-28 09:35