|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
22 | 22 |
|
| 23 | +import io.undertow.UndertowMessages; |
23 | 24 | import io.undertow.server.HttpHandler;
|
24 | 25 | import io.undertow.server.HttpServerExchange;
|
25 | 26 | import io.undertow.server.session.InMemorySessionManager;
|
@@ -190,7 +191,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
|
190 | 191 | Runnable r = new Runnable() {
|
191 | 192 | public void run() {
|
192 | 193 | Session innerThreadSession = manager.getSession(exchange, sessionConfig);
|
193 |
| - int iterations = ((maxInactiveIntervalInSeconds * 1000)/accessorThreadSleepInMilliseconds); |
| 194 | + int iterations = ((maxInactiveIntervalInSeconds * 1000) / accessorThreadSleepInMilliseconds); |
194 | 195 | for (int i = 0; i <= iterations; i++) {
|
195 | 196 | try {
|
196 | 197 | Thread.sleep(accessorThreadSleepInMilliseconds);
|
@@ -249,4 +250,30 @@ public void run() {
|
249 | 250 | client.getConnectionManager().shutdown();
|
250 | 251 | }
|
251 | 252 | }
|
| 253 | + |
| 254 | + @Test |
| 255 | + public void inMemorySessionNoConfigTest() throws IOException { |
| 256 | + try (TestHttpClient client = new TestHttpClient()) { |
| 257 | + client.setCookieStore(new BasicCookieStore()); |
| 258 | + |
| 259 | + final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), null); |
| 260 | + handler.setNext(new HttpHandler() { |
| 261 | + @Override |
| 262 | + public void handleRequest(final HttpServerExchange exchange) throws Exception { |
| 263 | + final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY); |
| 264 | + |
| 265 | + IllegalStateException thrown = Assert.assertThrows(IllegalStateException.class, () -> { |
| 266 | + manager.getSession(exchange, null); |
| 267 | + }); |
| 268 | + |
| 269 | + Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getCause(), thrown.getCause()); |
| 270 | + Assert.assertEquals(UndertowMessages.MESSAGES.couldNotFindSessionCookieConfig().getMessage(), thrown.getMessage()); |
| 271 | + } |
| 272 | + }); |
| 273 | + DefaultServer.setRootHandler(handler); |
| 274 | + |
| 275 | + HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/notamatchingpath"); |
| 276 | + client.execute(get); |
| 277 | + } |
| 278 | + } |
252 | 279 | }
|
0 commit comments