All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almis.awe.test.controller.SessionController Maven / Gradle / Ivy

There is a newer version: 0.0.13
Show newest version
package com.almis.awe.test.controller;

import com.almis.awe.model.component.AweSession;
import com.almis.awe.session.AweSessionDetails;
import com.almis.awe.test.listener.TestSessionListener;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by dfuentes on 29/05/2017.
 */
@Controller
@RequestMapping ("/session")
@Profile({"dev", "gitlab-ci"})
public class SessionController {

  @Autowired
  private AweSession session;

  @Autowired
  private AweSessionDetails aweSessionDetails;

  @Autowired
  private HttpSession httpSession;

  /**
   * Set session parameter
   * @param name Key
   * @param value Value
   * @return set
   */
  @PostMapping("/set/{name}")
  @ResponseBody
  public String setParameter(@PathVariable("name") String name, @RequestParam("value") String value) {

    // Initialize parameters
    session.setParameter(name, value);

    // Launch action
    return name + " = " + value;
  }

  /**
   * Get session parameter
   * @param name Parameter
   * @return Value
   */
  @GetMapping("/get/{name}")
  @ResponseBody
  public String getParameter(@PathVariable("name") String name) {

    // Launch action
    return (String) session.getParameter(name);
  }

  /**
   * Get session parameter
   * @param name Parameter
   * @return Value
   */
  @GetMapping("/remove/{name}")
  @ResponseBody
  public String removeParameter(@PathVariable("name") String name) {

    // Remove parameter
    session.removeParameter(name);

    // Launch action
    return name + " removed";
  }

  /**
   * Invalidate session
   * @return Value
   */
  @GetMapping("/invalidate")
  @ResponseBody
  public String invalidate(HttpServletRequest request) {
    TestSessionListener.getAllSessions().values().forEach(HttpSession::invalidate);

    // Return string
    return "session invalidated";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy