forked from eclipse-ee4j/jersey
-
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.
HttpKeepAlive test + add http.keepAlive to externalProperties
Signed-off-by: tvallin <thibault.vallin@oracle.com>
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
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
70 changes: 70 additions & 0 deletions
70
...erties/src/test/java/org/glassfish/jersey/tests/externalproperties/HttpKeepAliveTest.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,70 @@ | ||
package org.glassfish.jersey.tests.externalproperties; | ||
|
||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.handler.AbstractHandler; | ||
import org.glassfish.jersey.ExternalProperties; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class HttpKeepAliveTest { | ||
|
||
private final String SERVER_URI = "http://localhost:9997/"; | ||
private final String CONNECTION_HEADER = "Connection"; | ||
private final String RESPONSE_HEADER = "result"; | ||
private final String FALSE = "false"; | ||
private final int PORT = 9997; | ||
private Server server; | ||
|
||
@Test | ||
public void testHttpKeepAlive() { | ||
System.setProperty(ExternalProperties.HTTP_KEEPALIVE, FALSE); | ||
|
||
Response response = ClientBuilder.newClient().target(SERVER_URI).request().get(); | ||
|
||
Object result = response.getHeaders().getFirst(RESPONSE_HEADER); | ||
|
||
Assert.assertEquals(200, response.getStatus()); | ||
Assert.assertEquals("close", result.toString()); | ||
} | ||
|
||
@Before | ||
public void startHandler() { | ||
server = new Server(PORT); | ||
server.setHandler(new CustomHandler()); | ||
try { | ||
server.start(); | ||
} catch (Exception e) { | ||
} | ||
} | ||
|
||
@After | ||
public void stopHandler() { | ||
try { | ||
server.stop(); | ||
} catch (Exception e) { | ||
|
||
} | ||
} | ||
|
||
class CustomHandler extends AbstractHandler { | ||
@Override | ||
public void handle(String target, | ||
Request baseRequest, | ||
HttpServletRequest request, | ||
HttpServletResponse response) { | ||
|
||
response.setStatus(200); | ||
response.addHeader(RESPONSE_HEADER, request.getHeader(CONNECTION_HEADER)); | ||
baseRequest.setHandled(true); | ||
} | ||
} | ||
|
||
} |
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