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

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

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()

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:

确定