title: RestTemplate handle [image/jpg] response content type in java
body: <p>Sorry, i am newbie on java web development.</p>
  
  <p>I got some task to fetch user profile picture from 3rd party company via HTTP rest(GET method). Their api only can be accessed using session id on the header parameter and the api will return some byte[] array looks like <code>’ÑÒBRSb¢ÂáTr²ñ#‚4“â3C</code> etc. </p>
  
  <p><strong>How to handle rest response with content type image/jpg in Rest Template?</strong> </p>
  
  <p>I do my best like this</p>
  
  <pre><code>private RestTemplate restTemplate;
  
  public byte[] getProfilePic(){
    String canonicalPath = "http://dockertest/bankingapp/customer/profpicFile";
    String sessionId= "MTQ4NzE5Mz...etc";
  
    HttpEntity&lt;byte[]&gt; request = new HttpEntity&lt;byte[]&gt;(null, getHeaders(true, "GET", null, canonicalPath, sessionId));
    //getHeaders() will return HttpHeaders with those parameter
  
    ResponseEntity&lt;byte[]&gt; response = null;
    try {
      response = this.restTemplate.exchange(uri, HttpMethod.GET, request, byte[].class);
    } catch( HttpServerErrorException hse ){
      throw hse;
    }
    return response;
  }
  </code></pre>
  
  <p>This code will return an error</p>
  
  <blockquote>
    <p>org.springframework.web.client.RestClientException: Could not extract
    response: no suitable HttpMessageConverter found for response type
    [[B] and content type [image/jpg]</p>
  </blockquote>
  
  <p>Any suggestion or help will be appreciated!</p>
  
  <p>Thank you</p>
  
  <p><strong>Update</strong></p>
  
  <p>Using stackoveflower suggestions i can manage to solve this.</p>
  
  <pre><code>private RestTemplate restTemplate;
  
  public byte[] getProfilePic(){
    String canonicalPath = "/mobile/customer/profpicFile";
    String sessionId= "MTQ4NzE5Mz...etc";
  
    HttpEntity&lt;byte[]&gt; request = new HttpEntity&lt;byte[]&gt;(null, getHeaders(true, "GET", null, canonicalPath, sessionId));
    //getHeaders() will return HttpHeaders with those parameter
  
    ResponseEntity&lt;byte[]&gt; response = null;
    try {
      restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
      response = this.restTemplate.exchange(uri, HttpMethod.GET, request, byte[].class).getBody();
      return response;
    } catch( HttpServerErrorException hse ){
      throw hse;
    }
    return null;
  }
  </code></pre>
  
  <p>Note about HttpMessageConverter, instead using list, i can directly add a <code>ByteArrayHttpMessageConverter()</code></p>