List of usage examples for javax.servlet.http HttpServletResponse reset
public void reset();
From source file:org.talend.mdm.webapp.browserecords.server.servlet.DownloadData.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { XSSFWorkbook workbook = new XSSFWorkbook(); cs = workbook.createCellStyle();/* w ww . jav a 2 s . co m*/ XSSFFont f = workbook.createFont(); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cs.setFont(f); XSSFSheet sheet = workbook.createSheet(SHEET_LABEL); sheet.setDefaultColumnWidth((short) 20); XSSFRow row = sheet.createRow((short) 0); try { setParameter(request); response.reset(); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); //$NON-NLS-1$ response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fillHeader(row); fillSheet(sheet); } catch (Exception e) { LOG.error(e.getMessage(), e); } OutputStream out = response.getOutputStream(); workbook.write(out); out.close(); }
From source file:de.escidoc.core.aa.servlet.Login.java
/** * Handles the failure case of a deactivated user account<br> An error page is presented to the user. * * * @param response The http response./* w w w . ja v a 2 s .c o m*/ * @throws IOException Thrown in case of an I/O error. * @throws WebserverSystemException Thrown if cookie creation fails due to an internal error. */ private void sendDeactivatedUserAccount(final HttpServletResponse response) throws IOException, WebserverSystemException { response.reset(); response.setContentType("text/html"); // delete the session cookie of spring security to allow restarting the // login process response.addCookie(deleteSpringSecurityCookie()); sendResponse(response, getDeactivatedUserAccountErrorPage()); }
From source file:com.nabla.dc.server.ImageService.java
private boolean exportImage(final String imageId, final HttpServletResponse response) throws IOException, SQLException, InternalErrorException { final Connection conn = db.getConnection(); try {/*from ww w .j a v a2s . c o m*/ final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT * FROM image WHERE id=?;", imageId); try { final ResultSet rs = stmt.executeQuery(); try { if (!rs.next()) { if (log.isDebugEnabled()) log.debug("failed to find report ID= " + imageId); return false; } if (log.isTraceEnabled()) log.trace("exporting image " + imageId); response.reset(); response.setBufferSize(DEFAULT_BUFFER_SIZE); response.setContentType(rs.getString("content_type")); response.setHeader("Content-Length", String.valueOf(rs.getInt("length"))); response.setHeader("Content-Disposition", MessageFormat.format("inline; filename=\"{0}\"", rs.getString("name"))); // to prevent images to be downloaded every time user hovers one image final Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MONTH, 2); response.setDateHeader("Expires", cal.getTime().getTime()); final BufferedInputStream input = new BufferedInputStream(rs.getBinaryStream("content"), DEFAULT_BUFFER_SIZE); try { final BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE); try { final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int length; while ((length = input.read(buffer)) > 0) output.write(buffer, 0, length); } finally { output.close(); } } finally { input.close(); } } finally { rs.close(); } } finally { stmt.close(); } } finally { conn.close(); } return true; }
From source file:de.escidoc.core.aa.servlet.Login.java
/** * Sends the response in case of successful logout of the user.<br> <ul> <li>The cookie containing the eSciDoc user * handle is deleted.</li> <li>Either <ul> <li>the user is redirected to the provided targetUrl, or</li> <li>a * default logout page is presented to the user, if no targetUrl has been provided</li> </ul> </li> </ul> * * @param request The http request./*ww w . j a v a2 s.co m*/ * @param response The http response. * @throws IOException In case of an error. * @throws WebserverSystemException Thrown if cookie creation fails due to an internal error. */ private void sendLoggedOut(final HttpServletRequest request, final HttpServletResponse response) throws IOException, WebserverSystemException { response.reset(); response.setContentType("text/html"); // delete cookies response.addCookie(deleteAuthCookie()); response.addCookie(deleteSpringSecurityCookie()); String redirectUrl; try { redirectUrl = retrieveDecodedTarget(request); } catch (final MissingParameterException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Error on retriving decoded target.", e); } redirectUrl = null; } if (redirectUrl == null) { sendResponse(response, getLoggedOutPage(null)); } else { sendRedirectingResponse(response, getLoggedOutPage(redirectUrl), redirectUrl); } }
From source file:at.gv.egovernment.moa.id.protocols.stork2.MandateRetrievalRequest.java
public SLOInformationInterface processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, IAuthData authData) throws MOAIDException { Logger.debug("Entering AttributeRequest for MandateProvider"); httpResp.reset(); this.representingIdentityLink = authData.getIdentityLink(); this.QAALevel = translateQAALevel(authData.getQAALevel()); // preparing original content and removing sensitive data from it this.originalContent = authData.getMISMandate().getMandate(); // TODO ERROR //Logger.debug("Original content " + StringUtils.newStringUtf8(authData.getMISMandate().getMandate())); String originalMandate = StringUtils.newStringUtf8(authData.getMISMandate().getMandate()).replaceAll( "<pd:Value>.*?==</pd:Value><pd:Type>urn:publicid:gv.at:baseid</pd:Type>", "<pd:Value></pd:Value><pd:Type></pd:Type>"); ;/*from w ww .ja v a 2 s . c om*/ Logger.debug("Removing personal identification value and type from original mandate "); originalContent = StringUtils.getBytesUtf8(originalMandate); OAAuthParameter oaParam = AuthConfigurationProvider.getInstance() .getOnlineApplicationParameter(req.getOAURL()); if (oaParam == null) throw new AuthenticationException("stork.12", new Object[] { req.getOAURL() }); MOASTORKResponse moaStorkResponse = new MOASTORKResponse(); STORKAttrQueryResponse attrResponse = new STORKAttrQueryResponse(); this.authData = authData; if ((req instanceof MOASTORKRequest)) { this.moaStorkRequest = (MOASTORKRequest) req; } else { Logger.error("Internal error - did not receive MOASTORKRequest as expected"); throw new MOAIDException("stork.16", new Object[] {}); // TODO } if (!(moaStorkRequest.isAttrRequest() || moaStorkRequest.getStorkAttrQueryRequest() == null)) { Logger.error("Did not receive attribute request as expected"); throw new MOAIDException("stork.16", new Object[] {}); // TODO } MandateContainer mandateContainer = null; try { mandateContainer = new CorporateBodyMandateContainer( new String(authData.getMISMandate().getMandate(), "UTF-8")); } catch (Exception ex) { try { mandateContainer = new PhyPersonMandateContainer( new String(authData.getMISMandate().getMandate(), "UTF-8")); } catch (Exception ex2) { Logger.error("Could not extract data and create mandate container."); throw new MOAIDException("stork.16", new Object[] {}); // TODO } } IPersonalAttributeList sourceAttributeList = moaStorkRequest.getStorkAttrQueryRequest() .getPersonalAttributeList(); IPersonalAttributeList attributeList = new PersonalAttributeList(); for (PersonalAttribute currentAttribute : sourceAttributeList) { Logger.debug("Evaluating currentattribute " + currentAttribute.getName()); if (currentAttribute.getName().equals("mandateContent")) { MandateContentType mandateContent = getMandateContent(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, mandateContent)); } else if (currentAttribute.getName().equals("representative")) { // TODO CHECK IN DETAIL RepresentationPersonType representative = getRepresentative(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, representative)); //attributeList.add(getRepresentative(mandateContainer, currentAttribute)); } else if (currentAttribute.getName().equals("represented")) { //attributeList.add(getRepresented(mandateContainer, currentAttribute)); RepresentationPersonType represented = getRepresented(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, represented)); } else if (currentAttribute.getName().equals("mandate")) { //attributeList.add(getMandateType(mandateContainer, currentAttribute)); MandateType mandateType = getMandateType(mandateContainer, currentAttribute); attributeList.add(marshallComplexAttribute(currentAttribute, mandateType)); } else if (currentAttribute.getName().equals("legalName")) { String legalName = getLegalName(mandateContainer, currentAttribute); if (legalName.length() > 0) { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(legalName), AttributeStatusType.AVAILABLE.value())); } else { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(legalName), AttributeStatusType.NOT_AVAILABLE.value())); } } else if (currentAttribute.getName().equals("eLPIdentifier")) { String eLPIdentifier = geteLPIdentifier(mandateContainer, currentAttribute); if (eLPIdentifier.length() > 0) { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(eLPIdentifier), AttributeStatusType.AVAILABLE.value())); } else { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(eLPIdentifier), AttributeStatusType.NOT_AVAILABLE.value())); } } else if (currentAttribute.getName().equals("type")) { String type = getCompanyType(mandateContainer, currentAttribute); if (type.length() > 0) { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), AttributeStatusType.AVAILABLE.value())); } else { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(type), AttributeStatusType.NOT_AVAILABLE.value())); } } else if (currentAttribute.getName().equals("status")) { String status = getCompanyStatus(mandateContainer, currentAttribute); if (status.length() > 0) { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(status), AttributeStatusType.AVAILABLE.value())); } else { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(status), AttributeStatusType.NOT_AVAILABLE.value())); } } else if (currentAttribute.getName().equals("translatableType")) { String translatableType = getCompanyTranslatableType(mandateContainer, currentAttribute); if (translatableType.length() > 0) { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(translatableType), AttributeStatusType.AVAILABLE.value())); } else { attributeList .add(new PersonalAttribute(currentAttribute.getName(), currentAttribute.isRequired(), Arrays.asList(translatableType), AttributeStatusType.NOT_AVAILABLE.value())); } } } // if (attrResponse.getPersonalAttributeList().size() == 0) { // Logger.error("AttributeList empty - could not retrieve attributes"); // throw new MOAIDException("stork.16", new Object[]{}); // TODO MESSAGE // } attrResponse.setPersonalAttributeList(attributeList); moaStorkResponse.setSTORKAttrResponse(attrResponse); Logger.debug("Attributes retrieved: " + moaStorkResponse.getStorkAttrQueryResponse().getPersonalAttributeList().size() + " for SP country " + attrResponse.getCountry()); // Prepare extended attributes Logger.debug("Preparing data container"); // create fresh container DataContainer container = new DataContainer(); // - fill in the request we extracted above container.setRequest(moaStorkRequest); // - fill in the partial response created above container.setResponse(moaStorkResponse); container.setRemoteAddress(httpReq.getRemoteAddr()); Logger.debug("Data container prepared"); // ask for consent if necessary if (oaParam.isRequireConsentForStorkAttributes()) new ConsentEvaluator().requestConsent(container, httpResp, oaParam); else new ConsentEvaluator().generateSTORKResponse(httpResp, container); return null; }
From source file:org.apache.click.MockContainer.java
/** * Reset container internal state./*from w ww.jav a2 s . co m*/ * * @see #start() */ void reset() { Context.getContextStack().clear(); HttpServletResponse response = getResponse(); if (response != null) { response.reset(); } ActionEventDispatcher.getDispatcherStack().clear(); ControlRegistry.getRegistryStack().clear(); }
From source file:com.scooter1556.sms.server.service.AdaptiveStreamingService.java
public void sendSubtitleSegment(HttpServletResponse response) throws IOException { List<String> segment = new ArrayList<>(); segment.add("WEBVTT"); // Write segment to buffer so we can get the content length StringWriter segmentWriter = new StringWriter(); for (String line : segment) { segmentWriter.write(line + "\n"); }// www .ja v a 2 s . c om // Set Header Parameters response.reset(); response.setContentType("text/vtt"); response.setContentLength(segmentWriter.toString().length()); // Enable CORS response.setHeader(("Access-Control-Allow-Origin"), "*"); response.setHeader("Access-Control-Allow-Methods", "GET"); response.setIntHeader("Access-Control-Max-Age", 3600); // Write segment out to the client response.getWriter().write(segmentWriter.toString()); }
From source file:de.escidoc.core.aa.servlet.Login.java
/** * Sends the response in case of successfully authenticating the user.<br> The provided handle that identifies the * user in the system is sent back in the {@code Authorization} header (to be used by the redirecting * application) and via a cookie to enable handling of later calls to the servlet of the same user and to enable * direct accesses of the user to the framework by using a web browser. * * @param request The http request.// w ww.j a v a 2s. co m * @param response The http response. * @param handle The handle identifying the user. * @throws IOException Thrown in case of an error. * @throws WebserverSystemException Thrown in case of an internal error. */ private void sendAuthenticated(final HttpServletRequest request, final HttpServletResponse response, final String handle) throws IOException, WebserverSystemException { response.reset(); // add escidoc cookie response.addCookie(UserHandleCookieUtil.createAuthCookie(handle)); // FIXME: should method return null instead of exception? String redirectUrlWithHandle; try { redirectUrlWithHandle = createRedirectUrl(request, handle); } catch (final MissingParameterException e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Error on creating redirect URL."); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Error on creating redirect URL.", e); } redirectUrlWithHandle = null; } if (redirectUrlWithHandle == null) { sendResponse(response, getAuthenticatedPage(null)); } else { sendRedirectingResponse(response, getAuthenticatedPage(redirectUrlWithHandle), redirectUrlWithHandle); } }
From source file:helma.servlet.AbstractServletClient.java
void sendError(HttpServletResponse response, int code, String message) throws IOException { if (response.isCommitted()) { return;// w ww . j a v a 2s .c o m } response.reset(); response.setStatus(code); response.setContentType("text/html"); if (!"true".equalsIgnoreCase(getApplication().getProperty("suppressErrorPage"))) { Writer writer = response.getWriter(); writer.write("<html><body><h3>"); writer.write("Error in application "); try { writer.write(getApplication().getName()); } catch (Exception besafe) { // ignore } writer.write("</h3>"); writer.write(message); writer.write("</body></html>"); writer.flush(); } }
From source file:edu.jhu.cvrg.ceptools.main.SearchPubs.java
public void downloadFile(String filename, String filetype) { String contentType = "application/zip"; if (filetype.equals("abf")) { contentType = "text/abf"; }/*from w ww . j a v a2 s . co m*/ FacesContext facesContext = (FacesContext) FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); PortletResponse portletResponse = (PortletResponse) externalContext.getResponse(); HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse); File file = new File(selecteddownloadfile.getFilelocation(), filename); BufferedInputStream input = null; BufferedOutputStream output = null; try { input = new BufferedInputStream(new FileInputStream(file), 10240); response.reset(); response.setHeader("Content-Type", contentType); response.setHeader("Content-Length", String.valueOf(file.length())); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.flushBuffer(); output = new BufferedOutputStream(response.getOutputStream(), 10240); byte[] buffer = new byte[10240]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } output.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { output.close(); input.close(); } catch (IOException e) { e.printStackTrace(); } } facesContext.responseComplete(); }