Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
/* Add additional stylesheets below
|
||||
-------------------------------------------------- */
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (C) 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package conf;
|
||||
|
||||
import java.util.List;
|
||||
import ninja.Filter;
|
||||
|
||||
public class Filters implements ninja.application.ApplicationFilters {
|
||||
|
||||
@Override
|
||||
public void addFilters(List<Class<? extends Filter>> filters) {
|
||||
// Add your application - wide filters here
|
||||
// filters.add(MyFilter.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (C) 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package conf;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import services.UserService;
|
||||
import services.UserServiceImpl;
|
||||
|
||||
@Singleton
|
||||
public class Module extends AbstractModule {
|
||||
|
||||
|
||||
protected void configure() {
|
||||
|
||||
// bind your injections here!
|
||||
bind(UserService.class).to(UserServiceImpl.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (C) 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package conf;
|
||||
|
||||
|
||||
import ninja.AssetsController;
|
||||
import ninja.Router;
|
||||
import ninja.application.ApplicationRoutes;
|
||||
import controllers.ApplicationController;
|
||||
|
||||
public class Routes implements ApplicationRoutes {
|
||||
|
||||
@Override
|
||||
public void init(Router router) {
|
||||
|
||||
router.GET().route("/").with(ApplicationController::index);
|
||||
router.GET().route("/hello_world.json").with(ApplicationController::helloWorldJson);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Assets (pictures / javascript)
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
router.GET().route("/assets/webjars/{fileName: .*}").with(AssetsController::serveWebJars);
|
||||
router.GET().route("/assets/{fileName: .*}").with(AssetsController::serveStatic);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Index / Catchall shows index page
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
router.GET().route("/.*").with(ApplicationController::index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# The main properties file to configure your application
|
||||
#
|
||||
# Properties can be prefixed by "%".
|
||||
# "%"" matches a mode you can set as system property. For instance when you
|
||||
# are using maven you can do: mvn -Dmode=test jetty:run
|
||||
#
|
||||
# Using that the following property:
|
||||
# %test.myproperty=test property
|
||||
# would overwrite the property
|
||||
# myproperty=my property
|
||||
#
|
||||
# You can define as many environments as you want. Simply set them in the mode.
|
||||
application.name=baeldung ninja application
|
||||
|
||||
application.cookie.prefix=NINJA
|
||||
|
||||
#ISO Language Code, optionally followed by a valid ISO Country Code.
|
||||
application.languages=en
|
||||
|
||||
application.session.expire_time_in_seconds=3600
|
||||
application.session.send_only_if_changed=true
|
||||
application.session.transferred_over_https_only=false
|
||||
|
||||
# enable ssl with self-signed cert in dev & test modes
|
||||
ninja.ssl.port=8443
|
||||
application.secret = fxSjSL9Q017BSL7gBnkyo2Prln7uXaXIT35gotXRIED8c46OSa8s4QdoIQdTsEtj
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# Copyright (C) 2012 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# This file is utf-8
|
||||
header.title=Hello World!
|
||||
header.home=BAM!
|
||||
hello.world=Hello World!
|
||||
hello.world.json=There is also Json rendering you can check out!
|
||||
@@ -0,0 +1,36 @@
|
||||
package controllers;
|
||||
|
||||
import ninja.Result;
|
||||
import ninja.Results;
|
||||
import services.UserService;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ApplicationController {
|
||||
|
||||
private static Log logger = LogFactory.getLog(ApplicationController.class);
|
||||
|
||||
@Inject
|
||||
UserService userService;
|
||||
|
||||
public Result index() {
|
||||
return Results.html();
|
||||
}
|
||||
|
||||
public Result helloWorldJson() {
|
||||
SimplePojo simplePojo = new SimplePojo();
|
||||
simplePojo.content = "Hello World! Hello Json!";
|
||||
logger.info(userService.getUserName());
|
||||
return Results.json().render(simplePojo);
|
||||
}
|
||||
|
||||
public static class SimplePojo {
|
||||
public String content;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">
|
||||
|
||||
<defaultCache
|
||||
maxElementsInMemory="10000"
|
||||
eternal="false"
|
||||
timeToIdleSeconds="120"
|
||||
timeToLiveSeconds="120"
|
||||
overflowToDisk="false"
|
||||
maxElementsOnDisk="10000000"
|
||||
diskPersistent="false"
|
||||
diskExpiryThreadIntervalSeconds="120"
|
||||
memoryStoreEvictionPolicy="LRU"
|
||||
/>
|
||||
|
||||
</ehcache>
|
||||
@@ -0,0 +1,33 @@
|
||||
<configuration>
|
||||
|
||||
<!-- Uncomment to enable file-based logging with
|
||||
daily (or size exceeding) gzip archival.
|
||||
Also uncomment the "ROLLING" reference in <root>.
|
||||
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>mylog.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>mylog.%d{yyyy-MM-dd}.%i.log.gz</FileNamePattern>
|
||||
<MaxHistory>30</MaxHistory>
|
||||
<timeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender> -->
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<!-- <appender-ref ref="ROLLING" /> -->
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,7 @@
|
||||
package services;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
String getUserName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package services;
|
||||
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public String getUserName() {
|
||||
return "Eugen Parashic";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<#import "../layout/defaultLayout.ftl.html" as layout>
|
||||
<@layout.myLayout "Home page">
|
||||
|
||||
|
||||
<h1>${i18n("hello.world")}</h1>
|
||||
<p>${i18n("hello.world.json")}</p>
|
||||
<a href="/hello_world.json">Hello World Json</a>
|
||||
|
||||
</@layout.myLayout>
|
||||
@@ -0,0 +1,58 @@
|
||||
<#macro myLayout title="Layout example">
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>${title}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<!-- Le styles -->
|
||||
<link href="/assets/webjars/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- Optional theme -->
|
||||
<link rel="stylesheet" href="/assets/webjars/bootstrap/3.3.4/css/bootstrap-theme.min.css">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
padding-top: 60px;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
.error-template {padding: 40px 15px;text-align: center;}
|
||||
</style>
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<#include "header.ftl.html"/>
|
||||
|
||||
<#if (flash.error)??>
|
||||
<div class="alert alert-danger">
|
||||
${flash.error}
|
||||
</div>
|
||||
</#if>
|
||||
|
||||
<#if (flash.success)??>
|
||||
<div class="alert alert-success">
|
||||
${flash.success}
|
||||
</div>
|
||||
</#if>
|
||||
|
||||
<#nested/>
|
||||
|
||||
<#include "footer.ftl.html"/>
|
||||
|
||||
</div> <!-- /container -->
|
||||
<script type="text/javascript" src="/assets/webjars/jquery/2.1.3/jquery.js"></script>
|
||||
<script type="text/javascript" src="/assets/webjars/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</#macro>
|
||||
@@ -0,0 +1,5 @@
|
||||
<hr>
|
||||
<footer>
|
||||
Built with <a href="http://www.ninjaframework.org">Ninja framework</a>.
|
||||
</footer>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/">${i18n("header.title")}</a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="active"><a href="/">${i18n("header.home")}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!--/.navbar-collapse -->
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,18 @@
|
||||
<#import "../layout/defaultLayout.ftl.html" as layout>
|
||||
<@layout.myLayout "Error. Forbidden.">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="error-template">
|
||||
<h1>
|
||||
Oops!</h1>
|
||||
<h2>
|
||||
403 Forbidden</h2>
|
||||
<div class="error-details">
|
||||
Sorry, an error has occured. Requested page is forbidden!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</@layout.myLayout>
|
||||
@@ -0,0 +1,18 @@
|
||||
<#import "../layout/defaultLayout.ftl.html" as layout>
|
||||
<@layout.myLayout "Error. Not found.">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="error-template">
|
||||
<h1>
|
||||
Oops!</h1>
|
||||
<h2>
|
||||
404 Not Found</h2>
|
||||
<div class="error-details">
|
||||
Sorry, an error has occured. Requested page not found!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</@layout.myLayout>
|
||||
Reference in New Issue
Block a user