我正在使用portal
javascript库与我的Java套接字进行交互。我似乎无法确定如何将请求映射到下面的资源上的方法。正在使用@Path("workstation/approval/{uuid}")
正确建立套接字,然后通过连接传递JSON数据。但是在Java方面,如何将数据推送映射到方法,以便我可以处理它?</ strong>
@Path("workstation/approval/{uuid}")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class WorkstationResource {
ObjectMapper mapper = new ObjectMapper();
@Context
private BroadcasterFactory broadcasterFactory;
@GET
@Suspend
public Broadcastable get(@PathParam("uuid") String uuid) {
return new Broadcastable(getBroadcaster(uuid));
}
private Broadcaster getBroadcaster(String uuid) {
return broadcasterFactory.lookup(JerseyBroadcaster.class, "workstation/approval/"+uuid, true);
}
public String onMessage(String message) throws IOException {
return mapper.writeValueAsString("This is a test");
}
}
答案 0 :(得分:1)
萨吕,
你正在使用WebSocket或Comet吗?在任何情况下,尝试添加@Post注释方法,这将起作用。如果您有更多问题,请查看大气层ML,或查看project sample。- Jeanfrancois
答案 1 :(得分:0)
public Broadcastable get(@PathParam("uuid") String uuid) {
return new Broadcastable(getBroadcaster(uuid));
}
到
public Broadcastable get(@PathParam("uuid") String uuid,String postData) {
return new Broadcastable(getBroadcaster(uuid));
}
您将使用postData参数
中的连接传递数据