Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate endpoint info on About page based on provided HTTP host header #822

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import de.rwth.idsg.steve.repository.SettingsRepository;
import de.rwth.idsg.steve.service.MailService;
import de.rwth.idsg.steve.service.ReleaseCheckService;
import de.rwth.idsg.steve.web.dto.EndpointInfo;
import de.rwth.idsg.steve.web.dto.WebEndpointInfo;
import de.rwth.idsg.steve.web.dto.SettingsForm;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
Expand All @@ -35,6 +35,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;
Expand Down Expand Up @@ -66,14 +67,18 @@ public class AboutSettingsController {
// -------------------------------------------------------------------------

@RequestMapping(value = ABOUT_PATH, method = RequestMethod.GET)
public String getAbout(Model model) {
public String getAbout(HttpServletRequest request, Model model) {
WebEndpointInfo info = new WebEndpointInfo();
info.getOcppSoap().setUrlPrefix("http", request.getServerName());
info.getOcppWebSocket().setUrlPrefix("ws", request.getServerName());

model.addAttribute("version", CONFIG.getSteveVersion());
model.addAttribute("db", genericRepository.getDBVersion());
model.addAttribute("logFile", logController.getLogFilePath());
model.addAttribute("systemTime", DateTime.now());
model.addAttribute("systemTimeZone", DateTimeZone.getDefault());
model.addAttribute("releaseReport", releaseCheckService.check());
model.addAttribute("endpointInfo", EndpointInfo.INSTANCE);
model.addAttribute("endpointInfo", info);
return "about";
}

Expand Down
47 changes: 47 additions & 0 deletions src/main/java/de/rwth/idsg/steve/web/dto/WebEndpointInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SteVe - SteckdosenVerwaltung - https://github.com/RWTH-i5-IDSG/steve
* Copyright (C) 2013-2022 RWTH Aachen University - Information Systems - Intelligent Distributed Systems Group (IDSG).
* All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.web.dto;

import lombok.Getter;

/**
* @author Michael Heimpold <[email protected]>
*/
@Getter
public final class WebEndpointInfo {
private final ItemsWithInfo ocppSoap = new ItemsWithInfo("SOAP endpoint for OCPP", "/services/CentralSystemService");
private final ItemsWithInfo ocppWebSocket = new ItemsWithInfo("WebSocket/JSON endpoint for OCPP", "/websocket/CentralSystemService/(chargeBoxId)");

@Getter
public static class ItemsWithInfo {
private final String info;
private final String path;
private String url;

private ItemsWithInfo(String info, String path) {
this.info = info;
this.path = path;
this.url = "";
}

public synchronized void setUrlPrefix(String scheme, String serverName) {
this.url = scheme + "://" + serverName + path;
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/webapp/WEB-INF/views/about.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
<table class="userInputFullPage">
<tr>
<td>${endpointInfo.ocppSoap.info}:</td>
<td><c:forEach items="${endpointInfo.ocppSoap.data}" var="i">${i}<br></c:forEach></td>
<td>${endpointInfo.ocppSoap.url}</td>
<tr>
<td>${endpointInfo.ocppWebSocket.info}:</td>
<td><c:forEach items="${endpointInfo.ocppWebSocket.data}" var="i">${i}<br></c:forEach></td>
<td>${endpointInfo.ocppWebSocket.url}</td>
</tr>
</tr>
</table>
Expand Down