Question

I have proxied the Stripe Web services in wso2 and I am not able to post data using curl as well as by creating HttpClient .

Related files content: synapse config file in wso2---

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
        <parameter name="cachableDuration">15000</parameter>
    </registry>
    <proxy name="stripe" transports="https http" startOnLoad="true" trace="disable">
        <target>
            <endpoint>
                <address uri="https://api.stripe.com/v1"/>
            </endpoint>
            <inSequence/>
            <outSequence>
                <log level="full"/>
                <send/>
            </outSequence>
        </target>
    </proxy>
    <sequence name="fault">
        <log level="full">
            <property name="MESSAGE" value="Executing default 'fault' sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
        </log>
        <drop/>
    </sequence>
    <sequence name="main">
        <in>
            <log level="full"/>
            <filter source="get-property('To')" regex="http://localhost:9000.*">
                <send/>
            </filter>
        </in>
        <out>
            <send/>
        </out>
        <description>The main sequence for the message mediation</description>
    </sequence>
</definitions>

and cURL POST request as documented in stripe api: Proxy endpoint : https://127.0.0.1:8243/services/stripe Stripe Endpoint : https://api.stripe.com/v1

curl https://127.0.0.1:8243/services/stripe/customers    -u ******************:    -d "description=Customer for example@gmail.com"   -d "card[number]=4242424242424242"   -d "card[exp_month]=6"   -d "card[exp_year]=2013"  --insecure

and i also tried

curl https://127.0.0.1:8243/services/stripe/customers    -u ******************:    -d "description=Customer for example@gmail.com"   -d "card[number]=4242424242424242"   -d "card[exp_month]=6"   -d "card[exp_year]=2013"  --insecure -H "Content-Type : application/json"

and

curl https://127.0.0.1:8243/services/stripe/customers    -u ******************:    -d "description=Customer for example@gmail.com"   -d "card[number]=4242424242424242"   -d "card[exp_month]=6"   -d "card[exp_year]=2013"  --insecure -H "Accept : application/json"

and Error I m getting during execution of above request :

[2012-06-17 14:49:47,130]  WARN - ClientHandler Received an unexpected response - of content type : text/html and status code : 411 with reason : Length Required For : 50.18.195.3:443 For Request : Axis2Request [Message ID : urn:uuid:93391e51-d026-4c6e-9279-9d82101ab4a5] [Status Completed : true] [Status SendingCompleted : true]
[2012-06-17 14:49:47,137]  WARN - ClientWorker Unexpected response received. HTTP response code : 411 HTTP status : Length Required exception : com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </body>; expected </hr>.
 at [row,col {unknown-source}]: [6,6]
[2012-06-17 14:49:47,153] ERROR - NativeWorkerPool Uncaught exception
java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMTextImpl cannot be cast to org.apache.axiom.om.OMElement
    at org.apache.synapse.util.MessageHelper.cloneSOAPFault(MessageHelper.java:441)
    at org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:254)
    at org.apache.synapse.core.axis2.SOAPUtils.convertSOAP11toSOAP12(SOAPUtils.java:95)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:323)
    at org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:160)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.synapse.transport.nhttp.ClientWorker.run(ClientWorker.java:275)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:173)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

and my axi2.xml has following formatters & builders :

<messageFormatters>
        <messageFormatter contentType="application/x-www-form-urlencoded"
                          class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
        <messageFormatter contentType="multipart/form-data"
                          class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
        <messageFormatter contentType="application/xml"
                          class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
        <messageFormatter contentType="text/xml"
                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
        <messageFormatter contentType="application/soap+xml"
                         class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>

        <!--JSON Message Formatters-->
        <messageFormatter contentType="application/json"
                          class="org.apache.axis2.json.JSONMessageFormatter"/>
        <messageFormatter contentType="application/json/badgerfish"
                          class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
        <messageFormatter contentType="text/javascript"
                          class="org.apache.axis2.json.JSONMessageFormatter"/>

        <!--messageFormatter contentType="application/x-www-form-urlencoded"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="multipart/form-data"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="application/xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="text/html"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="application/soap+xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="text/xml"
                        class="org.wso2.carbon.relay.ExpandingMessageFormatter"/-->
        <!--messageFormatter contentType="x-application/hessian"
                         class="org.apache.synapse.format.hessian.HessianMessageFormatter"/-->
        <!--messageFormatter contentType=""
                         class="org.apache.synapse.format.hessian.HessianMessageFormatter"/-->
    </messageFormatters>

    <!-- ================================================= -->
    <!--                Message Builders                   -->
    <!-- ================================================= -->

    <!-- Following content type to builder mapping can be used to implement support for -->
    <!-- different message formats in Axis2. These message formats are expected to be -->
    <!-- resolved based on the content type. -->
    <messageBuilders>
        <messageBuilder contentType="application/xml"
                        class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
        <messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
        <messageBuilder contentType="multipart/form-data"
                        class="org.apache.axis2.builder.MultipartFormDataBuilder"/>

        <!--JSON Message Builders-->
        <messageBuilder contentType="application/json"
                        class="org.apache.axis2.json.JSONOMBuilder"/>
        <messageBuilder contentType="application/json/badgerfish"
                        class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
        <messageBuilder contentType="text/javascript"
                        class="org.apache.axis2.json.JSONOMBuilder"/>

    <!--messageBuilder contentType="application/xml"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="multipart/form-data"
                        class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="multipart/related"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="application/soap+xml"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="text/plain"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="text/xml"
                       class="org.wso2.carbon.relay.BinaryRelayBuilder"/-->
        <!--messageBuilder contentType="x-application/hessian"
                        class="org.apache.synapse.format.hessian.HessianMessageBuilder"/-->
        <!--messageBuilder contentType=""
                         class="org.apache.synapse.format.hessian.HessianMessageBuilder"/-->
    </messageBuilders>

I am not able to understand what is causing dis problem....

Was it helpful?

Solution

Define the following property at your outsequence and check..

<property name="messageType" scope="axis2" value="application/json"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top