I'm using the portal
javascript library to interact with my Java sockets. I can't seem to determine how to get a request mapped to a method on the below resource. A socket is being established correctly with @Path("workstation/approval/{uuid}")
and then JSON data is being passed through the connection. But on the Java side, how do I map that data push to a method so I can process it?
@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");
}
}
Are you using WebSocket or Comet? In any case, try adding a @Post annotated method and that will work. Come to the Atmosphere mailing list if you have more questions, or look at the project sample.