无法找到 MessageBodyReader

发布于 2024-08-24 22:31:04 字数 1546 浏览 3 评论 0原文

我有这个接口:

 @Path("inbox")
public interface InboxQueryResourceTest {

    @POST
    @Path("{membershipExternalId}/query")
    @Consumes(MediaType.APPLICATION_XML)
    @Produces("multipart/mixed")
    public MultipartOutput query(@PathParam("membershipExternalId") final String membershipExternalId,
                             @QueryParam("page") @DefaultValue("0") final int page,
                             @QueryParam("pageSize") @DefaultValue("10") final int pageSize,
                             @QueryParam("sortProperty") final List<String> sortPropertyList,
                             @QueryParam("sortReversed") final List<Boolean> sortReversed,
                             @QueryParam("sortType") final List<String> sortTypeString,
                             final InstanceQuery instanceQuery) throws IOException;
}

我已经实现了返回 MultipartOutput 的方法。 我从 Fiddler 发布了一个 xml 查询,并且毫无问题地收到了结果。

但是我已经对同一个接口进行了集成测试,我发送了相同的对象,并且我的响应如下:

final MultipartOutput multiPartOutput = getClient().query(getUserRestAuth(), 0, 25, null, null, null, instanceQuery);

但是在这里,从集成测试中,我收到一个奇怪的错误:

无法找到内容类型为 multipart/mixed;boundary="74c5b6b4-e820-452d-abea-4c56ffb514bb" 且类型为 org.jboss.resteasy.plugins.providers.multipart.MultipartOutput 的 MessageBodyReader

任何人都知道为什么只在集成中测试我收到此错误?

PS:有些人会说我不发送 application/xml 作为 ContentType 而是 multipart,这当然是错误的,因为对象用所需的 @XmlRootElement 等进行了注释,否则来自 Fiddler 的 POST 都不起作用。

I have this interface:

 @Path("inbox")
public interface InboxQueryResourceTest {

    @POST
    @Path("{membershipExternalId}/query")
    @Consumes(MediaType.APPLICATION_XML)
    @Produces("multipart/mixed")
    public MultipartOutput query(@PathParam("membershipExternalId") final String membershipExternalId,
                             @QueryParam("page") @DefaultValue("0") final int page,
                             @QueryParam("pageSize") @DefaultValue("10") final int pageSize,
                             @QueryParam("sortProperty") final List<String> sortPropertyList,
                             @QueryParam("sortReversed") final List<Boolean> sortReversed,
                             @QueryParam("sortType") final List<String> sortTypeString,
                             final InstanceQuery instanceQuery) throws IOException;
}

I have implemented the method to return a MultipartOutput.
I am posting an xml query from Fiddler and i receive the result without any problem.

BUT i have done an integration test for the same interface, i send the same objects and i put the response like:

final MultipartOutput multiPartOutput = getClient().query(getUserRestAuth(), 0, 25, null, null, null, instanceQuery);

But here, so from integration tests, i receive a strange error:

Unable to find a MessageBodyReader of content-type multipart/mixed;boundary="74c5b6b4-e820-452d-abea-4c56ffb514bb" and type class org.jboss.resteasy.plugins.providers.multipart.MultipartOutput

Anyone has any ideea why only in integration tests i receive this error?

PS: Some of you will say that i do not send application/xml as ContentType but multipart, which of course is false because the objects are annotated with the required @XmlRootElement etc, otherways neither the POST from Fiddler would work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉薄对峙 2024-08-31 22:31:04

你可以试试这个:

ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
providerFactory.registerProvider(org.jboss.resteasy.plugins.providers.multipart.MimeMultipartProvider.class);

You can try this:

ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
providerFactory.registerProvider(org.jboss.resteasy.plugins.providers.multipart.MimeMultipartProvider.class);
煮酒 2024-08-31 22:31:04

类路径中是否包含用于多部分编码的相应 Resteasy 插件? (esteasy-multipart-provider)。

Are including in classpath the corresponding resteasy addon for multipart encoding? (esteasy-multipart-provider).

卷耳 2024-08-31 22:31:04

尝试将此方法添加到您的测试类中。这将注册已在您的服务器上注册的默认内置提供程序。

@BeforeClass
public static void registerProviders() {
    ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    RegisterBuiltin.register(providerFactory);
}

Try adding this method to your test class. This would register the default built-in providers which are already registered on your server.

@BeforeClass
public static void registerProviders() {
    ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    RegisterBuiltin.register(providerFactory);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文