List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:org.nsesa.editor.gwt.an.amendments.server.service.PdfExportService.java
@Override public void export(AmendmentContainerDTO object, HttpServletResponse response) { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=" + object.getAmendmentContainerID() + ".pdf"); response.setCharacterEncoding("UTF8"); final String content = object.getBody(); final InputSource inputSource; byte[] bytes = content.getBytes(Charset.forName("UTF-8")); inputSource = new InputSource(new ByteArrayInputStream(bytes)); try {/* w w w. ja v a 2 s.c o m*/ final NodeModel model = NodeModel.parse(inputSource); final Configuration configuration = new Configuration(); configuration.setDefaultEncoding("UTF-8"); configuration.setDirectoryForTemplateLoading(template.getFile().getParentFile()); final StringWriter sw = new StringWriter(); Map<String, Object> root = new HashMap<String, Object>(); root.put("amendment", model); configuration.getTemplate(template.getFile().getName()).process(root, sw); ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(sw.toString(), editorUrl + "/"); renderer.layout(); renderer.createPDF(response.getOutputStream()); response.setContentLength(sw.toString().length()); response.flushBuffer(); } catch (IOException e) { throw new RuntimeException("Could not read file.", e); } catch (SAXException e) { throw new RuntimeException("Could not parse file.", e); } catch (ParserConfigurationException e) { throw new RuntimeException("Could not parse file.", e); } catch (TemplateException e) { throw new RuntimeException("Could not load template.", e); } catch (DocumentException e) { throw new RuntimeException("Export to pdf failed", e); } }
From source file:de.arago.rike.leaderboard.LeaderBoardImagesServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/png"); try {// w w w . ja v a 2 s .c o m SVGDataServlet.addExpires(response); int pos = request.getRequestURL().lastIndexOf("/"); String name = request.getRequestURL().substring(pos + 1); File tmp = new File(System.getProperty("java.io.tmpdir"), name); if (!tmp.exists()) { String uri = GlobalConfig.get(GlobalConfig.PATH_TO_PERSONAL_PICS); URL resource = (new URI(uri + name)).toURL(); FileUtils.copyURLToFile(resource, tmp); } FileUtils.copyFile(tmp, response.getOutputStream()); } catch (Exception ex) { IOUtils.copy(LeaderBoardImagesServlet.class.getResourceAsStream("/unknown.png"), response.getOutputStream()); } }
From source file:org.mitre.openid.connect.view.JsonEntityView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding("UTF-8"); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK; // default to 200 }//from ww w.j ava2s. co m response.setStatus(code.value()); try { Writer out = response.getWriter(); Object obj = model.get(ENTITY); gson.toJson(obj, out); } catch (IOException e) { logger.error("IOException in JsonEntityView.java: ", e); } }
From source file:org.mitre.openid.connect.view.ClientInformationResponseView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); RegisteredClient c = (RegisteredClient) model.get("client"); //OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) model.get("token"); //String uri = (String)model.get("uri"); //request.getRequestURL() + "/" + c.getClientId(); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK;// www. jav a2 s . c o m } response.setStatus(code.value()); JsonObject o = ClientDetailsEntityJsonProcessor.serialize(c); try { Writer out = response.getWriter(); gson.toJson(o, out); } catch (JsonIOException e) { logger.error("JsonIOException in ClientInformationResponseView.java: ", e); } catch (IOException e) { logger.error("IOException in ClientInformationResponseView.java: ", e); } }
From source file:com.antelink.sourcesquare.server.servlet.PublishServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/json;charset=utf-8"); Gson gson = new Gson(); try {/* w ww. java 2 s . co m*/ response.getWriter().append(gson.toJson(this.sourceSquareResult != null)); } catch (IOException e) { logger.error("error getting the server state", e); } }
From source file:net.sf.jasperreports.web.servlets.RequirejsConfigServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/javascript; charset=UTF-8"); setNoExpire(response);/* w w w .j a v a 2 s . c om*/ JasperReportsContext jrContext = getJasperReportsContext(); DefaultWebRequestContext webRequestContext = new DefaultWebRequestContext(); webRequestContext.setJasperReportsContext(jrContext); webRequestContext.setRequest(request); RequirejsConfigCreator configCreator = RequirejsConfigCreator.getInstance(webRequestContext); String requirejsConfig = configCreator.getRequirejsConfig(); PrintWriter out = response.getWriter(); out.write(requirejsConfig); }
From source file:org.ng200.openolympus.controller.auth.OpenOlympusAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.setContentType("application/json"); AuthenticationResponder.writeLoginStatusJson(response.getWriter(), "succeded", null); }
From source file:com.gae.LoginServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String thisURL = req.getRequestURI(); resp.setContentType("text/html"); UserService userService = UserServiceFactory.getUserService(); PrintWriter pw = resp.getWriter(); if (req.getUserPrincipal() == null) { pw.println("<a href=\"" + userService.createLoginURL(thisURL) + "\">Login</a>"); } else {// w w w . j a v a2s.com User user = userService.getCurrentUser(); pw.println("<a href=\"" + userService.createLogoutURL(thisURL) + "\">Logout</a><br/>"); pw.println("name = " + req.getUserPrincipal().getName() + "<br/>"); pw.println("isAdmin = " + userService.isUserAdmin() + "<br/>"); pw.println("domain = " + user.getAuthDomain() + "<br/>"); pw.println("email = " + user.getEmail() + "<br/>"); pw.println("nickname = " + user.getNickname() + "<br/>"); } }
From source file:com.graphhopper.http.InvalidRequestServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setStatus(HttpServletResponse.SC_NOT_FOUND); res.setContentType("text/plain"); res.setContentType("UTF-8"); JSONObject json = new JSONObject(); json.put("error_code", "404"); writeJson(req, res, json);/*from w ww .j a va 2 s .c o m*/ }
From source file:elw.miniweb.ViewJackson.java
public void render(Map model, HttpServletRequest request, HttpServletResponse resp) throws Exception { resp.setContentType(getContentType() + "; charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); resp.setHeader("Pragma", "no-cache"); resp.setHeader("Cache-Control", "no-cache"); resp.setDateHeader("Expires", System.currentTimeMillis()); MAPPER.writeValue(resp.getWriter(), stateOrData); }