Example usage for org.springframework.web.context.request RequestContextHolder getRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder getRequestAttributes

Introduction

In this page you can find the example usage for org.springframework.web.context.request RequestContextHolder getRequestAttributes.

Prototype

@Nullable
public static RequestAttributes getRequestAttributes() 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public Transfer getTransferToPurchase(Integer cashstreamId)
        throws InsufficientBalanceException, LoginException, IllegalOperationException {
    Transfer transfer = new Transfer();
    transfer.setBaseUrl(innerThirdPaySupportService.getBaseUrl(innerThirdPaySupportService.ACTION_TRANSFER));
    Lender lender = lenderService.getCurrentUser();
    if (lender == null)
        throw new LoginException("??");

    CashStream cs = cashStreamDao.find(cashstreamId);
    if (cs == null) {
        throw new IllegalOperationException("??");
    }/*from w  w w.ja  v  a 2 s  .  c  o m*/

    if (cs.getAction() != CashStream.ACTION_PURCHASE) {
        throw new IllegalOperationException("?????");
    }

    if (cs.getLenderAccountId() != lender.getAccountId()) {
        throw new IllegalOperationException("??????");
    }

    if (cs.getState() != CashStream.STATE_INIT) {
        throw new IllegalOperationException("???");
    }

    Borrower borrower = borrowerDao.findByAccountID(cs.getBorrowerAccountId());

    Submit submit = submitService.find(cs.getSubmitId());

    Product product = productService.find(submit.getProductId());

    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    transfer.setAction(ThirdPartyState.THIRD_ACTION_MANUAL); //?
    transfer.setNeedAudit("1");//??
    transfer.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/purchase/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        transfer.setNotifyURL(
                innerThirdPaySupportService.getNotifyUrl() + "/account/purchase/response" + "/bg");
    else
        transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    transfer.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    transfer.setTransferAction(ThirdPartyState.THIRD_TRANSFERACTION_BUY);//
    transfer.setTransferType(ThirdPartyState.THIRD_TRANSFERTYPE_DIRECT);//

    List<LoanJson> loanJsons = new ArrayList<LoanJson>();
    LoanJson loanJson = new LoanJson();
    loanJson.setLoanOutMoneymoremore(lender.getThirdPartyAccount());
    loanJson.setLoanInMoneymoremore(borrower.getThirdPartyAccount());
    loanJson.setOrderNo(cashstreamId.toString());
    loanJson.setBatchNo(String.valueOf(product.getId()));
    //      loanJson.setExchangeBatchNo(null);
    //      loanJson.setAdvanceBatchNo(null);
    loanJson.setAmount(cs.getChiefamount().negate().add(cs.getInterest().negate()).toString());
    loanJson.setFullAmount("");
    loanJson.setTransferName("");
    loanJson.setRemark("");
    loanJson.setSecondaryJsonList("");
    loanJsons.add(loanJson);
    transfer.setLoanJsonList(Common.JSONEncode(loanJsons));
    transfer.setSignInfo(transfer.getSign(innerThirdPaySupportService.getPrivateKey()));
    try {
        transfer.setLoanJsonList(URLEncoder.encode(transfer.getLoanJsonList(), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return transfer;
}

From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java

protected ModelAndView invokeHandlerMethod(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler) throws Exception {

    final AnnotationHandlerMethodResolver methodResolver = getMethodResolver(handler);
    final WebMethodHandler handlerMethod = methodResolver.resolveHandlerMethod(request);
    final ServletWebRequest webRequest = new ServletWebRequest(request, response);
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    try {//from   w  w  w .  j  a v  a 2  s  .  co  m
        RequestContextHolder.setRequestAttributes(webRequest);
        final ExtendedModelMap implicitModel = new BindingAwareModelMap();

        final Object result = handlerMethod.invokeMethod(handler, request, response);
        if (result == null) {
            return null;
        } else {
            final ModelAndView mav = getModelAndView(handlerMethod.getMethod(), handler.getClass(), result,
                    implicitModel, webRequest);
            return mav;
        }
    } finally {
        RequestContextHolder.setRequestAttributes(requestAttributes);
    }
}

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public Transfer getTransferToBuy(Integer submitId, String pid)
        throws InsufficientBalanceException, LoginException {
    Transfer transfer = new Transfer();
    transfer.setBaseUrl(innerThirdPaySupportService.getBaseUrl(innerThirdPaySupportService.ACTION_TRANSFER));

    Lender lender = lenderService.getCurrentUser();
    if (lender == null)
        throw new LoginException("??");
    Submit submit = ObjectUtil.checkNullObject(Submit.class, submitService.find(submitId));

    if (submit.getState() == Submit.STATE_COMPLETEPAY) {
        throw new InsufficientBalanceException("???");
    }//  w w  w.  ja  va 2s  .c  o m

    GovermentOrder order = orderService.findGovermentOrderByProduct(submit.getProductId());
    Borrower borrower = borrowerService.find(order.getBorrowerId());

    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    transfer.setAction("1");
    transfer.setNeedAudit(null);//.?
    transfer.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/buy/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl() + "/account/buy/response" + "/bg");
    else
        transfer.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    transfer.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    transfer.setRemark1(pid);
    transfer.setTransferAction("1");//
    transfer.setTransferType("2");//

    List<LoanJson> loanJsons = new ArrayList<LoanJson>();
    Integer cashStreamId = null;
    //?? 
    CashStream cashStream = cashStreamDao.findBySubmitAndAction(submitId, CashStream.ACTION_FREEZE);
    if (cashStream == null)
        cashStreamId = accountService.freezeLenderAccount(lender.getAccountId(), submit.getAmount(), submitId,
                "");
    else
        cashStreamId = cashStream.getId();
    LoanJson loanJson = new LoanJson();
    loanJson.setLoanOutMoneymoremore(lender.getThirdPartyAccount());
    loanJson.setLoanInMoneymoremore(borrower.getThirdPartyAccount());
    loanJson.setOrderNo(cashStreamId.toString());
    loanJson.setBatchNo(String.valueOf(submit.getProductId()));//????
    //      loanJson.setExchangeBatchNo(null);
    //      loanJson.setAdvanceBatchNo(null);
    loanJson.setAmount(submit.getAmount().toString());
    loanJson.setFullAmount("");
    loanJson.setTransferName("");
    loanJson.setRemark("");
    loanJson.setSecondaryJsonList("");
    loanJsons.add(loanJson);
    transfer.setLoanJsonList(Common.JSONEncode(loanJsons));
    transfer.setSignInfo(transfer.getSign(innerThirdPaySupportService.getPrivateKey()));
    try {
        transfer.setLoanJsonList(URLEncoder.encode(transfer.getLoanJsonList(), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return transfer;
}

From source file:com.github.hateoas.forms.spring.AffordanceBuilder.java

/**
 * Copy of {@link ServletUriComponentsBuilder#getCurrentRequest()} until SPR-10110 gets fixed.
 *
 * @return request//www . ja  v a  2s .  c o  m
 */
private static HttpServletRequest getCurrentRequest() {

    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}

From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java

protected void initContext() {
    GrailsWebRequest requestAttributes = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
    contextHolder.get().push(new ContentCacheParameters(requestAttributes));
}

From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java

protected Object findArg(HttpServletRequest request, Class<?> type, String name) {

    if (String.class.equals(type)) {
        return request.getParameter(name);
    }/*from  ww w . j  a  v a 2  s. c om*/

    if (PRIMITIVE_CLASSES.contains(type) || TYPE_TO_CONVERSION_METHOD_NAME.containsKey(type)) {

        String conversionMethodName;
        if (TYPE_TO_CONVERSION_METHOD_NAME.containsKey(type)) {
            conversionMethodName = TYPE_TO_CONVERSION_METHOD_NAME.get(type);
        } else {
            conversionMethodName = type.getName();
        }

        GrailsWebRequest grailsRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
        GrailsParameterMap params = grailsRequest.getParams();

        return getParamValue(params, conversionMethodName, name);
    }

    log.warn("Unsupported parameter type " + type + " for parameter " + name);
    return null;
}

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public CardBinding getCardBinding() throws LoginException {
    CardBinding cardBinding = new CardBinding();
    cardBinding.setBaseUrl(/*from  w  ww  . ja v  a  2 s . c o  m*/
            innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CARDBINDING));
    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    HttpSession session = req.getSession();
    Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER);
    if (currentUser == null)
        throw new LoginException("??");
    cardBinding.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    cardBinding.setAction("2");
    //      RsaHelper rsa = RsaHelper.getInstance();
    //      cardBinding.setCardNo(cardNo);
    cardBinding.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/cardBinding/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        cardBinding.setNotifyURL(
                innerThirdPaySupportService.getNotifyUrl() + "/account/cardBinding/response" + "/bg");
    else
        cardBinding.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    if (currentUser instanceof Lender) {
        Lender lender = (Lender) currentUser;
        cardBinding.setMoneymoremoreId(lender.getThirdPartyAccount());
    } else if (currentUser instanceof Borrower) {
        Borrower borrower = (Borrower) currentUser;
        cardBinding.setMoneymoremoreId(borrower.getThirdPartyAccount());
    } else {
        throw new RuntimeException("??");
    }
    cardBinding.setSignInfo(cardBinding.getSign(innerThirdPaySupportService.getPrivateKey()));
    //      cardBinding.setCardNo(rsa.encryptData(cardNo, publicKey));
    return cardBinding;
}

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public Cash getCash(String amount)
        throws InsufficientBalanceException, LoginException, IllegalOperationException {
    Cash cash = new Cash();
    cash.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_CASH));
    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/*from ww w  .  j  ava  2  s  .co  m*/
    HttpSession session = req.getSession();
    Object currentUser = session.getAttribute(ILoginService.SESSION_ATTRIBUTENAME_USER);
    if (currentUser == null)
        throw new LoginException("??");
    cash.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    cash.setAmount(amount);
    Integer cashStreamId = null;
    String cardNo = null;
    gpps.model.CardBinding cardBinding = null;
    if (currentUser instanceof Lender) {
        Lender lender = (Lender) currentUser;
        cash.setWithdrawMoneymoremore(lender.getThirdPartyAccount());
        cashStreamId = accountService.cashLenderAccount(lender.getAccountId(),
                BigDecimal.valueOf(Double.valueOf(amount)), "??");
        cardBinding = cardBindingDao.find(lender.getCardBindingId());

    } else if (currentUser instanceof Borrower) {
        Borrower borrower = (Borrower) currentUser;
        // ??payback
        List<Integer> states = new ArrayList();
        states.add(PayBack.STATE_REPAYING);
        states.add(PayBack.STATE_WAITFORCHECK);
        int count = payBackDao.countByBorrowerAndState(borrower.getAccountId(), states, -1, -1);
        if (count > 0)
            throw new IllegalOperationException(
                    "????.");
        cash.setWithdrawMoneymoremore(borrower.getThirdPartyAccount());
        cashStreamId = accountService.cashBorrowerAccount(borrower.getAccountId(),
                BigDecimal.valueOf(Double.valueOf(amount)), "??");
        cardBinding = cardBindingDao.find(borrower.getCardBindingId());

        cash.setFeePercent("100"); //????
    } else {
        throw new RuntimeException("????");
    }
    if (cardBinding == null)
        throw new IllegalOperationException("?");
    cardNo = cardBinding.getCardNo();
    ////      cash.setFeeRate("0.0050");
    //      cash.setFeePercent("100");
    cash.setCardNo(cardNo);
    cash.setCardType(String.valueOf(cardBinding.getCardType()));
    cash.setBankCode(cardBinding.getBankCode());
    cash.setBranchBankName(cardBinding.getBranchBankName());
    cash.setProvince(cardBinding.getProvince());
    cash.setCity(cardBinding.getCity());
    cash.setOrderNo(String.valueOf(cashStreamId));
    cash.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/cash/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        cash.setNotifyURL(innerThirdPaySupportService.getNotifyUrl() + "/account/cash/response" + "/bg");
    else
        cash.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    cash.setSignInfo(cash.getSign(innerThirdPaySupportService.getPrivateKey()));
    RsaHelper rsa = RsaHelper.getInstance();
    cash.setCardNo(rsa.encryptData(cardNo, innerThirdPaySupportService.getPublicKey()));
    return cash;
}

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public Authorize getAuthorize() throws LoginException {
    Borrower borrower = borrowerService.getCurrentUser();
    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/*from  w w  w  . j  a  v  a  2  s .c o m*/
    if (borrower == null)
        throw new LoginException("??");
    Authorize authorize = new Authorize();
    authorize.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_AUTHORIZE));

    authorize.setMoneymoremoreId(borrower.getThirdPartyAccount());
    authorize.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    authorize.setAuthorizeTypeOpen("2");
    authorize.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/authorize/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        authorize.setNotifyURL(
                innerThirdPaySupportService.getNotifyUrl() + "/account/authorize/response" + "/bg");
    else
        authorize.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    authorize.setSignInfo(authorize.getSign(innerThirdPaySupportService.getPrivateKey()));
    return authorize;
}

From source file:gpps.service.impl.ThirdPaySupportServiceImpl.java

@Override
public Authorize getLenderAuthorize(String loginId) throws LoginException {

    Borrower borrower = borrowerService.getCurrentUser();
    if (borrower == null)
        throw new LoginException("???");

    if (borrower.getPrivilege() != Borrower.PRIVILEGE_PURCHASEBACK) {
        throw new LoginException("??????");
    }//from  w  w  w  . j  a  v a  2s .c o m

    if (loginId == null || !loginId.equals(borrower.getCorporationName())) {
        throw new LoginException("????????");
    }

    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();

    Lender lender = lenderDao.findByLoginId(loginId);

    if (lender == null)
        throw new LoginException("???");
    Authorize authorize = new Authorize();
    authorize.setBaseUrl(innerThirdPaySupportService.getBaseUrl(IInnerThirdPaySupportService.ACTION_AUTHORIZE));

    authorize.setMoneymoremoreId(lender.getThirdPartyAccount());
    authorize.setPlatformMoneymoremore(innerThirdPaySupportService.getPlatformMoneymoremore());
    authorize.setAuthorizeTypeOpen("2");
    authorize.setReturnURL(innerThirdPaySupportService.getReturnUrl() + "/account/lenderauthorize/response");
    if ("1".equals(innerThirdPaySupportService.getAppendFlag()))
        authorize.setNotifyURL(
                innerThirdPaySupportService.getNotifyUrl() + "/account/lenderauthorize/response" + "/bg");
    else
        authorize.setNotifyURL(innerThirdPaySupportService.getNotifyUrl());
    authorize.setSignInfo(authorize.getSign(innerThirdPaySupportService.getPrivateKey()));
    return authorize;
}