[英]Using queryParam linked or unlinked with WebTarget DELETE produces different results
I have a basic javax.ws.rs
REST API class: 我有一个基本的javax.ws.rs
REST API类:
@Path("/")
public class DeleteApi {
@DELETE
public void testDelete(@DefaultValue("false") @QueryParam("id") boolean id) {
logger.info("id [{}]", id);
}
}
I'm using a javax.ws.rs.client.Client
within a test to test this DELETE method: 我在测试中使用javax.ws.rs.client.Client
来测试此DELETE方法:
@Test
public void testCallDelete() {
// Not linked version
WebTarget target = client.target("http://127.0.0.1:8080/fscrawler/");
target.queryParam("id", true);
target.request().delete();
// Linked version
client.target("http://127.0.0.1:8080/fscrawler/")
.queryParam("id", true)
.request()
.delete();
}
It produces: 它产生:
23:37:14,870 INFO [f.p.e.c.f.r.RestApi] id [false]
23:37:14,910 INFO [f.p.e.c.f.r.RestApi] id [true]
In case it's helpful here is my main dependencies in my pom.xml
file: 如果这对我有帮助,这里是我的pom.xml
文件中的主要依赖项:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.25.1</version>
</dependency>
I know I'm doing something probably stupid but still can see what is my error here. 我知道我做的事情可能很愚蠢,但仍然可以看到我的错误在这里。 Any help would be greatly appreciated. 任何帮助将不胜感激。
Thanks! 谢谢!
The line 线
target.queryParam("id", true);
Doesn't modify target
, it just returns a new WebTarget with the queryparam set 不修改target
,它只返回带有queryparam设置的新 WebTarget
You could do 你可以做
target = target.queryParam("id", true);
but your second test is the correct way 但是第二次测试是正确的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.