我已经在wso2中代理了Stripe Web服务,但是我无法使用curl以及通过创建HttpClient来发布数据。
相关文件内容: 在wso2 ---
中的synapse配置文件<?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>
条带api中记录的和cURL POST请求:
代理端点:https://127.0.0.1:8243/services/stripe
条纹端点: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
我也试过
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"
和
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"
我在执行上述请求时遇到错误:
[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)
我的axi2.xml有以下格式化程序&amp;建设者:
<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>
我无法理解造成问题的原因....
答案 0 :(得分:1)
在你的序列中定义以下属性并检查..
<property name="messageType" scope="axis2" value="application/json"/>