added GuiServiceInfo

This commit is contained in:
anhefti 2020-08-20 19:30:39 +02:00
parent 343643b331
commit 2bea1f25c6
7 changed files with 118 additions and 28 deletions

View file

@ -22,13 +22,16 @@ public class GuiInit implements ApplicationListener<ApplicationReadyEvent> {
private final SEBServerInit sebServerInit;
private final Environment environment;
private final GuiServiceInfo guiServiceInfo;
protected GuiInit(
final SEBServerInit sebServerInit,
final Environment environment) {
final Environment environment,
final GuiServiceInfo guiServiceInfo) {
this.sebServerInit = sebServerInit;
this.environment = environment;
this.guiServiceInfo = guiServiceInfo;
}
@Override
@ -47,8 +50,18 @@ public class GuiInit implements ApplicationListener<ApplicationReadyEvent> {
final String webServiceAddress = this.environment.getRequiredProperty("sebserver.gui.webservice.address");
final String webServicePort = this.environment.getProperty("sebserver.gui.webservice.port", "80");
SEBServerInit.INIT_LOGGER.info("----> Webservice connection: " + webServiceProtocol + "://" + webServiceAddress
+ ":" + webServicePort);
SEBServerInit.INIT_LOGGER
.info("----> Webservice connection: " + webServiceProtocol + "://" + webServiceAddress
+ ":" + webServicePort);
SEBServerInit.INIT_LOGGER.info(
"----> GUI service internal connection : "
+ this.guiServiceInfo.getInternalServerURIBuilder().toUriString());
SEBServerInit.INIT_LOGGER.info(
"----> GUI service external connection : "
+ this.guiServiceInfo.getExternalServerURIBuilder().toUriString());
SEBServerInit.INIT_LOGGER.info(
"----> GUI service endpoint : "
+ this.guiServiceInfo.getEntryPoint());
final String webServiceAdminAPIEndpoint =
this.environment.getRequiredProperty("sebserver.gui.webservice.apipath");

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver.gui;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
@Component
@GuiProfile
public class GuiServiceInfo {
private final String externalScheme;
private final String internalServer;
private final String externalServer;
private final String internalPort;
private final String externalPort;
private final String entryPoint;
private final UriComponentsBuilder internalServerURIBuilder;
private final UriComponentsBuilder externalServerURIBuilder;
public GuiServiceInfo(
@Value("${sebserver.gui.http.external.scheme:https}") final String externalScheme,
@Value("${server.address}") final String internalServer,
@Value("${sebserver.gui.http.external.servername}") final String externalServer,
@Value("${server.port}") final String internalPort,
@Value("${sebserver.webservice.http.external.port}") final String externalPort,
@Value("${sebserver.gui.entrypoint:/gui}") final String entryPoint) {
this.externalScheme = externalScheme;
this.internalServer = internalServer;
this.externalServer = StringUtils.isNotBlank(externalServer) ? externalServer : internalServer;
this.internalPort = internalPort;
this.externalPort = externalPort;
this.entryPoint = entryPoint;
this.internalServerURIBuilder = UriComponentsBuilder
.fromHttpUrl("http://" + this.internalServer)
.port(this.internalPort);
this.externalServerURIBuilder = UriComponentsBuilder
.fromHttpUrl(this.externalScheme + "://" + this.externalServer)
.port(this.externalPort);
}
public String getExternalScheme() {
return this.externalScheme;
}
public String getInternalServer() {
return this.internalServer;
}
public String getExternalServer() {
return this.externalServer;
}
public String getInternalPort() {
return this.internalPort;
}
public String getExternalPort() {
return this.externalPort;
}
public String getEntryPoint() {
return this.entryPoint;
}
public UriComponentsBuilder getInternalServerURIBuilder() {
return this.internalServerURIBuilder.cloneBuilder();
}
public UriComponentsBuilder getExternalServerURIBuilder() {
return this.externalServerURIBuilder.cloneBuilder();
}
}

View file

@ -35,6 +35,7 @@ import ch.ethz.seb.sebserver.gbl.model.session.ExtendedClientEvent;
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.gui.GuiServiceInfo;
import ch.ethz.seb.sebserver.gui.ProctoringServlet;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
import ch.ethz.seb.sebserver.gui.service.ResourceService;
@ -95,6 +96,7 @@ public class MonitoringClientConnection implements TemplateComposer {
private final I18nSupport i18nSupport;
private final InstructionProcessor instructionProcessor;
private final SEBClientEventDetailsPopup sebClientLogDetailsPopup;
private final GuiServiceInfo guiServiceInfo;
private final long pollInterval;
private final int pageSize;
@ -107,6 +109,7 @@ public class MonitoringClientConnection implements TemplateComposer {
final PageService pageService,
final InstructionProcessor instructionProcessor,
final SEBClientEventDetailsPopup sebClientLogDetailsPopup,
final GuiServiceInfo guiServiceInfo,
@Value("${sebserver.gui.webservice.poll-interval:500}") final long pollInterval,
@Value("${sebserver.gui.list.page.size:20}") final Integer pageSize) {
@ -115,6 +118,7 @@ public class MonitoringClientConnection implements TemplateComposer {
this.resourceService = pageService.getResourceService();
this.i18nSupport = this.resourceService.getI18nSupport();
this.instructionProcessor = instructionProcessor;
this.guiServiceInfo = guiServiceInfo;
this.pollInterval = pollInterval;
this.sebClientLogDetailsPopup = sebClientLogDetailsPopup;
this.pageSize = pageSize;
@ -305,12 +309,12 @@ public class MonitoringClientConnection implements TemplateComposer {
ProctoringServlet.SESSION_ATTR_PROCTORING_DATA,
proctoringConnectionData);
final String webserviceServerAddress = this.pageService.getAuthorizationContextHolder()
.getWebserviceURIService()
.getExternalServerURL();
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format(OPEN_SINGEL_ROOM_SCRIPT, roomName, webserviceServerAddress, roomName);
final String script = String.format(
OPEN_SINGEL_ROOM_SCRIPT,
roomName,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
roomName);
javaScriptExecutor.execute(script);
return action;
}

View file

@ -14,7 +14,6 @@ import org.springframework.web.util.UriComponentsBuilder;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import io.micrometer.core.instrument.util.StringUtils;
@Component
@GuiProfile
@ -23,15 +22,13 @@ public class WebserviceURIService {
private final String servletContextPath;
private final String webserviceServerAddress;
private final UriComponentsBuilder webserviceURIBuilder;
private final UriComponentsBuilder externaGUIURIBuilder;
public WebserviceURIService(
@Value("${sebserver.gui.webservice.protocol}") final String webserviceProtocol,
@Value("${sebserver.gui.webservice.address}") final String webserviceServerAddress,
@Value("${sebserver.gui.webservice.port}") final String webserviceServerPort,
@Value("${server.servlet.context-path}") final String servletContextPath,
@Value("${sebserver.gui.webservice.apipath}") final String webserviceAPIPath,
@Value("${sebserver.gui.webservice.address.external}") final String externalServerName) {
@Value("${sebserver.gui.webservice.apipath}") final String webserviceAPIPath) {
this.servletContextPath = servletContextPath;
this.webserviceServerAddress =
@ -41,19 +38,6 @@ public class WebserviceURIService {
.port(webserviceServerPort)
.path(servletContextPath)
.path(webserviceAPIPath);
if (StringUtils.isNotBlank(externalServerName)) {
this.externaGUIURIBuilder = UriComponentsBuilder
.fromHttpUrl(webserviceProtocol + "://" + externalServerName)
.port(webserviceServerPort);
} else {
this.externaGUIURIBuilder = UriComponentsBuilder
.fromHttpUrl(webserviceProtocol + "://" + webserviceServerAddress)
.port(webserviceServerPort);
}
}
public String getExternalServerURL() {
return this.externaGUIURIBuilder.toUriString();
}
public String getWebserviceServerAddress() {

View file

@ -13,10 +13,12 @@ sebserver.gui.supported.languages=en
sebserver.gui.date.displayformat=de
# GUI API
sebserver.gui.http.external.scheme=https
sebserver.gui.http.external.servername=
sebserver.webservice.http.external.port=
sebserver.gui.entrypoint=/gui
sebserver.gui.webservice.protocol=http
sebserver.gui.webservice.address=localhost
sebserver.gui.webservice.address.external=${sebserver.webservice.http.external.servername}
sebserver.gui.webservice.port=8080
sebserver.gui.webservice.apipath=${sebserver.webservice.api.admin.endpoint}
# defines the polling interval that is used to poll the webservice for client connection data on a monitored exam page

View file

@ -19,8 +19,10 @@
<root level="DEBUG" additivity="true">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
<Logger name="ch.ethz.seb.SEB_SERVER_INIT" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
</Logger>
</springProfile>

View file

@ -71,7 +71,7 @@ public abstract class GuiIntegrationTest {
final HttpSession sessionMock = Mockito.mock(HttpSession.class);
final WebserviceURIService webserviceURIService = new WebserviceURIService(
"http", "localhost", "8080", "/", this.endpoint, "localhost");
"http", "localhost", "8080", "/", this.endpoint);
final ClientHttpRequestFactoryService clientHttpRequestFactoryService = Mockito
.mock(ClientHttpRequestFactoryService.class);