2)我在eclipse studio dev工具上创建了我的服务:
当我在终端上拨打curl时: 卷曲-v -i -H"内容类型:application / json" -H"接受:application / json" http://192.168.10.178:8280/mapa/1/101
显示消息:
尝试192.168.10.178 ...
> Connected to 192.168.10.178 (192.168.10.178) port 8280 (#0)
> GET /mapa/1/101 HTTP/1.1
> Host: 192.168.10.178:8280
> User-Agent: curl/7.43.0
> Content-Type: application/json
> Accept: application/json
> HTTP/1.1 404 Not Found
> HTTP/1.1 404 Not Found
> Date: Mon, 30 Jan 2017 12:38:51 GMT
> Transfer-Encoding: chunked
> Connection #0 to host 192.168.10.178 left intact
5)API XML:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/mapa" name="MapaServicesAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/mapa/{codigoAgenteCampo}/{codigoMunicipio}">
<inSequence>
<log description="Request Log" level="custom">
<property name="message" value=""Teste com o mapa services node""/>
</log>
<send>
<endpoint key="MapaRestEP"/>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
6)端点
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="MapaRestEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:8000/rest/rotas/completa/{codigoAgenteCampo}/{codigoMunicipio}"/>
</endpoint>
答案 0 :(得分:2)
****************************更新:***************** ***********************
正确的端点配置:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="MapaRestEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:8000/rest/rotas/completa/{uri.var.codigoAgenteCampo}/{uri.var.codigoMunicipio}"/>
</endpoint>
****************************结束更新***************** *******************
您需要调用的URL是api context + uri模板。在这种情况下:
http://localhost:8280/mapa/mapa/1/101
在我的场景中,我用soapui模拟后端json响应。
我的代理:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/mapa" name="MapaServicesAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/mapa/{codigoAgenteCampo}/{codigoMunicipio}">
<inSequence>
<log description="Request Log" level="custom">
<property name="message" value=""Teste com o mapa services node""/>
<property name="codigoAgenteCampo" expression="get-property('uri.var.codigoAgenteCampo')"/>
<property name="codigoMunicipio" expression="get-property('uri.var.codigoMunicipio')"/>
</log>
<send>
<endpoint key="MapaRestEP"/>
</send>
</inSequence>
<outSequence>
<log level="full"/>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
终点:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="MapaRestEP" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="http://localhost:8000/rest/rotas/completa/{uri.var.codigoAgenteCampo}/{uri.var.codigoMunicipio}"/>
</endpoint>
卷曲响应:
D:\integ\wso2am-2.0.0\bin>curl -v -i -H "Content-Type: application/json" -H "Accept: application/json" http://localhost:8283/mapa/mapa/1/101
* About to connect() to localhost port 8283 (#0)
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8283 (#0)
> GET /mapa/mapa/1/101 HTTP/1.1
> User-Agent: curl/7.25.0 (i386-pc-win32) libcurl/7.25.0 OpenSSL/0.9.8u zlib/1.2.6 libssh2/1.4.0
> Host: localhost:8283
> Content-Type: application/json
> Accept: application/json
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
Content-Type: application/json; charset=UTF-8
< Date: Tue, 31 Jan 2017 05:50:45 GMT
Date: Tue, 31 Jan 2017 05:50:45 GMT
< Transfer-Encoding: chunked
Transfer-Encoding: chunked
<
{
data:[
{
"id":1
},
{
"id":2
}
]
}* Connection #0 to host localhost left intact
* Closing connection #0
wso2 ESB日志:
[2017-01-31 00:50:45,409] INFO - LogMediator message = "Teste com o mapa services node", codigoAgenteCampo = 1, codigoMunicipio = 101
[2017-01-31 00:50:45,421] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:56597c92-d5fe-4003-b25a-d11b60dd28df, Di
rection: response, Payload: {
data:[
{
"id":1
},
{
"id":2
}
]
}