Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 440fd46

Browse files
author
Marek Potociar
committed
Removed unused import & E2E test fix attempt.
- ResourceMethodInvoker had an unused import. - Attempted a fix for frequently failing SSL tests: - added better synchronisation for variables storing the test SSL-secured HTTP server instances - selected a safer default port for the test SSL-secured HTTP server Change-Id: I711bb73ea7374f3d7d05fae06405e93ac197fe70 Signed-off-by: Marek Potociar <[email protected]>
1 parent 3185fb9 commit 440fd46

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

core-server/src/main/java/org/glassfish/jersey/server/model/ResourceMethodInvoker.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import org.glassfish.jersey.server.model.internal.ResourceMethodDispatcherFactory;
8484
import org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory;
8585
import org.glassfish.jersey.server.monitoring.RequestEvent;
86-
import org.glassfish.jersey.server.spi.ValidationInterceptor;
8786
import org.glassfish.jersey.server.spi.internal.ResourceMethodDispatcher;
8887
import org.glassfish.jersey.server.spi.internal.ResourceMethodInvocationHandlerProvider;
8988

tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/client/connector/ssl/Server.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.io.IOException;
4343
import java.io.InputStream;
4444
import java.net.URI;
45-
import java.util.logging.Level;
4645
import java.util.logging.Logger;
4746

4847
import javax.ws.rs.core.UriBuilder;
@@ -66,20 +65,21 @@ final class Server {
6665

6766
private static final String SERVER_TRUST_STORE = "truststore_server";
6867
private static final String SERVER_KEY_STORE = "keystore_server";
69-
private static HttpServer webServer;
7068
private static final Logger LOGGER = Logger.getLogger(Server.class.getName());
7169

7270
/**
7371
* Base server URI.
7472
*/
7573
public static final URI BASE_URI = getBaseURI();
7674

77-
private Server() {
78-
throw new AssertionError("Instantiation not allowed.");
75+
private final HttpServer webServer;
76+
77+
private Server(final HttpServer webServer) {
78+
this.webServer = webServer;
7979
}
8080

8181
private static URI getBaseURI() {
82-
return UriBuilder.fromUri("https://localhost/").port(getPort(4463)).build();
82+
return UriBuilder.fromUri("https://localhost/").port(getPort(8463)).build();
8383
}
8484

8585
private static int getPort(int defaultPort) {
@@ -100,8 +100,9 @@ private static int getPort(int defaultPort) {
100100
* Start SSL-secured HTTP test server.
101101
*
102102
* @throws IOException in case there is an error while reading server key store or trust store.
103+
* @return an instance of the started SSL-secured HTTP test server.
103104
*/
104-
static void startServer() throws IOException {
105+
public static Server start() throws IOException {
105106
final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
106107
final InputStream keyStore = Server.class.getResourceAsStream(SERVER_KEY_STORE);
107108

@@ -118,27 +119,24 @@ static void startServer() throws IOException {
118119
rc.register(new LoggingFilter(LOGGER, true));
119120
rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
120121

121-
try {
122-
webServer = GrizzlyHttpServerFactory.createHttpServer(
123-
getBaseURI(),
124-
rc,
125-
true,
126-
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true)
127-
);
122+
final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(
123+
getBaseURI(),
124+
rc,
125+
true,
126+
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true)
127+
);
128128

129-
// start Grizzly embedded server //
130-
LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
131-
webServer.start();
129+
// start Grizzly embedded server //
130+
LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
131+
grizzlyServer.start();
132132

133-
} catch (Exception ex) {
134-
LOGGER.log(Level.SEVERE, "Error while starting the server.", ex);
135-
}
133+
return new Server(grizzlyServer);
136134
}
137135

138136
/**
139137
* Stop SSL-secured HTTP test server.
140138
*/
141-
static void stopServer() {
139+
public void stop() {
142140
webServer.shutdownNow();
143141
}
144142
}

tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/client/connector/ssl/SslConnectorConfigurationTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class SslConnectorConfigurationTest {
9090
*/
9191
@Parameterized.Parameters(name = "{index}: {0}")
9292
public static Iterable<Object[]> testData() {
93-
return Arrays.asList(new Object[][]{
93+
return Arrays.asList(new Object[][] {
9494
{new HttpUrlConnectorProvider()},
9595
{new GrizzlyConnectorProvider()},
9696
{new JettyConnectorProvider()},
@@ -101,14 +101,29 @@ public static Iterable<Object[]> testData() {
101101
@Parameterized.Parameter(0)
102102
public ConnectorProvider connectorProvider;
103103

104+
private final Object serverGuard = new Object();
105+
private Server server = null;
106+
104107
@Before
105108
public void setUp() throws Exception {
106-
Server.startServer();
109+
synchronized (serverGuard) {
110+
if (server != null) {
111+
throw new IllegalStateException(
112+
"Test run sync issue: Another instance of the SSL-secured HTTP test server has been already started.");
113+
}
114+
server = Server.start();
115+
}
107116
}
108117

109118
@After
110119
public void tearDown() throws Exception {
111-
Server.stopServer();
120+
synchronized (serverGuard) {
121+
if (server == null) {
122+
throw new IllegalStateException("Test run sync issue: There is no SSL-secured HTTP test server to stop.");
123+
}
124+
server.stop();
125+
server = null;
126+
}
112127
}
113128

114129
private static SSLContext getSslContext() throws IOException {

0 commit comments

Comments
 (0)