fixed working with context path for webservice and guiservice

This commit is contained in:
anhefti 2021-04-30 15:59:15 +02:00
parent 8daeceeffa
commit eaf555ae11
6 changed files with 48 additions and 16 deletions

View file

@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.SEBServerInit; import ch.ethz.seb.sebserver.SEBServerInit;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.WebserviceURIService;
@Component @Component
@GuiProfile @GuiProfile
@ -23,15 +24,18 @@ public class GuiInit implements ApplicationListener<ApplicationReadyEvent> {
private final SEBServerInit sebServerInit; private final SEBServerInit sebServerInit;
private final Environment environment; private final Environment environment;
private final GuiServiceInfo guiServiceInfo; private final GuiServiceInfo guiServiceInfo;
private final WebserviceURIService webserviceURIService;
protected GuiInit( protected GuiInit(
final SEBServerInit sebServerInit, final SEBServerInit sebServerInit,
final Environment environment, final Environment environment,
final GuiServiceInfo guiServiceInfo) { final GuiServiceInfo guiServiceInfo,
final WebserviceURIService webserviceURIService) {
this.sebServerInit = sebServerInit; this.sebServerInit = sebServerInit;
this.environment = environment; this.environment = environment;
this.guiServiceInfo = guiServiceInfo; this.guiServiceInfo = guiServiceInfo;
this.webserviceURIService = webserviceURIService;
} }
@Override @Override
@ -46,13 +50,13 @@ public class GuiInit implements ApplicationListener<ApplicationReadyEvent> {
SEBServerInit.INIT_LOGGER.info("----> GUI Service successfully successfully started up!"); SEBServerInit.INIT_LOGGER.info("----> GUI Service successfully successfully started up!");
SEBServerInit.INIT_LOGGER.info("---->"); SEBServerInit.INIT_LOGGER.info("---->");
final String webServiceProtocol = this.environment.getProperty("sebserver.gui.webservice.protocol", "http"); // final String webServiceProtocol = this.environment.getProperty("sebserver.gui.webservice.protocol", "http");
final String webServiceAddress = this.environment.getRequiredProperty("sebserver.gui.webservice.address"); // final String webServiceAddress = this.environment.getRequiredProperty("sebserver.gui.webservice.address");
final String webServicePort = this.environment.getProperty("sebserver.gui.webservice.port", "80"); // final String webServicePort = this.environment.getProperty("sebserver.gui.webservice.port", "80");
SEBServerInit.INIT_LOGGER SEBServerInit.INIT_LOGGER.info(
.info("----> Webservice connection: " + webServiceProtocol + "://" + webServiceAddress "----> Webservice connection: {}",
+ ":" + webServicePort); this.webserviceURIService.getURIBuilder().build());
SEBServerInit.INIT_LOGGER.info( SEBServerInit.INIT_LOGGER.info(
"----> GUI service internal connection : " "----> GUI service internal connection : "
+ this.guiServiceInfo.getInternalServerURIBuilder().toUriString()); + this.guiServiceInfo.getInternalServerURIBuilder().toUriString());

View file

@ -25,6 +25,7 @@ public class GuiServiceInfo {
private final String internalPort; private final String internalPort;
private final String externalPort; private final String externalPort;
private final String entryPoint; private final String entryPoint;
private final String contextPath;
private final UriComponentsBuilder internalServerURIBuilder; private final UriComponentsBuilder internalServerURIBuilder;
private final UriComponentsBuilder externalServerURIBuilder; private final UriComponentsBuilder externalServerURIBuilder;
@ -34,7 +35,8 @@ public class GuiServiceInfo {
@Value("${sebserver.gui.http.external.scheme}") final String externalScheme, @Value("${sebserver.gui.http.external.scheme}") final String externalScheme,
@Value("${sebserver.gui.http.external.servername}") final String externalServer, @Value("${sebserver.gui.http.external.servername}") final String externalServer,
@Value("${sebserver.gui.http.external.port}") final String externalPort, @Value("${sebserver.gui.http.external.port}") final String externalPort,
@Value("${sebserver.gui.entrypoint:/gui}") final String entryPoint) { @Value("${sebserver.gui.entrypoint:/gui}") final String entryPoint,
@Value("${server.servlet.context-path:/}") final String contextPath) {
if (StringUtils.isBlank(externalScheme)) { if (StringUtils.isBlank(externalScheme)) {
throw new RuntimeException("Missing mandatory inital parameter sebserver.gui.http.external.servername"); throw new RuntimeException("Missing mandatory inital parameter sebserver.gui.http.external.servername");
@ -50,16 +52,23 @@ public class GuiServiceInfo {
this.internalPort = internalPort; this.internalPort = internalPort;
this.externalPort = externalPort; this.externalPort = externalPort;
this.entryPoint = entryPoint; this.entryPoint = entryPoint;
this.contextPath = contextPath;
this.internalServerURIBuilder = UriComponentsBuilder this.internalServerURIBuilder = UriComponentsBuilder
.fromHttpUrl("http://" + this.internalServer); .fromHttpUrl("http://" + this.internalServer);
if (StringUtils.isNotBlank(internalPort)) { if (StringUtils.isNotBlank(internalPort)) {
this.internalServerURIBuilder.port(this.internalPort); this.internalServerURIBuilder.port(this.internalPort);
} }
if (StringUtils.isNotBlank(contextPath) && !contextPath.equals("/")) {
this.internalServerURIBuilder.path(contextPath);
}
this.externalServerURIBuilder = UriComponentsBuilder this.externalServerURIBuilder = UriComponentsBuilder
.fromHttpUrl(this.externalScheme + "://" + this.externalServer); .fromHttpUrl(this.externalScheme + "://" + this.externalServer);
if (StringUtils.isNotBlank(externalPort)) { if (StringUtils.isNotBlank(externalPort)) {
this.externalServerURIBuilder.port(this.externalPort); this.externalServerURIBuilder.port(this.externalPort);
} }
if (StringUtils.isNotBlank(contextPath) && !contextPath.equals("/")) {
this.externalServerURIBuilder.path(contextPath);
}
} }
public String getExternalScheme() { public String getExternalScheme() {
@ -86,6 +95,10 @@ public class GuiServiceInfo {
return this.entryPoint; return this.entryPoint;
} }
public String getContextPath() {
return this.contextPath;
}
public UriComponentsBuilder getInternalServerURIBuilder() { public UriComponentsBuilder getInternalServerURIBuilder() {
return this.internalServerURIBuilder.cloneBuilder(); return this.internalServerURIBuilder.cloneBuilder();
} }

View file

@ -19,7 +19,7 @@ import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
@GuiProfile @GuiProfile
public class WebserviceURIService { public class WebserviceURIService {
private final String servletContextPath; private final String contextPath;
private final String webserviceServerAddress; private final String webserviceServerAddress;
private final UriComponentsBuilder webserviceURIBuilder; private final UriComponentsBuilder webserviceURIBuilder;
@ -27,19 +27,23 @@ public class WebserviceURIService {
@Value("${sebserver.gui.webservice.protocol}") final String webserviceProtocol, @Value("${sebserver.gui.webservice.protocol}") final String webserviceProtocol,
@Value("${sebserver.gui.webservice.address}") final String webserviceServerAddress, @Value("${sebserver.gui.webservice.address}") final String webserviceServerAddress,
@Value("${sebserver.gui.webservice.port}") final String webserviceServerPort, @Value("${sebserver.gui.webservice.port}") final String webserviceServerPort,
@Value("${server.servlet.context-path}") final String servletContextPath, @Value("${sebserver.gui.http.webservice.contextPath}") final String contextPath,
@Value("${sebserver.gui.webservice.apipath}") final String webserviceAPIPath) { @Value("${sebserver.gui.webservice.apipath}") final String webserviceAPIPath) {
this.servletContextPath = servletContextPath; this.contextPath = contextPath;
this.webserviceServerAddress = this.webserviceServerAddress =
webserviceProtocol + "://" + webserviceServerAddress + ":" + webserviceServerPort; webserviceProtocol + "://" + webserviceServerAddress + ":" + webserviceServerPort;
this.webserviceURIBuilder = UriComponentsBuilder this.webserviceURIBuilder = UriComponentsBuilder
.fromHttpUrl(webserviceProtocol + "://" + webserviceServerAddress) .fromHttpUrl(webserviceProtocol + "://" + webserviceServerAddress)
.port(webserviceServerPort) .port(webserviceServerPort)
.path(servletContextPath) .path(contextPath)
.path(webserviceAPIPath); .path(webserviceAPIPath);
} }
public String getContextPath() {
return this.contextPath;
}
public String getWebserviceServerAddress() { public String getWebserviceServerAddress() {
return this.webserviceServerAddress; return this.webserviceServerAddress;
} }
@ -50,14 +54,14 @@ public class WebserviceURIService {
public String getOAuthTokenURI() { public String getOAuthTokenURI() {
return UriComponentsBuilder.fromHttpUrl(this.webserviceServerAddress) return UriComponentsBuilder.fromHttpUrl(this.webserviceServerAddress)
.path(this.servletContextPath) .path(this.contextPath)
.path(API.OAUTH_TOKEN_ENDPOINT) .path(API.OAUTH_TOKEN_ENDPOINT)
.toUriString(); .toUriString();
} }
public String getOAuthRevokeTokenURI() { public String getOAuthRevokeTokenURI() {
return UriComponentsBuilder.fromHttpUrl(this.webserviceServerAddress) return UriComponentsBuilder.fromHttpUrl(this.webserviceServerAddress)
.path(this.servletContextPath) .path(this.contextPath)
.path(API.OAUTH_REVOKE_TOKEN_ENDPOINT) .path(API.OAUTH_REVOKE_TOKEN_ENDPOINT)
.toUriString(); .toUriString();
} }

View file

@ -44,6 +44,7 @@ public class WebserviceInfo {
private static final String WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY = private static final String WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY =
"sebserver.webservice.api.exam.endpoint.discovery"; "sebserver.webservice.api.exam.endpoint.discovery";
private static final String WEB_SERVICE_EXTERNAL_ADDRESS_ALIAS = "sebserver.webservice.lms.address.alias"; private static final String WEB_SERVICE_EXTERNAL_ADDRESS_ALIAS = "sebserver.webservice.lms.address.alias";
private static final String WEB_SERVICE_CONTEXT_PATH = "server.servlet.context-path";
private final String sebServerVersion; private final String sebServerVersion;
private final String testProperty; private final String testProperty;
@ -53,6 +54,7 @@ public class WebserviceInfo {
private final String serverPort; // internal private final String serverPort; // internal
private final String webserverPort; // external private final String webserverPort; // external
private final String discoveryEndpoint; private final String discoveryEndpoint;
private final String contextPath;
private final String serverURLPrefix; private final String serverURLPrefix;
private final boolean isDistributed; private final boolean isDistributed;
@ -70,6 +72,7 @@ public class WebserviceInfo {
this.serverPort = environment.getRequiredProperty(WEB_SERVICE_SERVER_PORT_KEY); this.serverPort = environment.getRequiredProperty(WEB_SERVICE_SERVER_PORT_KEY);
this.webserverPort = environment.getProperty(WEB_SERVICE_HTTP_PORT); this.webserverPort = environment.getProperty(WEB_SERVICE_HTTP_PORT);
this.discoveryEndpoint = environment.getRequiredProperty(WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY); this.discoveryEndpoint = environment.getRequiredProperty(WEB_SERVICE_EXAM_API_DISCOVERY_ENDPOINT_KEY);
this.contextPath = environment.getProperty(WEB_SERVICE_CONTEXT_PATH, "");
if (StringUtils.isEmpty(this.webserverName)) { if (StringUtils.isEmpty(this.webserverName)) {
log.warn("NOTE: External server name, property : 'sebserver.webservice.http.external.servername' " log.warn("NOTE: External server name, property : 'sebserver.webservice.http.external.servername' "
@ -84,7 +87,9 @@ public class WebserviceInfo {
if (StringUtils.isNotBlank(this.webserverPort)) { if (StringUtils.isNotBlank(this.webserverPort)) {
builder.port(this.webserverPort); builder.port(this.webserverPort);
} }
if (StringUtils.isNotBlank(this.contextPath) && !this.contextPath.equals("/")) {
builder.path(this.contextPath);
}
this.serverURLPrefix = builder.toUriString(); this.serverURLPrefix = builder.toUriString();
this.isDistributed = BooleanUtils.toBoolean(environment.getProperty( this.isDistributed = BooleanUtils.toBoolean(environment.getProperty(
@ -143,6 +148,10 @@ public class WebserviceInfo {
return this.webserverPort; return this.webserverPort;
} }
public Object getContextPath() {
return this.contextPath;
}
public String getDiscoveryEndpoint() { public String getDiscoveryEndpoint() {
return this.discoveryEndpoint; return this.discoveryEndpoint;
} }

View file

@ -99,6 +99,7 @@ public class WebserviceInit implements ApplicationListener<ApplicationReadyEvent
} }
SEBServerInit.INIT_LOGGER.info("---->"); SEBServerInit.INIT_LOGGER.info("---->");
SEBServerInit.INIT_LOGGER.info("----> Context Path: {}", this.webserviceInfo.getContextPath());
SEBServerInit.INIT_LOGGER.info("----> External-Host URL: {}", this.webserviceInfo.getExternalServerURL()); SEBServerInit.INIT_LOGGER.info("----> External-Host URL: {}", this.webserviceInfo.getExternalServerURL());
SEBServerInit.INIT_LOGGER.info("----> LMS-External-Address-Alias: {}", SEBServerInit.INIT_LOGGER.info("----> LMS-External-Address-Alias: {}",
this.webserviceInfo.getLmsExternalAddressAlias()); this.webserviceInfo.getLmsExternalAddressAlias());

View file

@ -20,6 +20,7 @@ sebserver.gui.http.external.port=${sebserver.webservice.http.external.port}
sebserver.gui.http.webservice.scheme=https sebserver.gui.http.webservice.scheme=https
sebserver.gui.http.webservice.servername=localhost sebserver.gui.http.webservice.servername=localhost
sebserver.gui.http.webservice.port=8080 sebserver.gui.http.webservice.port=8080
sebserver.gui.http.webservice.contextPath=${server.servlet.context-path}
sebserver.gui.entrypoint=/gui sebserver.gui.entrypoint=/gui
sebserver.gui.webservice.apipath=${sebserver.webservice.api.admin.endpoint} sebserver.gui.webservice.apipath=${sebserver.webservice.api.admin.endpoint}
@ -45,7 +46,7 @@ sebserver.webservice.api.admin.endpoint=/admin-api/v1
sebserver.webservice.api.admin.clientId=guiClient sebserver.webservice.api.admin.clientId=guiClient
sebserver.webservice.api.admin.clientSecret=${sebserver.password} sebserver.webservice.api.admin.clientSecret=${sebserver.password}
# NOTE: this is for convinience to have the same as in webservice (ws) # NOTE: this is for convenience to have the same as in webservice (ws)
sebserver.gui.webservice.protocol=${sebserver.gui.http.webservice.scheme} sebserver.gui.webservice.protocol=${sebserver.gui.http.webservice.scheme}
sebserver.gui.webservice.address=${sebserver.gui.http.webservice.servername} sebserver.gui.webservice.address=${sebserver.gui.http.webservice.servername}
sebserver.gui.webservice.port=${sebserver.gui.http.webservice.port} sebserver.gui.webservice.port=${sebserver.gui.http.webservice.port}