java Grizzly REST帖子总是404
在我的端点中,我有一些带有@GET
的方法和一些带有@POST
的方法@GET
运行正常,但是@POST
总是返回404
以下是端点接口的一些部分:
public interface TestEndpoint {
@GET
@Path("/ping")
Response ping();
@POST
@Path("/weather/{iata}/{pointType}")
Response updateWeather(@PathParam("iata") String iataCode,
@PathParam("pointType") String pointType,
String datapointJson);
@POST
@Path("/airport/{iata}/{lat}/{long}")
Response addAirport(@PathParam("iata") String iata,
@PathParam("lat") String latString,
@PathParam("long") String longString);
@GET
@Path("/exit")
Response exit();
}
以下是服务器初始化部分:
public class TestServer {
private static final String BASE_URL = "http://localhost:9090/";
public static void main(String[] args) {
try {
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(TestEndpointImpl.class);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URL), resourceConfig, false);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
server.shutdownNow();
}));
HttpServerProbe probe = new HttpServerProbe.Adapter() {
public void onRequestReceiveEvent(HttpServerFilter filter, Connection connection, Request request) {
System.out.println(request.getRequestURI());
}
};
server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
server.start();
Thread.currentThread().join();
server.shutdown();
} catch (IOException | InterruptedException ex) {
Logger.getLogger(TestServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
其中,TestEndpointImpl
是TestEndpoint
(顾名思义)的一个实现,带有类级注释@Path("/collect")
当我执行GET请求时,它工作正常。但帖子是有问题的。不调用相应的方法
作为补充说明,probe
按预期打印GET和POST请求,因此我确信请求到达服务器和路径是正常的
有什么建议吗
编辑:实现中的一些片段:
@Path("/collect")
public class TestEndpointImpl implements TestEndpoint {
...
@Override
public Response updateWeather(@PathParam("iata") String iataCode, @PathParam("pointType") String pointType,
String datapointJson) {
System.out.println("TRACE: " + datapointJson);
// do something and return a Response
}
...
}
注册的探测打印/collect/weather/BOS/wind
,但不调用updateWeather
共 (0) 个答案