Example usage for org.springframework.web.servlet.view RedirectView setStatusCode

List of usage examples for org.springframework.web.servlet.view RedirectView setStatusCode

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view RedirectView setStatusCode.

Prototype

public void setStatusCode(HttpStatus statusCode) 

Source Link

Document

Set the status code for this view.

Usage

From source file:org.ow2.proactive.inmemory_keyvalue_store.controller.SwaggerController.java

@RequestMapping("/")
public ModelAndView swagger() {
    RedirectView redirectView = new RedirectView("swagger-ui.html");
    redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    return new ModelAndView(redirectView);
}

From source file:ru.mystamps.web.controller.AccountController.java

@GetMapping(Url.ACTIVATE_ACCOUNT_PAGE_WITH_KEY)
public View showActivationFormWithKey(@PathVariable("key") String activationKey,
        RedirectAttributes redirectAttributes) {

    redirectAttributes.addAttribute("key", activationKey);

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.ACTIVATE_ACCOUNT_PAGE);

    return view;/*from  w  w  w . j  av a  2  s  .  c om*/
}

From source file:ru.mystamps.web.controller.CategoryController.java

@GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE)
public View showInfoById(@Category @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }/*from w w  w.  j  a  v a  2 s .  c o  m*/

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_CATEGORY_PAGE);

    return view;
}

From source file:ru.mystamps.web.controller.CollectionController.java

@GetMapping(Url.INFO_COLLECTION_BY_ID_PAGE)
public View showInfoById(@PathVariable("slug") String slug, HttpServletResponse response) throws IOException {

    if (slug == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }//from  w ww  .j  a  v a  2 s.  c om

    CollectionInfoDto collection = collectionService.findBySlug(slug);
    if (collection == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_COLLECTION_PAGE);

    return view;
}

From source file:ru.mystamps.web.controller.CountryController.java

/**
 * @author Aleksander Parkhomenko// ww  w.  jav  a2 s .c  o m
 */
@GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE)
public View showInfoById(@Country @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_COUNTRY_PAGE);

    return view;
}

From source file:ru.mystamps.web.controller.SeriesController.java

@GetMapping(Url.ADD_SERIES_WITH_CATEGORY_PAGE)
public View showFormWithCategory(@PathVariable("slug") String category, RedirectAttributes redirectAttributes) {

    redirectAttributes.addAttribute("category", category);

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.ADD_SERIES_PAGE);/* w ww . jav  a 2  s . c  o m*/

    return view;
}

From source file:ru.mystamps.web.controller.SeriesController.java

@GetMapping(Url.ADD_SERIES_WITH_COUNTRY_PAGE)
public View showFormWithCountry(@PathVariable("slug") String country, RedirectAttributes redirectAttributes) {

    redirectAttributes.addAttribute("country", country);

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.ADD_SERIES_PAGE);/*from   www . j  ava2s  . c  o  m*/

    return view;
}

From source file:net.canadensys.dataportal.occurrence.controller.OccurrenceController.java

/**
 * Resource contact message feedback sending form.
 * /*w ww. j a  v a  2 s.c o m*/
 * @param ipt
 *            resource identifier (sourcefileid).
 * @return
 */
@RequestMapping(value = "/feedback", method = RequestMethod.POST)
@I18nTranslation(resourceName = "feedback", translateFormat = "/feedback")
public ModelAndView handleFeedbackMsg(HttpServletRequest request) {
    // URL from the previous URL accessed that led to the contact form:
    Locale locale = RequestContextUtils.getLocale(request);
    HashMap<String, Object> modelRoot = new HashMap<String, Object>();

    // Set common stuff
    ControllerHelper.setPageHeaderVariables(request, "feedback", new String[] {}, appConfig, modelRoot);

    Map<String, Object> templateData = new HashMap<String, Object>();

    String namefrom = request.getParameter("name");
    String mailfrom = request.getParameter("email");
    String message = request.getParameter("message");
    String subject = request.getParameter("subject");
    String mailto = request.getParameter("mailto");
    LOGGER.error("*** " + subject);
    templateData.put("mailfrom", mailfrom);
    templateData.put("namefrom", namefrom);
    templateData.put("message", message);
    templateData.put("time", new SimpleDateFormat("EEEE, dd-MM-yyyy HH:mm z", locale).format(new Date()));
    String templateName = appConfig.getContactEmailTemplateName(locale);
    mailSender.sendMessage(mailto, subject, templateData, templateName);

    // Redirect back to main page
    RedirectView rv = new RedirectView(request.getContextPath());
    rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    return new ModelAndView(rv);
}

From source file:net.canadensys.dataportal.occurrence.controller.OccurrenceController.java

/**
 * Resource contact message sending form.
 * /*from w  w w.  j ava 2s .c om*/
 * @param ipt
 *            resource identifier (sourcefileid).
 * @return
 */
@RequestMapping(value = "/occurrences/{auto_id}", method = RequestMethod.POST)
@I18nTranslation(resourceName = "occurrence", translateFormat = "/occurrences/{}")
public ModelAndView handleResourceContactMsg(@PathVariable String auto_id, HttpServletRequest request) {
    OccurrenceModel occModel = occurrenceService.loadOccurrenceModel(auto_id, true);
    ResourceMetadataModel resourceInformationModel = occurrenceService
            .loadResourceMetadataModel(occModel.getSourcefileid());
    // Get resource contacts:
    Set<ContactModel> contacts = resourceInformationModel.getContacts();

    // URL from the previous URL accessed that led to the contact form:
    Locale locale = RequestContextUtils.getLocale(request);
    HashMap<String, Object> modelRoot = new HashMap<String, Object>();

    // Get full URL:
    String occurrenceUrl = I18nUrlBuilder.generateI18nResourcePath(locale.getLanguage(),
            OccurrencePortalConfig.I18N_TRANSLATION_HANDLER.getTranslationFormat("occurrence"),
            new String[] { auto_id });
    String domainName = request.getParameter("domainName");
    occurrenceUrl = domainName + request.getContextPath() + occurrenceUrl;
    // Set common stuff
    ControllerHelper.setPageHeaderVariables(request, "contact", new String[] { auto_id }, appConfig, modelRoot);

    Map<String, Object> templateData = new HashMap<String, Object>();
    ContactModel contact = null;
    for (ContactModel rcm : contacts) {
        if (rcm.getRole().equalsIgnoreCase("contact")) {
            contact = rcm;
            // Add contacts information
            modelRoot.put("contact", contact);
            break;
        }
    }

    String mailto = contact.getEmail();
    String nameto = contact.getName();

    if (mailto != null && !mailto.equalsIgnoreCase("")) {
        String namefrom = request.getParameter("name");
        String mailfrom = request.getParameter("email");
        String message = request.getParameter("message");
        // Later change to fetch from properties file
        // (resourcecontact.subject).
        String subject = request.getParameter("subject");
        templateData.put("subject", subject);
        templateData.put("mailto", mailto);
        templateData.put("nameto", nameto);
        templateData.put("mailfrom", mailfrom);
        templateData.put("namefrom", namefrom);
        templateData.put("message", message);
        templateData.put("occurrenceUrl", occurrenceUrl);
        templateData.put("time", new SimpleDateFormat("EEEE, dd-MM-yyyy HH:mm z", locale).format(new Date()));
        String templateName = appConfig.getContactEmailTemplateName(locale);
        boolean sent = mailSender.sendMessage(mailto, subject, templateData, templateName);
        LOGGER.error("*** Email enviado para o publicador: " + sent);
    }
    // Redirect back to occurrence:

    RedirectView rv = new RedirectView(occurrenceUrl);
    rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    return new ModelAndView(rv);
}