List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:org.mitre.openid.connect.view.JWKSetView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); //BiMap<String, PublicKey> keyMap = (BiMap<String, PublicKey>) model.get("keys"); Map<String, JWK> keys = (Map<String, JWK>) model.get("keys"); JWKSet jwkSet = new JWKSet(new ArrayList<>(keys.values())); try {/*from w ww .j a v a 2s . c o m*/ Writer out = response.getWriter(); out.write(jwkSet.toString()); } catch (IOException e) { logger.error("IOException in JWKSetView.java: ", e); } }
From source file:pl.maciejwalkowiak.plist.spring.PlistView.java
@Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { response.setContentType(getContentType()); response.setCharacterEncoding(ENCODING); if (this.disableCaching) { response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache, no-store, max-age=0"); response.addDateHeader("Expires", 1L); }/*from w ww. ja va2s. c o m*/ }
From source file:Binder.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); HttpSession session = req.getSession(true); SessionObject o = new SessionObject(getServletContext()); session.setAttribute("Binder.object", o); out.println("<html>"); out.println("<head>"); out.println("<title>Session Binder</title>"); out.println("</head>"); out.println("<body>"); out.println("Object bound to session " + session.getId()); out.println("</body>"); out.println("</html>"); out.flush();/* w w w . j ava 2s .co m*/ }
From source file:org.mitre.openid.connect.view.ExceptionAsJSONView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest requesr, HttpServletResponse response) { response.setContentType("application/json"); response.setStatus(HttpStatus.BAD_REQUEST.value()); final JsonObject jsonObject = new JsonObject(); Object ex = model.get("exception"); jsonObject.addProperty("error", ex.getClass().getName()); jsonObject.addProperty("error_description", ((Exception) ex).getMessage()); try {/*from w ww . ja v a 2 s . c o m*/ response.getWriter().write(jsonObject.toString()); } catch (IOException e) { logger.error("IOException in ExceptionAsJSONView.java: ", e); } }
From source file:io.v.positioning.BluetoothProximityServlet.java
/** * Processes a GET request for the nearby bluetooth records * * @param req The servlet request that includes <b>"androidId"</b> parameter * @param resp The servlet response with the number of nearby devices *//*from w ww. j a va 2s . c o m*/ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Query.Filter propertyFilter = new Query.FilterPredicate("androidId", Query.FilterOperator.EQUAL, req.getParameter("androidId")); Query q = new Query("bluetooth").setFilter(propertyFilter); List<Entity> list = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()); // for now, send the count. resp.getWriter().println("Number of nearby devices: " + list.size()); }
From source file:org.nsesa.editor.gwt.an.amendments.server.service.XMLExportService.java
@Override public void export(AmendmentContainerDTO object, HttpServletResponse response) throws IOException { try {//from ww w . j a v a 2 s . co m response.setContentType("text/xml"); response.setHeader("Content-Disposition", "attachment;filename=" + object.getAmendmentContainerID() + ".xml"); response.setCharacterEncoding("UTF8"); byte[] bytes = object.getBody().getBytes("utf-8"); IOUtils.copy(new ByteArrayInputStream(bytes), response.getOutputStream()); response.setContentLength(bytes.length); response.flushBuffer(); } catch (IOException e) { throw new RuntimeException("Failed to xml export", e); } }
From source file:org.wte4j.examples.showcase.server.services.GwtOrderServiceServlet.java
private void sendDocument(File file, HttpServletResponse resp) throws IOException { resp.setContentType(DOCUMENT_CONTENT_TYPE); resp.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName()); Files.copy(file, resp.getOutputStream()); }
From source file:com.lcw.one.modules.sys.web.MenuController.java
@RequiresUser @ResponseBody// www.ja va 2 s .c o m @RequestMapping(value = "treeData") public List<Map<String, Object>> treeData(@RequestParam(required = false) Long extId, HttpServletResponse response) { response.setContentType("application/json; charset=UTF-8"); List<Map<String, Object>> mapList = Lists.newArrayList(); List<Menu> list = systemService.findAllMenu(); for (int i = 0; i < list.size(); i++) { Menu e = list.get(i); if (extId == null || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1)) { Map<String, Object> map = Maps.newHashMap(); map.put("id", e.getId()); map.put("pId", e.getParent() != null ? e.getParent().getId() : 0); map.put("name", e.getName()); mapList.add(map); } } return mapList; }
From source file:io.v.positioning.GpsLocationServlet.java
/** * Processes a GET request and returns device's GPS location * * @param req The servlet request that includes <b>"androidId"</b> parameter * @param resp The servlet response with lat/long information *///ww w . jav a 2 s . c o m @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Query.Filter propertyFilter = new Query.FilterPredicate("androidId", Query.FilterOperator.EQUAL, req.getParameter("androidId")); Query q = new Query("gps").setFilter(propertyFilter); Entity e = datastore.prepare(q).asSingleEntity(); if (e == null) { resp.getWriter().println("Missing location for the given androidId."); } else { resp.getWriter().println("(" + e.getProperty("latitude") + ", " + e.getProperty("longitude") + ")"); } }
From source file:MainClass.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException { res.setContentType("text/html"); java.io.PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<HEAD><TITLE>User Example</TITLE></HEAD>"); out.println("<BODY>"); String username = req.getRemoteUser(); if (username == null) { out.println("Hello. You are not logged in."); } else if ("Bob".equals(username)) { out.println("Hello, Bob. Nice to see you again."); } else {/*from ww w .j ava 2 s .co m*/ out.println("Hello, " + username + "."); } out.println("</BODY>"); out.println("</HTML>"); out.close(); }