-->

How to send json request to restful webservice usi

2019-02-26 00:03发布

问题:

I am new to wso2.. I have asked lot of question regarding wso2 proxy service,i am not getting a correct response,can anyone help me on this please

I want to send a JSON request to a Restful webservice using a WSO2 proxy service.. I have tried the below configuration

<target>
    <inSequence>
        <log level="custom">
            <property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
        </log>
        <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
        <log level="custom">
            <property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
        </log>
        <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
        <send>
            <endpoint>
                <address uri="http://10.132.97.131:9763/RESTfulExample/rest/json/metallica/post/"/>
            </endpoint>
        </send>
    </inSequence>
    <outSequence>
        <send/>
    </outSequence>
    <faultSequence>
        <log level="full">
            <property name="MESSAGE" value="Executing default &quot;fault&quot; sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        </log>
    </faultSequence>
</target>

I am not getting the response :( The response is also a JSOn

JSON REQUEST ---- JSON RESPONSE

Need to do this using a proxy service

i am getting the error as below

To: /services/FilterMediatorProxy.FilterMediatorProxyHttpEndpoint/, From: 10.132.97.131, Direction: request, MESSAGE = Executing default "fault" sequence, ERROR_CODE = 0, ERROR_MESSAGE = Unexpected error during sending message out, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><Body></Body></soapenv:Envelope>

I am passing the JSON request as

{"title":"Enter Sandman","singer":"Metallica"}

But see the below error,it is not passing properly

Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><Body></Body></soapenv:Envelope>

It is trying to send as SOAP (xml format)

What configuration i have to do for this ? I am using wso2 carbon 4.2.0 and installed ESB on this

Please help me for the correct proxy service confiration

Thanks a lot in advance