2

当前不存在获取 JAX-RS 实体提供程序。当我尝试上传文件时出现异常。我如何注册任何错过的提供者?

使用 Apache Wink 客户端和媒体类型上传文件的最佳方法是 multipart/form-data。

    /* BufferedOutMultiPart requestEntity = new BufferedOutMultiPart();
    requestEntity.setBoundary("Simple-boundary-weqiftugcs");
    OutPart outPart = new OutPart();
    outPart.setBody(file);
    outPart.setContentType(MediaType.MULTIPART_FORM_DATA);
    outPart.addHeader("Content-Transfer-Encoding", "binary");
    outPart.addHeader("Content-Disposition", "form-data; name=\"uploadedFile\";");
    requestEntity.addPart(outPart); */

    MultipartEntity multiPartEntity = new MultipartEntity();
    FileBody fileBody = new FileBody(file);
    multiPartEntity.addPart("uploadFile", fileBody);

    ClientConfig clientConfig = new ClientConfig();
    RestClient restClient = new RestClient(clientConfig);

    Resource restResource = restClient.resource(serviceURL);
    restResource.accept("*/*");
    restResource.contentType(MediaType.MULTIPART_FORM_DATA);
    restResource.post(multiPartEntity);

线程“主”中的异常

org.apache.wink.client.ClientRuntimeException:java.lang.RuntimeException: java.lang.RuntimeException: 找不到类 org.apache.http.entity.mime.MultipartEntity 的 javax.ws.rs.ext.MessageBodyWriter 实现类型和多部分/表单数据媒体类型。验证所有实体提供者都已正确注册。如果当前不存在 JAX-RS 实体提供程序,请添加自定义 javax.ws.rs.ext.MessageBodyWriter 提供程序来处理类型和媒体类型。

4

0 回答 0