1

我想问一个与我在 Glassfish 4.0 Web 应用程序部署中遇到的问题相关的问题。

我使用 JAX-RS 创建了一个 REST Web 服务应用程序并将其部署在 Glassfish 3.1.2 上,没有任何问题。最近尝试在 Glassfish 4.0 上部署,遇到如下警告。

A servlet request to the URI http://localhost:8080/IipDev3/root/provider/publication/info:647254662 contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

我使用 javax.ws.rs.core.MultivaluedMap 来存储表单参数,但对于 HTTP POST 请求,它确实是空的。奇怪的是,对于 HTTP PUT 请求,它不是空的。我曾尝试在 Internet 上搜索解决方案,但被卡住了(在最坏的情况下,我当然可以回退到 Glassfish 3.1.2 部署)。

代码片段:

@POST
@Path("publication/{infoId}")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public String publishToAnInformationChannel(@PathParam("infoId") String infoId,
MultivaluedMap formParams, @Context SecurityContext sc) {
// formParams empty + warning
}

@PUT
@Path("registration/information/{infoId}")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/xml")
public String updateAnInformationChannel(@PathParam("infoId") String infoId,
MultivaluedMap formParams, @Context SecurityContext sc) {
// formParams filled in + no warning
}

如果有人知道如何解决这个问题,请告诉我。非常感谢。

4

1 回答 1

0

MultivaluedMap 需要通用信息:

MultivaluedMap<String, String> formParams
于 2014-10-15T12:29:06.280 回答