Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到多部分正文、多部分/表单数据的消息正文编写器_Java_Web Services_Rest_Jax Rs_Cxf - Fatal编程技术网

Java 未找到多部分正文、多部分/表单数据的消息正文编写器

Java 未找到多部分正文、多部分/表单数据的消息正文编写器,java,web-services,rest,jax-rs,cxf,Java,Web Services,Rest,Jax Rs,Cxf,我正在通过CXF客户端调用REST url以上载xml文件: WebClient webClient = WebClient.create("some base uri") .header("Authorization",createAuthorizationHeader); webClient.encoding("UTF-8"); webClient.type(MediaType.MULTIPART_FORM_DATA); Con

我正在通过CXF客户端调用REST url以上载xml文件:

WebClient webClient = WebClient.create("some base uri")
                                .header("Authorization",createAuthorizationHeader);
webClient.encoding("UTF-8");
webClient.type(MediaType.MULTIPART_FORM_DATA);
ContentDisposition cd = new ContentDisposition("attachment;filename=abc.xml");
Attachment att = new Attachment("root", stream, cd);
Response response = webClient.post(new MultipartBody(att));
但我在电话留言时遇到了以下异常

javax.ws.rs.ProcessingException:未找到org.apache.cxf.jaxrs.ext.multipart.MultipartBody类的消息正文编写器,ContentType:multipart/form data

我尝试添加提供者:

List providers = new ArrayList();
providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());
providers.add(new org.apache.cxf.jaxrs.provider.MultipartProvider());
WebClient webClient = WebClient.create(constant.getUploadURI(),providers)
                               .header("Authorization",createAuthorizationHeader);

我仍然得到了相同的异常

我测试了您的配置,它在这里工作是整个测试文件

import java.io.FileInputStream;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.junit.Test;

public class KPUploadTest {

    @Test
    public void testUpload() {

        try (FileInputStream stream = new FileInputStream("d:\\uploadtest.txt");) {
            WebClient webClient = WebClient
                    .create("http://localhost:8080/api/kp/rest/upload");
            webClient.encoding("UTF-8");
            webClient.type(MediaType.MULTIPART_FORM_DATA);
            ContentDisposition cd = new ContentDisposition(
                    "attachment;filename=abc.xml");
            Attachment att = new Attachment("root", stream, cd);
            Response response = webClient.post(new MultipartBody(att));
            System.out.println(response.readEntity(String.class));
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

}

请共享其失败的位置,服务器端还是客户端?进一步查明错误。还有您正在使用的cxf JAXRS版本

谢谢您的回复。客户端调用“org.apache.cxf.interceptor.Fault”后出现异常:未找到org.apache.cxf.jaxrs.ext.multipart.MultipartBody类的消息体编写器,ContentType:multipart/form data“cxf jaxrs版本3.1.2”。我需要为Multipart提供任何提供者吗?您发送的流是什么,是文件吗?默认情况下,为multipart/formdataI启用提供程序。我将在InputStream中发送一个xml文件。