multipart / form-data调用问题

时间:2018-04-03 12:34:55

标签: java rest spring-boot jax-rs resteasy

尝试调用接受multipart / form-data

的POST请求

使用带有以下配置选项的swagger代码生成客户端

<configOptions>
    <dateLibrary>java8</dateLibrary>
    <sourceFolder>src/main/java</sourceFolder>                              
    <invokerPackage>com.x.client.autogen.y</invokerPackage>
</configOptions>
 <output>target/generated-sources</output>
  <environmentVariables>
   <library>resteasy</library>
   </environmentVariables>
</configuration>

POM已将resteasy-multipart-provider添加为依赖

<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-multipart-provider</artifactId>
  <version>3.0.7.Final</version>
  <scope>runtime</scope>
 </dependency>

现在我以

的身份调用请求
ApiClient apiClient = new ApiClient();
        apiClient.setBasePath("http://x/getOutput");                
        apiClient.setUsername("u");
        apiClient.setPassword("u");
        DefaultApi api = new DefaultApi(apiClient);
        try {
            String response = api.getOutput("response", xml.concat(";type=application/xml"), "transactionId");

        } catch (Throwable e) {           
            e.printStackTrace();
        }

这会引发错误:

Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type multipart/form-data type: java.util.LinkedHashMap

然而

当我使用以下代码段调用时 - 请求通过 - 它还会尝试查找提供程序并获取提供程序

MultipartFormDataOutput mpfdo = new MultipartFormDataOutput();
        mpfdo.addFormData("InputData", xml, MediaType.TEXT_PLAIN_TYPE);
        mpfdo.addFormData("Destination", "response", MediaType.TEXT_PLAIN_TYPE);
        mpfdo.addFormData("TransactionId", "TransactionId", MediaType.TEXT_PLAIN_TYPE);
        Entity.entity(mpfdo, MediaType.MULTIPART_FORM_DATA_TYPE);

        Response response = ClientBuilder.newClient().target("http://x/getOutput")
                .register(new BasicAuthentication("u", "u"))
                .request().header("Accept", MediaType.MULTIPART_FORM_DATA_TYPE)
                .post(Entity.entity(mpfdo, MediaType.MULTIPART_FORM_DATA_TYPE));

我正在使用 spring-boot:run 来运行entier应用程序

所以RestEnpoint - &gt;服务 - &gt;服务调用客户端Enpoint

0 个答案:

没有答案
相关问题