forked from dropwizard/dropwizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for Jetty session support (dropwizard#4681)
Add a documentation section on session support and provide an e2e test explaining how to use it.
- Loading branch information
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
dropwizard-e2e/src/main/java/com/example/httpsessions/HttpSessionsApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.httpsessions; | ||
|
||
import io.dropwizard.Application; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.setup.Environment; | ||
import org.eclipse.jetty.server.session.SessionHandler; | ||
|
||
public class HttpSessionsApp extends Application<Configuration> { | ||
@Override | ||
public void run(Configuration configuration, Environment environment) throws Exception { | ||
environment.servlets().setSessionHandler(new SessionHandler()); | ||
environment.jersey().register(new HttpSessionsResource()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
dropwizard-e2e/src/main/java/com/example/httpsessions/HttpSessionsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.httpsessions; | ||
|
||
import io.dropwizard.jersey.sessions.Session; | ||
|
||
import javax.servlet.http.HttpSession; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/") | ||
public class HttpSessionsResource { | ||
@GET | ||
@Path("session") | ||
public Response isSessionInjected(@Session HttpSession httpSession) { | ||
return Response.ok(httpSession != null).build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dropwizard-e2e/src/test/java/com/example/httpsessions/HttpSessionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.httpsessions; | ||
|
||
import io.dropwizard.Configuration; | ||
import io.dropwizard.testing.ResourceHelpers; | ||
import io.dropwizard.testing.junit5.DropwizardAppExtension; | ||
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(DropwizardExtensionsSupport.class) | ||
class HttpSessionsTest { | ||
public static final DropwizardAppExtension<Configuration> RULE = | ||
new DropwizardAppExtension<>(HttpSessionsApp.class, ResourceHelpers.resourceFilePath("httpsessions/config.yml")); | ||
|
||
@Test | ||
void testInjectedSessionsIsNotNull() { | ||
Boolean sessionNotNull = RULE.client().target(String.format("http://localhost:%d/session", RULE.getLocalPort())).request().get(Boolean.class); | ||
assertThat(sessionNotNull).isNotNull().isTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
server: | ||
applicationConnectors: | ||
- type: http | ||
port: 0 | ||
adminConnectors: | ||
- type: http | ||
port: 0 |