Android的Jersey客户端com.sun.jersey.api.client.ClientHandlerException [英] Android Jersey Client com.sun.jersey.api.client.ClientHandlerException

查看:304
本文介绍了Android的Jersey客户端com.sun.jersey.api.client.ClientHandlerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从我的Andr​​oid应用程序的球衣客户端连接到Web服务。
的android的版本是1.6(API等级4)

我已引用球衣-核心1.12.jar和新泽西州的客户1.12.jar 库。

当我把C $光盘 MediaType.APPLICATION_FORM_URLEN $请求(应用程序/ x-WWW的形式urlen codeD)我得到以下异常

  com.sun.jersey.api.client.ClientHandlerException:邮件正文作家Java类型,类com.sun.jersey.core.util.MultivaluedMapImpl和MIME媒体类型,应用程序/ x-WWW的形式urlen codeD,没有被发现

使用相同的code。与JDK 1.6更新04 - 一切工作正常

下面是我的服务器code的请求的示例:

  @Path(/+ RequestNames.LOGIN)
公共类登录{    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLEN codeD)
    市民反应登录(
            @FormParam(RequestParams.USER_NAME_PARAM)字符串username,
            @FormParam(RequestParams.PASSWORD_PARAM)字符串密码){
...

下面是我的客户code的请求的示例:

  MultivaluedMap<字符串,字符串> FORMDATA =新MultivaluedMapImpl();
        formData.add(RequestParams.USER_NAME_PARAM,用户名);
        formData.add(RequestParams.PASSWORD_PARAM,密码);
        ClientResponse响应=
                service.path(REST_PATH)。路径(RequestNames.LOGIN).TYPE(
                        MediaType.APPLICATION_FORM_URLEN codeD)。员额(ClientResponse.class,FORMDATA);


解决方案

我有同样的问题以


  

一个消息正文作家Java类型,类com.sun.jersey.core.util.MultivaluedMapImpl


错误,它结束了是一个Maven的依赖问题。而不是使用单个球衣 - * 神器我包括球衣束和它的工作。例如。

 <&依赖性GT;
        <&的groupId GT; com.sun.jersey< /的groupId>
        <&的artifactId GT;球衣束< / artifactId的>
        <&版GT;&1.14 LT; /版本>
    < /依赖性>

I am using jersey client from my android app to connect to a web service. The version of android is 1.6 (api level 4)

I have referenced jersey-core-1.12.jar and jersey-client-1.12.jar libs.

When I call a request with MediaType.APPLICATION_FORM_URLENCODED (application/x-www-form-urlencoded) I am getting the following exception:

com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/x-www-form-urlencoded, was not found

Using the same code with JDK 1.6 update 04 - all works fine.

Here is the sample of my server code for the request:

@Path("/" + RequestNames.LOGIN)
public class Login {

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public Response login(
            @FormParam(RequestParams.USER_NAME_PARAM) String userName,
            @FormParam(RequestParams.PASSWORD_PARAM) String password) {
...

Here is the sample of my client code for the request:

MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
        formData.add(RequestParams.USER_NAME_PARAM, userName);
        formData.add(RequestParams.PASSWORD_PARAM, password);
        ClientResponse response =
                service.path(REST_PATH).path(RequestNames.LOGIN).type(
                        MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);

解决方案

I had the same problem with the

A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl

error and it ended up to be a maven dependency issue. Instead of using the single jersey-* artifacts I included jersey-bundle and it worked. E.g.

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.14</version>
    </dependency>

这篇关于Android的Jersey客户端com.sun.jersey.api.client.ClientHandlerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆