List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:com.thinkberg.moxo.dav.LockHandler.java
private void sendLockAcquiredResponse(HttpServletResponse response, Lock lock) throws IOException { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setHeader(HEADER_LOCK_TOKEN, "<" + lock.getToken() + ">"); Document propDoc = DocumentHelper.createDocument(); Element propEl = propDoc.addElement(TAG_PROP, "DAV:"); Element lockdiscoveryEl = propEl.addElement(TAG_LOCKDISCOVERY); lock.serializeToXml(lockdiscoveryEl); XMLWriter xmlWriter = new XMLWriter(response.getWriter()); xmlWriter.write(propDoc);/*w w w. j a v a 2 s. c om*/ log(propDoc); }
From source file:fr.aliasource.webmail.proxy.UpdateSieve.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.info("doGet on updateSieve servlet."); resp.setContentType("text/plain"); resp.getWriter().println("UpdateSieve servlet should be called with a POST HTTP request."); }
From source file:com.himtech.googlechart.GglPieChart.java
@RequestMapping(value = "/piechartJfree", method = RequestMethod.GET) public void drawPieChartJfree(ModelMap model, HttpServletResponse response) { response.setContentType("image/png"); PieDataset dataSet = createDataSet(); JFreeChart pieChart = createChart(dataSet, "Server Details"); //model.addAttribute("pieUrl", pieChart.toString()); try {// w w w .ja va 2 s . c o m ChartUtilities.writeChartAsPNG(response.getOutputStream(), pieChart, 750, 400); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.redoute.datamap.servlet.datamap.DeleteDatamap.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j av a2s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); try { String name = policy.sanitize(request.getParameter("id")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); IFactoryDatamap factoryDatamap = appContext.getBean(IFactoryDatamap.class); Datamap sqlLib = factoryDatamap.create(Integer.valueOf(name), null, null, null, null, null, null, null, null, null); datamapService.deleteDatamap(sqlLib); } finally { out.close(); } }
From source file:org.mitre.oauth2.view.TokenApiView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK; // default to 200 }/* w w w. j a v a2 s .c om*/ response.setStatus(code.value()); try { Writer out = response.getWriter(); Object obj = model.get(JsonEntityView.ENTITY); gson.toJson(obj, out); } catch (IOException e) { logger.error("IOException in JsonEntityView.java: ", e); } }
From source file:checkCoupon.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w.ja v a 2 s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String deviceId = request.getParameter("deviceId"); String couponId = request.getParameter("couponId"); String url = "https://tgl.standardchartered.com/bridgeheadi18n/mcoupon/check?deviceId=" + deviceId + "&couponId=" + couponId; HttpClient client = new DefaultHttpClient(); HttpGet req = new HttpGet(url); HttpResponse res = client.execute(req); BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent())); String line = ""; String total = ""; while ((line = rd.readLine()) != null) { total += line; } total = total.substring(0, total.length()); out.println(total); } }
From source file:com.epam.wilma.webapp.config.servlet.stub.upload.MultiPartFormUploadServlet.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else {//from ww w . j av a 2s . c o m try { List<FileItem> fields = upload.parseRequest(request); String msg = filesParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } }
From source file:edu.stanford.epad.common.util.EPADFileUtils.java
public static void sendFile(HttpServletRequest httpRequest, HttpServletResponse httpResponse, File file, String fileName, boolean download) throws Exception { InputStream is = null;/*from www. java 2s. com*/ try { is = new BufferedInputStream(new FileInputStream(file)); String mimeType = URLConnection.guessContentTypeFromStream(is); httpResponse.setContentType(mimeType); if (download) httpResponse.setHeader("Content-disposition", "attachment;filename=" + fileName); httpResponse.setHeader("pragma", "no-cache"); OutputStream outStream = null; String encoding = null; if (httpRequest != null) encoding = httpRequest.getHeader("Accept-Encoding"); if (false && encoding != null && encoding.indexOf("gzip") != -1) { httpResponse.setHeader("Content-Encoding", "gzip"); outStream = new GZIPOutputStream(httpResponse.getOutputStream()); } else if (false && encoding != null && encoding.indexOf("compress") != -1) { httpResponse.setHeader("Content-Encoding", "compress"); outStream = new ZipOutputStream(httpResponse.getOutputStream()); } else { outStream = httpResponse.getOutputStream(); } int chunk = 1024; byte[] buffer = new byte[chunk]; int length = -1; int i = 0; while ((length = is.read(buffer)) != -1) { outStream.write(buffer, 0, length); if (length < chunk) break; } is.close(); is = null; } finally { if (is != null) is.close(); } }
From source file:com.redoute.datamap.servlet.picture.UploadPicture.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww . j av a 2 s .c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); PrintWriter out = response.getWriter(); try { String image = request.getParameter("image"); String name = policy.sanitize(request.getParameter("id")); String columnName = policy.sanitize(request.getParameter("columnName")); String value = policy.sanitize(request.getParameter("value")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IPictureService pictureService = appContext.getBean(IPictureService.class); pictureService.updatePicture(name, "base64", image); } finally { out.close(); } }
From source file:tachyon.metrics.sink.MetricsServlet.java
private HttpServlet createServlet() { return new HttpServlet() { @Override//from ww w .java 2s . c o m protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(String.format("text/json;charset=utf-8")); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); String result = mObjectMapper.writeValueAsString(mMetricsRegistry); response.getWriter().println(result); } }; }