Skip to content

Commit

Permalink
Merge pull request #15 from marklogic/Quick-Start-TomcatDeployment
Browse files Browse the repository at this point in the history
Quick start tomcat deployment and initial page
  • Loading branch information
paxtonhare committed Jan 27, 2016
2 parents eba9cff + c424101 commit eaead63
Show file tree
Hide file tree
Showing 29 changed files with 10,226 additions and 6 deletions.
4 changes: 2 additions & 2 deletions data-hub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ ext {
}

task generateRewriter(type: com.marklogic.gradle.task.XccTask) {
String custom = new File("data-hub/src/hub-in-a-box/rewriter.xml").getText('UTF-8')
String xqueryToRun = new File("data-hub/src/hub-in-a-box/build-rewriter.xqy").getText('UTF-8')
String custom = new File("$projectDir/src/hub-in-a-box/rewriter.xml").getText('UTF-8')
String xqueryToRun = new File("$projectDir/src/hub-in-a-box/build-rewriter.xqy").getText('UTF-8')
xqueryToRun = xqueryToRun.replace('__CUSTOM_REWRITER__', custom)
xccUrl = contentXccUrl
xquery = xqueryToRun
Expand Down
17 changes: 17 additions & 0 deletions quick-start/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Data Hub In a Box - Quick Start

Quick Start is a single-page web application that is deployed in an embedded Tomcat.

## Configuring the Tomcat server port and web app context path
- edit application.properties file and edit server.port and server.contextPath

## Build and deploy the web app via command line
- run ```gradle build```
- run ```java -jar build/libs/quick-start-0.1.0.war```

## Build and deploy the web app via Eclipse
- Select Application.java then Run as Java Application

## Go to the main page
- The main page is accessible at http://localhost:[server.port]/[server.contextPath].
- If server.port is 8080 and server.contextPath is /quick-start in application.properties, go to http://localhost:8080/quick-start and you will see the main page.
12 changes: 10 additions & 2 deletions quick-start/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

jar {
baseName = 'gs-rest-service'
war {
baseName = 'quick-start'
version = '0.1.0'
}

Expand All @@ -24,8 +25,15 @@ repositories {
sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations {
providedRuntime
}

dependencies {
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("junit:junit")
}

23 changes: 22 additions & 1 deletion quick-start/src/main/java/com/marklogic/hub/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,32 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
import org.thymeleaf.templateresolver.TemplateResolver;

@SpringBootApplication
public class Application {
public class Application extends WebMvcConfigurerAdapter {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public TemplateResolver templateResolver() {
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/pages/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCacheable(false);

return templateResolver;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/WEB-INF/static/");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.marklogic.hub.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/***
*
* @author mturiana
* This class is used to get the value of the keys in application.properties
*/
@Component
public class EnvironmentConfiguration {

@Autowired
private Environment environment;

public String getServerPort() {
return this.environment.getProperty("server.port");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.marklogic.hub.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.marklogic.hub.config.EnvironmentConfiguration;

@Controller
public class MainPageController {

private static final Logger LOGGER = LoggerFactory.getLogger(MainPageController.class);

@Autowired
private EnvironmentConfiguration environmentConfiguration;

@RequestMapping(value = "/", method = RequestMethod.GET)
public String getHomePage(Model model) {
LOGGER.debug("Loading home page from port " + environmentConfiguration.getServerPort());
return "index";
}

@RequestMapping(value = "/deployToMarkLogic", method = RequestMethod.POST)
public String deployToMarkLogic(Model model) {
return "redirect:/";
}



}
5 changes: 5 additions & 0 deletions quick-start/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Spring embedded tomcat config. Does not apply when war file is deployed on external Tomcat.
server.port=8080
server.contextPath=/quick-start
spring.thymeleaf.cache=true
logging.level.com.marklogic.hub: DEBUG
2 changes: 2 additions & 0 deletions quick-start/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app.title=Data Hub in a Box
app.footer=©2016. Data Hub in a Box.
17 changes: 17 additions & 0 deletions quick-start/src/main/webapp/WEB-INF/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="templates/base-template">
<head>
</head>
<body>
<section layout:fragment="content">
<div id="message-div" class="row"></div>
<div class="row">
<div class="col-md-3 text-right">
<form th:action="@{/deployToMarkLogic}" method="post">
<button type="submit" class="btn btn-secondary">Deploy to MarkLogic</button>
</form>
</div>
</div>
</section>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title th:text="#{app.title}"></title>
<link th:href="@{/static/lib/bootstrap-3.3.6-dist/css/bootstrap.min.css}" rel="stylesheet"></link>
<link th:href="@{/static/css/quick-start.css}" rel="stylesheet"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script th:src="@{/static/lib/bootstrap-3.3.6-dist/js/bootstrap.min.js}"></script>
<script th:src="@{/static/js/quick-start.js}"></script>
</head>
<body>
<div id="header" class="container-fluid">
<div class="row">
<div class="col-xs-8 col-sm-8 col-md-8"><h1 id="sitename" th:text="#{app.title}"></h1></div>
</div>
</div>
<div class="alert alert-error alert-danger" role="alert" th:if="${#fields.hasErrors('*')} " th:each="err : ${#fields.errors('*')}" th:text="${err}"></div>

<section id="content" class="container-fluid" layout:fragment="content"></section>

<div id="footer" class="container-fluid">
<span th:utext="#{app.footer}"></span>
</div>

<div layout:fragment="page-script" th:remove="tag"></div>

</body>
</html>
29 changes: 29 additions & 0 deletions quick-start/src/main/webapp/WEB-INF/static/css/quick-start.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
div#header {
background-color: #404040;
border: 1px solid #909090;
padding: 5px 15px;
color: #ffffff;
}

#sitename {
color: #ffffff;
font-size: 25px;
font-weight: 400;
margin: 0px;
color: #FFF;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-transform: uppercase;
}

#content {
min-height: 450px;
padding: 10px;
}

#footer {
font-size: 12px;
text-align: center;
}

Empty file.
Loading

0 comments on commit eaead63

Please sign in to comment.