Custom Arquillian ArquillianResteasyResource application path- Error HTTP method POST is not supported by this URL

huangapple go评论95阅读模式
英文:

Custom Arquillian ArquillianResteasyResource application path- Error HTTP method POST is not supported by this URL

问题

  1. @Test
  2. @RunAsClient
  3. public void postTest(@ArquillianResteasyResource final WebTarget webTarget) {
  4. MyRequest request = new MyRequest();
  5. String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
  6. .post(Entity.json(request)).readEntity(String.class);
  7. Assert.assertEquals("OK", response);
  8. }
  1. @ApplicationPath("api")
  2. public class JaxRsActivator extends Application {
  3. }
  4. @Path("/demo")
  5. @Stateless
  6. public class DemoResource extends BaseResource {
  7. @POST
  8. public Response demo(MyRequest request) {
  9. return Response.ok().entity("OK").build();
  10. }
  11. }
英文:

My REST API works fine when deployed but my tests are failing using Jersey Arquillian extension:

  1. @Test
  2. @RunAsClient
  3. public void postTest(@ArquillianResteasyResource final WebTarget webTarget) {
  4. MyRequest request = new MyRequest();
  5. String response = webTarget.path("/demo").request(MediaType.APPLICATION_JSON)
  6. .post(Entity.json(request)).readEntity(String.class);
  7. Assert.assertEquals("OK", response);
  8. }

I get the error:

  1. Error HTTP method POST is not supported by this URL

My JAX-RS programs look OK:

  1. @ApplicationPath("api")
  2. public class JaxRsActivator extends Application {
  3. }
  4. @Path("/demo")
  5. @Stateless
  6. public class DemoResource extends BaseResource {
  7. @POST
  8. public Response demo(MyRequest request) {
  9. return Response.ok().entity("OK").build();
  10. }
  11. }

答案1

得分: 0

@ArquillianResteasyResource 的默认值是 rest,但是我的 JaxRsActivator 被设置为 api

为了解决这个问题,我使用了:

  1. @ArquillianResteasyResource("api")

获取完整的 URI:webTarget.getUri()

英文:

The default value for @ArquillianResteasyResource is rest, but my JaxRsActivator is set to api.

To solve it I used:

  1. @ArquillianResteasyResource("api")

To get the complete URI: webTarget.getUri()

huangapple
  • 本文由 发表于 2020年8月19日 06:03:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63477248.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定