Glassfish 4.0 JAX-RS空HTTP POST MultivaluedMap表单参数

问题描述 投票:1回答: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请求不是空的。我曾尝试在互联网上搜索解决方案但遇到困难(在最坏的情况下,我可以回退到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
}

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

http-post jax-rs glassfish-4
1个回答
0
投票

MultivaluedMap需要通用信息:

MultivaluedMap<String, String> formParams
© www.soinside.com 2019 - 2024. All rights reserved.