英文:
Custom Arquillian ArquillianResteasyResource application path- Error HTTP method POST is not supported by this URL
问题
@Test
@RunAsClient
public void postTest(@ArquillianResteasyResource final WebTarget webTarget) {
MyRequest request = new MyRequest();
String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
.post(Entity.json(request)).readEntity(String.class);
Assert.assertEquals("OK", response);
}
@ApplicationPath("api")
public class JaxRsActivator extends Application {
}
@Path("/demo")
@Stateless
public class DemoResource extends BaseResource {
@POST
public Response demo(MyRequest request) {
return Response.ok().entity("OK").build();
}
}
英文:
My REST API works fine when deployed but my tests are failing using Jersey Arquillian extension:
@Test
@RunAsClient
public void postTest(@ArquillianResteasyResource final WebTarget webTarget) {
MyRequest request = new MyRequest();
String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
.post(Entity.json(request)).readEntity(String.class);
Assert.assertEquals("OK", response);
}
I get the error:
Error HTTP method POST is not supported by this URL
My JAX-RS programs look OK:
@ApplicationPath("api")
public class JaxRsActivator extends Application {
}
@Path("/demo")
@Stateless
public class DemoResource extends BaseResource {
@POST
public Response demo(MyRequest request) {
return Response.ok().entity("OK").build();
}
}
答案1
得分: 0
@ArquillianResteasyResource
的默认值是 rest
,但是我的 JaxRsActivator
被设置为 api
。
为了解决这个问题,我使用了:
@ArquillianResteasyResource("api")
获取完整的 URI:webTarget.getUri()
。
英文:
The default value for @ArquillianResteasyResource
is rest
, but my JaxRsActivator is set to api
.
To solve it I used:
@ArquillianResteasyResource("api")
To get the complete URI: webTarget.getUri()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论