Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
e69296d7
Commit
e69296d7
authored
May 25, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix checkstyle violations in samples
parent
48534770
Changes
117
Hide whitespace changes
Inline
Side-by-side
Showing
117 changed files
with
453 additions
and
482 deletions
+453
-482
checkstyle-suppressions.xml
...ng-boot-parent/src/checkstyle/checkstyle-suppressions.xml
+5
-2
application.properties
...actuator-log4j2/src/main/resources/application.properties
+1
-2
application.properties
...ple-actuator-ui/src/main/resources/application.properties
+1
-1
application-cors.properties
...e-actuator/src/test/resources/application-cors.properties
+1
-1
application-endpoints.properties
...uator/src/test/resources/application-endpoints.properties
+1
-1
SampleAntApplicationIT.java
...-ant/src/test/java/sample/ant/SampleAntApplicationIT.java
+3
-2
application.properties
...boot-sample-ant/src/test/resources/application.properties
+1
-1
application.properties
...boot-sample-aop/src/main/resources/application.properties
+1
-1
SampleAtmosphereApplication.java
...n/java/sample/atmosphere/SampleAtmosphereApplication.java
+5
-5
SampleClient.java
...sample-cache/src/main/java/sample/cache/SampleClient.java
+2
-2
SampleLayout.java
...stom-layout/src/main/java/sample/layout/SampleLayout.java
+4
-2
CustomerRepository.java
...c/main/java/sample/data/cassandra/CustomerRepository.java
+3
-3
CustomerRepository.java
...in/java/sample/data/elasticsearch/CustomerRepository.java
+3
-3
CityServiceImpl.java
...rc/main/java/sample/data/jpa/service/CityServiceImpl.java
+1
-2
HotelServiceImpl.java
...c/main/java/sample/data/jpa/service/HotelServiceImpl.java
+3
-4
application-scratch.properties
...ata-jpa/src/test/resources/application-scratch.properties
+1
-1
Customer.java
...ata-mongodb/src/main/java/sample/data/mongo/Customer.java
+2
-2
application.properties
...le-data-mongodb/src/main/resources/application.properties
+0
-0
Customer.java
...-data-neo4j/src/main/java/sample/data/neo4j/Customer.java
+2
-2
CustomerRepository.java
...j/src/main/java/sample/data/neo4j/CustomerRepository.java
+3
-3
application.properties
...mple-data-neo4j/src/main/resources/application.properties
+0
-0
SampleNeo4jApplicationTests.java
...t/java/sample/data/neo4j/SampleNeo4jApplicationTests.java
+3
-4
application.properties
...ample-data-rest/src/main/resources/application.properties
+1
-1
Message.java
...ample-devtools/src/main/java/sample/devtools/Message.java
+8
-2
application.properties
...t-sample-flyway/src/main/resources/application.properties
+1
-3
CityServiceImpl.java
.../main/java/sample/hibernate4/service/CityServiceImpl.java
+1
-2
HotelServiceImpl.java
...main/java/sample/hibernate4/service/HotelServiceImpl.java
+3
-4
application-scratch.properties
...ernate4/src/test/resources/application-scratch.properties
+1
-1
CityServiceImpl.java
...main/java/sample/hibernate52/service/CityServiceImpl.java
+1
-2
HotelServiceImpl.java
...ain/java/sample/hibernate52/service/HotelServiceImpl.java
+3
-4
application-scratch.properties
...rnate52/src/test/resources/application-scratch.properties
+1
-1
application.properties
...hypermedia-gson/src/main/resources/application.properties
+1
-2
application.properties
...-hypermedia-jpa/src/main/resources/application.properties
+1
-1
application.properties
...e-hypermedia-ui/src/main/resources/application.properties
+1
-2
application.properties
...mple-hypermedia/src/main/resources/application.properties
+1
-2
application.properties
...-sample-jersey1/src/main/resources/application.properties
+0
-0
application.properties
...ample-jetty-ssl/src/main/resources/application.properties
+1
-1
application.properties
...mple-jetty8-ssl/src/main/resources/application.properties
+1
-1
application.properties
...le-jta-atomikos/src/main/resources/application.properties
+1
-1
application.properties
...le-jta-bitronix/src/main/resources/application.properties
+1
-1
application.properties
...le-jta-narayana/src/main/resources/application.properties
+1
-1
application.properties
...etrics-opentsdb/src/main/resources/application.properties
+1
-2
application.properties
...e-metrics-redis/src/main/resources/application.properties
+1
-1
SampleParentContextApplication.java
...in/java/sample/parent/SampleParentContextApplication.java
+6
-6
application.properties
...-parent-context/src/main/resources/application.properties
+1
-1
MessageService.java
.../src/main/java/sample/profile/service/MessageService.java
+1
-4
application.properties
...erty-validation/src/main/resources/application.properties
+1
-1
SampleSecureOAuth2ActuatorApplication.java
...auth2/actuator/SampleSecureOAuth2ActuatorApplication.java
+2
-2
SampleSecureOAuth2ActuatorApplicationTests.java
.../actuator/SampleSecureOAuth2ActuatorApplicationTests.java
+4
-3
Flight.java
...e/src/main/java/sample/secure/oauth2/resource/Flight.java
+2
-2
FlightRepository.java
.../java/sample/secure/oauth2/resource/FlightRepository.java
+2
-2
SampleSecureOAuth2ResourceApplicationTests.java
.../resource/SampleSecureOAuth2ResourceApplicationTests.java
+5
-4
Flight.java
...ure-oauth2/src/main/java/sample/secure/oauth2/Flight.java
+2
-2
FlightRepository.java
.../src/main/java/sample/secure/oauth2/FlightRepository.java
+2
-2
SampleSecureOAuth2ApplicationTests.java
...ple/secure/oauth2/SampleSecureOAuth2ApplicationTests.java
+4
-3
SampleService.java
...ple-secure/src/main/java/sample/secure/SampleService.java
+1
-5
application.properties
...t-sample-secure/src/main/resources/application.properties
+1
-1
test.properties
...ing-boot-sample-secure/src/test/resources/test.properties
+1
-1
VehicleIdentificationNumberNotFoundException.java
...service/VehicleIdentificationNumberNotFoundException.java
+1
-1
UserNameNotFoundException.java
.../main/java/sample/test/web/UserNameNotFoundException.java
+2
-2
application.properties
...mple-tomcat-jsp/src/main/resources/application.properties
+1
-1
SampleTomcatTwoConnectorsApplication.java
.../multiconnector/SampleTomcatTwoConnectorsApplication.java
+2
-2
SampleTomcatTwoConnectorsApplicationTests.java
...iconnector/SampleTomcatTwoConnectorsApplicationTests.java
+1
-1
NonAutoConfigurationSampleTomcatApplicationTests.java
...cat/NonAutoConfigurationSampleTomcatApplicationTests.java
+8
-8
application.properties
...ple-tomcat7-jsp/src/main/resources/application.properties
+1
-1
application.properties
...le-undertow-ssl/src/main/resources/application.properties
+1
-1
application.properties
...sample-undertow/src/main/resources/application.properties
+1
-1
SampleWarApplication.java
...le-war/src/main/java/sample/war/SampleWarApplication.java
+2
-5
application.properties
...-web-freemarker/src/main/resources/application.properties
+1
-1
application.properties
...roovy-templates/src/main/resources/application.properties
+1
-1
MessageControllerWebTests.java
...ava/sample/groovytemplates/MessageControllerWebTests.java
+6
-6
application.properties
...-sample-web-jsp/src/main/resources/application.properties
+1
-1
SampleMethodSecurityApplication.java
...mple/security/method/SampleMethodSecurityApplication.java
+11
-11
application.properties
...method-security/src/main/resources/application.properties
+1
-1
application.properties
...le-web-mustache/src/main/resources/application.properties
+1
-1
application.properties
...b-secure-custom/src/main/resources/application.properties
+1
-1
application.properties
...web-secure-jdbc/src/main/resources/application.properties
+1
-1
application.properties
...mple-web-secure/src/main/resources/application.properties
+1
-1
InMemoryMessageRepository.java
...java/sample/web/thymeleaf3/InMemoryMessageRepository.java
+1
-4
Message.java
...ymeleaf3/src/main/java/sample/web/thymeleaf3/Message.java
+0
-3
MessageRepository.java
...rc/main/java/sample/web/thymeleaf3/MessageRepository.java
+1
-4
MessageController.java
...ain/java/sample/web/thymeleaf3/mvc/MessageController.java
+3
-7
MessageControllerWebTests.java
...java/sample/web/thymeleaf3/MessageControllerWebTests.java
+5
-5
InMemoryMessageRepository.java
...rc/main/java/sample/web/ui/InMemoryMessageRepository.java
+1
-4
Message.java
...ot-sample-web-ui/src/main/java/sample/web/ui/Message.java
+8
-8
MessageRepository.java
...web-ui/src/main/java/sample/web/ui/MessageRepository.java
+9
-9
MessageController.java
...ui/src/main/java/sample/web/ui/mvc/MessageController.java
+3
-7
application.properties
...t-sample-web-ui/src/main/resources/application.properties
+1
-1
MessageControllerWebTests.java
...rc/test/java/sample/web/ui/MessageControllerWebTests.java
+5
-5
DefaultEchoService.java
...java/samples/websocket/jetty/echo/DefaultEchoService.java
+2
-2
Direction.java
...rc/main/java/samples/websocket/jetty/snake/Direction.java
+5
-6
Location.java
...src/main/java/samples/websocket/jetty/snake/Location.java
+15
-19
Snake.java
...ty/src/main/java/samples/websocket/jetty/snake/Snake.java
+5
-6
SnakeTimer.java
...c/main/java/samples/websocket/jetty/snake/SnakeTimer.java
+9
-7
SnakeUtils.java
...c/main/java/samples/websocket/jetty/snake/SnakeUtils.java
+18
-7
SnakeWebSocketHandler.java
.../samples/websocket/jetty/snake/SnakeWebSocketHandler.java
+10
-17
DefaultEchoService.java
...va/samples/websocket/jetty93/echo/DefaultEchoService.java
+2
-2
Direction.java
.../main/java/samples/websocket/jetty93/snake/Direction.java
+5
-6
Location.java
...c/main/java/samples/websocket/jetty93/snake/Location.java
+15
-19
Snake.java
.../src/main/java/samples/websocket/jetty93/snake/Snake.java
+5
-6
SnakeTimer.java
...main/java/samples/websocket/jetty93/snake/SnakeTimer.java
+9
-7
SnakeUtils.java
...main/java/samples/websocket/jetty93/snake/SnakeUtils.java
+18
-7
SnakeWebSocketHandler.java
...amples/websocket/jetty93/snake/SnakeWebSocketHandler.java
+10
-17
DefaultEchoService.java
...ava/samples/websocket/tomcat/echo/DefaultEchoService.java
+2
-2
Direction.java
...c/main/java/samples/websocket/tomcat/snake/Direction.java
+5
-6
Location.java
...rc/main/java/samples/websocket/tomcat/snake/Location.java
+15
-19
Snake.java
...t/src/main/java/samples/websocket/tomcat/snake/Snake.java
+5
-6
SnakeTimer.java
.../main/java/samples/websocket/tomcat/snake/SnakeTimer.java
+12
-10
SnakeUtils.java
.../main/java/samples/websocket/tomcat/snake/SnakeUtils.java
+18
-7
SnakeWebSocketHandler.java
...samples/websocket/tomcat/snake/SnakeWebSocketHandler.java
+10
-17
DefaultEchoService.java
...a/samples/websocket/undertow/echo/DefaultEchoService.java
+2
-2
Direction.java
...main/java/samples/websocket/undertow/snake/Direction.java
+5
-6
Location.java
.../main/java/samples/websocket/undertow/snake/Location.java
+15
-19
Snake.java
...src/main/java/samples/websocket/undertow/snake/Snake.java
+5
-6
SnakeTimer.java
...ain/java/samples/websocket/undertow/snake/SnakeTimer.java
+9
-7
SnakeUtils.java
...ain/java/samples/websocket/undertow/snake/SnakeUtils.java
+18
-7
SnakeWebSocketHandler.java
...mples/websocket/undertow/snake/SnakeWebSocketHandler.java
+10
-17
No files found.
spring-boot-parent/src/checkstyle/checkstyle-suppressions.xml
View file @
e69296d7
...
...
@@ -5,8 +5,7 @@
<suppressions>
<suppress
files=
"SpringApplicationTests\.java"
checks=
"FinalClass"
/>
<suppress
files=
".+Configuration\.java"
checks=
"HideUtilityClassConstructor"
/>
<suppress
files=
"LaunchScriptTestApplication\.java"
checks=
"HideUtilityClassConstructor"
/>
<suppress
files=
"DevToolsTestApplication\.java"
checks=
"HideUtilityClassConstructor"
/>
<suppress
files=
".+Application\.java"
checks=
"HideUtilityClassConstructor"
/>
<suppress
files=
"SignalUtils\.java"
checks=
"IllegalImport"
/>
<suppress
files=
"[\\/]src[\\/]test[\\/]java[\\/]cli[\\/]command[\\/]"
checks=
"ImportControl"
/>
<suppress
files=
"[\\/]src[\\/]main[\\/]java[\\/]sample[\\/]"
checks=
"ImportControl"
/>
...
...
@@ -23,4 +22,8 @@
<suppress
files=
"LogLevel\.java"
checks=
"JavadocVariable"
/>
<suppress
files=
"HelpMojo\.java"
checks=
".*"
/>
<suppress
files=
"[\\/]org.springframework.boot.configurationprocessor.json[\\/].*\.java$"
checks=
".*"
/>
<suppress
files=
"TripType\.java"
checks=
"JavadocVariable"
/>
<suppress
files=
"Rating\.java"
checks=
"JavadocVariable"
/>
<suppress
files=
"Direction\.java"
checks=
"JavadocVariable"
/>
<suppress
files=
"JooqExamples\.java"
checks=
"AvoidStaticImport"
/>
</suppressions>
spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties
View file @
e69296d7
endpoints.shutdown.enabled
=
true
management.security.enabled
=
false
\ No newline at end of file
management.security.enabled
=
false
spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties
View file @
e69296d7
health.diskspace.enabled
=
false
\ No newline at end of file
health.diskspace.enabled
=
false
spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-cors.properties
View file @
e69296d7
endpoints.cors.allowed-origins
=
http://localhost:8080
endpoints.cors.allowed-methods
=
GET
\ No newline at end of file
endpoints.cors.allowed-methods
=
GET
spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties
View file @
e69296d7
server.error.path
:
/oops
management.context-path
:
/admin
endpoints.health.sensitive
:
false
\ No newline at end of file
endpoints.health.sensitive
:
false
spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java
View file @
e69296d7
...
...
@@ -16,17 +16,18 @@
package
sample
.
ant
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.InputStreamReader
;
import
java.util.concurrent.TimeUnit
;
import
org.junit.Test
;
import
org.springframework.boot.loader.tools.JavaExecutable
;
import
org.springframework.util.FileCopyUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration Tests for {@code SampleAntApplication}.
*
...
...
spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties
View file @
e69296d7
name
:
Phil
\ No newline at end of file
name
:
Phil
spring-boot-samples/spring-boot-sample-aop/src/main/resources/application.properties
View file @
e69296d7
name
:
Phil
\ No newline at end of file
name
:
Phil
spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -59,6 +59,10 @@ public class SampleAtmosphereApplication {
return
registration
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleAtmosphereApplication
.
class
,
args
);
}
@Configuration
static
class
MvcConfiguration
extends
WebMvcConfigurerAdapter
{
...
...
@@ -79,8 +83,4 @@ public class SampleAtmosphereApplication {
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleAtmosphereApplication
.
class
,
args
);
}
}
spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -53,7 +53,7 @@ class SampleClient {
private
final
Random
random
;
public
SampleClient
(
CountryRepository
countryService
)
{
SampleClient
(
CountryRepository
countryService
)
{
this
.
countryService
=
countryService
;
this
.
random
=
new
Random
();
}
...
...
spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayout.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -24,7 +24,9 @@ import org.springframework.boot.loader.tools.Layouts;
import
org.springframework.boot.loader.tools.LoaderClassesWriter
;
/**
* @author pwebb
* An example layout.
*
* @author Phillip Webb
*/
public
class
SampleLayout
extends
Layouts
.
Jar
implements
CustomLoaderLayout
{
...
...
spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/CustomerRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -24,9 +24,9 @@ import org.springframework.data.repository.CrudRepository;
public
interface
CustomerRepository
extends
CrudRepository
<
Customer
,
String
>
{
@Query
(
"Select * from customer where firstname=?0"
)
public
Customer
findByFirstName
(
String
firstName
);
Customer
findByFirstName
(
String
firstName
);
@Query
(
"Select * from customer where lastname=?0"
)
public
List
<
Customer
>
findByLastName
(
String
lastName
);
List
<
Customer
>
findByLastName
(
String
lastName
);
}
spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -22,8 +22,8 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
public
interface
CustomerRepository
extends
ElasticsearchRepository
<
Customer
,
String
>
{
public
Customer
findByFirstName
(
String
firstName
);
Customer
findByFirstName
(
String
firstName
);
public
List
<
Customer
>
findByLastName
(
String
lastName
);
List
<
Customer
>
findByLastName
(
String
lastName
);
}
spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java
View file @
e69296d7
...
...
@@ -34,8 +34,7 @@ class CityServiceImpl implements CityService {
private
final
HotelRepository
hotelRepository
;
public
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
this
.
cityRepository
=
cityRepository
;
this
.
hotelRepository
=
hotelRepository
;
}
...
...
spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelServiceImpl.java
View file @
e69296d7
...
...
@@ -41,8 +41,7 @@ class HotelServiceImpl implements HotelService {
private
final
ReviewRepository
reviewRepository
;
public
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
this
.
hotelRepository
=
hotelRepository
;
this
.
reviewRepository
=
reviewRepository
;
}
...
...
@@ -82,7 +81,7 @@ class HotelServiceImpl implements HotelService {
private
final
Map
<
Rating
,
Long
>
ratingCount
;
public
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
this
.
ratingCount
=
new
HashMap
<
Rating
,
Long
>();
for
(
RatingCount
ratingCount
:
ratingCounts
)
{
this
.
ratingCount
.
put
(
ratingCount
.
getRating
(),
ratingCount
.
getCount
());
...
...
@@ -92,7 +91,7 @@ class HotelServiceImpl implements HotelService {
@Override
public
long
getNumberOfReviewsWithRating
(
Rating
rating
)
{
Long
count
=
this
.
ratingCount
.
get
(
rating
);
return
count
==
null
?
0
:
count
;
return
(
count
!=
null
?
count
:
0
)
;
}
}
...
...
spring-boot-samples/spring-boot-sample-data-jpa/src/test/resources/application-scratch.properties
View file @
e69296d7
spring.datasource.name
=
scratchdb
spring.jmx.default-domain
=
jpa.sample
\ No newline at end of file
spring.jmx.default-domain
=
jpa.sample
spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java
View file @
e69296d7
...
...
@@ -37,8 +37,8 @@ public class Customer {
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
id
,
firstName
,
lastName
);
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
this
.
id
,
this
.
firstName
,
this
.
lastName
);
}
}
spring-boot-samples/spring-boot-sample-data-mongodb/src/main/resources/application.properties
deleted
100644 → 0
View file @
48534770
spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java
View file @
e69296d7
...
...
@@ -39,8 +39,8 @@ public class Customer {
@Override
public
String
toString
()
{
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
id
,
firstName
,
lastName
);
return
String
.
format
(
"Customer[id=%s, firstName='%s', lastName='%s']"
,
this
.
id
,
this
.
firstName
,
this
.
lastName
);
}
}
spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/CustomerRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -22,8 +22,8 @@ import org.springframework.data.neo4j.repository.GraphRepository;
public
interface
CustomerRepository
extends
GraphRepository
<
Customer
>
{
public
Customer
findByFirstName
(
String
firstName
);
Customer
findByFirstName
(
String
firstName
);
public
List
<
Customer
>
findByLastName
(
String
lastName
);
List
<
Customer
>
findByLastName
(
String
lastName
);
}
spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties
deleted
100644 → 0
View file @
48534770
spring-boot-samples/spring-boot-sample-data-neo4j/src/test/java/sample/data/neo4j/SampleNeo4jApplicationTests.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
org.springframework.boot.test.rule.OutputCapture
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleNeo4jApplication}.
...
...
@@ -46,8 +46,7 @@ public class SampleNeo4jApplicationTests {
}
}
String
output
=
this
.
outputCapture
.
toString
();
assertTrue
(
"Wrong output: "
+
output
,
output
.
contains
(
"firstName='Alice', lastName='Smith'"
));
assertThat
(
output
).
contains
(
"firstName='Alice', lastName='Smith'"
);
}
private
boolean
neo4jServerRunning
(
Throwable
ex
)
{
...
...
spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/application.properties
View file @
e69296d7
spring.data.rest.base-path
=
/api
\ No newline at end of file
spring.data.rest.base-path
=
/api
spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/Message.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,8 +16,14 @@
package
sample
.
devtools
;
public
class
Message
{
public
final
class
Message
{
/**
* Sample message.
*/
public
static
String
MESSAGE
=
"Message"
;
private
Message
()
{
}
}
spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties
View file @
e69296d7
management.security.enabled
=
false
spring.jpa.hibernate.ddl-auto
=
validate
spring.h2.console.enabled
=
true
\ No newline at end of file
spring.h2.console.enabled
=
true
spring-boot-samples/spring-boot-sample-hibernate4/src/main/java/sample/hibernate4/service/CityServiceImpl.java
View file @
e69296d7
...
...
@@ -34,8 +34,7 @@ class CityServiceImpl implements CityService {
private
final
HotelRepository
hotelRepository
;
public
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
this
.
cityRepository
=
cityRepository
;
this
.
hotelRepository
=
hotelRepository
;
}
...
...
spring-boot-samples/spring-boot-sample-hibernate4/src/main/java/sample/hibernate4/service/HotelServiceImpl.java
View file @
e69296d7
...
...
@@ -41,8 +41,7 @@ class HotelServiceImpl implements HotelService {
private
final
ReviewRepository
reviewRepository
;
public
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
this
.
hotelRepository
=
hotelRepository
;
this
.
reviewRepository
=
reviewRepository
;
}
...
...
@@ -82,7 +81,7 @@ class HotelServiceImpl implements HotelService {
private
final
Map
<
Rating
,
Long
>
ratingCount
;
public
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
this
.
ratingCount
=
new
HashMap
<
Rating
,
Long
>();
for
(
RatingCount
ratingCount
:
ratingCounts
)
{
this
.
ratingCount
.
put
(
ratingCount
.
getRating
(),
ratingCount
.
getCount
());
...
...
@@ -92,7 +91,7 @@ class HotelServiceImpl implements HotelService {
@Override
public
long
getNumberOfReviewsWithRating
(
Rating
rating
)
{
Long
count
=
this
.
ratingCount
.
get
(
rating
);
return
count
==
null
?
0
:
count
;
return
(
count
!=
null
?
count
:
0
)
;
}
}
...
...
spring-boot-samples/spring-boot-sample-hibernate4/src/test/resources/application-scratch.properties
View file @
e69296d7
spring.datasource.name
=
scratchdb
spring.jmx.default-domain
=
jpa.sample
\ No newline at end of file
spring.jmx.default-domain
=
jpa.sample
spring-boot-samples/spring-boot-sample-hibernate52/src/main/java/sample/hibernate52/service/CityServiceImpl.java
View file @
e69296d7
...
...
@@ -34,8 +34,7 @@ class CityServiceImpl implements CityService {
private
final
HotelRepository
hotelRepository
;
public
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
CityServiceImpl
(
CityRepository
cityRepository
,
HotelRepository
hotelRepository
)
{
this
.
cityRepository
=
cityRepository
;
this
.
hotelRepository
=
hotelRepository
;
}
...
...
spring-boot-samples/spring-boot-sample-hibernate52/src/main/java/sample/hibernate52/service/HotelServiceImpl.java
View file @
e69296d7
...
...
@@ -41,8 +41,7 @@ class HotelServiceImpl implements HotelService {
private
final
ReviewRepository
reviewRepository
;
public
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
HotelServiceImpl
(
HotelRepository
hotelRepository
,
ReviewRepository
reviewRepository
)
{
this
.
hotelRepository
=
hotelRepository
;
this
.
reviewRepository
=
reviewRepository
;
}
...
...
@@ -82,7 +81,7 @@ class HotelServiceImpl implements HotelService {
private
final
Map
<
Rating
,
Long
>
ratingCount
;
public
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
ReviewsSummaryImpl
(
List
<
RatingCount
>
ratingCounts
)
{
this
.
ratingCount
=
new
HashMap
<
Rating
,
Long
>();
for
(
RatingCount
ratingCount
:
ratingCounts
)
{
this
.
ratingCount
.
put
(
ratingCount
.
getRating
(),
ratingCount
.
getCount
());
...
...
@@ -92,7 +91,7 @@ class HotelServiceImpl implements HotelService {
@Override
public
long
getNumberOfReviewsWithRating
(
Rating
rating
)
{
Long
count
=
this
.
ratingCount
.
get
(
rating
);
return
count
==
null
?
0
:
count
;
return
(
count
!=
null
?
count
:
0
)
;
}
}
...
...
spring-boot-samples/spring-boot-sample-hibernate52/src/test/resources/application-scratch.properties
View file @
e69296d7
spring.datasource.name
=
scratchdb
spring.jmx.default-domain
=
jpa.sample
\ No newline at end of file
spring.jmx.default-domain
=
jpa.sample
spring-boot-samples/spring-boot-sample-hypermedia-gson/src/main/resources/application.properties
View file @
e69296d7
# management.context-path=/admin
management.security.enabled
=
false
spring.http.converters.preferred-json-mapper
=
gson
\ No newline at end of file
spring.http.converters.preferred-json-mapper
=
gson
spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/main/resources/application.properties
View file @
e69296d7
management.context-path
=
/admin
endpoints.docs.curies.enabled
=
true
\ No newline at end of file
endpoints.docs.curies.enabled
=
true
spring-boot-samples/spring-boot-sample-hypermedia-ui/src/main/resources/application.properties
View file @
e69296d7
management.security.enabled
=
false
management.context-path
=
/admin
\ No newline at end of file
management.context-path
=
/admin
spring-boot-samples/spring-boot-sample-hypermedia/src/main/resources/application.properties
View file @
e69296d7
# management.context-path=/admin
management.security.enabled
=
false
endpoints.docs.curies.enabled
=
true
\ No newline at end of file
endpoints.docs.curies.enabled
=
true
spring-boot-samples/spring-boot-sample-jersey1/src/main/resources/application.properties
deleted
100644 → 0
View file @
48534770
spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties
View file @
e69296d7
server.port
=
8443
server.ssl.key-store
=
classpath:sample.jks
server.ssl.key-store-password
=
secret
server.ssl.key-password
=
password
\ No newline at end of file
server.ssl.key-password
=
password
spring-boot-samples/spring-boot-sample-jetty8-ssl/src/main/resources/application.properties
View file @
e69296d7
server.port
=
8443
server.ssl.key-store
=
classpath:sample.jks
server.ssl.key-store-password
=
secret
server.ssl.key-password
=
password
\ No newline at end of file
server.ssl.key-password
=
password
spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties
View file @
e69296d7
logging.level.com.atomikos
=
WARN
spring.artemis.embedded.queues
=
accounts
\ No newline at end of file
spring.artemis.embedded.queues
=
accounts
spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties
View file @
e69296d7
spring.artemis.embedded.queues
=
accounts
\ No newline at end of file
spring.artemis.embedded.queues
=
accounts
spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties
View file @
e69296d7
spring.artemis.embedded.queues
=
accounts
logging.level.com.arjuna
=
INFO
\ No newline at end of file
logging.level.com.arjuna
=
INFO
spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/resources/application.properties
View file @
e69296d7
management.security.enabled
=
false
service.name
=
Phil
metrics.names.tags.process
=
${spring.application.name:application}:${random.value:0000}
\ No newline at end of file
metrics.names.tags.process
=
${spring.application.name:application}:${random.value:0000}
spring-boot-samples/spring-boot-sample-metrics-redis/src/main/resources/application.properties
View file @
e69296d7
...
...
@@ -6,4 +6,4 @@ spring.metrics.export.redis.key=keys.metrics.sample
spring.metrics.export.aggregate.prefix
=
${random.value:0000}.${spring.application.name:application}
spring.metrics.export.aggregate.key-pattern
=
d
spring.jmx.default-domain
=
org.springframework.boot
spring.data.redis.repositories.enabled
=
false
\ No newline at end of file
spring.data.redis.repositories.enabled
=
false
spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -36,6 +36,11 @@ import org.springframework.integration.file.FileWritingMessageHandler;
@EnableConfigurationProperties
(
ServiceProperties
.
class
)
public
class
SampleParentContextApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SpringApplicationBuilder
(
Parent
.
class
)
.
child
(
SampleParentContextApplication
.
class
).
run
(
args
);
}
@EnableAutoConfiguration
protected
static
class
Parent
{
...
...
@@ -83,9 +88,4 @@ public class SampleParentContextApplication {
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SpringApplicationBuilder
(
Parent
.
class
)
.
child
(
SampleParentContextApplication
.
class
).
run
(
args
);
}
}
spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties
View file @
e69296d7
service.greeting
=
Hello
\ No newline at end of file
service.greeting
=
Hello
spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/MessageService.java
View file @
e69296d7
/*
* Copyright 2012-201
3
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,9 +16,6 @@
package
sample
.
profile
.
service
;
/**
* @author Dave Syer
*/
public
interface
MessageService
{
String
getMessage
();
...
...
spring-boot-samples/spring-boot-sample-property-validation/src/main/resources/application.properties
View file @
e69296d7
sample.host
=
192.168.0.1
sample.port
=
7070
\ No newline at end of file
sample.port
=
7070
spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/main/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -44,7 +44,7 @@ public class SampleSecureOAuth2ActuatorApplication {
private
String
value
;
public
Message
(
String
value
)
{
Message
(
String
value
)
{
this
.
value
=
value
;
}
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2-actuator/src/test/java/sample/secure/oauth2/actuator/SampleSecureOAuth2ActuatorApplicationTests.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -27,6 +27,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.web.FilterChainProxy
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.util.Base64Utils
;
import
org.springframework.web.context.WebApplicationContext
;
...
...
@@ -35,7 +36,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
setup
.
MockMvcBuilders
.
webAppContextSetup
;
/**
* Series of automated integration tests to verify proper behavior of auto-configured,
...
...
@@ -57,7 +57,8 @@ public class SampleSecureOAuth2ActuatorApplicationTests {
@Before
public
void
setUp
()
{
this
.
mvc
=
webAppContextSetup
(
this
.
context
).
addFilters
(
this
.
filterChain
).
build
();
this
.
mvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
context
)
.
addFilters
(
this
.
filterChain
).
build
();
SecurityContextHolder
.
clearContext
();
}
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/main/java/sample/secure/oauth2/resource/Flight.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -26,7 +26,7 @@ import javax.persistence.Id;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
/**
* Domain object for tracking flights
* Domain object for tracking flights
.
*
* @author Craig Walls
* @author Greg Turnquist
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/main/java/sample/secure/oauth2/resource/FlightRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -19,7 +19,7 @@ package sample.secure.oauth2.resource;
import
org.springframework.data.repository.CrudRepository
;
/**
* Spring Data interface with secured methods
* Spring Data interface with secured methods
.
*
* @author Craig Walls
* @author Greg Turnquist
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/test/java/sample/secure/oauth2/resource/SampleSecureOAuth2ResourceApplicationTests.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -28,16 +28,16 @@ import org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.web.FilterChainProxy
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
setup
.
MockMvcBuilders
.
webAppContextSetup
;
/**
* Series of automated integration tests to verify proper behavior of auto-configured,
* OAuth2-secured system
* OAuth2-secured system
.
*
* @author Greg Turnquist
* @author Dave Syer
...
...
@@ -56,7 +56,8 @@ public class SampleSecureOAuth2ResourceApplicationTests {
@Before
public
void
setUp
()
{
this
.
mvc
=
webAppContextSetup
(
this
.
context
).
addFilters
(
this
.
filterChain
).
build
();
this
.
mvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
context
)
.
addFilters
(
this
.
filterChain
).
build
();
SecurityContextHolder
.
clearContext
();
}
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/Flight.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -26,7 +26,7 @@ import javax.persistence.Id;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
/**
* Domain object for tracking flights
* Domain object for tracking flights
.
*
* @author Craig Walls
* @author Greg Turnquist
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2/src/main/java/sample/secure/oauth2/FlightRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -20,7 +20,7 @@ import org.springframework.data.repository.CrudRepository;
import
org.springframework.security.access.prepost.PreAuthorize
;
/**
* Spring Data interface with secured methods
* Spring Data interface with secured methods
.
*
* @author Craig Walls
* @author Greg Turnquist
...
...
spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -34,6 +34,7 @@ import org.springframework.security.web.FilterChainProxy;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MvcResult
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -42,7 +43,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
header
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
setup
.
MockMvcBuilders
.
webAppContextSetup
;
/**
* Series of automated integration tests to verify proper behavior of auto-configured,
...
...
@@ -66,7 +66,8 @@ public class SampleSecureOAuth2ApplicationTests {
@Before
public
void
setUp
()
{
this
.
mvc
=
webAppContextSetup
(
this
.
context
).
addFilters
(
this
.
filterChain
).
build
();
this
.
mvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
context
)
.
addFilters
(
this
.
filterChain
).
build
();
SecurityContextHolder
.
clearContext
();
}
...
...
spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java
View file @
e69296d7
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -20,10 +20,6 @@ import org.springframework.security.access.annotation.Secured;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Service
;
/**
* @author Dave Syer
*
*/
@Service
public
class
SampleService
{
...
...
spring-boot-samples/spring-boot-sample-secure/src/main/resources/application.properties
View file @
e69296d7
#
debug
:
true
\ No newline at end of file
# debug: true
spring-boot-samples/spring-boot-sample-secure/src/test/resources/test.properties
View file @
e69296d7
security.user.password
=
password
\ No newline at end of file
security.user.password
=
password
spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java
View file @
e69296d7
...
...
@@ -25,7 +25,7 @@ import sample.test.domain.VehicleIdentificationNumber;
*/
public
class
VehicleIdentificationNumberNotFoundException
extends
RuntimeException
{
private
VehicleIdentificationNumber
vehicleIdentificationNumber
;
private
final
VehicleIdentificationNumber
vehicleIdentificationNumber
;
public
VehicleIdentificationNumberNotFoundException
(
VehicleIdentificationNumber
vin
)
{
this
(
vin
,
null
);
...
...
spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserNameNotFoundException.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus
(
HttpStatus
.
NOT_FOUND
)
public
class
UserNameNotFoundException
extends
RuntimeException
{
private
String
username
;
private
final
String
username
;
public
UserNameNotFoundException
(
String
username
)
{
this
.
username
=
username
;
...
...
spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties
View file @
e69296d7
spring.mvc.view.prefix
:
/WEB-INF/jsp/
spring.mvc.view.suffix
:
.jsp
application.message
:
Hello Phil
\ No newline at end of file
application.message
:
Hello Phil
spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.util.SocketUtils
;
/**
* Sample Application to show Tomcat running two connectors
* Sample Application to show Tomcat running two connectors
.
*
* @author Brock Mills
* @author Andy Wilkinson
...
...
spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java
View file @
e69296d7
...
...
@@ -127,7 +127,7 @@ public class SampleTomcatTwoConnectorsApplicationTests {
private
final
HostnameVerifier
verifier
;
public
MySimpleClientHttpRequestFactory
(
final
HostnameVerifier
verifier
)
{
MySimpleClientHttpRequestFactory
(
final
HostnameVerifier
verifier
)
{
this
.
verifier
=
verifier
;
}
...
...
spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java
View file @
e69296d7
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -55,6 +55,13 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
@Autowired
private
TestRestTemplate
restTemplate
;
@Test
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
@Configuration
@Import
({
EmbeddedServletContainerAutoConfiguration
.
class
,
DispatcherServletAutoConfiguration
.
class
,
...
...
@@ -71,11 +78,4 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
}
@Test
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
this
.
restTemplate
.
getForEntity
(
"/"
,
String
.
class
);
assertThat
(
entity
.
getStatusCode
()).
isEqualTo
(
HttpStatus
.
OK
);
assertThat
(
entity
.
getBody
()).
isEqualTo
(
"Hello World"
);
}
}
spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/main/resources/application.properties
View file @
e69296d7
spring.mvc.view.prefix
:
/WEB-INF/jsp/
spring.mvc.view.suffix
:
.jsp
application.message
:
Hello Phil
\ No newline at end of file
application.message
:
Hello Phil
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/application.properties
View file @
e69296d7
server.port
=
8443
server.ssl.key-store
=
classpath:sample.jks
server.ssl.key-store-password
=
secret
server.ssl.key-password
=
password
\ No newline at end of file
server.ssl.key-password
=
password
spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties
View file @
e69296d7
...
...
@@ -2,4 +2,4 @@ server.undertow.accesslog.enabled=true
server.undertow.accesslog.dir
=
target/logs
server.undertow.accesslog.pattern
=
combined
server.compression.enabled
=
true
server.compression.min-response-size
=
1
\ No newline at end of file
server.compression.min-response-size
=
1
spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -21,11 +21,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.web.support.SpringBootServletInitializer
;
import
org.springframework.context.annotation.PropertySource
;
/**
* Sample WAR application
*/
@SpringBootApplication
@PropertySource
(
value
=
{
"WEB-INF/custom.properties"
}
)
@PropertySource
(
"WEB-INF/custom.properties"
)
public
class
SampleWarApplication
extends
SpringBootServletInitializer
{
public
static
void
main
(
String
[]
args
)
{
...
...
spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/application.properties
View file @
e69296d7
application.message
:
Hello, Andy
\ No newline at end of file
application.message
:
Hello, Andy
spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/application.properties
View file @
e69296d7
# Allow templates to be reloaded at dev time
spring.groovy.template.cache
:
false
logging.level.org.springframework.web
:
INFO
\ No newline at end of file
logging.level.org.springframework.web
:
INFO
spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -84,14 +84,10 @@ public class MessageControllerWebTests {
private
final
String
regex
;
public
RegexMatcher
(
String
regex
)
{
RegexMatcher
(
String
regex
)
{
this
.
regex
=
regex
;
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
@Override
public
boolean
matchesSafely
(
String
item
)
{
return
Pattern
.
compile
(
this
.
regex
).
matcher
(
item
).
find
();
...
...
@@ -108,6 +104,10 @@ public class MessageControllerWebTests {
.
appendText
(
this
.
regex
);
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
}
}
spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties
View file @
e69296d7
spring.mvc.view.prefix
:
/WEB-INF/jsp/
spring.mvc.view.suffix
:
.jsp
application.message
:
Hello Phil
\ No newline at end of file
application.message
:
Hello Phil
spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -41,6 +41,16 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@EnableGlobalMethodSecurity
(
securedEnabled
=
true
)
public
class
SampleMethodSecurityApplication
extends
WebMvcConfigurerAdapter
{
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
registry
.
addViewController
(
"/login"
).
setViewName
(
"login"
);
registry
.
addViewController
(
"/access"
).
setViewName
(
"access"
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SpringApplicationBuilder
(
SampleMethodSecurityApplication
.
class
).
run
(
args
);
}
@Controller
protected
static
class
HomeController
{
...
...
@@ -55,16 +65,6 @@ public class SampleMethodSecurityApplication extends WebMvcConfigurerAdapter {
}
@Override
public
void
addViewControllers
(
ViewControllerRegistry
registry
)
{
registry
.
addViewController
(
"/login"
).
setViewName
(
"login"
);
registry
.
addViewController
(
"/access"
).
setViewName
(
"access"
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SpringApplicationBuilder
(
SampleMethodSecurityApplication
.
class
).
run
(
args
);
}
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@Configuration
protected
static
class
AuthenticationSecurity
...
...
spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/application.properties
View file @
e69296d7
spring.thymeleaf.cache
:
false
logging.level.org.springframework.security
:
INFO
\ No newline at end of file
logging.level.org.springframework.security
:
INFO
spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/application.properties
View file @
e69296d7
application.message
:
Hello, Andy
\ No newline at end of file
application.message
:
Hello, Andy
spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/application.properties
View file @
e69296d7
spring.thymeleaf.cache
:
false
security.basic.enabled
:
false
logging.level.org.springframework.security
:
INFO
\ No newline at end of file
logging.level.org.springframework.security
:
INFO
spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/application.properties
View file @
e69296d7
debug
:
true
spring.thymeleaf.cache
:
false
security.basic.enabled
:
false
logging.level.org.springframework.security
:
INFO
\ No newline at end of file
logging.level.org.springframework.security
:
INFO
spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/application.properties
View file @
e69296d7
...
...
@@ -3,4 +3,4 @@ security.basic.enabled: false
# demo only:
security.user.password
:
password
logging.level.org.springframework.security
:
INFO
logging.level.org.springframework.boot.actuate.audit.listener.AuditListener
:
DEBUG
\ No newline at end of file
logging.level.org.springframework.boot.actuate.audit.listener.AuditListener
:
DEBUG
spring-boot-samples/spring-boot-sample-web-thymeleaf3/src/main/java/sample/web/thymeleaf3/InMemoryMessageRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -20,9 +20,6 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.atomic.AtomicLong
;
/**
* @author Dave Syer
*/
public
class
InMemoryMessageRepository
implements
MessageRepository
{
private
static
AtomicLong
counter
=
new
AtomicLong
();
...
...
spring-boot-samples/spring-boot-sample-web-thymeleaf3/src/main/java/sample/web/thymeleaf3/Message.java
View file @
e69296d7
...
...
@@ -20,9 +20,6 @@ import java.util.Calendar;
import
org.hibernate.validator.constraints.NotEmpty
;
/**
* @author Rob Winch
*/
public
class
Message
{
private
Long
id
;
...
...
spring-boot-samples/spring-boot-sample-web-thymeleaf3/src/main/java/sample/web/thymeleaf3/MessageRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,9 +16,6 @@
package
sample
.
web
.
thymeleaf3
;
/**
* @author Rob Winch
*/
public
interface
MessageRepository
{
Iterable
<
Message
>
findAll
();
...
...
spring-boot-samples/spring-boot-sample-web-thymeleaf3/src/main/java/sample/web/thymeleaf3/mvc/MessageController.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -31,10 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
/**
* @author Rob Winch
* @author Doo-Hwan Kwak
*/
@Controller
@RequestMapping
(
"/"
)
public
class
MessageController
{
...
...
@@ -77,14 +73,14 @@ public class MessageController {
throw
new
RuntimeException
(
"Expected exception in controller"
);
}
@GetMapping
(
value
=
"delete/{id}"
)
@GetMapping
(
"delete/{id}"
)
public
ModelAndView
delete
(
@PathVariable
(
"id"
)
Long
id
)
{
this
.
messageRepository
.
deleteMessage
(
id
);
Iterable
<
Message
>
messages
=
this
.
messageRepository
.
findAll
();
return
new
ModelAndView
(
"messages/list"
,
"messages"
,
messages
);
}
@GetMapping
(
value
=
"modify/{id}"
)
@GetMapping
(
"modify/{id}"
)
public
ModelAndView
modifyForm
(
@PathVariable
(
"id"
)
Message
message
)
{
return
new
ModelAndView
(
"messages/form"
,
"message"
,
message
);
}
...
...
spring-boot-samples/spring-boot-sample-web-thymeleaf3/src/test/java/sample/web/thymeleaf3/MessageControllerWebTests.java
View file @
e69296d7
...
...
@@ -84,14 +84,10 @@ public class MessageControllerWebTests {
private
final
String
regex
;
public
RegexMatcher
(
String
regex
)
{
RegexMatcher
(
String
regex
)
{
this
.
regex
=
regex
;
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
@Override
public
boolean
matchesSafely
(
String
item
)
{
return
Pattern
.
compile
(
this
.
regex
).
matcher
(
item
).
find
();
...
...
@@ -108,6 +104,10 @@ public class MessageControllerWebTests {
.
appendText
(
this
.
regex
);
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
}
}
spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/InMemoryMessageRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -20,9 +20,6 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.atomic.AtomicLong
;
/**
* @author Dave Syer
*/
public
class
InMemoryMessageRepository
implements
MessageRepository
{
private
static
AtomicLong
counter
=
new
AtomicLong
();
...
...
spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/Message.java
View file @
e69296d7
/*
* Copyright 2012-2018 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
* 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.
* 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
sample
.
web
.
ui
;
...
...
@@ -17,9 +20,6 @@ import java.util.Calendar;
import
org.hibernate.validator.constraints.NotEmpty
;
/**
* @author Rob Winch
*/
public
class
Message
{
private
Long
id
;
...
...
spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/MessageRepository.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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
* 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.
* 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
sample
.
web
.
ui
;
/**
* @author Rob Winch
*/
public
interface
MessageRepository
{
Iterable
<
Message
>
findAll
();
...
...
spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -31,10 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
/**
* @author Rob Winch
* @author Doo-Hwan Kwak
*/
@Controller
@RequestMapping
(
"/"
)
public
class
MessageController
{
...
...
@@ -77,14 +73,14 @@ public class MessageController {
throw
new
RuntimeException
(
"Expected exception in controller"
);
}
@GetMapping
(
value
=
"delete/{id}"
)
@GetMapping
(
"delete/{id}"
)
public
ModelAndView
delete
(
@PathVariable
(
"id"
)
Long
id
)
{
this
.
messageRepository
.
deleteMessage
(
id
);
Iterable
<
Message
>
messages
=
this
.
messageRepository
.
findAll
();
return
new
ModelAndView
(
"messages/list"
,
"messages"
,
messages
);
}
@GetMapping
(
value
=
"modify/{id}"
)
@GetMapping
(
"modify/{id}"
)
public
ModelAndView
modifyForm
(
@PathVariable
(
"id"
)
Message
message
)
{
return
new
ModelAndView
(
"messages/form"
,
"message"
,
message
);
}
...
...
spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/application.properties
View file @
e69296d7
# Allow Thymeleaf templates to be reloaded at dev time
spring.thymeleaf.cache
:
false
server.tomcat.access_log_enabled
:
true
server.tomcat.basedir
:
target/tomcat
\ No newline at end of file
server.tomcat.basedir
:
target/tomcat
spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java
View file @
e69296d7
...
...
@@ -84,14 +84,10 @@ public class MessageControllerWebTests {
private
final
String
regex
;
public
RegexMatcher
(
String
regex
)
{
RegexMatcher
(
String
regex
)
{
this
.
regex
=
regex
;
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
@Override
public
boolean
matchesSafely
(
String
item
)
{
return
Pattern
.
compile
(
this
.
regex
).
matcher
(
item
).
find
();
...
...
@@ -108,6 +104,10 @@ public class MessageControllerWebTests {
.
appendText
(
this
.
regex
);
}
public
static
org
.
hamcrest
.
Matcher
<
java
.
lang
.
String
>
matches
(
String
regex
)
{
return
new
RegexMatcher
(
regex
);
}
}
}
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/DefaultEchoService.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -21,7 +21,7 @@ public class DefaultEchoService implements EchoService {
private
final
String
echoFormat
;
public
DefaultEchoService
(
String
echoFormat
)
{
this
.
echoFormat
=
(
echoFormat
!=
null
)
?
echoFormat
:
"%s"
;
this
.
echoFormat
=
(
echoFormat
!=
null
?
echoFormat
:
"%s"
)
;
}
@Override
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Direction.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Location.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -19,16 +18,16 @@ package samples.websocket.jetty.snake;
public
class
Location
{
/**
* The X location.
*/
public
int
x
;
/**
* The Y location.
*/
public
int
y
;
public
static
final
int
GRID_SIZE
=
10
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
Location
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
...
...
@@ -37,13 +36,13 @@ public class Location {
public
Location
getAdjacentLocation
(
Direction
direction
)
{
switch
(
direction
)
{
case
NORTH:
return
new
Location
(
this
.
x
,
this
.
y
-
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
-
SnakeUtils
.
GRID_SIZE
);
case
SOUTH:
return
new
Location
(
this
.
x
,
this
.
y
+
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
+
SnakeUtils
.
GRID_SIZE
);
case
EAST:
return
new
Location
(
this
.
x
+
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
+
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
WEST:
return
new
Location
(
this
.
x
-
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
-
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
NONE:
// fall through
default
:
...
...
@@ -59,16 +58,13 @@ public class Location {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Location
location
=
(
Location
)
o
;
if
(
this
.
x
!=
location
.
x
)
{
return
false
;
}
if
(
this
.
y
!=
location
.
y
)
{
return
false
;
}
return
true
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
/**
* Sets up the timer for the multi-player snake game WebSocket example.
*/
public
class
SnakeTimer
{
public
final
class
SnakeTimer
{
private
static
final
long
TICK_DELAY
=
100
;
...
...
@@ -43,6 +42,9 @@ public class SnakeTimer {
private
static
Timer
gameTimer
=
null
;
private
SnakeTimer
()
{
}
public
static
void
addSnake
(
Snake
snake
)
{
synchronized
(
MONITOR
)
{
if
(
snakes
.
isEmpty
())
{
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -20,16 +19,28 @@ package samples.websocket.jetty.snake;
import
java.awt.Color
;
import
java.util.Random
;
public
class
SnakeUtils
{
public
final
class
SnakeUtils
{
/**
* The width of the playfield.
*/
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
/**
* The height of the playfield.
*/
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
/**
* The grid size.
*/
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
Random
random
=
new
Random
();
private
SnakeUtils
()
{
}
public
static
String
getRandomHexColor
()
{
float
hue
=
random
.
nextFloat
();
// sat between 0.1 and 0.3
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -29,12 +28,6 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public
class
SnakeWebSocketHandler
extends
TextWebSocketHandler
{
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
AtomicInteger
snakeIds
=
new
AtomicInteger
(
0
);
private
static
final
Random
random
=
new
Random
();
...
...
@@ -54,15 +47,15 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
}
public
static
Location
getRandomLocation
()
{
int
x
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_HEIGHT
));
int
x
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_HEIGHT
));
return
new
Location
(
x
,
y
);
}
private
static
int
roundByGridSize
(
int
value
)
{
value
=
value
+
(
GRID_SIZE
/
2
);
value
=
value
/
GRID_SIZE
;
value
=
value
*
GRID_SIZE
;
value
=
value
+
(
SnakeUtils
.
GRID_SIZE
/
2
);
value
=
value
/
SnakeUtils
.
GRID_SIZE
;
value
=
value
*
SnakeUtils
.
GRID_SIZE
;
return
value
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/echo/DefaultEchoService.java
View file @
e69296d7
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -21,7 +21,7 @@ public class DefaultEchoService implements EchoService {
private
final
String
echoFormat
;
public
DefaultEchoService
(
String
echoFormat
)
{
this
.
echoFormat
=
(
echoFormat
!=
null
)
?
echoFormat
:
"%s"
;
this
.
echoFormat
=
(
echoFormat
!=
null
?
echoFormat
:
"%s"
)
;
}
@Override
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Direction.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Location.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -19,16 +18,16 @@ package samples.websocket.jetty93.snake;
public
class
Location
{
/**
* The X location.
*/
public
int
x
;
/**
* The Y location.
*/
public
int
y
;
public
static
final
int
GRID_SIZE
=
10
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
Location
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
...
...
@@ -37,13 +36,13 @@ public class Location {
public
Location
getAdjacentLocation
(
Direction
direction
)
{
switch
(
direction
)
{
case
NORTH:
return
new
Location
(
this
.
x
,
this
.
y
-
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
-
SnakeUtils
.
GRID_SIZE
);
case
SOUTH:
return
new
Location
(
this
.
x
,
this
.
y
+
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
+
SnakeUtils
.
GRID_SIZE
);
case
EAST:
return
new
Location
(
this
.
x
+
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
+
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
WEST:
return
new
Location
(
this
.
x
-
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
-
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
NONE:
// fall through
default
:
...
...
@@ -59,16 +58,13 @@ public class Location {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Location
location
=
(
Location
)
o
;
if
(
this
.
x
!=
location
.
x
)
{
return
false
;
}
if
(
this
.
y
!=
location
.
y
)
{
return
false
;
}
return
true
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/Snake.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeTimer.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
/**
* Sets up the timer for the multi-player snake game WebSocket example.
*/
public
class
SnakeTimer
{
public
final
class
SnakeTimer
{
private
static
final
long
TICK_DELAY
=
100
;
...
...
@@ -43,6 +42,9 @@ public class SnakeTimer {
private
static
Timer
gameTimer
=
null
;
private
SnakeTimer
()
{
}
public
static
void
addSnake
(
Snake
snake
)
{
synchronized
(
MONITOR
)
{
if
(
snakes
.
isEmpty
())
{
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeUtils.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -20,16 +19,28 @@ package samples.websocket.jetty93.snake;
import
java.awt.Color
;
import
java.util.Random
;
public
class
SnakeUtils
{
public
final
class
SnakeUtils
{
/**
* The width of the playfield.
*/
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
/**
* The height of the playfield.
*/
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
/**
* The grid size.
*/
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
Random
random
=
new
Random
();
private
SnakeUtils
()
{
}
public
static
String
getRandomHexColor
()
{
float
hue
=
random
.
nextFloat
();
// sat between 0.1 and 0.3
...
...
spring-boot-samples/spring-boot-sample-websocket-jetty93/src/main/java/samples/websocket/jetty93/snake/SnakeWebSocketHandler.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -29,12 +28,6 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public
class
SnakeWebSocketHandler
extends
TextWebSocketHandler
{
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
AtomicInteger
snakeIds
=
new
AtomicInteger
(
0
);
private
static
final
Random
random
=
new
Random
();
...
...
@@ -54,15 +47,15 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
}
public
static
Location
getRandomLocation
()
{
int
x
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_HEIGHT
));
int
x
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_HEIGHT
));
return
new
Location
(
x
,
y
);
}
private
static
int
roundByGridSize
(
int
value
)
{
value
=
value
+
(
GRID_SIZE
/
2
);
value
=
value
/
GRID_SIZE
;
value
=
value
*
GRID_SIZE
;
value
=
value
+
(
SnakeUtils
.
GRID_SIZE
/
2
);
value
=
value
/
SnakeUtils
.
GRID_SIZE
;
value
=
value
*
SnakeUtils
.
GRID_SIZE
;
return
value
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/DefaultEchoService.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -21,7 +21,7 @@ public class DefaultEchoService implements EchoService {
private
final
String
echoFormat
;
public
DefaultEchoService
(
String
echoFormat
)
{
this
.
echoFormat
=
(
echoFormat
!=
null
)
?
echoFormat
:
"%s"
;
this
.
echoFormat
=
(
echoFormat
!=
null
?
echoFormat
:
"%s"
)
;
}
@Override
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Direction.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Location.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -19,16 +18,16 @@ package samples.websocket.tomcat.snake;
public
class
Location
{
/**
* The X location.
*/
public
int
x
;
/**
* The Y location.
*/
public
int
y
;
public
static
final
int
GRID_SIZE
=
10
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
Location
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
...
...
@@ -37,13 +36,13 @@ public class Location {
public
Location
getAdjacentLocation
(
Direction
direction
)
{
switch
(
direction
)
{
case
NORTH:
return
new
Location
(
this
.
x
,
this
.
y
-
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
-
SnakeUtils
.
GRID_SIZE
);
case
SOUTH:
return
new
Location
(
this
.
x
,
this
.
y
+
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
+
SnakeUtils
.
GRID_SIZE
);
case
EAST:
return
new
Location
(
this
.
x
+
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
+
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
WEST:
return
new
Location
(
this
.
x
-
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
-
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
NONE:
// fall through
default
:
...
...
@@ -59,16 +58,13 @@ public class Location {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Location
location
=
(
Location
)
o
;
if
(
this
.
x
!=
location
.
x
)
{
return
false
;
}
if
(
this
.
y
!=
location
.
y
)
{
return
false
;
}
return
true
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -25,24 +24,27 @@ import java.util.TimerTask;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
org.
apache.juli.logging.Log
;
import
org.
apache.juli.logging.Log
Factory
;
import
org.
slf4j.Logger
;
import
org.
slf4j.Logger
Factory
;
/**
* Sets up the timer for the multi-player snake game WebSocket example.
*/
public
class
SnakeTimer
{
public
final
class
SnakeTimer
{
private
static
final
long
TICK_DELAY
=
100
;
private
static
final
Object
MONITOR
=
new
Object
();
private
static
final
Log
log
=
LogFactory
.
getLog
(
SnakeTimer
.
class
);
private
static
final
Log
ger
log
=
LoggerFactory
.
getLogger
(
SnakeTimer
.
class
);
private
static
final
ConcurrentHashMap
<
Integer
,
Snake
>
snakes
=
new
ConcurrentHashMap
<
Integer
,
Snake
>();
private
static
Timer
gameTimer
=
null
;
private
SnakeTimer
()
{
}
public
static
void
addSnake
(
Snake
snake
)
{
synchronized
(
MONITOR
)
{
if
(
snakes
.
isEmpty
())
{
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -20,16 +19,28 @@ package samples.websocket.tomcat.snake;
import
java.awt.Color
;
import
java.util.Random
;
public
class
SnakeUtils
{
public
final
class
SnakeUtils
{
/**
* The width of the playfield.
*/
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
/**
* The height of the playfield.
*/
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
/**
* The grid size.
*/
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
Random
random
=
new
Random
();
private
SnakeUtils
()
{
}
public
static
String
getRandomHexColor
()
{
float
hue
=
random
.
nextFloat
();
// sat between 0.1 and 0.3
...
...
spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -29,12 +28,6 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public
class
SnakeWebSocketHandler
extends
TextWebSocketHandler
{
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
AtomicInteger
snakeIds
=
new
AtomicInteger
(
0
);
private
static
final
Random
random
=
new
Random
();
...
...
@@ -54,15 +47,15 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
}
public
static
Location
getRandomLocation
()
{
int
x
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_HEIGHT
));
int
x
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_HEIGHT
));
return
new
Location
(
x
,
y
);
}
private
static
int
roundByGridSize
(
int
value
)
{
value
=
value
+
(
GRID_SIZE
/
2
);
value
=
value
/
GRID_SIZE
;
value
=
value
*
GRID_SIZE
;
value
=
value
+
(
SnakeUtils
.
GRID_SIZE
/
2
);
value
=
value
/
SnakeUtils
.
GRID_SIZE
;
value
=
value
*
SnakeUtils
.
GRID_SIZE
;
return
value
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/DefaultEchoService.java
View file @
e69296d7
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -21,7 +21,7 @@ public class DefaultEchoService implements EchoService {
private
final
String
echoFormat
;
public
DefaultEchoService
(
String
echoFormat
)
{
this
.
echoFormat
=
(
echoFormat
!=
null
)
?
echoFormat
:
"%s"
;
this
.
echoFormat
=
(
echoFormat
!=
null
?
echoFormat
:
"%s"
)
;
}
@Override
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Direction.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Location.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -19,16 +18,16 @@ package samples.websocket.undertow.snake;
public
class
Location
{
/**
* The X location.
*/
public
int
x
;
/**
* The Y location.
*/
public
int
y
;
public
static
final
int
GRID_SIZE
=
10
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
Location
(
int
x
,
int
y
)
{
this
.
x
=
x
;
this
.
y
=
y
;
...
...
@@ -37,13 +36,13 @@ public class Location {
public
Location
getAdjacentLocation
(
Direction
direction
)
{
switch
(
direction
)
{
case
NORTH:
return
new
Location
(
this
.
x
,
this
.
y
-
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
-
SnakeUtils
.
GRID_SIZE
);
case
SOUTH:
return
new
Location
(
this
.
x
,
this
.
y
+
Location
.
GRID_SIZE
);
return
new
Location
(
this
.
x
,
this
.
y
+
SnakeUtils
.
GRID_SIZE
);
case
EAST:
return
new
Location
(
this
.
x
+
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
+
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
WEST:
return
new
Location
(
this
.
x
-
Location
.
GRID_SIZE
,
this
.
y
);
return
new
Location
(
this
.
x
-
SnakeUtils
.
GRID_SIZE
,
this
.
y
);
case
NONE:
// fall through
default
:
...
...
@@ -59,16 +58,13 @@ public class Location {
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
Location
location
=
(
Location
)
o
;
if
(
this
.
x
!=
location
.
x
)
{
return
false
;
}
if
(
this
.
y
!=
location
.
y
)
{
return
false
;
}
return
true
;
}
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory;
/**
* Sets up the timer for the multi-player snake game WebSocket example.
*/
public
class
SnakeTimer
{
public
final
class
SnakeTimer
{
private
static
final
long
TICK_DELAY
=
100
;
...
...
@@ -43,6 +42,9 @@ public class SnakeTimer {
private
static
Timer
gameTimer
=
null
;
private
SnakeTimer
()
{
}
public
static
void
addSnake
(
Snake
snake
)
{
synchronized
(
MONITOR
)
{
if
(
snakes
.
isEmpty
())
{
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -20,16 +19,28 @@ package samples.websocket.undertow.snake;
import
java.awt.Color
;
import
java.util.Random
;
public
class
SnakeUtils
{
public
final
class
SnakeUtils
{
/**
* The width of the playfield.
*/
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
/**
* The height of the playfield.
*/
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
/**
* The grid size.
*/
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
Random
random
=
new
Random
();
private
SnakeUtils
()
{
}
public
static
String
getRandomHexColor
()
{
float
hue
=
random
.
nextFloat
();
// sat between 0.1 and 0.3
...
...
spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java
View file @
e69296d7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2012-2018 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
*
...
...
@@ -29,12 +28,6 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
public
class
SnakeWebSocketHandler
extends
TextWebSocketHandler
{
public
static
final
int
PLAYFIELD_WIDTH
=
640
;
public
static
final
int
PLAYFIELD_HEIGHT
=
480
;
public
static
final
int
GRID_SIZE
=
10
;
private
static
final
AtomicInteger
snakeIds
=
new
AtomicInteger
(
0
);
private
static
final
Random
random
=
new
Random
();
...
...
@@ -54,15 +47,15 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
}
public
static
Location
getRandomLocation
()
{
int
x
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
PLAYFIELD_HEIGHT
));
int
x
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_WIDTH
));
int
y
=
roundByGridSize
(
random
.
nextInt
(
SnakeUtils
.
PLAYFIELD_HEIGHT
));
return
new
Location
(
x
,
y
);
}
private
static
int
roundByGridSize
(
int
value
)
{
value
=
value
+
(
GRID_SIZE
/
2
);
value
=
value
/
GRID_SIZE
;
value
=
value
*
GRID_SIZE
;
value
=
value
+
(
SnakeUtils
.
GRID_SIZE
/
2
);
value
=
value
/
SnakeUtils
.
GRID_SIZE
;
value
=
value
*
SnakeUtils
.
GRID_SIZE
;
return
value
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment