차단된 사이트에서 이미지를 가져와야 하는 경우가 생겨서
proxy로 이미지를 보여줄 수 있는 방법을 선택했다.
(그냥 이미지를 로딩하면 warning 페이지가 뜬다.)
ImageProxyServlet.java
public class ImageProxyServlet extends javax.servlet.http.HttpServlet { protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { doGet(request, response); } protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { try { String url = request.getParameter("url"); HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); InputStream inputStream = httpEntity.getContent(); response.setContentType("image/jpeg"); IOUtils.copy(inputStream, response.getOutputStream()); } catch (Exception e) { e.printStackTrace(); } } }
web.xml
ImageProxyServlet com.example.ImageProxyServlet ImageProxyServlet /imageProxy
댓글
댓글 쓰기