Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-8152 Micro Maven - Devmode - Store session state #284

Merged
merged 3 commits into from
Jan 23, 2024
Merged

FISH-8152 Micro Maven - Devmode - Store session state #284

merged 3 commits into from
Jan 23, 2024

Conversation

jGauravGupta
Copy link
Contributor

@jGauravGupta jGauravGupta commented Jan 16, 2024

This pull request enhances the Micro Maven plugin for Payara Micro by introducing a new configuration property, keepState. This property allows for the persistence of session state across multiple redeployments during the development process. By default, the keepState property is set to false for the start mojo and true for the dev mojo.

Use Case Testing

To validate this enhancement, a test servlet (NewServlet) has been created. The servlet utilizes the HttpSession to store and increment a session attribute ("count") with each request. The keepState property ensures that the session state is maintained across auto-reload processes, providing a seamless development experience for session-dependent functionalities.

Instructions for Testing

Build Payara Micro v5.59.0-SNAPSHOT:

https://github.com/payara/Payara-Enterprise/pull/1067

Create the Test Servlet:

Utilize the provided NewServlet class in your project.
This servlet handles GET requests, maintains a session count, and responds with the updated count.


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet(name = "NewServlet", urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            response.setContentType("text/html;charset=UTF-8");
            HttpSession session = request.getSession(true);
            Integer count = (Integer) session.getAttribute("count");
            if (count == null) {
                count = 1;
            } else {
                count++;
            }
            session.setAttribute("count", count);
            out.println("Session Count: " + count);
        }
    }

}

Start Payara Micro Instance:

Use the following command to activate dev mode:

mvn install payara-micro:dev -DpayaraVersion=5.59.0-SNAPSHOT

Alternatively, for auto-deploy with hot-deploy, use the following command:

mvn install payara-micro:start -DautoDeploy=true -DliveReload=true -DdeployWar=true -Dexploded=true -DkeepState=true - DpayaraVersion=5.59.0-SNAPSHOT

The addition of the keepState property enhances the development workflow with the Micro Maven plugin, providing flexibility in managing session state persistence.

Depends on:

Payara Community 6 - payara/Payara#6526
Payara Enterprise 5 - https://github.com/payara/Payara-Enterprise/pull/1067
Payara Enterprise 6 - https://payara.atlassian.net/browse/FISH-8213

@jGauravGupta jGauravGupta added this to the 2.1 milestone Jan 19, 2024
Copy link

@luiseufrasio luiseufrasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to test with hot deploy activated I had this error when saving a file in the project: [2024-01-21T20:33:29.796-0300] [] [INFO] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1705880009796] [levelValue: 800] Payara Micro 6 #badassmicrofish (build 883) ready in 10,351 (ms)

[ERROR]
org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=120.0.6099.225)
Build info: version: '4.16.1', revision: '9b4c83354e'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.17'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [02f91b1e1549a23c4228fc400de8842a, executeScript {script=document.title = 'Building HelloDev-1.0-SNAPSHOT';, args=[]}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 120.0.6099.225, chrome: {chromedriverVersion: 120.0.6099.109 (3419140ab66..., userDataDir: C:\Users\luise\AppData\Loca...}, f
edcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:53213}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(), se:cdp: ws://localhost:53213/
devtoo..., se:cdpVersion: 120.0.6099.225, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 02f91b1e1549a23c4228fc400de8842a
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance (Constructor.java:490)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException (W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:52)
at org.openqa.selenium.remote.HttpCommandExecutor.execute (HttpCommandExecutor.java:191)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute (DriverCommandExecutor.java:200)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute (DriverCommandExecutor.java:175)
at org.openqa.selenium.remote.RemoteWebDriver.execute (RemoteWebDriver.java:523)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript (RemoteWebDriver.java:468)
at fish.payara.maven.plugins.micro.AutoDeployHandler.updateTitle (AutoDeployHandler.java:350)
at fish.payara.maven.plugins.micro.AutoDeployHandler.run (AutoDeployHandler.java:200)
at java.lang.Thread.run (Thread.java:829)

Copy link

@aubi aubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm, Linux, OpenJDK 11

Copy link

@luiseufrasio luiseufrasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jGauravGupta jGauravGupta merged commit 908cef3 into payara:master Jan 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants