List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:com.myjeeva.spring.security.securechannel.AbstractCrossDomainRetryEntryPoint.java
/** * {@inheritDoc}/*w w w . j a v a2 s . c om*/ */ public void commence(ServletRequest req, ServletResponse res) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String pathInfo = request.getPathInfo(); String queryString = request.getQueryString(); String contextPath = request.getContextPath(); String destination = request.getServletPath() + ((pathInfo == null) ? "" : pathInfo) + ((queryString == null) ? "" : ("?" + queryString)); String redirectUrl = contextPath; Integer currentPort = new Integer(portResolver.getServerPort(request)); Integer redirectPort = getMappedPort(currentPort); if (redirectPort != null) { boolean includePort = redirectPort.intValue() != standardPort; redirectUrl = scheme + getMappedDomain(request.getServerName()) + ((includePort) ? (":" + redirectPort) : "") + contextPath + destination; } LOG.debug(" Cross Domain EntryPoint Redirecting to: " + redirectUrl); ((HttpServletResponse) res).sendRedirect(((HttpServletResponse) res).encodeRedirectURL(redirectUrl)); }
From source file:org.sample.endpoint.TestServlet.java
/** * Processes requests for both HTTP// w w w . j a v 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 { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet TestServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>"); Client client = ClientBuilder.newClient(); client.register(new LoggingFilter(Logger.getAnonymousLogger(), true)); WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruit"); // POST out.print("POSTing...<br>"); target.request().post(Entity.text("apple")); out.format("POSTed %1$s ...<br>", "apple"); // PUT out.print("<br>PUTing...<br>"); target.request().put(Entity.text("banana")); out.format("PUTed %1$s ...<br>", "banana"); // GET (all) out.print("<br>GETing...<br>"); String r = target.request().get(String.class); out.format("GETed %1$s items ...<br>", r); // GET (one) out.print("<br>GETing...<br>"); r = target.path("apple").request().get(String.class); out.format("GETed %1$s items ...<br>", r); // DELETE out.print("<br>DELETEing...<br>"); target.path("banana").request().delete(); out.format("DELETEed %1$s items ...<br>", "banana"); // GET (all) out.print("<br>GETing...<br>"); r = target.request().get(String.class); out.format("GETed %1$s items ...<br>", r); out.println("</body>"); out.println("</html>"); } }
From source file:com.icb123.Controller.BusinessController.java
@RequestMapping(value = "/appoint") public void customerAppointment(HttpServletRequest request, HttpServletResponse response) { try {/*from w ww .j av a2 s. c o m*/ 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:eg.agrimarket.controller.ProductController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String productName = request.getParameter("product_Name"); List<Product> products = (List<Product>) request.getServletContext().getAttribute("products"); if (products != null) { Iterator<Product> iterator = products.iterator(); while (iterator.hasNext()) { if (iterator.next().getName().equals(productName)) { iterator.remove();//from www . j a va2 s .c om } } request.getServletContext().setAttribute("products", products); } ProductDao dao = new ProductDaoImp(); dao.removeProduct(productName); response.sendRedirect("http://" + request.getServerName() + ":" + request.getServerPort() + "/AgriMarket/admin/getProducts?#product-div"); }
From source file:com.liusoft.dlog4j.velocity.DLOG_VelocityTool.java
/** * /*from www . j a va2 s . com*/ * @param site * @param ref_id * @param ref_type * @param req */ public void save_refer(SiteBean site, int ref_id, int ref_type, HttpServletRequest req) { if (!saveRefer) return; String refer = RequestUtils.getHeader(req, "refer"); if (StringUtils.isNotEmpty(refer)) { URL url; try { url = new URL(refer); String host = url.getHost(); if (!StringUtils.equals(req.getServerName(), host)) { ExternalReferBean rbean = new ExternalReferBean(); rbean.setUrl(refer); rbean.setClientAddr(req.getRemoteAddr()); rbean.setReferTime(new Date()); rbean.setRefId(ref_id); rbean.setRefType(ref_type); rbean.setSite(site); rbean.setHost(host); ExternalReferDAO.save(rbean); } } catch (Exception e) { log.error("Save refer failed, ip=" + req.getRemoteAddr() + ",refer=" + refer, e); } finally { url = null; } } }
From source file:cn.bc.web.util.DebugUtils.java
public static StringBuffer getDebugInfo(HttpServletRequest request, HttpServletResponse response) { @SuppressWarnings("rawtypes") Enumeration e;/* ww w. ja va 2s. co m*/ String name; StringBuffer html = new StringBuffer(); //session HttpSession session = request.getSession(); html.append("<div><b>session:</b></div><ul>"); html.append(createLI("Id", session.getId())); html.append(createLI("CreationTime", new Date(session.getCreationTime()).toString())); html.append(createLI("LastAccessedTime", new Date(session.getLastAccessedTime()).toString())); //session:attributes e = session.getAttributeNames(); html.append("<li>attributes:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, String.valueOf(session.getAttribute(name)))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //request html.append("<div><b>request:</b></div><ul>"); html.append(createLI("URL", request.getRequestURL().toString())); html.append(createLI("QueryString", request.getQueryString())); html.append(createLI("Method", request.getMethod())); html.append(createLI("CharacterEncoding", request.getCharacterEncoding())); html.append(createLI("ContentType", request.getContentType())); html.append(createLI("Protocol", request.getProtocol())); html.append(createLI("RemoteAddr", request.getRemoteAddr())); html.append(createLI("RemoteHost", request.getRemoteHost())); html.append(createLI("RemotePort", request.getRemotePort() + "")); html.append(createLI("RemoteUser", request.getRemoteUser())); html.append(createLI("ServerName", request.getServerName())); html.append(createLI("ServletPath", request.getServletPath())); html.append(createLI("ServerPort", request.getServerPort() + "")); html.append(createLI("Scheme", request.getScheme())); html.append(createLI("LocalAddr", request.getLocalAddr())); html.append(createLI("LocalName", request.getLocalName())); html.append(createLI("LocalPort", request.getLocalPort() + "")); html.append(createLI("Locale", request.getLocale().toString())); //request:headers e = request.getHeaderNames(); html.append("<li>Headers:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getHeader(name))); } html.append("</ul></li>\r\n"); //request:parameters e = request.getParameterNames(); html.append("<li>Parameters:<ul>\r\n"); while (e.hasMoreElements()) { name = (String) e.nextElement(); html.append(createLI(name, request.getParameter(name))); } html.append("</ul></li>\r\n"); html.append("</ul>\r\n"); //response html.append("<div><b>response:</b></div><ul>"); html.append(createLI("CharacterEncoding", response.getCharacterEncoding())); html.append(createLI("ContentType", response.getContentType())); html.append(createLI("BufferSize", response.getBufferSize() + "")); html.append(createLI("Locale", response.getLocale().toString())); html.append("<ul>\r\n"); return html; }
From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java
@RequestMapping(value = "/pulseVersion", method = RequestMethod.GET) public void pulseVersion(HttpServletRequest request, HttpServletResponse response) throws IOException { // json object to be sent as response ObjectNode responseJSON = mapper.createObjectNode(); try {//from www . j a va 2 s. com // Reference to repository Repository repository = Repository.get(); // set pulse web app url String pulseWebAppUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); repository.setPulseWebAppUrl(pulseWebAppUrl); // Response responseJSON.put("pulseVersion", PulseController.pulseVersion.getPulseVersion()); responseJSON.put("buildId", PulseController.pulseVersion.getPulseBuildId()); responseJSON.put("buildDate", PulseController.pulseVersion.getPulseBuildDate()); responseJSON.put("sourceDate", PulseController.pulseVersion.getPulseSourceDate()); responseJSON.put("sourceRevision", PulseController.pulseVersion.getPulseSourceRevision()); responseJSON.put("sourceRepository", PulseController.pulseVersion.getPulseSourceRepository()); } catch (Exception e) { if (LOGGER.fineEnabled()) { LOGGER.fine("Exception Occured : " + e.getMessage()); } } // Send json response response.getOutputStream().write(responseJSON.toString().getBytes()); }
From source file:org.jahia.modules.newsletter.action.SubscribeAction.java
private boolean sendConfirmationMail(JCRSessionWrapper session, String email, JCRNodeWrapper node, JCRNodeWrapper newSubscriptionNode, final Locale locale, HttpServletRequest req) throws RepositoryException, JSONException { if (mailConfirmationTemplate != null) { String confirmationKey = subscriptionService.generateConfirmationKey(newSubscriptionNode); newSubscriptionNode.setProperty(SubscriptionService.J_CONFIRMED, false); newSubscriptionNode.setProperty(SubscriptionService.J_CONFIRMATION_KEY, confirmationKey); session.save();/*from w w w . jav a2s. c o m*/ Map<String, Object> bindings = new HashMap<String, Object>(); bindings.put("newsletter", node); bindings.put("confirmationlink", req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + Jahia.getContextPath() + Render.getRenderServletPath() + "/live/" + node.getLanguage() + node.getPath() + ".confirm.do?key=" + confirmationKey + "&exec=add"); try { mailService.sendMessageWithTemplate(mailConfirmationTemplate, bindings, email, mailService.defaultSender(), null, null, locale, "Jahia Newsletter"); } catch (ScriptException e) { logger.error("Cannot generate confirmation mail", e); } return true; } return false; }