Announcement Announcement Module
Collapse
No announcement yet.
RESTful Call:No suitable converter found for content type [application/octet-stream] Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RESTful Call:No suitable converter found for content type [application/octet-stream]

    I have one RESTful service that gives a List of objects in JSON.
    It is deployed to two different servers, hence have two different URIs.

    I made a REST client web application that can access both URIs. Below is a snippet of my code (I've grayed out/commented out some implementations I tried):
    Code:
    		// #1
    		// Prepare acceptable media type
    		List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    		acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
    		// Prepare header
    		HttpHeaders headers = new HttpHeaders();
    		headers.setAccept(acceptableMediaTypes);
    		// not working headers #2
    //		HttpHeaders headers = new HttpHeaders();
    //		headers.add("Content-Type", "application/json");
    //		headers.add("Accept", "*/*");	
    		// #3
    //		HttpHeaders headers = new HttpHeaders();
    //		headers.set("Content-Type", "application/json");
    //		headers.set("Accept", "*/*");	
                    // #4
    //		List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
    //		interceptors.add(new AcceptHeaderHttpRequestInterceptor());
    //		restTemplate.setInterceptors(interceptors);
    
    		HttpEntity<MyRequest> myEntityRequest= new HttpEntity<MyRequest>(
    				myRequestStuff, headers);
    		
    //		ResponseEntity<List> objects= 
    //				restTemplate.postForEntity(myURI, myEntityRequest, List.class);
    
    		ResponseEntity<List> objects= restTemplate.exchange(myURI, 
    				HttpMethod.POST,
    				myEntityRequest, List.class);
    Accessing and getting the JSON result from the REST service in server#1 works fine with my code.
    The REST service in server#2 however is encountering this error:

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [java.util.List] and content type [application/octet-stream]
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    There is nothing wrong with the servers. Both of these are working if I use org.apache.http libraries for REST and some magic with java.io.InputStream.

    I could really go to the apache libraries to resolve this.. But, I just want to know, what could have gone wrong with my Spring's restTemplate implementation? As you can see, I tried a lot of ways on setting up the headers but it seems that restTemplate doesn't recognize my headers sometimes.
Working...
X