相关疑难解决方法(0)

在JerseyTest中找不到媒体类型= multipart/form-data的MessageBodyWriter

我正在尝试为POSTJersey程序中的资源类中的方法创建一个测试.

这是POST资源的方法:

@POST @Path("/new")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response HTTPPostMethod(@FormDataParam("file") InputStream fileIS, 
                           @FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
    // ... some code that handles the InputStream
}
Run Code Online (Sandbox Code Playgroud)

ResourceConfig的创建方式如下:

public class MyApp extends ResourceConfig {

    public MyApp(String param) {
        register(createMoxyJsonResolver());     
        register(MultiPartFeature.class);
        register(MyResource.class);
    }

     private static ContextResolver<MoxyJsonConfig> createMoxyJsonResolver() {
        final MoxyJsonConfig moxyJsonConfig = new MoxyJsonConfig();
        Map<String, String> nsPrefixManager = new HashMap<String, String>(1);
        nsPrefixManager.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
        moxyJsonConfig.setNamespacePrefixMapper(nsPrefixManager).setNamespaceSeparator(':');
        return moxyJsonConfig.resolver();
    }

    /**
     * Start the Grizzly HTTP Server
     * 
     */
    public final void …
Run Code Online (Sandbox Code Playgroud)

java testing multipartform-data jersey jersey-test-framework

8
推荐指数
1
解决办法
7223
查看次数

Jersey客户端异常:找不到消息正文编写器

我正在使用Jersey客户端来访问PHP Web服务以获取图像上载功能.我收到以下异常:

Caused by: com.sun.jersey.api.client.ClientHandlerException: 
A message body writer for Java type, class 
com.sun.jersey.multipart.FormDataMultiPart, and MIME media type, 
multipart/form-data, was not found
    at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
    ... 63 more
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的代码:

WebResource webResource = Client.create().resource(HTTP_REST_URI);
JSONObject jSONObj = webResource.queryParams(queryParams)
      .type(MediaType.MULTIPART_FORM_DATA)
      .post(JSONObject.class, formDataMultiPart);
Run Code Online (Sandbox Code Playgroud)

如何解决这个异常?

rest web-services jersey

7
推荐指数
2
解决办法
3万
查看次数