title: How to send an Image from Web Service in Spring
body: <p>I am facing problem while sending an Image using Spring Web Service.</p>
  
  <p>I have written controller as below</p>
  
  <pre><code>@Controller
  public class WebService {
  
      @RequestMapping(value = "/image", headers = "Accept=image/jpeg, image/jpg, image/png, image/gif", method = RequestMethod.GET)
      public @ResponseBody byte[] getImage() {
          try {
              InputStream inputStream = this.getClass().getResourceAsStream("myimage.jpg");
              BufferedImage bufferedImage = ImageIO.read(inputStream);
              ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
              ImageIO.write( bufferedImage  , "jpg", byteArrayOutputStream);
              return byteArrayOutputStream.toByteArray();
  
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  
  <p><code>@ResponseBody</code> converts response into JSON. </p>
  
  <p>I am using RestClient to test Web Service.</p>
  
  <p>But When I'm hitting with <code>http://localhost:8080/my-war-name/rest/image</code> URL.</p>
  
  <pre><code>Header 
  Accept=image/jpg
  </code></pre>
  
  <p>I facing following error on RestClient</p>
  
  <blockquote>
    <p>Response body conversion to string using windows-1252 encoding failed. Response body not set!</p>
  </blockquote>
  
  <p>When i'm using browsers Chrome and Firefox</p>
  
  <p>Headers are not added so error was expected (Please guide me on this)</p>
  
  <pre>
  HTTP Status 405 - Request method 'GET' not supported
  
  type Status report
  
  message Request method 'GET' not supported
  
  description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).
  </pre>
  
  <p>I have also faced below error once</p>
  
  <blockquote>
    <p>The resource identified by this request is only capable 
    of generating responses with characteristics not acceptable according to the request "accept" headers ()</p>
  </blockquote>
  
  <p>I have followed 
  <a href="http://krams915.blogspot.com/2011/02/spring-3-rest-web-service-provider-and.html" rel="noreferrer">http://krams915.blogspot.com/2011/02/spring-3-rest-web-service-provider-and.html</a> tutorial.</p>
  
  <p>My requirment is to send image in byte format to Android Client.</p>