List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:com.jaspersoft.jasperserver.war.OlapPrint.java
/** * Set parameters to include the chart in the printed Excel or PDF * * @param chartRef/*from w ww . j ava2s .c om*/ * @param request * @return */ private Map getChartParameters(String chartRef, HttpServletRequest request) { Map parameters = new HashMap(); // add parameters and image from chart if visible ChartComponent chart = (ChartComponent) request.getSession().getAttribute(chartRef); if (chart == null || !chart.isVisible()) { return parameters; } String host = request.getServerName(); int port = request.getServerPort(); String location = request.getContextPath(); String scheme = request.getScheme(); String chartServlet = scheme + "://" + host + ":" + port + location + "/GetChart"; parameters.put("chartimage", chartServlet + "?filename=" + chart.getFilename()); parameters.put("chartheight", new Integer(chart.getChartHeight())); parameters.put("chartwidth", new Integer(chart.getChartWidth())); return parameters; }
From source file:org.apache.ranger.security.web.filter.RangerKrbFilter.java
/** * If the request has a valid authentication token it allows the request to continue to the target resource, * otherwise it triggers an authentication sequence using the configured {@link AuthenticationHandler}. * * @param request the request object.// w w w.ja v a 2s . c o m * @param response the response object. * @param filterChain the filter chain object. * * @throws IOException thrown if an IO error occurred. * @throws ServletException thrown if a processing error occurred. */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { boolean unauthorizedResponse = true; int errCode = HttpServletResponse.SC_UNAUTHORIZED; AuthenticationException authenticationEx = null; HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; boolean isHttps = "https".equals(httpRequest.getScheme()); try { boolean newToken = false; AuthenticationToken token; try { token = getToken(httpRequest); } catch (AuthenticationException ex) { ex.printStackTrace(); LOG.warn("AuthenticationToken ignored: " + ex.getMessage()); // will be sent back in a 401 unless filter authenticates authenticationEx = ex; token = null; } if (authHandler.managementOperation(token, httpRequest, httpResponse)) { if (token == null) { if (LOG.isDebugEnabled()) { LOG.debug("Request [{}] triggering authentication", getRequestURL(httpRequest)); } token = authHandler.authenticate(httpRequest, httpResponse); if (token != null && token.getExpires() != 0 && token != AuthenticationToken.ANONYMOUS) { token.setExpires(System.currentTimeMillis() + getValidity() * 1000); } newToken = true; } if (token != null) { unauthorizedResponse = false; if (LOG.isDebugEnabled()) { LOG.debug("Request [{}] user [{}] authenticated", getRequestURL(httpRequest), token.getUserName()); } final AuthenticationToken authToken = token; httpRequest = new HttpServletRequestWrapper(httpRequest) { @Override public String getAuthType() { return authToken.getType(); } @Override public String getRemoteUser() { return authToken.getUserName(); } @Override public Principal getUserPrincipal() { return (authToken != AuthenticationToken.ANONYMOUS) ? authToken : null; } }; if (newToken && !token.isExpired() && token != AuthenticationToken.ANONYMOUS) { String signedToken = signer.sign(token.toString()); createAuthCookie(httpResponse, signedToken, getCookieDomain(), getCookiePath(), token.getExpires(), isHttps); } doFilter(filterChain, httpRequest, httpResponse); } } else { unauthorizedResponse = false; } } catch (AuthenticationException ex) { // exception from the filter itself is fatal ex.printStackTrace(); errCode = HttpServletResponse.SC_FORBIDDEN; authenticationEx = ex; LOG.warn("Authentication exception: " + ex.getMessage(), ex); } if (unauthorizedResponse) { if (!httpResponse.isCommitted()) { createAuthCookie(httpResponse, "", getCookieDomain(), getCookiePath(), 0, isHttps); // If response code is 401. Then WWW-Authenticate Header should be // present.. reset to 403 if not found.. if ((errCode == HttpServletResponse.SC_UNAUTHORIZED) && (!httpResponse.containsHeader(KerberosAuthenticator.WWW_AUTHENTICATE))) { errCode = HttpServletResponse.SC_FORBIDDEN; } if (authenticationEx == null) { String agents = PropertiesUtil.getProperty(BROWSER_USER_AGENT_PARAM, RangerCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT); if (agents == null) { agents = RangerCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT; } parseBrowserUserAgents(agents); if (isBrowser(httpRequest.getHeader(RangerCSRFPreventionFilter.HEADER_USER_AGENT))) { ((HttpServletResponse) response).setHeader(KerberosAuthenticator.WWW_AUTHENTICATE, ""); filterChain.doFilter(request, response); } else { boolean chk = true; Collection<String> headerNames = httpResponse.getHeaderNames(); for (String headerName : headerNames) { String value = httpResponse.getHeader(headerName); if (headerName.equalsIgnoreCase("Set-Cookie") && value.startsWith("RANGERADMINSESSIONID")) { chk = false; break; } } String authHeader = httpRequest.getHeader("Authorization"); if (authHeader == null && chk) { filterChain.doFilter(request, response); } else if (authHeader != null && authHeader.startsWith("Basic")) { filterChain.doFilter(request, response); } } } else { httpResponse.sendError(errCode, authenticationEx.getMessage()); } } } }
From source file:com.icb123.Controller.BusinessController.java
@RequestMapping(value = "/appoint") public void customerAppointment(HttpServletRequest request, HttpServletResponse response) { try {/* www.j av a 2 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:org.alfresco.web.forms.xforms.XFormsBean.java
/** * Initializes the chiba process with the xform and registers any necessary * event listeners./*from ww w .j av a 2 s .c o m*/ */ public XFormsSession createSession(final Document formInstanceData, final String formInstanceDataName, final Form form) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("initializing xforms session with form " + form.getName() + " and instance data " + formInstanceDataName + " (" + formInstanceData + ")"); } final FacesContext facesContext = FacesContext.getCurrentInstance(); final ExternalContext externalContext = facesContext.getExternalContext(); final HttpServletRequest request = (HttpServletRequest) externalContext.getRequest(); final String baseUrl = (request.getScheme() + "://" + request.getServerName() + ':' + request.getServerPort() + request.getContextPath()); return this.new XFormsSession(formInstanceData, formInstanceDataName, form, baseUrl, getSchema2XFormsProperties().isFormatCaption()); }
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 {/* w w w .j av a2 s .c om*/ // 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();//w w w . j av a 2 s . 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; }
From source file:edu.isi.wings.portal.classes.config.Config.java
private void createDefaultPortalConfig(HttpServletRequest request) { String server = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String storageDir = null;/*from ww w .j av a 2 s.co m*/ String home = System.getProperty("user.home"); if (home != null && !home.equals("")) storageDir = home + File.separator + ".wings" + File.separator + "storage"; else storageDir = System.getProperty("java.io.tmpdir") + File.separator + "wings" + File.separator + "storage"; if (!new File(storageDir).mkdirs()) System.err.println("Cannot create storage directory: " + storageDir); PropertyListConfiguration config = new PropertyListConfiguration(); config.addProperty("storage.local", storageDir); config.addProperty("storage.tdb", storageDir + File.separator + "TDB"); config.addProperty("server", server); File loc1 = new File("/usr/bin/dot"); File loc2 = new File("/usr/local/bin/dot"); config.addProperty("graphviz", loc2.exists() ? loc2.getAbsolutePath() : loc1.getAbsolutePath()); config.addProperty("ontology.data", ontdirurl + "/data.owl"); config.addProperty("ontology.component", ontdirurl + "/component.owl"); config.addProperty("ontology.workflow", ontdirurl + "/workflow.owl"); config.addProperty("ontology.execution", ontdirurl + "/execution.owl"); config.addProperty("ontology.resource", ontdirurl + "/resource.owl"); this.addEngineConfig(config, new ExeEngine("Local", LocalExecutionEngine.class.getCanonicalName(), ExeEngine.Type.BOTH)); this.addEngineConfig(config, new ExeEngine("Distributed", DistributedExecutionEngine.class.getCanonicalName(), ExeEngine.Type.BOTH)); /*this.addEngineConfig(config, new ExeEngine("OODT", OODTExecutionEngine.class.getCanonicalName(), ExeEngine.Type.PLAN)); this.addEngineConfig(config, new ExeEngine("Pegasus", PegasusExecutionEngine.class.getCanonicalName(), ExeEngine.Type.PLAN));*/ try { config.save(this.configFile); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.pivotal.gemfire.tools.pulse.internal.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 JSONObject responseJSON = new JSONObject(); try {// w ww . j ava 2 s . c o m // 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 (JSONException eJSON) { LOGGER.logJSONError(eJSON, new String[] { "pulseVersionData :" + PulseController.pulseVersion }); } 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.mitre.ptmatchadapter.service.ServerAuthorizationService.java
/** * Process a request to create a Server Authorization (i.e., request to grant * ptmatchadapter authorization to access a particular fhir server) * /* www .j av a 2s .com*/ * @param serverAuth * @param reqHdrs * @param respHdrs * @return */ private final ServerAuthorization processServerAuthRequest(ServerAuthorization serverAuth, @Headers Map<String, Object> reqHdrs, @OutHeaders Map<String, Object> respHdrs) { final String serverUrl = serverAuth.getServerUrl(); final String accessToken = serverAuth.getAccessToken(); // if request doesn't contain a server URL, it is an error if (serverUrl == null || serverUrl.isEmpty()) { respHdrs.put(Exchange.HTTP_RESPONSE_CODE, 400); // BAD REQUEST return null; } // else if the request body doesn't include an access token, redirect user // to an authorization server else if (accessToken == null || accessToken.isEmpty()) { // create a state identifier final String stateKey = newStateKey(); respHdrs.put(STATE_PARAM, stateKey); final AuthorizationRequestInfo requestInfo = new AuthorizationRequestInfo(); requestInfo.put(SERVER_AUTH, serverAuth); sessionData.put(stateKey, requestInfo); // Construct URL we will invoke on authorization server // GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz // &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb final StringBuilder authUrl = new StringBuilder(100); if (getAuthorizationServer() != null) { authUrl.append(getAuthorizationServer()); } authUrl.append(getAuthorizationEndpoint()); authUrl.append("?"); authUrl.append("response_type=code&client_id="); try { authUrl.append(URLEncoder.encode(getClientId(), "UTF-8")); authUrl.append("&"); authUrl.append(STATE_PARAM); authUrl.append("="); authUrl.append(stateKey); authUrl.append("&redirect_uri="); final HttpServletRequest req = (HttpServletRequest) reqHdrs.get(Exchange.HTTP_SERVLET_REQUEST); final String redirectUri = URLEncoder.encode( getClientAuthRedirectUri(req.getScheme(), req.getServerName(), req.getServerPort()), "UTF-8"); authUrl.append(redirectUri); // we need to provide redirect uri with access token request, so save it requestInfo.put("redirectUri", redirectUri); } catch (UnsupportedEncodingException e) { // Should never happen, which is why I wrap all above once LOG.error("Usupported encoding used on authorization redirect", e); } respHdrs.put(Exchange.HTTP_RESPONSE_CODE, 302); // FOUND respHdrs.put(Exchange.CONTENT_TYPE, "text/plain"); respHdrs.put("Location", authUrl.toString()); return null; } else { LOG.warn("NOT IMPLEMENTED"); return null; } }