【问题标题】:JAX-RS Form within a WidflyWildfly 中的 JAX-RS 表单
【发布时间】:2016-07-06 18:36:24
【问题描述】:

我需要对接口进行 REST 调用。为此,我使用以下代码:

ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
Response res = client.target(url).
    request().
    header("Authorization", "Basic " + basicAuthString).
    buildPost(Entity.form(new Form("grant_type", "client_credentials"))).
    invoke();

在使用 JAX-RS 的独立应用程序中,这可以按预期工作。当我在 Wildfly 应用程序服务器中使用该代码时,我收到以下错误:

20:16:15,186 ERROR [stderr] (default task-5) Caused by:
javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/x-www-form-urlencoded type: javax.ws.rs.core.Form

Wildfly 不知道如何处理javax.ws.rs.core.Form,从而创建了Content-Type: application/x-www-form-urlencoded。我错过了哪个依赖项?

[编辑:2016-07-07]

我要发送的任何数据都会出现此错误。这会引发类似的错误:

ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
Response res = client.target(url).
    request().
    post(Entity.entity("DATA", MediaType.TEXT_PLAIN));

【问题讨论】:

  • 。将此添加到您的请求中或检查它期望的内容类型并将其添加到 header header("Content-Type", "application/x-www-form-urlencoded")
  • 导致同样的错误。
  • 尝试在其调用的 API 上添加 @Consumes ("application/x-www-form-urlencoded")
  • 是另一方提供的API。一旦我创建请求,此错误就会发生在 Wildfly 。请求永远不会离开服务器。

标签: java jboss jax-rs wildfly


【解决方案1】:

终于调试了一天:去掉ClientConfig就是解决办法!

Client client = ClientBuilder.newClient();
Response res = client.target(url).
    request().
    post(Entity.entity("DATA", MediaType.TEXT_PLAIN));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-23
    • 2015-10-15
    • 1970-01-01
    相关资源
    最近更新 更多