为什么我无法使用RestEasy创建端点 [英] Why I cannot create endpoint with RestEasy

查看:92
本文介绍了为什么我无法使用RestEasy创建端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的REST端点实施测试,如下所述:

I'm trying to implement a test for my REST endpoint, described here: http://antoniogoncalves.org/2012/12/19/test-your-jax-rs-2-0-web-service-uris-without-mocks/. Mentioned solution uses Jersey implementation of JAX-RS, but I want to use RestEasy. When I run my test I get

java.lang.UnsupportedOperationException
at org.jboss.resteasy.spi.ResteasyProviderFactory.createEndpoint(ResteasyProviderFactory.java:2176)

有人知道为什么JBossJAX-RS实现不支持创建端点,但是Jersey的实现(因为它位于我的文章开头的链接下)吗?

Any idea why JBoss's implementation of JAX-RS does not support creating endpoints, but Jersey's does (as it is under the link from the beginning of my post)?

推荐答案

看看RESTeasy文档,

Take a look at the RESTeasy documentation, Chapter 36. Embedded Containers. You will find examples for four different types of containers and their usage in testing:

  • 下拖
  • Sun HttpServer
  • TJWS
  • 净额

您可以选择口味.

这是使用Sun HttpServer的完整示例(如您链接到的示例):

Here's a complete example using the Sun HttpServer (as in the example you linked to):

public class SunHttpServerTest {

    @Path("simple")
    public static class SimpleResource {

        @GET
        public String get() {
            return "Hello Sun";
        }
    }

    private HttpContextBuilder contextBuilder;
    private HttpServer httpServer;

    @Before
    public void setUp() throws Exception {
        httpServer = HttpServer.create(new InetSocketAddress(8000), 10);
        contextBuilder = new HttpContextBuilder();
        contextBuilder.getDeployment().getActualResourceClasses().add(SimpleResource.class);
        HttpContext context = contextBuilder.bind(httpServer);
        context.getAttributes().put("some.config.info", "42");
        httpServer.start();
    }

    @After
    public void tearDown() {
        contextBuilder.cleanup();
        httpServer.stop(0);
    }

    @Test
    public void shouldReturnCorrectMessage() {
        Client client = ClientBuilder.newClient();
        Response response = client.target("http://localhost:8000/simple")
                .request().get();
        assertEquals(200, response.getStatus());
        String message = response.readEntity(String.class);
        assertEquals("Hello Sun", message);
        System.out.println(message);
        response.close();
    }
}

要实现此目的还需要以下依赖项

Also needed for this to work is the following dependency

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jdk-http</artifactId>
    <version>3.0.9.Final</version>
</dependency>

这篇关于为什么我无法使用RestEasy创建端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆