package main.java.rest.resource;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Base64;

import javax.imageio.ImageIO;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/image")
public class ImageRestService {
	
	@GET
	@Path("/{id}")
	public String getImage(@PathParam("id") String id) {
		String imageEncoded = null;
		imageEncoded = encodeToBase64(id);
		
		return imageEncoded;
	}
	
	public String encodeToBase64(String id) {
		String response = null;
		String location = "C:/"+id+".png";
		try {
			BufferedImage img = ImageIO.read(new File(location));
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ImageIO.write(img, "png", baos);
			baos.flush();
			response = Base64.getEncoder().encodeToString(baos.toByteArray());
			baos.close();			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return response;
	}
}

@@ -285,16 +285,50 @@
 thParam;
+%0Aimport javax.ws.rs.core.Response;
 %0A%0A@Path(
@@ -401,22 +401,24 @@
 %09public 
-String
+Response
  getImag
@@ -455,97 +455,33 @@
 %7B%0A%09%09
-String imageEncoded = null;%0A%09%09imageEncoded = encodeToBase64(id);%0A%09%09%0A%09%09return imageEncoded
+return encodeToBase64(id)
 ;%0A%09%7D
@@ -491,22 +491,24 @@
 %09public 
-String
+Response
  encodeT
@@ -537,24 +537,23 @@
 %09String 
-response
+encoded
  = null;
@@ -772,24 +772,23 @@
 h();%0A%09%09%09
-response
+encoded
  = Base6
@@ -858,77 +858,92 @@
 e();
+%0A
 %09%09%09
-%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO Auto-generated catch block
+return Response.status(200).entity(encoded).build();%0A%09%09%7D catch (IOException e) %7B
 %0A%09%09%09
@@ -964,21 +964,16 @@
 ace();%0A%09
-%09%7D%0A%09%0A
 %09%09return
@@ -977,17 +977,118 @@
 urn 
-r
+R
 esponse
-;
+.status(500).entity(%22Something went wrong fetching the image, the file might not exist%22).build();%0A%09%09%7D%0A
 %0A%09%7D%0A

Update ImageRestService.java