List of usage examples for javax.servlet.http HttpServletResponse setCharacterEncoding
public void setCharacterEncoding(String charset);
From source file:dk.itst.oiosaml.sp.service.LogoutServiceSOAPHandler.java
/** * Return the <LogoutResponse> to the caller * /* www .j av a 2 s . c om*/ * @param response * The {@link HttpServletResponse} * @param logoutResponse * The <LogoutResponse> to return to the caller */ private void returnResponse(HttpServletResponse response, OIOLogoutResponse logoutResponse, Credential credential) { logoutResponse.sign(credential); // Build output... String envelope = logoutResponse.toSoapEnvelope(); if (log.isDebugEnabled()) log.debug("Response..: " + envelope); byte[] b; try { b = envelope.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new WrappedException(Layer.CLIENT, e); } response.setContentLength(b.length); response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.setStatus(HttpServletResponse.SC_OK); try { response.getOutputStream().write(b); } catch (IOException e) { throw new WrappedException(Layer.CLIENT, e); } }
From source file:com.konakart.actions.ipn.AuthorizeNetCallbackAction.java
/** * The response is an HTML page which immediately redirects to the desired page. * /*from ww w. j av a 2 s . c o m*/ * @param kkAppEng * @param ok * @param request * @param response * @throws Exception */ private void createResponse(KKAppEng kkAppEng, boolean ok, HttpServletRequest request, HttpServletResponse response) throws Exception { String url = kkAppEng.getConfig(ConfigConstants.KK_BASE_URL); if (url == null || url.length() == 0) { throw new KKException("The KK_BASE_URL has not been defined"); } if (ok) { url += "CheckoutFinished.action"; } else { url += "AuthorizenetDPM.action?e=t"; } response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); // Create page to return StringBuffer sb = new StringBuffer(); sb.append( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"); sb.append("<html><head></head><body><script type=\"text/javascript\">"); sb.append("document.location = \""); sb.append(url); sb.append("\";"); sb.append("</script></body></html>"); response.getWriter().append(sb); }
From source file:com.icb123.Controller.BusinessController.java
@RequestMapping(value = "/appoint") public void customerAppointment(HttpServletRequest request, HttpServletResponse response) { try {//from www . j ava 2s .c om request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); Constants.root = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String sysRootPath = request.getSession().getServletContext().getRealPath("\\"); SystemStaticArgsSet.setSysRootPath(sysRootPath); String requestType = request.getParameter("requestType") == null ? "" : request.getParameter("requestType"); String userCode = request.getParameter("userCode") == null ? "" : request.getParameter("userCode"); String openid = request.getParameter("openid") == null ? "" : request.getParameter("openid"); //openid="111111"; if (StringUtils.isBlank(openid) && StringUtils.isNotBlank(userCode)) { openid = WeixinUntil.getUserOoenid(userCode); } if (weixinCustomerManager.findByOpenid(openid) == null) { String accessToken = WeixinUntil.getAccessToken(); WeixinCustomer wx = customerBusinessManager.getCustomerInfo(openid, accessToken, ""); weixinCustomerManager.save(wx); } //System.out.println(PropertiesUtils.getValueByKey("token")); Employee emp = (Employee) request.getSession().getAttribute("Employee"); String empCode = ""; if (emp != null) { empCode = emp.getCode(); } else { if (!"".equals(openid)) { empCode = employeeManager.findEmployeeCodeByOpenid(openid); } } if ("1".equals(requestType)) {// String paramObj = request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); JSONArray arr = (JSONArray) json.get("service"); String[] serviceArray = new String[arr.size()]; serviceArray = (String[]) arr.toArray(serviceArray); Map<String, String> result = null; if (StringUtils.isNotBlank((String) json.get("userCode"))) { openid = WeixinUntil.getUserOoenid((String) json.get("userCode")); } else { openid = null; } try { result = businessManager.appointmentMaintenance((String) json.get("date"), (String) json.get("timeCode"), (String) json.get("mobile"), (String) json.get("name"), openid, (String) json.get("carCode"), (String) json.get("license"), (String) json.get("code"), (String) json.get("totalPrice"), (String) json.get("address"), (String) json.get("remark"), (String) json.get("appTypeCode"), (String) json.get("type"), serviceArray); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } OutputUtil.outPutJsonObject(response, result); } else if ("2".equals(requestType)) {// String status = request.getParameter("status") == null ? "" : request.getParameter("status"); String currentPageStr = request.getParameter("currentPage") == null ? "" : request.getParameter("currentPage"); String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize"); String ctime = request.getParameter("ctime") == null ? "" : request.getParameter("ctime"); String mobile = request.getParameter("smobile") == null ? "" : request.getParameter("smobile"); String atime = request.getParameter("atime") == null ? "" : request.getParameter("atime"); try { Map<String, String> argMap = new HashMap<String, String>(); argMap.put("status", status); if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) { int currentPage = Integer.valueOf(currentPageStr); int size = Integer.valueOf(sizeStr); int begin = (currentPage - 1) * size; argMap.put("size", size + ""); argMap.put("begin", begin + ""); argMap.put("currentPage", currentPageStr); argMap.put("ctime", ctime); argMap.put("atime", atime); argMap.put("mobile", mobile); } PageBean page = businessManager.selectAppointment(argMap); OutputUtil.outPutJsonObject(response, page); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "?", e); } } else if ("3".equals(requestType)) {// String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); Map map = businessManager.findDetailedAppointment(appcode); OutputUtil.outPutJsonObject(response, map); } else if ("4".equals(requestType)) {// String paramObj = request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); JSONArray arr = (JSONArray) json.get("service"); String[] serviceArray = new String[arr.size()]; serviceArray = (String[]) arr.toArray(serviceArray); Map<String, String> result = null; try { result = businessManager.appointmentConfirm((String) json.get("timeCode"), (String) json.get("date"), (String) json.get("time"), (String) json.get("carCode"), (String) json.get("license"), (String) json.get("haveCar"), (String) json.get("modelsCode"), (String) json.get("modelsStr"), (String) json.get("cusCode"), (String) json.get("mobile"), (String) json.get("name"), (String) json.get("address"), (String) json.get("code"), (String) json.get("remark"), (String) json.get("totalPrice"), serviceArray, emp.getCode(), (String) json.get("status"), (String) json.get("wxCode")); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } OutputUtil.outPutJsonObject(response, result); } else if ("5".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String reason = request.getParameter("reason") == null ? "" : request.getParameter("reason"); Map<String, String> result = businessManager.appointmentCancel(appcode, empCode, reason); OutputUtil.outPutJsonObject(response, result); } else if ("6".equals(requestType)) {//? String date = request.getParameter("date") == null ? "" : request.getParameter("date"); String time = request.getParameter("time") == null ? "" : request.getParameter("time"); List<Team> list = businessManager.findFreeTeam(date, time); OutputUtil.outPutJsonArrary(response, list); } else if ("7".equals(requestType)) {// String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); String teamCode = request.getParameter("teamCode") == null ? "" : request.getParameter("teamCode"); String[] empArr = request.getParameterValues("emp"); Map<String, String> result = businessManager.distributeWork(appCode, empCode, teamCode, empArr); OutputUtil.outPutJsonObject(response, result); } else if ("8".equals(requestType)) {// String currentPageStr = request.getParameter("currentPage") == null ? "" : request.getParameter("currentPage"); String sizeStr = request.getParameter("pageSize") == null ? "" : request.getParameter("pageSize"); try { Map<String, String> argMap = new HashMap<String, String>(); argMap.put("empCode", empCode); if (StringUtils.isNotBlank(currentPageStr) && StringUtils.isNotBlank(sizeStr)) { int currentPage = Integer.valueOf(currentPageStr); int size = Integer.valueOf(sizeStr); int begin = (currentPage - 1) * size; argMap.put("size", size + ""); argMap.put("begin", begin + ""); argMap.put("currentPage", currentPageStr); } PageBean page = businessManager.selectPersonalAppointment(argMap); OutputUtil.outPutJsonObject(response, page); } catch (Exception e) { outPutErrorInfor(BusinessController.class.getName(), "", e); } } else if ("9".equals(requestType)) {// String empcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String position = request.getParameter("position") == null ? "" : request.getParameter("position"); List<Employee> list = businessManager.findFreeEmp(empcode, position); OutputUtil.outPutJsonArrary(response, list); } else if ("10".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); Map<String, String> result = businessManager.daleteDistributeWork(appcode, empCode); OutputUtil.outPutJsonObject(response, result); } else if ("11".equals(requestType)) {//? String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); List<WorkRecord> list = workRecordManager.findByAppCode(appcode); OutputUtil.outPutJsonArrary(response, list); } else if ("12".equals(requestType)) {//??? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); Map<String, String> result = sendManager.mobileValidate(mobile); OutputUtil.outPutJsonObject(response, result); } else if ("13".equals(requestType)) {//? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); String validate = request.getParameter("validate") == null ? "" : request.getParameter("validate"); Map<String, String> result = businessManager.mobileValidate(mobile, validate);//? OutputUtil.outPutJsonObject(response, result); } else if ("14".equals(requestType)) {//?? /*String model=request.getParameter("model") == null ? "": request.getParameter("model"); String appcode=request.getParameter("code") == null ? "": request.getParameter("code"); String weixinCode=request.getParameter("weixinCode") == null ? "": request.getParameter("weixinCode"); Map<String, String> result=businessManager.writeAccessoriesModel(appcode,model,weixinCode); OutputUtil.outPutJsonObject(response, result);*/ } else if ("15".equals(requestType)) {// String appcode = request.getParameter("code") == null ? "" : request.getParameter("code"); String vipCondition = request.getParameter("condition") == null ? "" : request.getParameter("condition"); Map<String, String> result = businessManager.finishAppointment(appcode, vipCondition); OutputUtil.outPutJsonObject(response, result); } else if ("16".equals(requestType)) {//?? String kfpwd = "qweasd"; String validate = request.getParameter("code") == null ? "" : request.getParameter("code"); Map<String, String> result = new HashMap<String, String>(); if (validate.equals(kfpwd)) { result.put("flag", "1"); } else { result.put("flag", "-1"); } OutputUtil.outPutJsonObject(response, result); } else if ("17".equals(requestType)) {//??? String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); List<Map<String, Object>> result = businessManager .searchCustomerPensonalAppointmentByMobile(mobile); OutputUtil.outPutJsonArrary(response, result); } else if ("18".equals(requestType)) { //? response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "No-cache"); response.setDateHeader("Expires", 0); //? response.setContentType("image/jpeg"); IdentifyingImg img = new IdentifyingImg(); ImageIO.write(img.creat(), "JPEG", response.getOutputStream()); } else if ("19".equals(requestType)) {//?? Map<String, Object> map = weixinCustomerManager.findCustomerInfo(openid); OutputUtil.outPutJsonObject(response, map); } else if ("20".equals(requestType)) {//???? List<Map> result = businessManager.findCurrentAppByOpenid(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("21".equals(requestType)) {//??? //List<Map> result=businessManager.searchCustomerPensonalAppointmentByOpenid(openid); List<CustomerCar> result = businessManager.findHistoryCar(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("22".equals(requestType)) {//?? Map<String, String> result = new HashMap<String, String>(); String path = weixinCustomerManager.creatEwmByWeixinCustomer(openid); result.put("path", path); OutputUtil.outPutJsonObject(response, result); } else if ("23".equals(requestType)) {//??? Map<String, String> result = null; Customer cus = customerManager.findCustomerByOpenid(openid); if (cus != null) { result = new HashMap<String, String>(); result.put("name", cus.getName()); result.put("mobile", cus.getMobile()); } OutputUtil.outPutJsonObject(response, result); } else if ("24".equals(requestType)) {//?? String name = request.getParameter("name") == null ? "" : request.getParameter("name"); String mobile = request.getParameter("mobile") == null ? "" : request.getParameter("mobile"); Map<String, String> result = weixinCustomerManager.saveCustomerInfo(openid, name, mobile); OutputUtil.outPutJsonObject(response, result); } else if ("25".equals(requestType)) {//?? List<Map> result = businessManager.findCurrentCar(openid); OutputUtil.outPutJsonArrary(response, result); } else if ("26".equals(requestType)) {//? List<Map<String, String>> list = weixinCustomerManager.findConsumptionRecordByOpenid(openid); OutputUtil.outPutJsonArrary(response, list); } else if ("27".equals(requestType)) {//?? String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type"); String totalPrice = request.getParameter("totalPrice") == null ? "" : request.getParameter("totalPrice"); double pay = integralManager.maxOutIntegral(openid, Integer.valueOf(busnessType), Double.valueOf(totalPrice)); Map<String, String> map = new HashMap<String, String>(); map.put("pay", (int) pay + ""); OutputUtil.outPutJsonObject(response, map); } else if ("28".equals(requestType)) {// String code = request.getParameter("code") == null ? "" : request.getParameter("code"); String busnessType = request.getParameter("type") == null ? "" : request.getParameter("type"); String pay = request.getParameter("pay") == null ? "" : request.getParameter("pay"); Map<String, String> map = businessManager.integralPay(code, openid, busnessType, pay); OutputUtil.outPutJsonObject(response, map); } else if ("29".equals(requestType)) {//? String date = request.getParameter("date") == null ? "" : request.getParameter("date"); List<AppointmentTime> list = businessManager.findAppTime(date); OutputUtil.outPutJsonArrary(response, list); } else if ("30".equals(requestType)) {//? String code = request.getParameter("code") == null ? "" : request.getParameter("code"); String score = request.getParameter("scorce") == null ? "" : request.getParameter("scorce"); Map<String, String> result = businessManager.saveCustomerScore(code, score); OutputUtil.outPutJsonObject(response, result); } else if ("31".equals(requestType)) {//? String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode"); Map<String, Object> result = weixinCustomerManager.openGiftView(code); OutputUtil.outPutJsonObject(response, result); } else if ("32".equals(requestType)) {// String code = request.getParameter("weixinCode") == null ? "" : request.getParameter("weixinCode"); String accept = request.getParameter("accept") == null ? "" : request.getParameter("accept"); List<WeixinAcceptRecord> list = weixinCustomerManager.acceptGift(code, accept); OutputUtil.outPutJsonArrary(response, list); } else if ("33".equals(requestType)) {//?? String carCdoe = request.getParameter("code") == null ? "" : request.getParameter("code"); List<Map> list = businessManager.findHistoryAppByCarCode(carCdoe); OutputUtil.outPutJsonArrary(response, list); } else if ("100".equals(requestType)) {//??? String paramObj = request.getParameter("paramObj") == null ? "" : request.getParameter("paramObj"); JSONObject json = JSONObject.fromObject(paramObj); Map<String, String> result = businessManager.inPutFinishInfo(json, emp.getCode()); OutputUtil.outPutJsonObject(response, result); } else if ("101".equals(requestType)) {// String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); List<CustomerCarSituation> list = customerManager.findByAppCode(appCode); Map<String, List<CustomerCarSituation>> result = new HashMap<String, List<CustomerCarSituation>>(); result.put("ccs", list); OutputUtil.outPutJsonObject(response, result); } else if ("102".equals(requestType)) {//? String position = request.getParameter("position") == null ? "" : request.getParameter("position"); List<Employee> list = employeeManager.findEmployeeByPosition(position); OutputUtil.outPutJsonArrary(response, list); } else if ("103".equals(requestType)) {//?? String appCode = request.getParameter("appCode") == null ? "" : request.getParameter("appCode"); List<WorkRecord> list = workRecordManager.findByAppCode(appCode); OutputUtil.outPutJsonArrary(response, list); } else if ("104".equals(requestType)) {// List<Team> list = carMaintenanceManager.findAllTeam(); OutputUtil.outPutJsonArrary(response, list); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block outPutErrorInfor(BusinessController.class.getName(), "?", e); } catch (IOException e) { outPutErrorInfor(BusinessController.class.getName(), "?", e); } }
From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java
private void doProcess(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { for (String[] h : additionalResponseHeaders) { resp.addHeader(h[0], h[1]);// w ww . jav a 2 s .com } resp.setCharacterEncoding("UTF-8"); String serviceName = getServiceName(request); JsonRpcRequest req = null; if (request.getMethod().equals("GET")) { req = decodeFromPC(new URLParameterContext(request.getQueryString())); } else { req = JSON.decode(StreamUtil.readAsString(request.getInputStream(), "UTF-8"), JsonRpcRequest.class); String cb = request.getParameter("callback"); if (cb != null) { req.setCallback(cb); } if (req.getHeaders() == null) { req.setHeaders(new RpcHeader[] {}); } } // The handler is acquired from the service name. JsonRpcHandler h = handlers.get(serviceName); // Execution of service if (h == null) { h = new JsonRpcDynamicHandler(); } ServiceContext sc = new ServletServiceContext(getServletConfig(), request, Arrays.asList(req.getHeaders())); ServiceLoader loader = new ServiceLoader(sc, defaultLoaders); OutputStream os = resp.getOutputStream(); h.handle(sc, loader, serviceName, req, resp, os); os.flush(); }
From source file:importer.handler.get.ImporterGetHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws ImporterException { try {/* ww w.ja v a2 s.com*/ String prefix = Utils.first(urn); urn = Utils.pop(urn); if (prefix != null) { if (prefix.equals(Service.JSON)) new ImporterJSONHandler().handle(request, response, urn); else if (prefix.equals(Service.COLLECTION)) new ImporterListCollectionHandler().handle(request, response, urn); } else throw new ImporterException("Invalid urn (prefix was null) " + urn); } catch (Exception e) { try { response.setCharacterEncoding("UTF-8"); response.getWriter().println(e.getMessage()); } catch (Exception ex) { throw new ImporterException(ex); } } }
From source file:com.aaasec.sigserv.csspserver.SpServlet.java
/** * Processes requests for both HTTP/*ww w. j av a 2 s . c o m*/ * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); SpSession session = getSession(request, response); RequestModel req = reqFactory.getRequestModel(request, session); AuthData authdata = req.getAuthData(); // Supporting devmode login if (SpModel.isDevmode()) { authdata = TestIdentities.getTestID(request, req); req.setAuthData(authdata); if (authdata.getAuthType().length() == 0) { authdata.setAuthType("devlogin"); } session.setIdpEntityId(authdata.getIdpEntityID()); session.setSignerAttribute(RequestModelFactory.getAttrOidString(authdata.getIdAttribute())); session.setSignerId(authdata.getId()); } //Terminate if no valid request data if (req == null) { response.setStatus(HttpServletResponse.SC_NO_CONTENT); response.getWriter().write(""); return; } // Handle form post from web page boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { response.getWriter().write(SpServerLogic.processFileUpload(request, response, req)); return; } // Handle auth data request if (req.getAction().equals("authdata")) { response.setContentType("application/json"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write(gson.toJson(authdata)); return; } // Get list of serverstored xml documents if (req.getAction().equals("doclist")) { response.setContentType("application/json"); response.getWriter().write(SpServerLogic.getDocList()); return; } // Provide info about the session for logout handling if (req.getAction().equals("logout")) { response.setContentType("application/json"); Logout lo = new Logout(); lo.authType = (request.getAuthType() == null) ? "" : request.getAuthType(); lo.devmode = String.valueOf(SpModel.isDevmode()); response.getWriter().write(gson.toJson(lo)); return; } // Respons to a client alive check to test if the server session is alive if (req.getAction().equals("alive")) { response.setContentType("application/json"); response.getWriter().write("[]"); return; } // Handle sign request and return Xhtml form with post data to the signature server if (req.getAction().equals("sign")) { boolean addSignMessage = (req.getParameter().equals("message")); String xhtml = SpServerLogic.prepareSignRedirect(req, addSignMessage); response.getWriter().write(xhtml); return; } // Get status data about the current session if (req.getAction().equals("status")) { response.setContentType("application/json"); response.getWriter().write(gson.toJson(session.getStatus())); return; } // Handle a declined sign request if (req.getAction().equals("declined")) { if (SpModel.isDevmode()) { response.sendRedirect("index.jsp?declined=true"); return; } response.sendRedirect("https://eid2cssp.3xasecurity.com/sign/index.jsp?declined=true"); return; } // Return Request and response data as a file. if (req.getAction().equalsIgnoreCase("getReqRes")) { response.setContentType("text/xml;charset=UTF-8"); byte[] data = TestCases.getRawData(req); BufferedInputStream fis = new BufferedInputStream(new ByteArrayInputStream(data)); ServletOutputStream output = response.getOutputStream(); if (req.getParameter().equalsIgnoreCase("download")) { response.setHeader("Content-Disposition", "attachment; filename=" + req.getId() + ".xml"); } int readBytes = 0; byte[] buffer = new byte[10000]; while ((readBytes = fis.read(buffer, 0, 10000)) != -1) { output.write(buffer, 0, readBytes); } output.flush(); output.close(); fis.close(); return; } // Return the signed document if (req.getAction().equalsIgnoreCase("getSignedDoc") || req.getAction().equalsIgnoreCase("getUnsignedDoc")) { // If the request if for a plaintext document, or only if the document has a valid signature if (session.getStatus().signedDocValid || req.getAction().equalsIgnoreCase("getUnsignedDoc")) { response.setContentType(session.getDocumentType().getMimeType()); switch (session.getDocumentType()) { case XML: response.getWriter().write(new String(session.getSignedDoc(), Charset.forName("UTF-8"))); return; case PDF: File docFile = session.getDocumentFile(); if (req.getAction().equalsIgnoreCase("getSignedDoc") && session.getStatus().signedDocValid) { docFile = session.getSigFile(); } FileInputStream fis = new FileInputStream(docFile); ServletOutputStream output = response.getOutputStream(); if (req.getParameter().equalsIgnoreCase("download")) { response.setHeader("Content-Disposition", "attachment; filename=" + "signedPdf.pdf"); } int readBytes = 0; byte[] buffer = new byte[10000]; while ((readBytes = fis.read(buffer, 0, 10000)) != -1) { output.write(buffer, 0, readBytes); } output.flush(); output.close(); fis.close(); return; } return; } else { if (SpModel.isDevmode()) { response.sendRedirect("index.jsp"); return; } response.sendRedirect("https://eid2cssp.3xasecurity.com/sign/index.jsp"); return; } } // Process a sign response from the signature server if (req.getSigResponse().length() > 0) { try { byte[] sigResponse = Base64Coder.decode(req.getSigResponse().trim()); // Handle response SpServerLogic.completeSignedDoc(sigResponse, req); } catch (Exception ex) { } if (SpModel.isDevmode()) { response.sendRedirect("index.jsp"); return; } response.sendRedirect("https://eid2cssp.3xasecurity.com/sign/index.jsp"); return; } // Handle testcases if (req.getAction().equals("test")) { boolean addSignMessage = (req.getParameter().equals("message")); String xhtml = TestCases.prepareTestRedirect(request, response, req, addSignMessage); respond(response, xhtml); return; } // Get test data for display such as request data, response data, certificates etc. if (req.getAction().equals("info")) { switch (session.getDocumentType()) { case PDF: File returnFile = null; if (req.getId().equalsIgnoreCase("document")) { respond(response, getDocIframe("getUnsignedDoc", needPdfDownloadButton(request))); } if (req.getId().equalsIgnoreCase("formSigDoc")) { respond(response, getDocIframe("getSignedDoc", needPdfDownloadButton(request))); } respond(response, TestCases.getTestData(req)); return; default: respond(response, TestCases.getTestData(req)); return; } } if (req.getAction().equals("verify")) { response.setContentType("text/xml;charset=UTF-8"); String sigVerifyReport = TestCases.getTestData(req); if (sigVerifyReport != null) { respond(response, sigVerifyReport); return; } } nullResponse(response); }
From source file:ru.histone.spring.mvc.HistoneView.java
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { ObjectMapper jackson = new ObjectMapper(); ObjectNode context = jackson.createObjectNode(); for (Map.Entry<String, Object> entry : model.entrySet()) { if (entry.getKey().startsWith("context.")) { String key = entry.getKey().substring(8); Object val = entry.getValue(); if (val instanceof JsonNode) { context.put(key, (JsonNode) val); } else { JsonNode jsonVal = jackson.valueToTree(val); context.put(key, jsonVal); }// w w w .j a v a 2 s . c o m } } response.setCharacterEncoding("UTF-8"); Reader content = new InputStreamReader(getServletContext().getResourceAsStream(getUrl()), "UTF-8"); getHistone().setGlobalProperty(GlobalProperty.BASE_URI, "webapp:" + getUrl()); String result = getHistone().evaluate(getUrl(), content, context); response.getOutputStream().write(result.getBytes("UTF-8")); }
From source file:com.hp.action.CalendarAction.java
public String delete() throws IOException { HttpServletRequest request = (HttpServletRequest) ActionContext.getContext() .get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse) ActionContext.getContext() .get(ServletActionContext.HTTP_RESPONSE); HttpSession session = request.getSession(); response.setContentType("text/html; charset=UTF-8"); response.setCharacterEncoding("text/html; charset=UTF-8"); String id = StringUtils.trimToEmpty(request.getParameter("id")); int stt = 0;//from w w w . j av a2s. co m try { stt = Integer.parseInt(id); } catch (Exception e) { e.printStackTrace(); response.getOutputStream().write("Li khng xc nh, hy th li sau!".getBytes("UTF-8")); return null; } Calendar calendar = null; if (stt > 0) calendar = calendarDAO.getCalendar(stt); if (calendar != null && calendar.getStatus() != 2) { if (calendarDAO.delete(calendar)) { response.getOutputStream().write("Xa lch cng tc thnh cng".getBytes("UTF-8")); return null; } } response.getOutputStream() .write("Xa lch cng tc tht bi, hy th li sau!".getBytes("UTF-8")); return null; }
From source file:net.duckling.ddl.web.api.pan.APIPanDownloadController.java
@WebLog(method = "mobilePanPage", params = "pid,itemType") @RequestMapping/*from w w w . jav a 2 s .c o m*/ public void service(@RequestParam("pid") String rid, @RequestParam("itemType") String itemType, HttpServletRequest request, HttpServletResponse response) { String imageSize = request.getParameter("imageType"); rid = decode(rid); PanAcl acl = PanAclUtil.getInstance(request); MeePoMeta meta = null; try { meta = panService.ls(acl, rid, true); } catch (MeePoException e1) { LOG.error(e1.getMessage()); return; } OutputStream os = null; long[] re = getOffer(request, meta.size); long offset = re[0]; long size = re[1]; long p0 = System.currentTimeMillis(); long tmpSize = size; try { response.setCharacterEncoding("utf-8"); String headerValue = ResponseHeaderUtils.buildResponseHeader(request, meta.name, true); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", headerValue); response.setContentLength((int) size); response.setHeader("Content-Length", tmpSize + ""); os = response.getOutputStream(); //??? //if(FileType.IMAGE.equals(FileTypeHelper.getName(meta.name))){ // panService.thumbnails(acl, rid, convertPanImageType(imageSize), os); //}else{ panService.download(PanAclUtil.getInstance(request), rid, meta.version, os, offset, size); //} } catch (UnsupportedEncodingException e) { LOG.error("", e); } catch (MeePoException e) { LOG.error("", e); } catch (IOException e) { LOG.error("", e); } catch (Exception e) { LOG.error("", e); } finally { IOUtils.closeQuietly(os); long p1 = System.currentTimeMillis(); LOG.info("Download document[name:" + meta.name + ",size:" + tmpSize + "] use time " + (p1 - p0)); } }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: GET Processes get requests to perform a search. It performs an * index search with the keyword in that header. Requires a valid api key to * work.//from w w w. j av a 2 s . c o m */ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { MokapSearchController sCont = new MokapSearchController(); // Check api key try { if (!ApiKeyVerifier.checkApiKey(req, resp)) { PrintWriter out = resp.getWriter(); out.print("Wrong API key."); out.flush(); out.close(); } else { PrintWriter out = resp.getWriter(); // Get the parameters from the header / parameter SearchParams sp = SearchParamsFactory.create(req); String str = sCont.performSearch(sp); // Set the response encoding resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); out.print(str); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }