我的API端点看起来像

@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("groups/{groupName}")
public Response getCategoriesByGroupName(@PathParam("groupName") @Nonnull final String groupName) {
    return Response.ok(getCategoryTO().getCategoriesByGroupName(categoryManager, groupName)).build();
}


当我尝试击中终点时

curl -H"Content-Type: application/json" -H"BEARER:792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000"  "https://myapp.com/rest/categories/groups/Utilities"


我得到正确的JSON返回,这意味着groupName被正确地替换为Utilities

但是当我这样做

curl -H"Content-Type: application/json" -H"BEARER:792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000"  "https://myapp.com/rest/categories/groups/Food & Drink"


我看到服务器错误为

Caused by: javax.ejb.EJBException: javax.persistence.NoResultException: no categories exists with groupName: Food


问题是groupName被替换为Food而不是Food & Drink

我尝试使用其他groupName并意识到,只要我的groupName包含空格,就只会将第一个单词替换为groupName

如何解决此问题,以使在URL中传递的整个字符串变为groupName

我的服务器部署在Wildfly 8

最佳答案

这与我的端点无关。

如@Sotirios所述,我需要先将URL编码后再发送到服务器。

当我做那件事开始工作

curl -H"Content-Type: application/json" -H"BEARER: 792345452:78f7f8a4-a8c9-454a-93a8-6633a1076781:169000000"  "https://myapp.com/rest/categories/groups/Food%20%26%20Drink"

[{"id":"9b1e97f2-ac7d-4caf-85fc-476cd97dd6cb","name":"Alcohol & Bars","groupName":"Food & Drink"}]

10-08 01:26