【问题标题】:Custom Arquillian ArquillianResteasyResource application path- Error HTTP method POST is not supported by this URL自定义 Arquillian ArquillianResteasyResource 应用程序路径 - 此 URL 不支持错误 HTTP 方法 POST
【发布时间】:2020-08-18 22:03:29
【问题描述】:

我的 REST API 在部署时工作正常,但我的测试使用 Jersey Arquillian 扩展失败:

@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);

}

我得到错误:

Error HTTP method POST is not supported by this URL

我的 JAX-RS 程序看起来不错:

@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();
    }
}

【问题讨论】:

    标签: java resteasy jboss-arquillian


    【解决方案1】:

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

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

    @ArquillianResteasyResource("api")
    

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

    【讨论】:

      猜你喜欢
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-31
      • 2016-07-02
      • 2017-01-28
      • 2018-04-03
      • 2020-09-17
      相关资源
      最近更新 更多