小编Van*_*avv的帖子

使用Response参数的方法中的IllegalStateException

我写了一个简单的类来测试响应读取实体方法(如果它按预期工作).但它没有奏效.

当我启动课程时,我收到以下错误response.readEntity():

Exception in thread "main" java.lang.IllegalStateException: Method not supported on an outbound message.  
  at org.glassfish.jersey.message.internal.OutboundJaxrsResponse.readEntity(OutboundJaxrsResponse.java:150)
Run Code Online (Sandbox Code Playgroud)

这是我写的代码

public static void main(String[] args) {
        List<Entity> representations = new ArrayList<>();
        representations.add(new Entity("foo", "baz", false));
        representations.add(new Entity("foo1", "baz1", true));
        representations.add(new Entity("foo2", "baz2", false));
        Response build = Response.ok(representations).build();
        printEntitesFromResponse(build);
    }

public static void printEntitesFromResponse(Response response) {
        response
                .readEntity(new GenericType<List<Entity>>() {})
                .stream()
                .forEach(entity -> System.out.println(entity));
    }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

java jax-rs dropwizard

15
推荐指数
1
解决办法
1万
查看次数

如何在 Jersey-Test 中发布 JSON 请求

我正在为我的 REST 应用程序编写单元测试,但我被卡住了。当我使用标题参数时,测试很明显。但是现在,我的请求是 JSON,我不知道如何测试它。也许有一种方法可以用泽西岛或者杰克逊来做到这一点。我从我的资源获得响应的行如下所示:

final Response response = RULE.getJerseyTest().target("/actors/1").request().post(/* json request */);
Run Code Online (Sandbox Code Playgroud)

其中 RULE 是 ResourceTestRule。

我应该怎么做才能让它发布资源?

java json jersey

6
推荐指数
1
解决办法
3632
查看次数

如何使用H2-in-memory数据库测试JDBI DAO?

我正在将Dropwizard框架与JDBI和h2-in-memory一起用于我的测试目的.我也写了我的DAO,现在我想用单元测试来测试它们.我来了DBUnit,似乎符合我的要求.

但是如何将它与JDBI集成并用测试数据填充?

java testing dao jdbi dropwizard

3
推荐指数
1
解决办法
4980
查看次数

如何使用Dropwizard读取JSON请求体

我一直在编写简单的dropwizard应用程序,一切正常,直到我不得不更改请求类型.因为我之前从Header得到了我的参数,现在我必须从JSON请求的主体中获取它们.最可悲的是 - 没有关于dropwizard或任何文章的完整文档,这对我有帮助.这是我的代码:

@Path("/actors")
@Produces("application/json")
public class ActorResource {
    private final ActorDAO dao;

    public ActorResource(ActorDAO dao) {
        this.dao = dao;
    }

    @POST
    @UnitOfWork
    public Saying postActor(@HeaderParam("actorName") String name,@HeaderParam("actorBirthDate") String birthDate) {
        Actor actor = dao.create(new Actor(name,birthDate));
        return new Saying("Added : " + actor.toString());
    }
Run Code Online (Sandbox Code Playgroud)

有没有人有办法解决吗?

java json jackson dropwizard

2
推荐指数
1
解决办法
8674
查看次数

标签 统计

java ×4

dropwizard ×3

json ×2

dao ×1

jackson ×1

jax-rs ×1

jdbi ×1

jersey ×1

testing ×1