【发布时间】:2018-01-28 16:25:24
【问题描述】:
我需要从 lambda 返回一个响应,而不需要额外的渲染。我试着这样做:
On.post("/locations/{id:\\d+}").serve((Integer id, Req req, Resp resp) -> {
if (!storageService.locationIsPresent(id)) {
return resp.code(404).json("Location not found!");
}
try {
String request = new String(req.body());
Location location = mapper.readValue(request, Location.class);
storageService.updateLocation(id, location.getCountry(), location.getCity(), location.getPlace(), location.getDistance() );
} catch (Exception ex) {
return resp.code(400).json("Bad request!");
}
return resp.code(200).body(EMPTY_RESP);
});
但结果我得到了一个例外:
ERROR | 20/Aug/2017 14:19:53:460 | executor2 | org.rapidoid.http.impl.lowlevel.LowLevelHttpIO | Error occurred when handling request! | error = java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.rapidoid.http.impl.RespImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.rapidoid.http.impl.RespImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
请告诉我如何正确操作。
而且我还想知道如何配置服务器,以便在每秒处理大量请求时获得更快的响应。因为在我的情况下它非常慢。
提前谢谢你!
【问题讨论】: