Example usage for javax.servlet.http HttpServletRequest getLocalAddr

List of usage examples for javax.servlet.http HttpServletRequest getLocalAddr

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getLocalAddr.

Prototype

public String getLocalAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the interface on which the request was received.

Usage

From source file:org.tolven.web.RegisterAction.java

public String sendTestMessage() throws Exception {
    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();//  w ww .  j  ava  2  s  .  c  o m
    ExpressionEvaluator ee = new ExpressionEvaluator();
    ee.addVariable("now", getNow());
    ee.addVariable("subject", "Test Message");
    ee.addVariable("bodyProperty", "org.tolven.message.testMessage");
    ee.addVariable("accountUser", getAccountUser());
    ee.addVariable("brand", request.getLocalAddr());
    getInvitationLocal().sendMessage(ee);

    FacesContext.getCurrentInstance().addMessage("register:uid", new FacesMessage("Test message sent"));
    return "success";
}

From source file:com.jd.survey.web.settings.SurveyDefinitionController.java

/**
 * Exports the survey definition as a JSON file
 * @param surveyDefinitionId/* w ww.  ja v a 2  s .  c o m*/
 * @param response
 */
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/{id}", params = "export", produces = "text/html")
public void exportToJson(@PathVariable("id") Long surveyDefinitionId, Principal principal,
        HttpServletRequest httpServletRequest, HttpServletResponse response) {
    try {
        String login = principal.getName();
        User user = userService.user_findByLogin(login);
        //Check if the user is authorized
        if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            response.sendRedirect("../../accessDenied");

        }

        SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId);
        //set the exported survey definition status to Inactive
        surveyDefinition.setStatus(SurveyDefinitionStatus.I);

        String json = jsonHelperService.serializeSurveyDefinition(surveyDefinition);
        //response.setContentType("text/html; charset=utf-8");
        response.setContentType("application/octet-stream");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache,must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Content-Disposition", "inline;filename=surveyDef" + surveyDefinitionId + ".jsn");
        ServletOutputStream servletOutputStream = response.getOutputStream();
        servletOutputStream.write(json.getBytes("UTF-8"));
        servletOutputStream.flush();
        //Returning the original survey's status to Published.
        surveyDefinition.setStatus(SurveyDefinitionStatus.P);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:net.shopxx.plugin.alipayBankPayment.AlipayBankPaymentPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SystemUtils.getSetting();
    PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(sn);
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "create_direct_pay_by_user");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(PaymentPlugin.NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(PaymentPlugin.NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    String bank = request.getParameter(BANK_PARAMETER_NAME);
    parameterMap.put("defaultbank", StringUtils.isNotEmpty(bank) ? bank : DEFAULT_BANK);
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", paymentLog.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "bankPay");
    parameterMap.put("extend_param", "isv^1860648a1");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "shopxx");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:com.jd.survey.web.settings.SurveyDefinitionController.java

/**
 * Returns the survey logo image binary  
 * @param departmentId//from   w w  w . j av  a2 s . c o m
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/qr/{id}", produces = "text/html")
public void getSurveyQRCode(@PathVariable("id") Long surveyDefinitionId, Model uiModel, Principal principal,
        HttpServletRequest httpServletRequest, HttpServletResponse response) {
    try {
        uiModel.asMap().clear();
        User user = userService.user_findByLogin(principal.getName());
        //Check if the user is authorized
        if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            throw (new RuntimeException("Unauthorized access to logo"));
        }

        SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId);
        //String surveyLink =messageSource.getMessage(EXTERNAL_SITE_BASE_URL, null, LocaleContextHolder.getLocale());
        String surveyLink = externalBaseUrl;
        if (surveyDefinition.getIsPublic()) {
            if (surveyLink.endsWith("/")) {
                surveyLink = surveyLink + "open/" + surveyDefinitionId + "?list";
            } else {
                surveyLink = surveyLink + "/open/" + surveyDefinitionId + "?list";
            }
        } else {
            if (surveyLink.endsWith("/")) {
                surveyLink = surveyLink + "private/" + surveyDefinitionId + "?list";
            } else {
                surveyLink = surveyLink + "/private/" + surveyDefinitionId + "?list";
            }
        }

        response.setContentType("image/png");
        ServletOutputStream servletOutputStream = response.getOutputStream();

        QRCodeWriter writer = new QRCodeWriter();
        BitMatrix bitMatrix = null;
        try {
            bitMatrix = writer.encode(surveyLink, BarcodeFormat.QR_CODE, 600, 600);
            MatrixToImageWriter.writeToStream(bitMatrix, "png", servletOutputStream);

        } catch (WriterException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        servletOutputStream.flush();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:net.groupbuy.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);//w  w w . j  av a  2 s.  c  o m
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "groupbuy");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:net.shopxx.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);/*from  w ww.j av a 2  s .co m*/
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "shopxx");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:com.dp2345.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);/*  w w w. ja v  a  2 s .  c o m*/
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "dp2345");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:gov.guilin.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);/*from   w w  w. jav a  2s .c o  m*/
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "guilin");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:net.osxx.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);/* ww  w.j  av a2  s. c  o  m*/
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "osxx");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}

From source file:com.sammyun.plugin.alipayDual.AlipayDualPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    Setting setting = SettingUtils.get();
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);//from w w w.  ja  v a2 s . co m
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("service", "trade_create_by_buyer");
    parameterMap.put("partner", pluginConfig.getAttribute("partner"));
    parameterMap.put("_input_charset", "utf-8");
    parameterMap.put("sign_type", "MD5");
    parameterMap.put("return_url", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("notify_url", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("out_trade_no", sn);
    parameterMap.put("subject",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60));
    parameterMap.put("body",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600));
    parameterMap.put("payment_type", "1");
    parameterMap.put("logistics_type", "EXPRESS");
    parameterMap.put("logistics_fee", "0");
    parameterMap.put("logistics_payment", "SELLER_PAY");
    parameterMap.put("price", payment.getAmount().setScale(2).toString());
    parameterMap.put("quantity", "1");
    parameterMap.put("seller_id", pluginConfig.getAttribute("partner"));
    parameterMap.put("total_fee", payment.getAmount().setScale(2).toString());
    parameterMap.put("show_url", setting.getSiteUrl());
    parameterMap.put("paymethod", "directPay");
    parameterMap.put("exter_invoke_ip", request.getLocalAddr());
    parameterMap.put("extra_common_param", "preschoolEdu");
    parameterMap.put("sign", generateSign(parameterMap));
    return parameterMap;
}