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:com.sammyun.plugin.pay99billBank.Pay99billBankPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    Payment payment = getPayment(sn);//from   w w  w . j av  a2 s .c o  m
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("inputCharset", "1");
    parameterMap.put("pageUrl", getNotifyUrl(sn, NotifyMethod.sync));
    parameterMap.put("bgUrl", getNotifyUrl(sn, NotifyMethod.async));
    parameterMap.put("version", "v2.0");
    parameterMap.put("language", "1");
    parameterMap.put("signType", "1");
    parameterMap.put("merchantAcctId", pluginConfig.getAttribute("partner"));
    parameterMap.put("payerIP", request.getLocalAddr());
    parameterMap.put("orderId", sn);
    parameterMap.put("orderAmount", payment.getAmount().multiply(new BigDecimal(100)).setScale(0).toString());
    parameterMap.put("orderTime", new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
    parameterMap.put("orderTimestamp", new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
    parameterMap.put("productName",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 100));
    parameterMap.put("productDesc",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 400));
    parameterMap.put("ext1", "preschoolEdu");
    parameterMap.put("payType", "10");
    String bank = request.getParameter(BANK_PARAMETER_NAME);
    parameterMap.put("bankId", StringUtils.isNotEmpty(bank) ? bank : DEFAULT_BANK);
    parameterMap.put("signMsg", generateSign(parameterMap));
    return parameterMap;
}

From source file:net.shopxx.plugin.pay99billPayment.Pay99billPaymentPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(sn);
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("inputCharset", "1");
    parameterMap.put("pageUrl", getNotifyUrl(PaymentPlugin.NotifyMethod.sync));
    parameterMap.put("bgUrl", getNotifyUrl(PaymentPlugin.NotifyMethod.async));
    parameterMap.put("version", "v2.0");
    parameterMap.put("language", "1");
    parameterMap.put("signType", "1");
    parameterMap.put("merchantAcctId", pluginConfig.getAttribute("partner"));
    parameterMap.put("payerIP", request.getLocalAddr());
    parameterMap.put("orderId", sn);
    parameterMap.put("orderAmount",
            paymentLog.getAmount().multiply(new BigDecimal(100)).setScale(0).toString());
    parameterMap.put("orderTime", DateFormatUtils.format(new Date(), "yyyyMMddhhmmss"));
    parameterMap.put("orderTimestamp", DateFormatUtils.format(new Date(), "yyyyMMddhhmmss"));
    parameterMap.put("productName",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 100));
    parameterMap.put("productDesc",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 400));
    parameterMap.put("ext1", "shopxx");
    parameterMap.put("payType", "00");
    parameterMap.put("signMsg", generateSign(parameterMap));
    return parameterMap;
}

From source file:net.shopxx.plugin.pay99billBankPayment.Pay99billBankPaymentPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(sn);
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("inputCharset", "1");
    parameterMap.put("pageUrl", getNotifyUrl(PaymentPlugin.NotifyMethod.sync));
    parameterMap.put("bgUrl", getNotifyUrl(PaymentPlugin.NotifyMethod.async));
    parameterMap.put("version", "v2.0");
    parameterMap.put("language", "1");
    parameterMap.put("signType", "1");
    parameterMap.put("merchantAcctId", pluginConfig.getAttribute("partner"));
    parameterMap.put("payerIP", request.getLocalAddr());
    parameterMap.put("orderId", sn);
    parameterMap.put("orderAmount",
            paymentLog.getAmount().multiply(new BigDecimal(100)).setScale(0).toString());
    parameterMap.put("orderTime", DateFormatUtils.format(new Date(), "yyyyMMddhhmmss"));
    parameterMap.put("orderTimestamp", DateFormatUtils.format(new Date(), "yyyyMMddhhmmss"));
    parameterMap.put("productName",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 100));
    parameterMap.put("productDesc",
            StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 400));
    parameterMap.put("ext1", "shopxx");
    parameterMap.put("payType", "10");
    String bank = request.getParameter(BANK_PARAMETER_NAME);
    parameterMap.put("bankId", StringUtils.isNotEmpty(bank) ? bank : DEFAULT_BANK);
    parameterMap.put("signMsg", generateSign(parameterMap));
    return parameterMap;
}

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

/**
 * prepares the page to import a dataset from a csv file       
 * @param dataSetId/*from   ww w.j a v a  2  s .  c om*/
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/{id}", params = "import", produces = "text/html")
public String prepareForImport(@PathVariable("id") Long dataSetId, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    try {
        String login = principal.getName();
        User user = userService.user_findByLogin(login);
        if (!user.isAdmin()) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        uiModel.addAttribute("dataSet", surveySettingsService.dataSet_findById(dataSetId));
        return "settings/datasets/upload";
    }

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

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

@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, Principal principal, Model uiModel,
        HttpServletRequest httpServletRequest) {
    log.info("delete(): id=" + id);
    try {/*w  ww . ja  v  a2  s.  c  om*/
        User user = userService.user_findByLogin(principal.getName());
        if (!user.isAdmin()) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";

        }
        surveySettingsService.dataSet_remove(id);
        return "redirect:/settings/datasets";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:com.jd.survey.web.statistics.StatisticsController.java

/**
 * export the single Survey to a PDF //from  ww w  .  java2s.  com
 * @param surveyId
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/pdf/{id}", produces = "text/html")
public ModelAndView exportSurveyToPdf(@PathVariable("id") Long surveyDefinitionId, Principal principal,
        HttpServletRequest httpServletRequest, HttpServletResponse response) {

    try {

        User user = userService.user_findByLogin(principal.getName());
        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"));
        }
        ModelAndView modelAndView = new ModelAndView("statisticsPdf");

        Map<String, String> messages = new TreeMap<String, String>();

        messages.put("surveyLabel",
                messageSource.getMessage(SURVEY_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("totalLabel",
                messageSource.getMessage(TOTAL_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("completedLabel",
                messageSource.getMessage(COMPLETED_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("optionFrequencyLabel",
                messageSource.getMessage(OPTION_FREQUENCY_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("noStatstisticsMessage",
                messageSource.getMessage(NO_STATSTISTICS_MESSAGE, null, LocaleContextHolder.getLocale()));

        messages.put("pageLabel", messageSource.getMessage(PAGE_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("optionLabel",
                messageSource.getMessage(OPTION_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("minimumLabel",
                messageSource.getMessage(MINIMUM_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("maximumLabel",
                messageSource.getMessage(MAXIMUM_LABEL, null, LocaleContextHolder.getLocale()));

        messages.put("averageLabel",
                messageSource.getMessage(AVERAGE_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("standardDeviationLabel",
                messageSource.getMessage(STANDARD_DEVIATION_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("date_format",
                messageSource.getMessage(DATE_FORMAT, null, LocaleContextHolder.getLocale()));
        messages.put("falseLabel",
                messageSource.getMessage(FALSE_LABEL, null, LocaleContextHolder.getLocale()));
        messages.put("trueLabel", messageSource.getMessage(TRUE_LABEL, null, LocaleContextHolder.getLocale()));

        SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(surveyDefinitionId);
        SurveyStatistic surveyStatistic = surveyService.surveyStatistic_get(surveyDefinitionId);
        Long recordCount = surveyStatistic.getSubmittedCount();
        modelAndView.addObject("surveyDefinition", surveyDefinition);
        modelAndView.addObject("surveyStatistic", surveyStatistic);
        modelAndView.addObject("messages", messages);
        Map<String, List<QuestionStatistic>> allquestionStatistics = new TreeMap<String, List<QuestionStatistic>>();

        for (SurveyDefinitionPage page : surveyDefinition.getPages()) {
            for (Question question : page.getQuestions()) {
                List<QuestionStatistic> questionStatistics = surveyService
                        .questionStatistic_getStatistics(question, recordCount);
                allquestionStatistics.put("q" + question.getId().toString(), questionStatistics);
            }
        }
        modelAndView.addObject("allquestionStatistics", allquestionStatistics);
        return modelAndView;

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

From source file:com.jd.survey.web.surveys.SurveyController.java

/**
 * Shows a list of Survey Entries for a Survey Definition, Supports Paging 
 * @param surveyId/*from  w w  w. j a  v a2  s  . c  o m*/
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/list", produces = "text/html", method = RequestMethod.GET)
public String listSurveyEntries(@RequestParam(value = "id", required = true) Long surveyDefinitionId,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size, Model uiModel, Principal principal,
        HttpServletRequest httpServletRequest) {
    try {
        User user = userService.user_findByLogin(principal.getName());
        Set<SurveyDefinition> surveyDefinitions = surveySettingsService
                .surveyDefinition_findAllCompletedInternal(user);

        if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }

        uiModel.addAttribute("surveyDefinitions", surveyDefinitions);
        uiModel.addAttribute("surveyDefinition",
                surveySettingsService.surveyDefinition_findById(surveyDefinitionId));
        uiModel.addAttribute("surveyStatistic", surveyService.surveyStatistic_get(surveyDefinitionId));
        int sizeNo = size == null ? 25 : size.intValue();
        final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
        Set<SurveyEntry> surveyEntries = surveyService.surveyEntry_getAll(surveyDefinitionId, firstResult,
                sizeNo);
        float nrOfPages = (float) surveyService.surveyEntry_getCount(surveyDefinitionId) / sizeNo;
        int maxPages = (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages);
        uiModel.addAttribute("maxPages", maxPages);
        uiModel.addAttribute("surveyEntries", surveyEntries);
        return "surveys/entries";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

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

/**
 * Shows the list of Survey Invitations for a Survey Definition, Supports Paging 
 * @param surveyId// w  ww.j av a  2s  . c om
 * @param principal
 * @param uiModel
 * @param httpServletRequest
 * @return
 */
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" })
@RequestMapping(value = "/list", produces = "text/html", method = RequestMethod.GET)
public String listSurveyInvitations(@RequestParam(value = "id", required = true) Long surveyDefinitionId,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size,
        @RequestParam(value = "fileContentError", required = false) boolean contentError, Model uiModel,
        Principal principal, HttpServletRequest httpServletRequest) {

    try {
        User user = userService.user_findByLogin(principal.getName());

        if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        Set<SurveyDefinition> surveyDefinitions = surveySettingsService
                .surveyDefinition_findAllCompletedInternal(user);
        uiModel.addAttribute("surveyDefinitions", surveyDefinitions);
        uiModel.addAttribute("surveyDefinition",
                surveySettingsService.surveyDefinition_findById(surveyDefinitionId));
        Long surveyInvitationsCount = surveySettingsService.invitation_getSurveyCount(surveyDefinitionId);
        uiModel.addAttribute("surveyInvitationsCount", surveyInvitationsCount);
        uiModel.addAttribute("surveyInvitationsOpenedCount",
                surveySettingsService.invitation_getSurveyOpenedCount(surveyDefinitionId));

        int sizeNo = size == null ? 25 : size.intValue();
        final int firstResult = page == null ? 0 : (page.intValue() - 1) * sizeNo;
        Set<Invitation> invitations = surveySettingsService.invitation_findSurveyAll(surveyDefinitionId,
                firstResult, sizeNo);
        float nrOfPages = (float) surveyInvitationsCount / sizeNo;
        int maxPages = (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages);
        uiModel.addAttribute("maxPages", maxPages);
        uiModel.addAttribute("invitations", invitations);
        uiModel.addAttribute("fileContentError", contentError);// Used to carry error from file upload over and make it available to the view
        return "settings/invitations/invitations";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

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

@Secured({ "ROLE_ADMIN" })
@RequestMapping(params = "create", produces = "text/html")
public String createDataSet(Principal principal, Model uiModel, HttpServletRequest httpServletRequest) {
    log.info("createForm(): handles param form");
    try {/* www.j  a v  a 2  s .  c  o m*/
        User user = userService.user_findByLogin(principal.getName());
        if (!user.isAdmin()) {
            log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo()
                    + " attempted by user login:" + principal.getName() + "from IP:"
                    + httpServletRequest.getLocalAddr());
            return "accessDenied";
        }
        DataSet dataSet = new DataSet();
        populateEditForm(uiModel, dataSet, user);
        return "settings/datasets/create";
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }
}

From source file:br.com.fatecpg.core.common.ApplicationExceptionHandler.java

@Override
public ModelAndView resolveException(HttpServletRequest hsr, HttpServletResponse hsr1, Object o,
        Exception excptn) {/* w w w .  j  a v  a 2s.  c om*/

    Log log = new Log();

    String message = excptn.getMessage();
    String username = null;

    if (message == null || message.isEmpty()) {
        message = "Erro de aplicao.";
    }

    if (hsr.getSession() != null) {
        Object obj = hsr.getSession().getAttribute("student");
        if (obj != null) {
            Student student = (Student) obj;
            username = student.getEnrollment();
        }
    }

    log.setApplicationName(this.applicationName);
    log.setCreatedDate(new Date());
    log.setDetails(CommonHelper.formatStackTraceToString(excptn));
    log.setIpAddress(hsr.getLocalAddr());
    log.setMessage(message);
    log.setUrl(hsr.getRequestURI());
    log.setUsername(username);

    try {
        logRepository.add(log);
    } catch (Exception ex) {
    }

    ErrorModel model = new ErrorModel();
    model.setLogId(log.getId());
    model.setMessage(log.getMessage());

    if (WebHelper.isAjaxRequest(hsr)) {
        hsr1.setStatus(500);
        hsr1.setContentType("text/html");
        return new ModelAndView("/shared/_error", "model", model);
    } else {
        return new ModelAndView("/shared/error", "model", model);
    }

}