android 4 jersey2,Android Jersey Client com.sun.jersey.api.client.ClientHandlerException

问题

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 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);

回答1:

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.

com.sun.jersey

jersey-bundle

1.14

来源:https://stackoverflow.com/questions/11996866/android-jersey-client-com-sun-jersey-api-client-clienthandlerexception

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值