├── .babelrc
├── .editorconfig
├── .eslintrc
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── CHANGELOG.md
├── README.md
├── build
├── index.template.html
├── karma.conf.js
├── webpack.base.conf.js
├── webpack.dev.conf.js
└── webpack.prod.conf.js
├── mvnw
├── mvnw.cmd
├── npm
├── npm.cmd
├── package.json
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── shardis
│ │ ├── ShardisFrameworkApplication.java
│ │ ├── cons
│ │ └── Profiles.java
│ │ ├── controllers
│ │ ├── error
│ │ │ └── ErrorHandlerController.java
│ │ ├── rest
│ │ │ ├── ChatController.java
│ │ │ └── SampleRestController.java
│ │ └── web
│ │ │ └── MainPageController.java
│ │ ├── dto
│ │ ├── chat
│ │ │ └── ChatMessage.java
│ │ ├── error
│ │ │ └── ServerErrorDTO.java
│ │ └── user
│ │ │ └── UserPost.java
│ │ └── utils
│ │ └── EnvironmentProvider.java
├── resources
│ ├── application.properties
│ ├── static
│ │ ├── css
│ │ │ └── dev.css
│ │ ├── images
│ │ │ └── development_ribbon.png
│ │ └── index.html
│ └── templates
│ │ └── error.html
└── vuejs
│ ├── app.vue
│ ├── assets
│ ├── images
│ │ └── logo.png
│ └── scss
│ │ ├── _animations.scss
│ │ ├── _bootstrap.scss
│ │ ├── _fonts.scss
│ │ ├── _layout.scss
│ │ ├── _variables.scss
│ │ ├── _vue.scss
│ │ └── main.scss
│ ├── components
│ ├── about.vue
│ ├── chat.vue
│ ├── hello.vue
│ ├── home.vue
│ ├── layout
│ │ ├── page-footer.vue
│ │ └── page-header.vue
│ ├── not-found.vue
│ ├── survey
│ │ ├── data.js
│ │ ├── question.vue
│ │ └── survey.vue
│ └── user
│ │ ├── index.vue
│ │ ├── posts.vue
│ │ ├── profile.vue
│ │ └── settings.vue
│ ├── config
│ └── routes.js
│ ├── main.js
│ └── stores
│ └── store.js
└── test
├── java
└── com
│ └── shardis
│ └── ShardisFrameworkApplicationTests.java
└── vuejs
└── unit
├── Hello.spec.js
└── index.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-2"],
3 | "plugins": ["transform-runtime"],
4 | "comments": false
5 | }
6 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Unix-style newlines with a newline ending every file
7 | [*]
8 | end_of_line = lf
9 | insert_final_newline = true
10 |
11 | # Set default charset
12 | [*.{js,java,vue}]
13 | charset = utf-8
14 |
15 | # 4 space indentation
16 | [*.java]
17 | indent_style = space
18 | indent_size = 4
19 |
20 | # 2 space indentation
21 | [*.{js,vue}]
22 | indent_style = space
23 | indent_size = 2
24 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "node": true
5 | },
6 |
7 | "ecmaFeatures": {
8 | "arrowFunctions": true,
9 | "destructuring": true,
10 | "classes": true,
11 | "defaultParams": true,
12 | "blockBindings": true,
13 | "modules": true,
14 | "objectLiteralComputedProperties": true,
15 | "objectLiteralShorthandMethods": true,
16 | "objectLiteralShorthandProperties": true,
17 | "restParams": true,
18 | "spread": true,
19 | "forOf": true,
20 | "generators": true,
21 | "templateStrings": true,
22 | "superInFunctions": true,
23 | "experimentalObjectRestSpread": true
24 | },
25 |
26 | "globals": {
27 | "$": true,
28 | "jQuery": true,
29 | "window.jQuery": true,
30 | "Tether": true,
31 | "window.Tether": true
32 | },
33 |
34 | "rules": {
35 | "accessor-pairs": 2,
36 | "array-bracket-spacing": 0,
37 | "block-scoped-var": 0,
38 | "brace-style": [2, "1tbs", { "allowSingleLine": true }],
39 | "camelcase": 0,
40 | "comma-dangle": [2, "never"],
41 | "comma-spacing": [2, { "before": false, "after": true }],
42 | "comma-style": [2, "last"],
43 | "complexity": 0,
44 | "computed-property-spacing": 0,
45 | "consistent-return": 0,
46 | "consistent-this": 0,
47 | "constructor-super": 2,
48 | "curly": [2, "multi-line"],
49 | "default-case": 0,
50 | "dot-location": [2, "property"],
51 | "dot-notation": 0,
52 | "eol-last": 2,
53 | "eqeqeq": [2, "allow-null"],
54 | "func-names": 0,
55 | "func-style": 0,
56 | "generator-star-spacing": [2, { "before": true, "after": true }],
57 | "guard-for-in": 0,
58 | "handle-callback-err": [2, "^(err|error)$" ],
59 | "indent": [2, 2, { "SwitchCase": 1 }],
60 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
61 | "linebreak-style": 0,
62 | "lines-around-comment": 0,
63 | "max-nested-callbacks": 0,
64 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
65 | "new-parens": 2,
66 | "newline-after-var": 0,
67 | "no-alert": 0,
68 | "no-array-constructor": 2,
69 | "no-caller": 2,
70 | "no-catch-shadow": 0,
71 | "no-cond-assign": 2,
72 | "no-console": 0,
73 | "no-constant-condition": 0,
74 | "no-continue": 0,
75 | "no-control-regex": 2,
76 | "no-debugger": 2,
77 | "no-delete-var": 2,
78 | "no-div-regex": 0,
79 | "no-dupe-args": 2,
80 | "no-dupe-keys": 2,
81 | "no-duplicate-case": 2,
82 | "no-else-return": 0,
83 | "no-empty": 0,
84 | "no-empty-character-class": 2,
85 | "no-empty-label": 2,
86 | "no-eq-null": 0,
87 | "no-eval": 2,
88 | "no-ex-assign": 2,
89 | "no-extend-native": 2,
90 | "no-extra-bind": 2,
91 | "no-extra-boolean-cast": 2,
92 | "no-extra-parens": 0,
93 | "no-extra-semi": 0,
94 | "no-fallthrough": 2,
95 | "no-floating-decimal": 2,
96 | "no-func-assign": 2,
97 | "no-implied-eval": 2,
98 | "no-inline-comments": 0,
99 | "no-inner-declarations": [2, "functions"],
100 | "no-invalid-regexp": 2,
101 | "no-irregular-whitespace": 2,
102 | "no-iterator": 2,
103 | "no-label-var": 2,
104 | "no-labels": 2,
105 | "no-lone-blocks": 2,
106 | "no-lonely-if": 0,
107 | "no-loop-func": 0,
108 | "no-mixed-requires": 0,
109 | "no-mixed-spaces-and-tabs": 2,
110 | "no-multi-spaces": 2,
111 | "no-multi-str": 2,
112 | "no-multiple-empty-lines": [2, { "max": 1 }],
113 | "no-native-reassign": 2,
114 | "no-negated-in-lhs": 2,
115 | "no-nested-ternary": 0,
116 | "no-new": 2,
117 | "no-new-func": 0,
118 | "no-new-object": 2,
119 | "no-new-require": 2,
120 | "no-new-wrappers": 2,
121 | "no-obj-calls": 2,
122 | "no-octal": 2,
123 | "no-octal-escape": 2,
124 | "no-param-reassign": 0,
125 | "no-path-concat": 0,
126 | "no-process-env": 0,
127 | "no-process-exit": 0,
128 | "no-proto": 0,
129 | "no-redeclare": 2,
130 | "no-regex-spaces": 2,
131 | "no-restricted-modules": 0,
132 | "no-return-assign": 2,
133 | "no-script-url": 0,
134 | "no-self-compare": 2,
135 | "no-sequences": 2,
136 | "no-shadow": 0,
137 | "no-shadow-restricted-names": 2,
138 | "no-spaced-func": 2,
139 | "no-sparse-arrays": 2,
140 | "no-sync": 0,
141 | "no-ternary": 0,
142 | "no-this-before-super": 2,
143 | "no-throw-literal": 2,
144 | "no-trailing-spaces": 2,
145 | "no-undef": 2,
146 | "no-undef-init": 2,
147 | "no-undefined": 0,
148 | "no-underscore-dangle": 0,
149 | "no-unexpected-multiline": 2,
150 | "no-unneeded-ternary": 2,
151 | "no-unreachable": 2,
152 | "no-unused-expressions": 0,
153 | "no-unused-vars": [2, { "vars": "all", "args": "none" }],
154 | "no-use-before-define": 0,
155 | "no-var": 0,
156 | "no-void": 0,
157 | "no-warning-comments": 0,
158 | "no-with": 2,
159 | "object-curly-spacing": 0,
160 | "object-shorthand": 0,
161 | "one-var": [2, { "initialized": "never" }],
162 | "operator-assignment": 0,
163 | "operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
164 | "padded-blocks": 0,
165 | "prefer-const": 0,
166 | "quote-props": 0,
167 | "quotes": [2, "single", "avoid-escape"],
168 | "radix": 2,
169 | "semi": [1, "always"],
170 | "semi-spacing": 0,
171 | "sort-vars": 0,
172 | "space-after-keywords": [2, "always"],
173 | "space-before-blocks": [2, "always"],
174 | "space-before-function-paren": [2, "always"],
175 | "space-in-parens": [2, "never"],
176 | "space-infix-ops": 2,
177 | "space-return-throw-case": 2,
178 | "space-unary-ops": [2, { "words": true, "nonwords": false }],
179 | "spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!"] }],
180 | "strict": 0,
181 | "use-isnan": 2,
182 | "valid-jsdoc": 0,
183 | "valid-typeof": 2,
184 | "vars-on-top": 0,
185 | "wrap-iife": [2, "any"],
186 | "wrap-regex": 0,
187 | "yoda": [2, "never"]
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### idea
2 | .idea/
3 | *.iml
4 | ### dist
5 | src/main/resources/static/dist/
6 | ### maven
7 | target/
8 | ### node
9 | etc/
10 | node/
11 | node_modules/
12 | npm-debug.log
13 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kucharzyk/vuejs-java-starter/e55e5fd4a968494a2436ce70906491858db289d0/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 0.1.1 (2016-01-17)
2 |
3 | * added Simple survey as Vue.js example
4 |
5 | ## 0.1.0 (2016-01-15)
6 |
7 | * added Vuex (It's like flux)
8 | * refactor counter example to Vuex
9 | * some other refactorings
10 |
11 | ## 0.0.9 (2016-01-14)
12 |
13 | * added realtime chat example (SSE)
14 |
15 | ## 0.0.8 (2016-01-13)
16 |
17 | * added active class to menu links
18 | * added dropdown to menu
19 | * added two-way binding example
20 | * added font-awesome and some icons
21 |
22 | ## 0.0.7 (2016-01-13)
23 |
24 | * switched from semantic-ui to bootstrap 4
25 | * semantic-ui was too big
26 | * switched from less to sass
27 | * style app with bootstrap
28 |
29 | ## 0.0.6 (2016-01-12)
30 |
31 | * styled application with semantic-ui
32 | * updated npm packages
33 | * configured autoprefixer
34 |
35 | ## 0.0.5 (2016-01-12)
36 |
37 | * styled application with semantic-ui
38 | * refactor webpack configuration
39 | * refactor styles configuration
40 | * add less-css support
41 |
42 | ## 0.0.4 (2016-01-11)
43 |
44 | * fixed 404 status code in routing
45 | * fixed hot reload issues with images and fonts
46 | * Added jquery and semantic-ui
47 | * Added file loader for fonts
48 |
49 | ## 0.0.3 (2016-01-11)
50 |
51 | * Added basic vue-resource example
52 | * Configured proxy from webpack-dev-server to backend
53 | * Added .editorconfig
54 |
55 | ## 0.0.2 (2016-01-10)
56 |
57 | * Added vue-router example
58 | * Handle html5 history router from java
59 | * Added json error handler
60 |
61 | ## 0.0.1 (2016-01-09)
62 |
63 | * Initial version
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vuejs-java-starter
2 |
3 | > Vue.js spring boot starter project
4 |
5 | ## Features:
6 | * Spring Boot
7 | * Vue.js
8 | * Hot module replacement (from webpack dev server and from java)
9 | * vue-router for routing (working well with spring router)
10 | * vue-resources for data fetching
11 | * development and production profiles
12 | * fully automated maven workflow
13 | * bootstrap 4 integration
14 | * font-awesome
15 | * less-css support
16 | * sass support
17 | * and will be more...
18 |
19 | ## Changelog
20 |
21 | ## 0.1.1 (2016-01-17)
22 |
23 | * added Simple survey as Vue.js example
24 |
25 | ## 0.1.0 (2016-01-15)
26 |
27 | * added Vuex (It's like flux)
28 | * refactor counter example to Vuex
29 | * some other refactorings
30 |
31 | ## 0.0.9 (2016-01-14)
32 |
33 | * added realtime chat example (SSE)
34 |
35 | [show full changelog](CHANGELOG.md)
36 |
37 | ## Run in production mode
38 |
39 | ``` bash
40 | # compile and start in production mode
41 | mvn spring-boot:run
42 | ```
43 |
44 | server will start on [http://localhost:8080/](http://localhost:8080/)
45 |
46 | ## Run in development mode
47 |
48 | ``` bash
49 | # compile and start in development mode
50 | mvn spring-boot:run -Dspring.profiles.active=dev
51 |
52 | # start webpack development server for HMR
53 | npm run dev
54 | ```
55 |
56 | java server will start on [http://localhost:8080/](http://localhost:8080/)
57 | webpack server will start on [http://localhost:3000/](http://localhost:3000/)
58 |
59 | Hot module replacement will be available from both servers
60 |
61 | ##Running tests
62 |
63 | ``` bash
64 | # run karma tests
65 | npm run tests
66 |
67 | # run java and karma
68 | mvn test
69 | ```
70 |
71 | ## Directory structure
72 |
73 | ```
74 | .
75 | ├ build # webpack build configuration
76 | ├ .mvn # maven wrapper directory
77 | ├ node # maven will install node here
78 | ├ node_modules # node modules
79 | ├ target # compiled java sources
80 | ├ src # sources
81 | │ ├ main
82 | │ │ ├ java # java sources
83 | │ │ ├ vuejs # javascript sources
84 | │ │ └ resources # resources
85 | │ │ ├ static # static resources
86 | │ │ │ ├ css # styles
87 | │ │ │ ├ images # images
88 | │ │ │ ├ dist # generated javascript goes here
89 | │ │ │ └ index.html # development index.html
90 | │ │ └ application.properties # spring boot configuration properties
91 | │ └ test # test sources
92 | │ ├ java # java tests
93 | │ └ vuejs # vue.js tests
94 | ├ .babelrc # babel configuration
95 | ├ .eslintrc # eslint configuration
96 | ├ .gitignore # gitignore
97 | ├ package.json # node configuration
98 | ├ pom.xml # maven configuration
99 | ├ mvnw # maven linux wrapper
100 | ├ mvnw.cmd # maven windows wrapper
101 | ├ npm # local npm linux wrapper
102 | ├ npm.cmd # local npm windows wrapper
103 | └ README.md # this file
104 | ```
105 |
--------------------------------------------------------------------------------
/build/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | vuejs-java-starter
7 | {% for (var css in o.htmlWebpackPlugin.files.css) { %}
8 |
9 | {% } %}
10 |
11 |
12 |
13 | {% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %}
14 |
15 | {% } %}
16 |
17 |
18 |
--------------------------------------------------------------------------------
/build/karma.conf.js:
--------------------------------------------------------------------------------
1 | var webpackConf = require('./webpack.base.conf');
2 | delete webpackConf.entry;
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | browsers: ['PhantomJS'],
7 | frameworks: ['jasmine'],
8 | reporters: ['spec'],
9 | files: ['../src/test/vuejs/unit/index.js'],
10 | preprocessors: {
11 | '../src/test/vuejs/unit/index.js': ['webpack']
12 | },
13 | webpack: webpackConf,
14 | webpackMiddleware: {
15 | noInfo: true
16 | }
17 | });
18 | };
19 |
--------------------------------------------------------------------------------
/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var path = require('path');
3 |
4 | module.exports = {
5 | entry: {
6 | app: './src/main/vuejs/main.js'
7 | },
8 | output: {
9 | path: path.resolve(__dirname, '../src/main/resources/static/dist/'),
10 | filename: '[name].js'
11 | },
12 | resolve: {
13 | extensions: ['', '.js', '.vue'],
14 | alias: {
15 | 'src': path.resolve(__dirname, '../src')
16 | }
17 | },
18 | module: {
19 | loaders: [
20 | {
21 | test: /\.vue$/,
22 | loader: 'vue'
23 | },
24 | {
25 | test: /\.js$/,
26 | loader: 'babel!eslint',
27 | exclude: /node_modules/
28 | },
29 | {
30 | test: /\.json$/,
31 | loader: 'json'
32 | },
33 | {
34 | test: /\.(png|jpg|gif|svg)/,
35 | loader: 'url',
36 | query: {
37 | limit: 10000,
38 | name: '[name].[ext]?[hash]'
39 | }
40 | },
41 | {
42 | test: /\.(woff|eot|ttf|woff(2)?|otf)/i,
43 | loader: 'file-loader?[name].[ext]?[hash]'
44 | }
45 | ]
46 | },
47 | vue: {
48 | loaders: {
49 | js: 'babel!eslint'
50 | },
51 | autoprefixer: {
52 | browsers: ['last 2 versions']
53 | }
54 | },
55 | eslint: {
56 | formatter: require('eslint-friendly-formatter')
57 | },
58 | plugins: [
59 | new webpack.ProvidePlugin({
60 | $: 'jquery',
61 | jQuery: 'jquery',
62 | 'window.jQuery': 'jquery',
63 | 'Tether': 'tether',
64 | 'window.Tether': 'tether'
65 | })
66 | ]
67 | };
68 |
--------------------------------------------------------------------------------
/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | var config = require('./webpack.base.conf');
2 |
3 | config.devtool = 'eval-source-map';
4 |
5 | // set output path for development
6 | config.output.publicPath = 'http://localhost:3000/dist/';
7 |
8 | config.devServer = {
9 | host: '0.0.0.0',
10 | port: 3000,
11 | historyApiFallback: true,
12 | noInfo: true,
13 | contentBase: 'src/main/resources/static/',
14 | proxy: {
15 | '/rest/*': 'http://localhost:8080'
16 | }
17 | };
18 |
19 | module.exports = config;
20 |
--------------------------------------------------------------------------------
/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var config = require('./webpack.base.conf');
3 | var ExtractTextPlugin = require('extract-text-webpack-plugin');
4 | var HtmlWebpackPlugin = require('html-webpack-plugin');
5 |
6 | // naming output files with hashes for better caching.
7 | // dist/index.html will be auto-generated with correct URLs.
8 | config.output.filename = '[name].[chunkhash].js';
9 | config.output.chunkFilename = '[id].[chunkhash].js';
10 |
11 | // set output path for production
12 | config.output.publicPath = '/dist/';
13 |
14 | // whether to generate source map for production files.
15 | // disabling this can speed up the build.
16 | var SOURCE_MAP = true;
17 |
18 | config.devtool = SOURCE_MAP ? 'source-map' : false;
19 |
20 | // generate loader string to be used with extract text plugin
21 | function generateExtractLoaders (loaders) {
22 | return loaders.map(function (loader) {
23 | return loader + '-loader' + (SOURCE_MAP ? '?sourceMap' : '');
24 | }).join('!');
25 | }
26 |
27 | config.vue.loaders = {
28 | js: 'babel!eslint',
29 | // http://vuejs.github.io/vue-loader/configurations/extract-css.html
30 | css: ExtractTextPlugin.extract('vue-style-loader', generateExtractLoaders(['css'])),
31 | less: ExtractTextPlugin.extract('vue-style-loader', generateExtractLoaders(['css', 'less'])),
32 | sass: ExtractTextPlugin.extract('vue-style-loader', generateExtractLoaders(['css', 'sass'])),
33 | stylus: ExtractTextPlugin.extract('vue-style-loader', generateExtractLoaders(['css', 'stylus']))
34 | };
35 |
36 | config.plugins = (config.plugins || []).concat([
37 | // http://vuejs.github.io/vue-loader/workflow/production.html
38 | new webpack.DefinePlugin({
39 | 'process.env': {
40 | NODE_ENV: '"production"'
41 | }
42 | }),
43 | new webpack.optimize.UglifyJsPlugin({
44 | compress: {
45 | warnings: false
46 | }
47 | }),
48 | new webpack.optimize.OccurenceOrderPlugin(),
49 | // extract css into its own file
50 | new ExtractTextPlugin('[name].[contenthash].css'),
51 | // generate dist index.html with correct asset hash for caching.
52 | // you can customize output by editing /build/index.template.html
53 | // see https://github.com/ampedandwired/html-webpack-plugin
54 | new HtmlWebpackPlugin({
55 | filename: 'index.html',
56 | template: 'build/index.template.html'
57 | })
58 | ]);
59 |
60 | module.exports = config;
61 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | #
58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look
59 | # for the new JDKs provided by Oracle.
60 | #
61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
62 | #
63 | # Apple JDKs
64 | #
65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
66 | fi
67 |
68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
69 | #
70 | # Apple JDKs
71 | #
72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
73 | fi
74 |
75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
76 | #
77 | # Oracle JDKs
78 | #
79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
80 | fi
81 |
82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
83 | #
84 | # Apple JDKs
85 | #
86 | export JAVA_HOME=`/usr/libexec/java_home`
87 | fi
88 | ;;
89 | esac
90 |
91 | if [ -z "$JAVA_HOME" ] ; then
92 | if [ -r /etc/gentoo-release ] ; then
93 | JAVA_HOME=`java-config --jre-home`
94 | fi
95 | fi
96 |
97 | if [ -z "$M2_HOME" ] ; then
98 | ## resolve links - $0 may be a link to maven's home
99 | PRG="$0"
100 |
101 | # need this for relative symlinks
102 | while [ -h "$PRG" ] ; do
103 | ls=`ls -ld "$PRG"`
104 | link=`expr "$ls" : '.*-> \(.*\)$'`
105 | if expr "$link" : '/.*' > /dev/null; then
106 | PRG="$link"
107 | else
108 | PRG="`dirname "$PRG"`/$link"
109 | fi
110 | done
111 |
112 | saveddir=`pwd`
113 |
114 | M2_HOME=`dirname "$PRG"`/..
115 |
116 | # make it fully qualified
117 | M2_HOME=`cd "$M2_HOME" && pwd`
118 |
119 | cd "$saveddir"
120 | # echo Using m2 at $M2_HOME
121 | fi
122 |
123 | # For Cygwin, ensure paths are in UNIX format before anything is touched
124 | if $cygwin ; then
125 | [ -n "$M2_HOME" ] &&
126 | M2_HOME=`cygpath --unix "$M2_HOME"`
127 | [ -n "$JAVA_HOME" ] &&
128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
129 | [ -n "$CLASSPATH" ] &&
130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
131 | fi
132 |
133 | # For Migwn, ensure paths are in UNIX format before anything is touched
134 | if $mingw ; then
135 | [ -n "$M2_HOME" ] &&
136 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
137 | [ -n "$JAVA_HOME" ] &&
138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
139 | # TODO classpath?
140 | fi
141 |
142 | if [ -z "$JAVA_HOME" ]; then
143 | javaExecutable="`which javac`"
144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
145 | # readlink(1) is not available as standard on Solaris 10.
146 | readLink=`which readlink`
147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
148 | if $darwin ; then
149 | javaHome="`dirname \"$javaExecutable\"`"
150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
151 | else
152 | javaExecutable="`readlink -f \"$javaExecutable\"`"
153 | fi
154 | javaHome="`dirname \"$javaExecutable\"`"
155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
156 | JAVA_HOME="$javaHome"
157 | export JAVA_HOME
158 | fi
159 | fi
160 | fi
161 |
162 | if [ -z "$JAVACMD" ] ; then
163 | if [ -n "$JAVA_HOME" ] ; then
164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
165 | # IBM's JDK on AIX uses strange locations for the executables
166 | JAVACMD="$JAVA_HOME/jre/sh/java"
167 | else
168 | JAVACMD="$JAVA_HOME/bin/java"
169 | fi
170 | else
171 | JAVACMD="`which java`"
172 | fi
173 | fi
174 |
175 | if [ ! -x "$JAVACMD" ] ; then
176 | echo "Error: JAVA_HOME is not defined correctly." >&2
177 | echo " We cannot execute $JAVACMD" >&2
178 | exit 1
179 | fi
180 |
181 | if [ -z "$JAVA_HOME" ] ; then
182 | echo "Warning: JAVA_HOME environment variable is not set."
183 | fi
184 |
185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
186 |
187 | # For Cygwin, switch paths to Windows format before running java
188 | if $cygwin; then
189 | [ -n "$M2_HOME" ] &&
190 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
191 | [ -n "$JAVA_HOME" ] &&
192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
193 | [ -n "$CLASSPATH" ] &&
194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
195 | fi
196 |
197 | # traverses directory structure from process work directory to filesystem root
198 | # first directory with .mvn subdirectory is considered project base directory
199 | find_maven_basedir() {
200 | local basedir=$(pwd)
201 | local wdir=$(pwd)
202 | while [ "$wdir" != '/' ] ; do
203 | if [ -d "$wdir"/.mvn ] ; then
204 | basedir=$wdir
205 | break
206 | fi
207 | wdir=$(cd "$wdir/.."; pwd)
208 | done
209 | echo "${basedir}"
210 | }
211 |
212 | # concatenates all lines of a file
213 | concat_lines() {
214 | if [ -f "$1" ]; then
215 | echo "$(tr -s '\n' ' ' < "$1")"
216 | fi
217 | }
218 |
219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
221 |
222 | # Provide a "standardized" way to retrieve the CLI args that will
223 | # work with both Windows and non-Windows executions.
224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
225 | export MAVEN_CMD_LINE_ARGS
226 |
227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
228 |
229 | exec "$JAVACMD" \
230 | $MAVEN_OPTS \
231 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
232 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
233 | ${WRAPPER_LAUNCHER} "$@"
234 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | set MAVEN_CMD_LINE_ARGS=%*
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 |
121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
123 |
124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
125 | if ERRORLEVEL 1 goto error
126 | goto end
127 |
128 | :error
129 | set ERROR_CODE=1
130 |
131 | :end
132 | @endlocal & set ERROR_CODE=%ERROR_CODE%
133 |
134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
138 | :skipRcPost
139 |
140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
142 |
143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
144 |
145 | exit /B %ERROR_CODE%
--------------------------------------------------------------------------------
/npm:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | "node/node" "node/node_modules/npm/bin/npm-cli.js" "$@"
3 |
--------------------------------------------------------------------------------
/npm.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | %~dp0node/node node/node_modules/npm/bin/npm-cli.js %*
3 | @echo on
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vuejs-java-starter",
3 | "description": "vue.js java starter",
4 | "repository": {
5 | "type": "git",
6 | "url": "git+https://github.com/kucharzyk/vuejs-java-starter.git"
7 | },
8 | "author": "Tomasz Kucharzyk",
9 | "license": "MIT",
10 | "bugs": {
11 | "url": "https://github.com/kucharzyk/vuejs-java-starter/issues"
12 | },
13 | "private": true,
14 | "scripts": {
15 | "dev": "webpack-dev-server --inline --hot --config build/webpack.dev.conf.js",
16 | "build": "rimraf src/main/resources/static/dist && webpack --progress --hide-modules --config build/webpack.prod.conf.js",
17 | "test": "karma start build/karma.conf.js --single-run"
18 | },
19 | "dependencies": {
20 | "bootstrap": "4.0.0-alpha.2",
21 | "es6-promise": "3.0.2",
22 | "font-awesome": "4.5.0",
23 | "jquery": "2.2.0",
24 | "tether": "1.1.1",
25 | "vue": "1.0.14",
26 | "vue-resource": "0.6.1",
27 | "vue-router": "0.7.8",
28 | "vuex": "0.2.0"
29 | },
30 | "devDependencies": {
31 | "autoprefixer": "6.3.1",
32 | "babel-core": "6.3.13",
33 | "babel-loader": "6.2.0",
34 | "babel-plugin-transform-runtime": "6.4.3",
35 | "babel-preset-es2015": "6.1.2",
36 | "babel-preset-stage-2": "6.1.2",
37 | "babel-runtime": "6.1.18",
38 | "css-loader": "0.23.0",
39 | "eslint": "1.10.3",
40 | "eslint-friendly-formatter": "1.2.2",
41 | "eslint-loader": "1.3.0",
42 | "extract-text-webpack-plugin": "0.9.1",
43 | "file-loader": "0.8.4",
44 | "function-bind": "1.0.2",
45 | "html-webpack-plugin": "1.7.0",
46 | "inject-loader": "2.0.1",
47 | "jasmine-core": "2.4.1",
48 | "json-loader": "0.5.4",
49 | "karma": "0.13.19",
50 | "karma-jasmine": "0.3.6",
51 | "karma-phantomjs-launcher": "0.2.1",
52 | "karma-spec-reporter": "0.0.23",
53 | "karma-webpack": "1.7.0",
54 | "less": "2.5.3",
55 | "less-loader": "2.2.2",
56 | "node-sass": "3.4.2",
57 | "phantomjs": "2.1.7",
58 | "rimraf": "2.5.0",
59 | "sass-loader": "3.1.2",
60 | "style-loader": "0.13.0",
61 | "url-loader": "0.5.7",
62 | "vue-hot-reload-api": "1.2.0",
63 | "vue-html-loader": "1.0.0",
64 | "vue-loader": "8.0.0",
65 | "vue-style-loader": "1.0.0",
66 | "webpack": "1.12.11",
67 | "webpack-dev-server": "1.14.1"
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.shardis
7 | vuejs-java-starter
8 | 0.1.1
9 | jar
10 |
11 | vuejs-java-starter
12 | vuejs-java-starter
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.3.1.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.8
24 | 0.0.27
25 | 1.16.6
26 | 9.4-1201-jdbc41
27 | v4.2.4
28 | 3.5.3
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-cache
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-data-jpa
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-data-rest
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-devtools
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-starter-hateoas
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-starter-mail
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter-web
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-starter-websocket
63 |
64 |
65 | org.springframework.boot
66 | spring-boot-starter-thymeleaf
67 |
68 |
69 |
70 | org.projectlombok
71 | lombok
72 | ${lombok.version}
73 |
74 |
75 | org.postgresql
76 | postgresql
77 | ${postgresql.version}
78 | runtime
79 |
80 |
81 |
82 | com.h2database
83 | h2
84 | runtime
85 |
86 |
87 | org.springframework.boot
88 | spring-boot-starter-test
89 | test
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 | org.springframework.boot
98 | spring-boot-maven-plugin
99 |
100 |
101 | com.github.eirslett
102 | frontend-maven-plugin
103 | ${frontend-maven-plugin.version}
104 |
105 |
106 | install node and npm
107 |
108 | install-node-and-npm
109 |
110 |
111 | ${frontend-maven-plugin.nodeVersion}
112 | ${frontend-maven-plugin.npmVersion}
113 |
114 |
115 |
116 | npm install
117 |
118 | npm
119 |
120 |
121 | install
122 |
123 |
124 |
125 | npm build
126 |
127 | npm
128 |
129 |
130 | run build
131 |
132 |
133 |
134 | npm test
135 | test
136 |
137 | npm
138 |
139 |
140 | run test
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/ShardisFrameworkApplication.java:
--------------------------------------------------------------------------------
1 | package com.shardis;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
6 | import org.springframework.boot.context.embedded.ErrorPage;
7 | import org.springframework.cache.annotation.EnableCaching;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.http.HttpStatus;
10 |
11 | /**
12 | * Created by Tomasz Kucharzyk
13 | */
14 | @SpringBootApplication
15 | @EnableCaching
16 | public class ShardisFrameworkApplication {
17 |
18 | @Bean
19 | public EmbeddedServletContainerCustomizer containerCustomizer() {
20 |
21 | return (container -> {
22 | ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/");
23 | container.addErrorPages(error404Page);
24 | });
25 | }
26 |
27 | public static void main(String[] args) {
28 | SpringApplication.run(ShardisFrameworkApplication.class, args);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/cons/Profiles.java:
--------------------------------------------------------------------------------
1 | package com.shardis.cons;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Getter;
5 |
6 | /**
7 | * Created by Tomasz Kucharzyk
8 | */
9 |
10 | @Getter
11 | @AllArgsConstructor
12 | public enum Profiles {
13 |
14 | DEV("dev"),
15 | PROD("prod");
16 |
17 | private String profileName;
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/controllers/error/ErrorHandlerController.java:
--------------------------------------------------------------------------------
1 | package com.shardis.controllers.error;
2 |
3 | import com.google.common.collect.Lists;
4 | import com.shardis.dto.error.ServerErrorDTO;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.apache.catalina.connector.ClientAbortException;
7 | import org.springframework.http.HttpStatus;
8 | import org.springframework.http.ResponseEntity;
9 | import org.springframework.web.HttpMediaTypeNotAcceptableException;
10 | import org.springframework.web.bind.annotation.ControllerAdvice;
11 | import org.springframework.web.bind.annotation.ExceptionHandler;
12 | import org.springframework.web.bind.annotation.ResponseBody;
13 | import org.springframework.web.bind.annotation.ResponseStatus;
14 |
15 | import javax.servlet.http.HttpServletRequest;
16 |
17 | /**
18 | * Created by Tomasz Kucharzyk
19 | */
20 |
21 | @Slf4j
22 | @ControllerAdvice
23 | public class ErrorHandlerController {
24 |
25 | @ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
26 | public void procesHttpMediaTypeNotAcceptableException(HttpMediaTypeNotAcceptableException ex) {
27 | log.debug(ex.getMessage(),ex);
28 | }
29 |
30 | @ExceptionHandler(ClientAbortException.class)
31 | public void processClientAbortException(ClientAbortException ex) {
32 | log.debug(ex.getMessage(),ex);
33 | log.debug("client disconected");
34 | }
35 |
36 | @ExceptionHandler(Exception.class)
37 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
38 | @ResponseBody
39 | public ServerErrorDTO processException(Exception ex) {
40 | log.error(ex.getMessage(),ex);
41 | return new ServerErrorDTO(ex.getClass().getCanonicalName(), ex.getMessage(), Lists.newArrayList());
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/controllers/rest/ChatController.java:
--------------------------------------------------------------------------------
1 | package com.shardis.controllers.rest;
2 |
3 |
4 | import com.shardis.dto.chat.ChatMessage;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.http.MediaType;
7 | import org.springframework.web.bind.annotation.*;
8 | import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
9 |
10 | import java.io.IOException;
11 | import java.util.ArrayList;
12 | import java.util.Collections;
13 | import java.util.List;
14 | import java.util.concurrent.TimeUnit;
15 |
16 | /**
17 | * Created by Tomasz Kucharzyk
18 | */
19 |
20 | @Slf4j
21 | @RestController
22 | @RequestMapping("/rest/chat")
23 | public class ChatController {
24 |
25 | private final List sseEmitters = Collections.synchronizedList(new ArrayList<>());
26 |
27 | @RequestMapping(path = "/post", method = RequestMethod.POST, produces = "application/json")
28 | @ResponseBody
29 | ChatMessage jsonCreate(@RequestBody ChatMessage chatMessage) throws IOException {
30 | log.info("Message received -> resending to " + sseEmitters.size() + " client(s)");
31 | synchronized (sseEmitters) {
32 | for (SseEmitter sseEmitter : sseEmitters) {
33 | sseEmitter.send(chatMessage, MediaType.APPLICATION_JSON);
34 | }
35 | }
36 | return chatMessage;
37 | }
38 |
39 | @RequestMapping("/sse/updates")
40 | SseEmitter subscribeUpdates() {
41 | SseEmitter sseEmitter = new SseEmitter(TimeUnit.MINUTES.toMillis(1));
42 | synchronized (sseEmitters) {
43 | this.sseEmitters.add(sseEmitter);
44 | log.info("Client connected");
45 | sseEmitter.onCompletion(() -> {
46 | synchronized (sseEmitters) {
47 | sseEmitters.remove(sseEmitter);
48 | log.info("Client disconnected");
49 | }
50 | });
51 | }
52 | return sseEmitter;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/controllers/rest/SampleRestController.java:
--------------------------------------------------------------------------------
1 | package com.shardis.controllers.rest;
2 |
3 |
4 | import com.google.common.collect.Lists;
5 | import com.shardis.dto.user.UserPost;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import java.time.LocalDateTime;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by Tomasz Kucharzyk
15 | */
16 |
17 | @RestController
18 | @RequestMapping("/rest")
19 | public class SampleRestController {
20 |
21 | @RequestMapping("/test")
22 | public List test() {
23 | return Lists.newArrayList("Vue.js", "is", "great");
24 | }
25 |
26 | @RequestMapping("/fail")
27 | public List fail() {
28 | throw new RuntimeException("method failed");
29 | }
30 |
31 | @RequestMapping("/user/{userId}/posts")
32 | public List userPosts(@PathVariable("userId") Long userId) {
33 | List posts = Lists.newArrayList();
34 | for (long i = 1; i <= 8; i++) {
35 | posts.add(new UserPost(i, "Post #" + i + " of user " + userId, "sample content #" + i, LocalDateTime.now()));
36 | }
37 | return posts;
38 | }
39 |
40 | @RequestMapping("/user/{userId}/settings")
41 | public List userSettings(@PathVariable("userId") Long userId) throws InterruptedException {
42 | //Don't do that at home
43 | Thread.currentThread().sleep(1000);
44 |
45 | List settings = Lists.newArrayList();
46 | for (int i = 0; i < 10; i++) {
47 | settings.add("Setting #" + i+" of user "+userId);
48 | }
49 | return settings;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/controllers/web/MainPageController.java:
--------------------------------------------------------------------------------
1 | package com.shardis.controllers.web;
2 |
3 | import com.shardis.utils.EnvironmentProvider;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.stereotype.Controller;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.ResponseStatus;
9 | import org.springframework.web.servlet.ModelAndView;
10 |
11 | /**
12 | * Created by Tomasz Kucharzyk
13 | */
14 |
15 | @Controller
16 | @RequestMapping("/")
17 | public class MainPageController {
18 |
19 | @Autowired
20 | EnvironmentProvider environmentProvider;
21 |
22 | @ResponseStatus(HttpStatus.OK)
23 | @RequestMapping("/")
24 | public ModelAndView mainPage() {
25 | if (environmentProvider.isProduction()) {
26 | return new ModelAndView("forward://dist/index.html");
27 | } else {
28 | return new ModelAndView("forward://index.html");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/dto/chat/ChatMessage.java:
--------------------------------------------------------------------------------
1 | package com.shardis.dto.chat;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 | import lombok.NoArgsConstructor;
7 |
8 | /**
9 | * Created by tomasz on 14.01.16.
10 | * All rights reserved Bazus 2016
11 | */
12 | @Data
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | @EqualsAndHashCode
16 | public class ChatMessage {
17 | private String message;
18 | private String author;
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/shardis/dto/error/ServerErrorDTO.java:
--------------------------------------------------------------------------------
1 | package com.shardis.dto.error;
2 |
3 | import com.google.common.collect.Lists;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by Tomasz Kucharzyk
12 | */
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | @Data
16 | public class ServerErrorDTO {
17 | private String error;
18 | private String description;
19 | private List