英文:
how to rejected request missing header or wrong header in wso2
问题
我在WSO2 API中有这样的代码:
<api context="/request" name="Request" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/Executionreport/{vtid}/{token}">
<inSequence>
<property expression="get-property('uri.var.vtid')" name="Vtid" scope="default" type="STRING"/>
<property expression="get-property('uri.var.token')" name="token" scope="default" type="STRING"/>
<filter regex="1234" source="$ctx:token">
<then>
<log>
<property name="sukses masuk token" value="0"/>
</log>
<sequence key="select_Execution_report"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
</then>
<else/>
</filter>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
所以,对于这个请求,我将像这样使用:
http://localhost:8280/request/Executionreport/1100/1234
所以,如果令牌错误,我将重新发送这个:
HTTP/1.1 200 OK
soapaction: urn:mediate
Host: localhost:8280
Accept-Encoding: gzip,deflate
cache-control:
Content-Type: application/json; charset=UTF-8
Date: Thu, 23 Jul 2020 07:51:59 GMT
Transfer-Encoding: chunked
Connection: Keep-Alive
{ "status":"401 Not Authenticated" }
我想要更改逻辑,使请求如下:
http://localhost:8280/request/Executionreport/1100
使用GET
方法,并且具有标头token=1234
,因此如果标头请求中的令牌错误,WSO2将拒绝,因此状态将为HTTP/1.1 401 unauthorized
。
所以我的问题是如何在WSO2中创建具有GET
方法和需要标头的API?
如何在WSO2中创建具有GET
方法和需要标头的API?
英文:
I have code in API WSO2 like this
<api context="/request" name="Request" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/Executionreport/{vtid}/{token}">
<inSequence>
<property expression="get-property('uri.var.vtid')" name="Vtid" scope="default" type="STRING"/>
<property expression="get-property('uri.var.token')" name="token" scope="default" type="STRING"/>
<filter regex="1234" source="$ctx:token">
<then>
<log>
<property name="sukses masuk token" value="0"/>
</log>
<sequence key="select_Execution_report"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
</then>
<else/>
</filter>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
so for this request I will use like this one
http://localhost:8280/request/Executionreport/1100/1234
so if the token is wrong I will replay this one
HTTP/1.1 200 OK
soapaction: urn:mediate
Host: localhost:8280
Accept-Encoding: gzip,deflate
cache-control:
Content-Type: application/json; charset=UTF-8
Date: Thu, 23 Jul 2020 07:51:59 GMT
Transfer-Encoding: chunked
Connection: Keep-Alive
{ "status":"401 Not Authenticated" }
i want to change the logic like the request is like
http://localhost:8280/request/Executionreport/1100
with methods GET
and have header token=1234
so if token wrong in header request wso2 will rejected so status will be HTTP/1.1 401 unauthorized
.
so my question how to create API methods GET
and need header in WSO2 ?
答案1
得分: 0
你可以按照以下方式读取传入的标头。
<property name="Token" expression="get-property('token')" scope="transport" type="STRING" />
基于此,您可以执行任何操作。
英文:
You can read the incoming header as below.
<property name="Token" expression="get-property('token')" scope="transport" type="STRING" />
Based on that you can perform any action.
专注分享java语言的经验与见解,让所有开发者获益!
评论