List of usage examples for javax.servlet.http HttpServletResponse reset
public void reset();
From source file:fll.web.api.JudgesServlet.java
@Override protected final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final ServletContext application = getServletContext(); final DataSource datasource = ApplicationAttributes.getDataSource(application); Connection connection = null; try {//from w w w . j a va 2 s.co m connection = datasource.getConnection(); final ObjectMapper jsonMapper = new ObjectMapper(); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); final int currentTournament = Queries.getCurrentTournament(connection); final Collection<JudgeInformation> judges = JudgeInformation.getJudges(connection, currentTournament); jsonMapper.writeValue(writer, judges); } catch (final SQLException e) { throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:org.sakaiproject.kernel.webapp.filter.SakaiAuthenticationFilter.java
/** * {@inheritDoc}/* www . j a va 2s. com*/ * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hrequest = (HttpServletRequest) request; HttpServletResponse hresponse = (HttpServletResponse) response; if (hrequest.getHeader("Authorization") != null) { try { doBasicAuth(hrequest); } catch (SecurityException se) { // catch any Security exceptions and send a 401 LOG.info("Login Failed: " + se.getMessage()); hresponse.reset(); hresponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, se.getMessage()); return; } } else { if ("1".equals(hrequest.getParameter("l"))) { try { AuthenticationType authNType = AuthenticationType.valueOf(request.getParameter("a")); if (debug) { LOG.debug("Authentication Filter: " + authNType); } switch (authNType) { case BASIC: doBasicAuth(hrequest); break; case FORM: doForm(hrequest); break; case TRUSTED: doTrusted(hrequest); break; } } catch (SecurityException se) { // catch any Security exceptions and send a 401 LOG.info("Login Failed " + se.getMessage()); hresponse.reset(); hresponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, se.getMessage()); return; } catch (IllegalArgumentException e) { LOG.info("Authentication type " + request.getParameter("a") + " is not supported by this filter"); } } } chain.doFilter(request, response); }
From source file:fll.web.api.TournamentTeamsServlet.java
@Override protected final void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final ServletContext application = getServletContext(); final DataSource datasource = ApplicationAttributes.getDataSource(application); Connection connection = null; try {/* ww w .j ava2s .c o m*/ connection = datasource.getConnection(); final Map<Integer, TournamentTeam> teamMap = Queries.getTournamentTeams(connection); final ObjectMapper jsonMapper = new ObjectMapper(); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); final String pathInfo = request.getPathInfo(); if (null != pathInfo && pathInfo.length() > 1) { final String teamNumberStr = pathInfo.substring(1); try { final int teamNumber = Integer.parseInt(teamNumberStr); LOGGER.info("Found team number: " + teamNumber); final TournamentTeam team = teamMap.get(teamNumber); if (null != team) { jsonMapper.writeValue(writer, team); return; } else { throw new RuntimeException("No team found with number " + teamNumber); } } catch (final NumberFormatException e) { throw new RuntimeException("Error parsing team number " + teamNumberStr, e); } } final Collection<TournamentTeam> teams = teamMap.values(); jsonMapper.writeValue(writer, teams); } catch (final SQLException e) { throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:org.ngrinder.perftest.controller.PerfTestControllerTest.java
@Test public void testDownloadReportData() { String testName = "test1"; PerfTest test = createPerfTest(testName, Status.FINISHED, new Date()); HttpServletResponse resp = new MockHttpServletResponse(); try {//from w w w. j av a2 s .c o m controller.downloadCSV(getTestUser(), test.getId(), resp); } catch (IllegalStateException e) { // the report file doesn't exist assertTrue(true); } resp.reset(); controller.downloadLog(getTestUser(), test.getId(), "log", resp); }
From source file:org.mrgeo.services.wms.WmsGenerator.java
private void writeError(final Exception e, final HttpServletResponse response) throws ParserConfigurationException, IOException, TransformerException { response.reset(); Document doc;//from w ww . jav a2 s . c o m final DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = dBF.newDocumentBuilder(); doc = builder.newDocument(); final Element ser = doc.createElement("ServiceExceptionReport"); doc.appendChild(ser); ser.setAttribute("version", WMS_VERSION); final Element se = XmlUtils.createElement(ser, "ServiceException"); String code = e.getLocalizedMessage(); if (code == null || code.isEmpty()) { code = e.getClass().getName(); } se.setAttribute("code", code); final ByteArrayOutputStream strm = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(strm)); se.setAttribute("locator", strm.toString()); final PrintWriter out = response.getWriter(); DocumentUtils.writeDocument(doc, version, out); }
From source file:org.apache.sling.httpauth.impl.AuthorizationHeaderAuthenticationHandler.java
/** * Sends back the form to log into the system. * /*from w w w . j a v a 2 s . c o m*/ * @param request The request object * @param response The response object to which to send the request * @return <code>true</code> is always returned by this handler * @throws IOException if an error occurrs sending back the form. */ public boolean requestAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { // if the response is already committed, we have a problem !! if (!response.isCommitted()) { // reset the response response.reset(); response.setStatus(HttpServletResponse.SC_OK); String form = getLoginForm(); if (form != null) { form = replaceVariables(form, "@@contextPath@@", request.getContextPath(), "/"); form = replaceVariables(form, "@@authType@@", request.getAuthType(), ""); form = replaceVariables(form, "@@user@@", request.getRemoteUser(), ""); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.getWriter().print(form); } else { // have no form, so just send 401/UNATHORIZED for simple login sendUnauthorized(response); } } else { log.error("requestAuthentication: Response is committed, cannot request authentication"); } return true; }
From source file:br.org.indt.ndg.servlets.ReceiveImage.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.debug("RECEIVE IMAGE: executing doPost method."); response.reset(); response.setContentType("image/jpg"); InputStream inputStream = request.getInputStream(); DataOutputStream dataOutputStream = new DataOutputStream(response.getOutputStream()); if (inputStream != null) { log.debug("RECEIVE IMAGE: creating file ImageFromClient.jpg..."); FileOutputStream fileOutputStream = new FileOutputStream("ImageFromClient.jpg"); byte buffer[] = new byte[1024 * 128]; int i = 0; while ((i = inputStream.read(buffer)) != -1) { fileOutputStream.write(buffer, 0, i); }//from ww w. ja v a 2 s.c o m fileOutputStream.close(); inputStream.close(); dataOutputStream.writeBytes(SUCCESS); dataOutputStream.close(); log.debug("RECEIVE IMAGE: SUCCESS"); } else { dataOutputStream.writeBytes(FAILURE); log.debug("RECEIVE IMAGE: FAILURE"); } }
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
@RequestMapping({ "/exportIncomeCommonReport" }) public String exportIncomeCommonReport(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset(); response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.incomeCommonReport(workbook, queryMap); workbook.write(os);//from www . ja va 2 s . com os.flush(); os.close(); return "train/exportIncomeCommonReport"; }
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
/** * /*ww w. j a v a 2 s .c o m*/ * @param modelMap * @param request * @param response * @param formMap * @return * @throws IOException */ @RequestMapping({ "/exportPayoutCommonReport" }) public String exportPayoutCommonReport(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset(); response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.payoutCommonReport(workbook, queryMap); workbook.write(os); os.flush(); os.close(); return "train/exportPayoutCommonReport"; }
From source file:xx.tream.chengxin.ms.action.TrainReportAction.java
@RequestMapping({ "/exportReportDetail" }) public String exportReportDetail(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, FormMap formMap) throws IOException { Map<String, Object> queryMap = formMap.getFormMap(); OutputStream os = response.getOutputStream(); response.reset(); response.setCharacterEncoding("UTF-8"); String title = "" + getDateFile() + ".xls"; response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(title, "UTF-8")); response.setContentType("application/vnd.ms-excel"); HSSFWorkbook workbook = new HSSFWorkbook(); this.reportService.financialStatementsDetail(workbook, queryMap); workbook.write(os);// w w w . j a v a2 s. co m os.flush(); os.close(); return "train/exportReportDetail"; }