List of usage examples for javax.servlet ServletOutputStream print
public void print(double d) throws IOException
double
value to the client, with no carriage return-line feed (CRLF) at the end. From source file:com.wisemapping.rest.view.ImportTransformationView.java
@Override protected void renderMergedOutputModel(@NotNull Map<String, Object> viewMap, @NotNull HttpServletRequest request, @NotNull final HttpServletResponse response) throws Exception { final String content = (String) viewMap.get("content"); final String filename = (String) viewMap.get("filename"); // Convert to map ... final InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8")); final Mindmap mindMap = importer.importMap("filename", "filename", is); // Set file name...:http://stackoverflow.com/questions/5325322/java-servlet-download-filename-special-characters/13359949#13359949 final String fileName = (filename != null ? filename : "map") + "." + "xwise"; setContentDisposition(request, response, fileName); // Write the conversion content ... final ServletOutputStream outputStream = response.getOutputStream(); outputStream.print(mindMap.getXmlStr()); }
From source file:io.logspace.hq.rest.event.EventStreamResource.java
private Object postEventStream(Request req, Response res) throws IOException { EventFilter eventFilter = this.readFilter(req.body()); int offset = getQueryParam(req, PARAMETER_OFFSET, DEFAULT_STREAM_OFFSET, MIN_OFFSET, MAX_OFFSET); int count = getQueryParam(req, PARAMETER_COUNT, DEFAULT_COUNT, MIN_COUNT, MAX_STREAM_COUNT); res.raw().setContentType("application/json;charset=UTF-8"); ServletOutputStream outputStream = res.raw().getOutputStream(); outputStream.print('['); this.eventStreamService.stream(eventFilter, count, offset, new JsonEventStreamer(outputStream)); outputStream.print(']'); outputStream.close();//from w w w . j av a 2 s . c o m return ""; }
From source file:io.logspace.hq.rest.EventStreamResource.java
private Object postEventStream(Request req, Response res) throws IOException { EventFilter eventFilter = this.readFilter(req.body()); int offset = getQueryParam(req, PARAMETER_OFFSET, DEFAULT_STREAM_OFFSET, MIN_OFFSET, MAX_OFFSET); int count = getQueryParam(req, PARAMETER_COUNT, DEFAULT_COUNT, MIN_COUNT, MAX_STREAM_COUNT); res.raw().setContentType("application/json;charset=UTF-8"); ServletOutputStream outputStream = res.raw().getOutputStream(); outputStream.print('['); this.eventService.stream(eventFilter, count, offset, new JsonEventStreamer(outputStream)); outputStream.print(']'); outputStream.close();/*from w ww. j av a 2 s . c o m*/ return ""; }
From source file:com.jsquant.servlet.YahooFinanceProxy.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* http://ichart.finance.yahoo.com/table.csv?a=00&c=2005&b=01&e=03&d=05&g=d&f=2008&ignore=.csv&s=GOOG Date,Open,High,Low,Close,Volume,Adj Close 2008-06-03,576.50,580.50,560.61,567.30,4305300,567.30 2008-06-02,582.50,583.89,571.27,575.00,3674200,575.00 *//*from www . j a v a 2 s .co m*/ int fromMM = Integer.valueOf(request.getParameter("a")); // 00 == January int fromDD = Integer.valueOf(request.getParameter("b")); int fromYYYY = Integer.valueOf(request.getParameter("c")); int toMM = Integer.valueOf(request.getParameter("d")); int toDD = Integer.valueOf(request.getParameter("e")); int toYYYY = Integer.valueOf(request.getParameter("f")); String resolution = request.getParameter("g").substring(0, 1); // == "d"ay "w"eek "m"onth "y"ear ValidationUtils.validateResolution(resolution); String symbol = request.getParameter("s"); ValidationUtils.validateSymbol(symbol); String queryString = String.format("a=%02d&b=%02d&c=%d&d=%02d&e=%02d&f=%d&g=%s&s=%s&ignore=.csv", fromMM, fromDD, fromYYYY, toMM, toDD, toYYYY, URLEncoder.encode(resolution, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), URLEncoder.encode(symbol, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING)); String cacheKey = String.format("%02d%02d%d-%02d%02d%d-%s-%s-%tF.csv.gz", fromMM, fromDD, fromYYYY, toMM, toDD, toYYYY, URLEncoder.encode(resolution, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), URLEncoder.encode(symbol, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), new Date()); // include server date to limit to 1 day, for case where future dates might return less data, but fill cache FileCache fileCache = JsquantContextListener.getFileCache(request); String responseBody = fileCache.get(cacheKey); if (responseBody == null) { HttpGet httpget = new HttpGet("http://ichart.finance.yahoo.com/table.csv?" + queryString); ResponseHandler<String> responseHandler = new BasicResponseHandler(); log.debug("requesting uri=" + httpget.getURI()); responseBody = JsquantContextListener.getHttpClient(request).execute(httpget, responseHandler); //httpget.setReleaseTrigger(releaseTrigger); // no need to close? fileCache.put(cacheKey, responseBody); } ServletOutputStream out = response.getOutputStream(); out.print(responseBody); }
From source file:fedora.server.security.servletfilters.FilterRestApiFlash.java
/** * Perform flash client response filtering *//*from www.j a v a2s . com*/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (log.isDebugEnabled()) { log.debug("Entering FilterRestApiFlash.doThisSubclass()"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String queryString = httpRequest.getQueryString(); if (queryString != null && queryString.contains("flash=true")) { StatusHttpServletResponseWrapper sHttpResponse = new StatusHttpServletResponseWrapper(httpResponse); filterChain.doFilter(request, sHttpResponse); if (sHttpResponse.status != sHttpResponse.realStatus) { // Append the error indicator with real status try { ServletOutputStream out = sHttpResponse.getOutputStream(); out.print("::ERROR(" + sHttpResponse.realStatus + ")"); } catch (IllegalStateException ise) { PrintWriter out = sHttpResponse.getWriter(); out.print("::ERROR(" + sHttpResponse.realStatus + ")"); } } } else { filterChain.doFilter(request, response); } }
From source file:org.apache.jena.fuseki.mgt.ActionDataset.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { // request.getRemoteUser() ; // request.getUserPrincipal() ; String dataset = FusekiLib.safeParameter(request, "dataset"); HttpSession session = request.getSession(true); session.setAttribute("dataset", dataset); session.setMaxInactiveInterval(15 * 60); // 10 mins boolean known = DatasetRegistry.get().isRegistered(dataset); if (!known) { response.sendError(HttpSC.BAD_REQUEST_400, "No such dataset: " + dataset); return;/*from www . j a v a 2 s. co m*/ } if (true) { // Redirect to GET page. response.setHeader(HttpNames.hLocation, PageNames.pageAfterLogin); response.setStatus(HttpSC.SEE_OTHER_303); } else { // Welcome style - but HTML inline :-( response.setContentType("text/html"); response.setStatus(HttpSC.OK_200); ServletOutputStream out = response.getOutputStream(); out.print("<p>" + dataset + "(" + known + ")</p>"); for (String name : DatasetRegistry.get().keys()) { out.print("<li>"); out.print(name); out.println("</li>"); } out.println("</ul>"); out.println("<p><a href=\"info\">Next</a></p>"); } // Cookie cookie = new Cookie("org.apache.jena.fuseki.session", dataset) ; // // 24 hours. // cookie.setMaxAge(24*60*60) ; }
From source file:org.loklak.api.admin.CrawlerServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Query post = RemoteAccess.evaluate(request); boolean localhost = post.isLocalhostAccess(); String callback = post.get("callback", ""); boolean jsonp = callback != null && callback.length() > 0; String[] incubation = post.get("start", new String[0], ","); int depth = Math.min(localhost ? 8 : 1, post.get("depth", 0)); boolean hashtags = post.get("hashtags", true); boolean users = post.get("users", true); for (String query : incubation) Crawler.stack(query, depth, hashtags, users, true); post.setResponse(response, "application/javascript"); // generate json JSONObject json = new JSONObject(true); if (incubation == null || incubation.length == 0) json.put("_hint", "start a crawl: start=<terms, comma-separated>, depth=<crawl depth> (dflt: 0), hashtags=<true|false> (dflt: true), users=<true|false> (dflt: true)"); if (!localhost) json.put("_hint", "you are connecting from a non-localhost client " + post.getClientHost() + " , depth is limited to 1"); JSONObject index_sizes = new JSONObject(true); json.put("index_sizes", index_sizes); index_sizes.put("messages", DAO.countLocalMessages(-1)); index_sizes.put("users", DAO.countLocalUsers()); json.put("crawler_status", Crawler.toJSON()); // write json ServletOutputStream sos = response.getOutputStream(); if (jsonp)/*w ww. ja v a 2 s . co m*/ sos.print(callback + "("); sos.print(json.toString(2)); if (jsonp) sos.println(");"); sos.println(); post.finalize(); }
From source file:org.itracker.web.actions.admin.language.ExportLanguageAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ActionMessages errors = new ActionMessages(); if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) { return mapping.findForward("unauthorized"); }// w w w . ja v a2s . com try { ConfigurationService configurationService = ServletContextUtils.getItrackerServices() .getConfigurationService(); String locale = (String) PropertyUtils.getSimpleProperty(form, "locale"); if (locale != null && !locale.equals("")) { StringBuffer output = new StringBuffer( "# ITracker language properties file for locale " + locale + "\n\n"); List<NameValuePair> items = configurationService.getDefinedKeysAsArray(locale); for (int i = 0; i < items.size(); i++) { if (items.get(i).getName() != null && items.get(i).getValue() != null) { output.append( ITrackerResources.escapeUnicodeString(items.get(i).getName(), false) + "=" + ITrackerResources.escapeUnicodeString( HTMLUtilities.escapeNewlines(items.get(i).getValue()), false) + "\n"); } } response.setHeader("Content-Disposition", "attachment; filename=\"ITracker" + (locale.equals(ITrackerResources.BASE_LOCALE) ? "" : "_" + locale) + ".properties\""); response.setHeader("Content-Type", "application/x-itracker-language-export; charset=UTF-8"); ServletOutputStream out = response.getOutputStream(); out.print(output.toString()); out.flush(); return null; } errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidlocale")); } catch (RuntimeException e) { log.error("Exception while exporting language.", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system")); } catch (IllegalAccessException e) { log.error("Exception while exporting language.", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system")); } catch (InvocationTargetException e) { log.error("Exception while exporting language.", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system")); } catch (NoSuchMethodException e) { log.error("Exception while exporting language.", e); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system")); } if (!errors.isEmpty()) { saveErrors(request, errors); } return mapping.findForward("error"); }
From source file:fi.jyu.student.jatahama.onlineinquirytool.server.LoadSaveServlet.java
@Override public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { try {// w w w. j a v a 2 s. c o m // Always server same page. Used to check if Servlet exists. response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); response.setHeader("Cache-Control", "no-cache"); response.setHeader(Utils.httpHeaderNameHello, "Hello!"); // response.setStatus(307); // response.setHeader("Location", "../"); ServletOutputStream out = response.getOutputStream(); out.print("<html><head><META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=../\"><!-- " + Utils.httpHeaderNameHello + ": Hello! --></head><body><a href=\"../\">App</a></body></html>"); out.flush(); } catch (Exception ex) { throw new ServletException(ex); } }
From source file:ar.com.zauber.commons.web.filter.JSONPRequestFilter.java
/** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) *//*from w ww.j ava 2s . c o m*/ public final void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException("This filter can " + " only process HttpServletRequest requests"); } final HttpServletRequest httpRequest = (HttpServletRequest) request; final String callback = httpRequest.getParameter(callbackParameterName); if (StringUtils.isNotBlank(callback) && acceptsJSONP(httpRequest)) { ServletOutputStream out = response.getOutputStream(); out.print(callback + "("); chain.doFilter(request, response); out.print(");"); response.setContentType(responseContentType); } else { chain.doFilter(request, response); } }