seb-server/src/main/java/ch/ethz/seb/sebserver/gui/GuiServiceInfo.java

92 lines
3.3 KiB
Java
Raw Normal View History

2020-08-20 19:30:39 +02:00
/*
* 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,
2020-09-19 09:54:40 +02:00
@Value("${sebserver.gui.http.external.port}") final String externalPort,
2020-08-20 19:30:39 +02:00
@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
2020-09-29 17:48:50 +02:00
.fromHttpUrl("http://" + this.internalServer);
if (StringUtils.isNotBlank(internalPort)) {
this.internalServerURIBuilder.port(this.internalPort);
}
2020-08-20 19:30:39 +02:00
this.externalServerURIBuilder = UriComponentsBuilder
2020-09-29 17:48:50 +02:00
.fromHttpUrl(this.externalScheme + "://" + this.externalServer);
if (StringUtils.isNotBlank(externalPort)) {
this.externalServerURIBuilder.port(this.externalPort);
} else if (StringUtils.isNotBlank(internalPort)) {
this.externalServerURIBuilder.port(this.internalPort);
}
2020-08-20 19:30:39 +02:00
}
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();
}
}