wso2 是多部分/表单数据发布请求的网关转发 [英] wso2 am gateway forwarding of multipart/form-data post requests

查看:22
本文介绍了wso2 是多部分/表单数据发布请求的网关转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个演示 API,它接收文件和注释作为 multipart/form-data 输入并显示文件和注释的内容.这是一个正确运行 API 的示例 HTML:

I am using a demo API which receives a file and note as multipart/form-data input and displays the content of the file and the note. Here is a sample HTML which runs the API correctly:

<html>   
  <body>
    <FORM action="http://cgi-lib.berkeley.edu/ex/fup.cgi" method="post">
      <P>Choose file: <INPUT type="file" name="upfile">
      <p>Note: <INPUT type="text" name="note">
      <p><INPUT type="submit" value="Send"> 
    </FORM>
  </body>
</html>

现在我正在尝试在 WSO2 APIM 发布者中创建托管 API.以下是我填写的参数:

Now I'm trying to created a managed API in the WSO2 APIM publisher. Below are the parameters I filled in:

我正在替换 HTML 的操作以通过我添加的 API:

I'm replacing the action of the HTML to go through the API I added:

<FORM action="http://ec2-52-48-93-41.eu-west-1.compute.amazonaws.com:8280/test" method="post">

但现在当我运行 HTML 时,我从 API 收到以下错误:

But now when I run the HTML I get the following error from the API:

cgi-lib.pl: Unknown Content-type: application/x-www-form-urlencoded; charset=UTF-8

似乎 WSO2 网关将请求转发为 application/x-www-form-urlencoded 而不是 mulipart/form-data.

Seems like the WSO2 gateway forwarded the request as application/x-www-form-urlencoded rather than as mulipart/form-data.

基于以下讨论多部分表单数据文件上传使用WSO2 API 管理器? 我试图注释掉

Based on the following discussion multipart form data file upload using WSO2 API manger ? I tried to comment out

   <messageFormatter contentType="multipart/form-data"
        class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
   <messageBuilder contentType="multipart/form-data"
        class="org.apache.axis2.builder.MultipartFormDataBuilder"/>

并将它们替换为

 <messageFormatter contentType="multipart/form-data" 
     class="org.wso2.carbon.relay.ExpandingMessageFormatter"/> 
 <messageBuilder contentType="multipart/form-data" 
     class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

然后重启了服务器,但没有造成任何影响.

Then restarted the server, but it did not cause any impact.

任何想法都会受到赞赏.

Any ideas will be appreciated.

我收集的一些日志消息.目标 API 不同,但它也是一个多部分/表单数据 API,它会转储它接收到的任何内容.

Some log messages that I collected. The target API is different, but it is also a multipart/form-data API which dumps whatever it receives.

传入的请求确实有content-type multipart/form-data,content-length为292

The incoming request does have content-type multipart/form-data, with content-length of 292

DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> POST /test/1.0.0 HTTP/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Host: ec2-52-48-93-41.eu-west-1.compute.amazonaws.com:8280 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Connection: keep-alive {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Content-Length: 292 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Cache-Control: max-age=0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Origin: null {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Upgrade-Insecure-Requests: 1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqwBdAwOnlDYeHNNR {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Accept-Encoding: gzip, deflate {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Accept-Language: en-US,en;q=0.8,he;q=0.6 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Cookie: region3_registry_menu=visible; region1_manage_menu=visible; region1_identity_menu=visible; menuPanel=visible; menuPanelType=main; csrftoken=n1g69f3slt1d90qvtaa28rtm1b {org.apache.synapse.transport.http.headers}

传出请求没有内容类型:

The outgoing request does not have content-type:

DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> POST /sample2/api/company/upload HTTP/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Cookie: region3_registry_menu=visible; region1_manage_menu=visible; region1_identity_menu=visible; menuPanel=visible; menuPanelType=main; csrftoken=n1g69f3slt1d90qvtaa28rtm1b {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Origin: null {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Cache-Control: max-age=0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Upgrade-Insecure-Requests: 1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Accept-Encoding: gzip, deflate {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Accept-Language: en-US,en;q=0.8,he;q=0.6 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Transfer-Encoding: chunked {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Host: localhost:8080 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> Connection: Keep-Alive {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 >> User-Agent: Synapse-PT-HttpComponents-NIO {org.apache.synapse.transport.http.headers}

自然,传入的响应有 HTTP 415,不支持的媒体:

Naturally, the incoming response has HTTP 415, unsupported media:

DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 << HTTP/1.1 415 Unsupported Media Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 << Server: Apache-Coyote/1.1 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 << Content-Length: 0 {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-outgoing-1 << Date: Mon, 28 Mar 2016 13:53:05 GMT {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << HTTP/1.1 415 Unsupported Media Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Access-Control-Allow-Origin: * {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Access-Control-Allow-Methods: POST {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Date: Mon, 28 Mar 2016 13:53:05 GMT {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Transfer-Encoding: chunked {org.apache.synapse.transport.http.headers}
DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Connection: keep-alive {org.apache.synapse.transport.http.headers}

API 的突触也值得加载:

Also worth loading is the synapse of the API:

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
     name="admin--test"
     context="/test/1.0.0"
     version="1.0.0"
     version-type="context">
   <resource methods="POST" url-mapping="/*" faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <property name="api.ut.backendRequestTime"
                         expression="get-property('SYSTEM_TIME')"/>
               <send>
                  <endpoint name="admin--test_APIproductionEndpoint_0">
                     <http uri-template="http://localhost:8080/sample2/api/company/upload"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
         <send/>
      </outSequence>
   </resource>
   <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler">
         <property name="apiImplementationType" value="ENDPOINT"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
         <property name="policyKeyApplication"
                   value="gov:/apimgt/applicationdata/app-tiers.xml"/>
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
         <property name="policyKeyApplication"
                   value="gov:/apimgt/applicationdata/app-tiers.xml"/>
         <property name="id" value="A"/>
         <property name="policyKeyResource"
                   value="gov:/apimgt/applicationdata/res-tiers.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
         <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
   </handlers>
</api>

推荐答案

只是为了强调Ajanthan的回答,为了正确保留headers,正确的更改是在passthru-http.properties中添加以下内容

Just to stress Ajanthan answer, in order to preserve the headers correctly, the correct change would be to add the following to passthru-http.properties

http.headers.preserve=Content-Length,Content-Type

这是 ESB 4.9.0 的一个新特性,所以没有太多的文档,但是你可以在这个博客中阅读它:http://prabu-lk.blogspot.co.il/2015/09/how-to-preserving-http-headers-in-wso2.html

It's a new feature of ESB 4.9.0, so not much documented, but you can read about it in this blog: http://prabu-lk.blogspot.co.il/2015/09/how-to-preserving-http-headers-in-wso2.html

这篇关于wso2 是多部分/表单数据发布请求的网关转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆