如何在 JAX-RS 中访问 Flex 客户端发送的 JSON 请求的数据字段
我有以下 JAX-RS 服务。
@Path("config")
public class ConfigurationResponder {
@GET
@Produces({"application/json"})
@Consumes({"application/json"})
public SomeResponse handleMessage() {
SomeResponse response = new SomeResponse();
// calculations...
return response;
}
}
我在 Flex 客户端中构建了一些请求。
var message:Object = {};
message.type = "get_configuration";
message.data = "some data";
var request:URLRequest = new URLRequest(fullUrl);
request.contentRype = "application/json";
request.data = message;
request.method = URLRequestMethod.GET;
var loader:URLLoader = ...
loader.load(request);
JAX-RS 服务接收请求并成功响应一些虚拟响应,但我无权访问 request.data
字段。
如何访问请求消息的数据(在此特定示例中为 {"type":"get_configuration","data":"some data"}
)?我认为我应该向 handleMessage
方法添加一些参数,例如
public SomeResponse handleMessage(Object message) {...
,但这根本不起作用。该请求得到了 415 响应。
I have the following JAX-RS service.
@Path("config")
public class ConfigurationResponder {
@GET
@Produces({"application/json"})
@Consumes({"application/json"})
public SomeResponse handleMessage() {
SomeResponse response = new SomeResponse();
// calculations...
return response;
}
}
I build some request in a Flex client.
var message:Object = {};
message.type = "get_configuration";
message.data = "some data";
var request:URLRequest = new URLRequest(fullUrl);
request.contentRype = "application/json";
request.data = message;
request.method = URLRequestMethod.GET;
var loader:URLLoader = ...
loader.load(request);
The JAX-RS service receives the request and respond successfully with some dummy response, but I have no access to the request.data
field.
How do I access the data of the request message (which is {"type":"get_configuration","data":"some data"}
in this particular example)? I think that I'm supposed to add some parameters to the handleMessage
method like
public SomeResponse handleMessage(Object message) {...
but this does not work at all. The request got 415 response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
@QueryParam
将查询参数注册为方法参数。You need to use
@QueryParam
to register the query parameter as method argument.