- 我尝试使用 WSO2 调用我的休息服务。
- 我使用 wso 版本 5.0.0。 Java 1.8。 eclipse 火星2。
- 我点击了网址:https://docs.wso2.com/display/ESB500/Sending+a+Simple+Message
2) 我在 eclipse studio 开发工具上创建了我的服务:
当我在终端上调用curl时: curl -v -i -H“内容类型:application/json”-H“接受:application/json”http://192.168.10.178:8280/mapa/1/101
显示消息:
Trying 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>
最佳答案
****************************更新:**************** **********************
正确的端点配置:
<?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上下文+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>
curl 响应:
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
}
]
}
关于java - WSO2 端口 8082 访问问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41939492/