Skip to content

Commit

Permalink
Working solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Jan 27, 2020
1 parent bd910bc commit 0fab57f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
7 changes: 6 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ bootWar {
)
}
from(tasks.findByPath(':ui:npm_run_buildProd').outputs) {
//Copying into this particular classpath location due too
//deployment to external Tomcat would not work with /public location
//This way, it works with both embedded and extarnal Tomcat
into 'WEB-INF/classes/resources'
}
archiveName = "${baseName}-${version}.war"
Expand All @@ -106,6 +109,9 @@ bootJar {
)
}
from(tasks.findByPath(':ui:npm_run_buildProd').outputs) {
//Copying into this particular classpath location due too
//deployment to external Tomcat would not work with /public location
//This way, it works with both embedded and external Tomcat
into 'WEB-INF/classes/resources'
}
archiveName = "${baseName}-${version}.jar"
Expand Down Expand Up @@ -164,7 +170,6 @@ dependencies {
//So it works on Java 9 without explicitly requiring to load that module (needed by Hibernate)
runtimeOnly 'javax.xml.bind:jaxb-api:2.3.0'

// TODO: these will likely only be runtimeOnly or test scope, unless we want to ship the libraries with the final product
compile "com.h2database:h2"
runtimeOnly "org.postgresql:postgresql"
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.stream.Collectors;

@Controller
public class RootUiViewController {

@Value("classpath:/resources/index.html")
Resource indexHtmlResource;

@RequestMapping("/")
//@ResponseBody
public void index(HttpServletRequest request, HttpServletResponse response) throws IOException {
//TODO: Use Jsoup lib to inject context path into DOM before writing to response buffer
public String index() {
return "redirect:/index.html";
}

final String ctxPath = request.getContextPath();
@RequestMapping(value = {"**/index.html", "/dashboard/**", "/metadata/**"})
public void indexHtml(HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException {
//This method is necessary in order for Angular framework to honor dynamic ServletContext
//under which shib ui application is deployed, both during initial index.html load and subsequest page refreshes
String content = new BufferedReader(new InputStreamReader(request.getServletContext()
.getResourceAsStream("/WEB-INF/classes/resources/index.html")))
.lines()
.collect(Collectors.joining("\n"));

//This does not work! In order form Angular to kick in we need to redirect to index.html
String indexHtmlAsString = StreamUtils.copyToString(indexHtmlResource.getInputStream(), Charset.defaultCharset());
//byte[] indexHtmlBytes = ByteStreams.toByteArray(indexHtmlResource.getInputStream());
response.setHeader("Content-Type", "text/html");
response.getWriter().print(indexHtmlAsString);
//os.write(ctxPath.getBytes(), 0, ctxPath.length());
content = content.replaceFirst("<base.+>", "<base href=\"" + request.getContextPath() + "/\">");
response.setContentType("text/html");
try (OutputStream writer = response.getOutputStream()) {
writer.write(content.getBytes());
}
}
}

0 comments on commit 0fab57f

Please sign in to comment.