mercredi 15 avril 2015

HttpMessageConverter found for request type [com.sun.jersey.core.util.MultivaluedMapImpl]

Sorry for my really bad english. I'm trying to improve it but i hope it will not be too hard to understand me.


It's like 3 days i'm blocking by a problem for my android app. I try to use the android annotation for my posts request and after few errors like "unsupported media type", i finaly have this error :



org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.sun.jersey.core.util.MultivaluedMapImpl]



I tried lot of things, but i don't find the error. I really need another eyes on my code.


Here my request :



import org.androidannotations.annotations.rest.Accept;
import org.androidannotations.annotations.rest.Post;
import org.androidannotations.annotations.rest.Rest;
import org.androidannotations.api.rest.MediaType;
import org.androidannotations.api.rest.RestClientErrorHandling;
import org.springframework.http.converter.FormHttpMessageConverter;

import javax.ws.rs.core.MultivaluedMap;

import worldline.rd.ebasket.model.massilia.customer.Customer;
import worldline.rd.ebasket.utils.Constants;

@Rest(rootUrl = Constants.HTTP.CUSTOMER_URL, converters = {FormHttpMessageConverter.class})
public interface ICustomerFormUrlEncoder extends RestClientErrorHandling {

@Post(value = "/customer/{identifier}/authentication/authenticate")
@Accept(MediaType.APPLICATION_JSON)
public Customer authenticate(MultivaluedMap data, String identifier);


The auto generation of this code is this :



@Override
public Customer authenticate(MultivaluedMap data, String identifier) {
try {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType("application/json")));
HttpEntity<MultivaluedMap> requestEntity = new HttpEntity<MultivaluedMap>(data, httpHeaders);
HashMap<String, Object> urlVariables = new HashMap<String, Object>();
urlVariables.put("identifier", identifier);
return restTemplate.exchange(rootUrl.concat("/customer/{identifier}/authentication/authenticate"), HttpMethod.POST, requestEntity, Customer.class, urlVariables).getBody();
} catch (NestedRuntimeException e) {
if (restErrorHandler!= null) {
restErrorHandler.onRestClientExceptionThrown(e);
return null;
} else {
throw e;
}
}
}


I'm calling this method in an async async task with the doInBackground method :



@Override
protected Customer doInBackground(String... strings) {
Customer test;
String password = strings[1];
MultivaluedMap<String, String> data = new MultivaluedMapImpl();
data.add("password",password);
//data.add("responseGroups","RG.Customer.ALL");
Customer customer = mICustomerFormUrlEncoder.authenticate(data, strings[0]);
test = customer;
return test;
}


I tried to use MultiValueMap instead of MultiValuedMap but it just give me and bad request. I also tried to change the converter but nothing better.


My request : http://ift.tt/1IdfyF6


I really hope someone can help me. If you need any other informations, i'll add them as fast i can.


Aucun commentaire:

Enregistrer un commentaire