Я пытаюсь запустить несколько серверов Jetty (каждый на своем порте) в тесте jUnit и проверить одну и ту же конечную точку отдыха для каждого из этих серверов Jetty.
Я могу запустить их успешно, однако всякий раз, когда Я запрашиваю конечную точку на любом из серверов, запрос всегда принимается одним сервером Jetty независимо от того, на какой порт я отправил запрос.
Я подтвердил, что все серверы Jetty запущены на разных портах и на каждом из этих портов есть служба прослушивания. Только запрос всегда принимается на один и тот же порт независимо от того, на какой порт он фактически отправлен.
Разве невозможно запустить несколько серверов Jetty на разных портах, обслуживающих один и тот же путь? Кто-нибудь мог сделать это раньше?
Код:
// Starting the jettyServer
jettyServer = new Server();
handlerCollection = new HandlerCollection(true);
ServerConnector serverConnector = new ServerConnector(jettyServer);
// The port is passed in to this class. Verified that this is being done correctly.
serverConnector.setPort(this.port);
jettyServer.setConnectors(new ServerConnector[] { serverConnector });
jettyServer.setHandler(handlerCollection);
jettyServer.start();
// Config has been configured correctly for the application, verified that
ServletContextHandler context = new ServletContextHandler();
context.setContextPath(conf.getString("pathForRestContext"));
org.glassfish.jersey.server.ResourceConfig config = new ResourceConfig();
config.packages(conf.getString("packageForRest"));
ServletHolder servletHolder = new ServletHolder(new ServletContainer(config));
context.addServlet(servletHolder, "/*");
// Append our handler to any existing handlers
handlerCollection.addHandler(newHandler);
try {
newHandler.start();
} catch (Exception e) {
LOG.error("Error starting new handler: ", e);
throw e;
}
// Sending the request
URI uri = new URIBuilder()
.setScheme(httpProtocol)
.setHost(server.getHostName())
.setPort(portForJetty)
.setPath(restEndpoint)
.build();
// Using the same httpclient for all of the requests, however using individual clients does not solve the problem.
Response response = httpClient.target(uri).request(MediaType.APPLICATION_JSON).get();
// responseType is a custom class which is the expected data type for the incoming data.
response.readEntity(responseType)