List of usage examples for org.springframework.web.context.request RequestContextHolder getRequestAttributes
@Nullable public static RequestAttributes getRequestAttributes()
From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java
@Override public Recharge getQuickRecharge(String amount) throws LoginException { float am = Float.parseFloat(amount); if (am < 100.0) { throw new LoginException("?100"); }/*from w w w .j a va 2s . c o m*/ Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); recharge.setRechargeType("2"); //RechargeType==2?? recharge.setFeeType("2"); //??FeeType==2??3.5 Integer cashStreamId = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; recharge.setRechargeMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.rechargeLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; }
From source file:de.hybris.platform.addressaddon.controllers.pages.checkout.steps.ChineseDeliveryAddressCheckoutStepController.java
@Override @RequestMapping(value = "/select", method = RequestMethod.POST) @RequireHardLogIn//from w w w . j av a 2 s .c om public String doSelectSuggestedAddress(final AddressForm addressForm, final RedirectAttributes redirectModel) { if (!addressForm.getCountryIso().equals(CHINA_ISOCODE)) { return super.doSelectSuggestedAddress(addressForm, redirectModel); } final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); final ChineseAddressForm chineseAddressForm = new ChineseAddressForm(); BeanUtils.copyProperties(addressForm, chineseAddressForm); if (addressForm.getCountryIso().equals(CHINA_ISOCODE)) { chineseAddressForm.setCityIso(request.getParameter("cityIso")); chineseAddressForm.setDistrictIso(request.getParameter("districtIso")); chineseAddressForm.setFullname(request.getParameter("fullname")); chineseAddressForm.setCellphone(request.getParameter("cellphone")); } final Set<String> resolveCountryRegions = org.springframework.util.StringUtils .commaDelimitedListToSet(Config.getParameter("resolve.country.regions")); final AddressData selectedAddress = chineseAddressHandler.prepareAddressData(chineseAddressForm); final CountryData countryData = getI18NFacade().getCountryForIsocode(addressForm.getCountryIso()); selectedAddress.setCountry(countryData); selectedAddress.setPhone(addressForm.getPhone()); if (resolveCountryRegions.contains(countryData.getIsocode()) && addressForm.getRegionIso() != null && !StringUtils.isEmpty(addressForm.getRegionIso())) { final RegionData regionData = getI18NFacade().getRegion(addressForm.getCountryIso(), addressForm.getRegionIso()); selectedAddress.setRegion(regionData); } if (addressForm.getSaveInAddressBook() != null) { selectedAddress.setVisibleInAddressBook(addressForm.getSaveInAddressBook().booleanValue()); } if (Boolean.TRUE.equals(addressForm.getEditAddress())) { getUserFacade().editAddress(selectedAddress); } else { getUserFacade().addAddress(selectedAddress); } final AddressData previousSelectedAddress = getCheckoutFacade().getCheckoutCart().getDeliveryAddress(); // Set the new address as the selected checkout delivery address getCheckoutFacade().setDeliveryAddress(selectedAddress); if (previousSelectedAddress != null && !previousSelectedAddress.isVisibleInAddressBook()) { // temporary address should be removed getUserFacade().removeAddress(previousSelectedAddress); } GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "checkout.multi.address.added"); return getCheckoutStep().nextStep(); }
From source file:com.ziduye.base.web.Servlets.java
/** * ??/*from ww w.j ava 2 s . c om*/ * @return */ public static HttpServletRequest request() { try { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); } catch (Exception e) { return null; } }
From source file:com.ziduye.base.web.Servlets.java
public static HttpServletResponse response() { try {/*from www . j a va 2s . c om*/ return ((ServletWebRequest) RequestContextHolder.getRequestAttributes()).getResponse(); } catch (Exception e) { return null; } }
From source file:com.kingen.web.CommonController.java
/** * request//from w ww. jav a 2 s. c o m * * @return */ public HttpServletRequest getRequest() { // return ServletActionContext.getRequest(); return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); }
From source file:com.kingen.web.CommonController.java
/** * session// ww w. j a v a 2 s. c o m * * @return */ public HttpSession getSession() { // return ServletActionContext.getRequest().getSession(); return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession(); }
From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java
@Override public Recharge getRecharge(String amount) throws LoginException { Recharge recharge = new Recharge(); recharge.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_RECHARGE)); HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();/*from w w w . j a va2 s .co m*/ HttpSession session = req.getSession(); Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER); if (currentUser == null) throw new LoginException("??"); recharge.setAmount(amount); recharge.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/recharge/response"); if ("1".equals(innerThirdPaySupportService.getAppendFlag())) recharge.setNotifyURL( innerThirdPaySupportService.getNotifyUrl() + "/account/recharge/response" + "/bg"); else recharge.setNotifyURL(innerThirdPaySupportService.getNotifyUrl()); recharge.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore()); // recharge.setRechargeType("4"); // recharge.setFeeType("1"); // recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); Integer cashStreamId = null; if (currentUser instanceof Lender) { Lender lender = (Lender) currentUser; recharge.setRechargeMoneymoremore(lender.getThirdPartyAccount()); cashStreamId = accountService.rechargeLenderAccount(lender.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else if (currentUser instanceof Borrower) { Borrower borrower = (Borrower) currentUser; recharge.setRechargeMoneymoremore(borrower.getThirdPartyAccount()); cashStreamId = accountService.rechargeBorrowerAccount(borrower.getAccountId(), BigDecimal.valueOf(Double.valueOf(amount)), ""); } else { throw new RuntimeException("??"); } recharge.setOrderNo(String.valueOf(cashStreamId)); recharge.setSignInfo(recharge.getSign(innerThirdPaySupportService.getPrivateKey())); return recharge; }
From source file:com.evolveum.midpoint.security.api.SecurityUtil.java
/** * Returns current connection information, as derived from HTTP request stored in current thread. * May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background). *//* ww w.ja va2 s. c o m*/ public static HttpConnectionInformation getCurrentConnectionInformation() { RequestAttributes attr = RequestContextHolder.getRequestAttributes(); if (!(attr instanceof ServletRequestAttributes)) { return null; } ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr; HttpServletRequest request = servletRequestAttributes.getRequest(); if (request == null) { return null; } HttpConnectionInformation rv = new HttpConnectionInformation(); HttpSession session = request.getSession(false); if (session != null) { rv.setSessionId(session.getId()); } rv.setLocalHostName(request.getLocalName()); rv.setRemoteHostAddress(getRemoteHostAddress(request)); return rv; }
From source file:ezbake.security.client.EzbakeSecurityClient.java
/** * Make a best attempt to get the user DN from the HTTP headers. This will use the RequestContextHolder to * get the HttpServletRequest. Requires that org.springframework.web.context.request.RequestContextListener be * registered in the deployment descriptor. * * @deprecated HTTP headers no longer contain a valid EzSecurityPrincipal. Use * {@link ezbake.security.client.EzbakeSecurityClient#requestPrincipalFromRequest()} instead * * @return valid EzSecurityPrincipal if able to get one, otherwise null. If in mock mode, return a mock principal *//* ww w. j a v a 2 s . co m*/ @Deprecated public EzSecurityPrincipal clientDnFromRequest() throws EzSecurityTokenException { // Return user from configuration if in 'mock' mode if (securityConfigurationHelper.useMock()) { return new EzSecurityPrincipal(securityConfigurationHelper.getMockUser(), new ValidityCaveats("EzSecurity", "", System.currentTimeMillis() + expiry, "")); } ServletRequestAttributes reqAttributes = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); if (reqAttributes == null) { log.error( "Unable to get request attributes. Make sure you have org.springframework.web.context.request.RequestContextListener registered in your web.xml"); return null; } HttpServletRequest req = reqAttributes.getRequest(); if (req == null) { log.error("Unable to get request from attributes"); return null; } return clientDnFromRequest(req); }
From source file:ezbake.security.client.EzbakeSecurityClient.java
/** * Attempt to read the proxy princiapl from the HTTP headers. This will use the RquestContextHolder to * get the HttpServletRequest. Requires that org.springframework.web.context.request.RequestContextListener be * registered in the deployment descriptor. * * @return the proxy principal that was contained in the HTTP headers * @throws EzSecurityTokenException/*from ww w . j av a2 s.c om*/ */ @Override public ProxyPrincipal requestPrincipalFromRequest() throws EzSecurityTokenException { // Return user from configuration if in 'mock' mode if (securityConfigurationHelper.useMock()) { return new ProxyPrincipal(generateMockProxyToken(securityConfigurationHelper.getMockUser()), ""); } ServletRequestAttributes reqAttributes = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); if (reqAttributes == null) { log.error("Unable to get request attributes. Make sure you have " + "org.springframework.web.context.request.RequestContextListener registered in your web.xml"); throw new EzSecurityTokenException("Unable to get request attributes. Make sure you have " + "org.springframework.web.context.request.RequestContextListener registered in your web.xml?"); } HttpServletRequest req = reqAttributes.getRequest(); if (req == null) { log.error("Unable to get request from attributes"); throw new EzSecurityTokenException("Unable to get HttpServletRequest from ServletRequestAttributes"); } return requestPrincipalFromRequest(req); }