├── public ├── javascripts │ └── main.js ├── stylesheets │ └── main.css └── images │ └── favicon.png ├── project ├── build.properties └── plugins.sbt ├── README.md ├── conf ├── routes ├── posts.routes ├── META-INF │ └── persistence.xml ├── application.conf └── logback.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── app ├── views │ ├── timeout.scala.html │ └── index.scala.html ├── controllers │ └── HomeController.java ├── v1 │ └── post │ │ ├── PostRepository.java │ │ ├── PostExecutionContext.java │ │ ├── PostData.java │ │ ├── PostResource.java │ │ ├── PostController.java │ │ ├── PostResourceHandler.java │ │ ├── JPAPostRepository.java │ │ └── PostAction.java └── Module.java ├── scripts ├── test-sbt ├── script-helper └── test-gradle ├── NOTICE ├── .mergify.yml ├── .travis.yml ├── gatling └── simulation │ └── GatlingSpec.scala ├── test └── it │ └── IntegrationTest.java ├── gradlew.bat ├── .github └── settings.yml ├── gradlew └── LICENSE /public/javascripts/main.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/stylesheets/main.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.8 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MOVED TO https://github.com/playframework/play-samples 2 | -------------------------------------------------------------------------------- /public/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/playframework/play-java-rest-api-example/2.7.x/public/images/favicon.png -------------------------------------------------------------------------------- /conf/routes: -------------------------------------------------------------------------------- 1 | GET / controllers.HomeController.index 2 | 3 | -> /v1/posts posts.Routes 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/playframework/play-java-rest-api-example/2.7.x/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | target 3 | build 4 | /.idea 5 | /.idea_modules 6 | /.classpath 7 | /.gradle 8 | /.project 9 | /.settings 10 | /RUNNING_PID 11 | 12 | /.vscode 13 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // The Play plugin 2 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0") 3 | 4 | // Load testing tool: 5 | // http://gatling.io/docs/2.2.2/extensions/sbt_plugin.html 6 | addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2") 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | -------------------------------------------------------------------------------- /app/views/timeout.scala.html: -------------------------------------------------------------------------------- 1 | @() 2 | 3 | 4 | 5 | 6 | Timeout Page 7 | 8 | 9 |

Timeout Page

10 | 11 | Database timed out, so showing this page instead. 12 | 13 | 14 | -------------------------------------------------------------------------------- /scripts/test-sbt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/script-helper" 4 | 5 | echo "+----------------------------+" 6 | echo "| Executing tests using sbt |" 7 | echo "+----------------------------+" 8 | sbt ++$TRAVIS_SCALA_VERSION test 9 | -------------------------------------------------------------------------------- /conf/posts.routes: -------------------------------------------------------------------------------- 1 | 2 | GET / v1.post.PostController.list(request:Request) 3 | POST / v1.post.PostController.create(request:Request) 4 | 5 | GET /:id v1.post.PostController.show(request:Request,id) 6 | PUT /:id v1.post.PostController.update(request:Request, id) 7 | -------------------------------------------------------------------------------- /app/controllers/HomeController.java: -------------------------------------------------------------------------------- 1 | package controllers; 2 | 3 | import play.mvc.*; 4 | 5 | /** 6 | * This controller contains an action to handle HTTP requests 7 | * to the application's home page. 8 | */ 9 | public class HomeController extends Controller { 10 | 11 | public Result index() { 12 | return ok(views.html.index.render()); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Written by Lightbend 2 | 3 | To the extent possible under law, the author(s) have dedicated all copyright and 4 | related and neighboring rights to this software to the public domain worldwide. 5 | This software is distributed without any warranty. 6 | 7 | You should have received a copy of the CC0 Public Domain Dedication along with 8 | this software. If not, see . 9 | -------------------------------------------------------------------------------- /app/v1/post/PostRepository.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import java.util.Optional; 4 | import java.util.concurrent.CompletionStage; 5 | import java.util.stream.Stream; 6 | 7 | public interface PostRepository { 8 | 9 | CompletionStage> list(); 10 | 11 | CompletionStage create(PostData postData); 12 | 13 | CompletionStage> get(Long id); 14 | 15 | CompletionStage> update(Long id, PostData postData); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /scripts/script-helper: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -o pipefail 5 | 6 | java_version=$(java -version 2>&1 | java -version 2>&1 | awk -F '"' '/version/ {print $2}') 7 | 8 | if [[ $java_version = 1.8* ]] ; then 9 | echo "The build is using Java 8 ($java_version). No addional JVM params needed." 10 | else 11 | echo "The build is using Java 9+ ($java_version). We need additional JVM parameters" 12 | export _JAVA_OPTIONS="$_JAVA_OPTIONS --add-modules=java.xml.bind" 13 | fi 14 | -------------------------------------------------------------------------------- /app/v1/post/PostExecutionContext.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import akka.actor.ActorSystem; 4 | import play.libs.concurrent.CustomExecutionContext; 5 | 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * Custom execution context wired to "post.repository" thread pool 10 | */ 11 | public class PostExecutionContext extends CustomExecutionContext { 12 | 13 | @Inject 14 | public PostExecutionContext(ActorSystem actorSystem) { 15 | super(actorSystem, "post.repository"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/v1/post/PostData.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import javax.persistence.*; 4 | 5 | /** 6 | * Data returned from the database 7 | */ 8 | @Entity 9 | @Table(name = "posts") 10 | public class PostData { 11 | 12 | public PostData() { 13 | } 14 | 15 | public PostData(String title, String body) { 16 | this.title = title; 17 | this.body = body; 18 | } 19 | 20 | @Id 21 | @GeneratedValue(strategy= GenerationType.AUTO) 22 | public Long id; 23 | public String title; 24 | public String body; 25 | } 26 | -------------------------------------------------------------------------------- /scripts/test-gradle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | . "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/script-helper" 4 | 5 | # Using cut because TRAVIS_SCALA_VERSION is the full Scala 6 | # version (for example 2.12.4), but Gradle expects just the 7 | # binary version (for example 2.12) 8 | scala_binary_version=$(echo $TRAVIS_SCALA_VERSION | cut -c1-4) 9 | 10 | echo "+------------------------------+" 11 | echo "| Executing tests using Gradle |" 12 | echo "+------------------------------+" 13 | ./gradlew -Dscala.binary.version=$scala_binary_version check -i --stacktrace 14 | -------------------------------------------------------------------------------- /conf/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | org.hibernate.jpa.HibernatePersistenceProvider 8 | DefaultDS 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/views/index.scala.html: -------------------------------------------------------------------------------- 1 | @() 2 | 3 | 4 | 5 | 6 | 7 | Play REST API 8 | 9 | 10 | 11 |

Play REST API

12 | 13 |

14 | This is a placeholder page to show you the REST API. Use httpie to post JSON to the application. 15 |

16 | 17 |

18 | To see all posts, you can do a GET: 19 |

20 | 21 | 22 |
23 |     http GET localhost:9000/v1/posts/
24 | 
25 | 26 |

27 | To create new posts, do a post 28 |

29 | 30 |

31 |     http POST localhost:9000/v1/posts/ title="Some title" body="Some Body"
32 | 
33 | 34 |

35 | You can always look at the API directly: /v1/posts 36 |

37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: Merge PRs that are ready 3 | conditions: 4 | - status-success=Travis CI - Pull Request 5 | - status-success=typesafe-cla-validator 6 | - "#approved-reviews-by>=1" 7 | - "#review-requested=0" 8 | - "#changes-requested-reviews-by=0" 9 | - label!=status:block-merge 10 | actions: 11 | merge: 12 | method: squash 13 | strict: smart 14 | 15 | - name: Merge TemplateControl's PRs that are ready 16 | conditions: 17 | - status-success=Travis CI - Pull Request 18 | - "#review-requested=0" 19 | - "#changes-requested-reviews-by=0" 20 | - label!=status:block-merge 21 | - label=status:merge-when-green 22 | - label!=status:block-merge 23 | actions: 24 | merge: 25 | method: squash 26 | strict: smart 27 | 28 | - name: Delete the PR branch after merge 29 | conditions: 30 | - merged 31 | actions: 32 | delete_head_branch: {} 33 | -------------------------------------------------------------------------------- /conf/application.conf: -------------------------------------------------------------------------------- 1 | # This is the main configuration file for the application. 2 | # https://www.playframework.com/documentation/latest/ConfigFile 3 | play.http.secret.key=this-is-a-very-long-key-12764978qteriugwfiabcou 4 | 5 | # Point JPA at our database configuration 6 | jpa.default=defaultPersistenceUnit 7 | 8 | # Number of database connections 9 | # See https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing 10 | fixedConnectionPool = 9 11 | 12 | db.default { 13 | driver = org.h2.Driver 14 | url = "jdbc:h2:mem:play" 15 | 16 | # Provided for JPA access 17 | jndiName=DefaultDS 18 | 19 | # Set Hikari to fixed size 20 | hikaricp.minimumIdle = ${fixedConnectionPool} 21 | hikaricp.maximumPoolSize = ${fixedConnectionPool} 22 | } 23 | 24 | # disable the built in filters 25 | play.http.filters = play.api.http.NoHttpFilters 26 | 27 | # Job queue sized to HikariCP connection pool 28 | post.repository { 29 | executor = "thread-pool-executor" 30 | throughput = 1 31 | thread-pool-executor { 32 | fixed-pool-size = ${fixedConnectionPool} 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/v1/post/PostResource.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | /** 4 | * Resource for the API. This is a presentation class for frontend work. 5 | */ 6 | public class PostResource { 7 | private String id; 8 | private String link; 9 | private String title; 10 | private String body; 11 | 12 | public PostResource() { 13 | } 14 | 15 | public PostResource(String id, String link, String title, String body) { 16 | this.id = id; 17 | this.link = link; 18 | this.title = title; 19 | this.body = body; 20 | } 21 | 22 | public PostResource(PostData data, String link) { 23 | this.id = data.id.toString(); 24 | this.link = link; 25 | this.title = data.title; 26 | this.body = data.body; 27 | } 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public String getLink() { 34 | return link; 35 | } 36 | 37 | public String getTitle() { 38 | return title; 39 | } 40 | 41 | public String getBody() { 42 | return body; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | scala: 2.12.8 3 | script: $SCRIPT 4 | 5 | env: 6 | matrix: 7 | - SCRIPT=scripts/test-sbt TRAVIS_JDK=adopt@1.8.202-08 8 | - SCRIPT=scripts/test-sbt TRAVIS_JDK=adopt@1.11.0-2 9 | - SCRIPT=scripts/test-gradle TRAVIS_JDK=adopt@1.8.202-08 10 | - SCRIPT=scripts/test-gradle TRAVIS_JDK=adopt@1.11.0-2 11 | 12 | matrix: 13 | fast_finish: true 14 | allow_failures: 15 | - env: SCRIPT=scripts/test-gradle TRAVIS_JDK=adopt@1.8.202-08 # current gradle doesn't support play 2.7 16 | - env: SCRIPT=scripts/test-gradle TRAVIS_JDK=adopt@1.11.0-2 # current gradle doesn't support play 2.7 17 | - env: SCRIPT=scripts/test-sbt TRAVIS_JDK=adopt@1.11.0-2 # not fully supported but allows problem discovery 18 | 19 | before_install: curl -Ls https://git.io/jabba | bash && . ~/.jabba/jabba.sh 20 | install: jabba install "$TRAVIS_JDK" && jabba use "$_" && java -Xmx32m -version 21 | 22 | cache: 23 | directories: 24 | - "$HOME/.gradle/caches" 25 | - "$HOME/.ivy2/cache" 26 | - "$HOME/.jabba/jdk" 27 | - "$HOME/.sbt" 28 | 29 | before_cache: 30 | - find $HOME/.ivy2 -name "ivydata-*.properties" -delete 31 | - find $HOME/.sbt -name "*.lock" -delete 32 | -------------------------------------------------------------------------------- /conf/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ${application.home:-.}/logs/application.log 8 | 9 | %date [%level] from %logger in %thread - %message%n%xException 10 | 11 | 12 | 13 | 14 | 15 | %coloredLevel %logger{15} - %message%n%xException{10} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /gatling/simulation/GatlingSpec.scala: -------------------------------------------------------------------------------- 1 | package simulation 2 | 3 | import io.gatling.core.Predef._ 4 | import io.gatling.http.Predef._ 5 | import scala.concurrent.duration._ 6 | import scala.language.postfixOps 7 | 8 | // run with "sbt gatling:test" on another machine so you don't have resources contending. 9 | // http://gatling.io/docs/2.2.2/general/simulation_structure.html#simulation-structure 10 | class GatlingSpec extends Simulation { 11 | 12 | // change this to another machine, make sure you have Play running in producion mode 13 | // i.e. sbt stage / sbt dist and running the script 14 | val httpConf = http.baseURL("http://localhost:9000") 15 | 16 | val readClients = scenario("Clients").exec(Index.refreshManyTimes) 17 | 18 | setUp( 19 | // For reference, this hits 25% CPU on a 5820K with 32 GB, running both server and load test. 20 | // In general, you want to ramp up load slowly, and measure with a JVM that has been "warmed up": 21 | // https://groups.google.com/forum/#!topic/gatling/mD15aj-fyo4 22 | readClients.inject(rampUsers(2000) over (100 seconds)).protocols(httpConf) 23 | ) 24 | } 25 | 26 | object Index { 27 | 28 | def post = { 29 | val body = StringBody("""{ "title": "hello", "body": "world" }""") 30 | exec(http("Index").post("/v1/posts/").body(body).asJSON.check(status.is(200))).pause(1) 31 | } 32 | 33 | def refreshAfterOneSecond = 34 | exec(http("Index").get("/").check(status.is(200))).pause(1) 35 | 36 | val refreshManyTimes = repeat(500) { 37 | refreshAfterOneSecond 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/v1/post/PostController.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import play.libs.Json; 5 | import play.libs.concurrent.HttpExecutionContext; 6 | import play.mvc.*; 7 | 8 | import javax.inject.Inject; 9 | import java.util.List; 10 | import java.util.concurrent.CompletionStage; 11 | import java.util.stream.Collectors; 12 | 13 | @With(PostAction.class) 14 | public class PostController extends Controller { 15 | 16 | private HttpExecutionContext ec; 17 | private PostResourceHandler handler; 18 | 19 | @Inject 20 | public PostController(HttpExecutionContext ec, PostResourceHandler handler) { 21 | this.ec = ec; 22 | this.handler = handler; 23 | } 24 | 25 | public CompletionStage list(Http.Request request) { 26 | return handler.find(request).thenApplyAsync(posts -> { 27 | final List postList = posts.collect(Collectors.toList()); 28 | return ok(Json.toJson(postList)); 29 | }, ec.current()); 30 | } 31 | 32 | public CompletionStage show(Http.Request request, String id) { 33 | return handler.lookup(request, id).thenApplyAsync(optionalResource -> { 34 | return optionalResource.map(resource -> 35 | ok(Json.toJson(resource)) 36 | ).orElseGet(Results::notFound); 37 | }, ec.current()); 38 | } 39 | 40 | public CompletionStage update(Http.Request request, String id) { 41 | JsonNode json = request.body().asJson(); 42 | PostResource resource = Json.fromJson(json, PostResource.class); 43 | return handler.update(request, id, resource).thenApplyAsync(optionalResource -> { 44 | return optionalResource.map(r -> 45 | ok(Json.toJson(r)) 46 | ).orElseGet(Results::notFound 47 | ); 48 | }, ec.current()); 49 | } 50 | 51 | public CompletionStage create(Http.Request request) { 52 | JsonNode json = request.body().asJson(); 53 | final PostResource resource = Json.fromJson(json, PostResource.class); 54 | return handler.create(request, resource).thenApplyAsync(savedResource -> { 55 | return created(Json.toJson(savedResource)); 56 | }, ec.current()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/Module.java: -------------------------------------------------------------------------------- 1 | import com.codahale.metrics.ConsoleReporter; 2 | import com.codahale.metrics.MetricRegistry; 3 | import com.codahale.metrics.Slf4jReporter; 4 | import com.google.inject.AbstractModule; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import v1.post.PostRepository; 8 | import v1.post.JPAPostRepository; 9 | 10 | import javax.inject.Provider; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | /** 14 | * This class is a Guice module that tells Guice how to bind several 15 | * different types. This Guice module is created when the Play 16 | * application starts. 17 | * 18 | * Play will automatically use any class called `Module` that is in 19 | * the root package. You can create modules in other locations by 20 | * adding `play.modules.enabled` settings to the `application.conf` 21 | * configuration file. 22 | */ 23 | public class Module extends AbstractModule { 24 | 25 | @Override 26 | public void configure() { 27 | bind(MetricRegistry.class).toProvider(MetricRegistryProvider.class).asEagerSingleton(); 28 | bind(PostRepository.class).to(JPAPostRepository.class).asEagerSingleton(); 29 | } 30 | } 31 | 32 | class MetricRegistryProvider implements Provider { 33 | private static final Logger logger = LoggerFactory.getLogger("application.Metrics"); 34 | 35 | private static final MetricRegistry registry = new MetricRegistry(); 36 | 37 | private void consoleReporter() { 38 | ConsoleReporter reporter = ConsoleReporter.forRegistry(registry) 39 | .convertRatesTo(TimeUnit.SECONDS) 40 | .convertDurationsTo(TimeUnit.MILLISECONDS) 41 | .build(); 42 | reporter.start(1, TimeUnit.SECONDS); 43 | } 44 | 45 | private void slf4jReporter() { 46 | final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry) 47 | .outputTo(logger) 48 | .convertRatesTo(TimeUnit.SECONDS) 49 | .convertDurationsTo(TimeUnit.MILLISECONDS) 50 | .build(); 51 | reporter.start(1, TimeUnit.MINUTES); 52 | } 53 | 54 | public MetricRegistryProvider() { 55 | //consoleReporter(); 56 | // slf4jReporter(); 57 | } 58 | 59 | @Override 60 | public MetricRegistry get() { 61 | return registry; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/it/IntegrationTest.java: -------------------------------------------------------------------------------- 1 | package it; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import org.junit.Test; 5 | import play.Application; 6 | import play.inject.guice.GuiceApplicationBuilder; 7 | import play.libs.Json; 8 | import play.mvc.Http; 9 | import play.mvc.Result; 10 | import play.test.WithApplication; 11 | import v1.post.PostData; 12 | import v1.post.PostRepository; 13 | import v1.post.PostResource; 14 | 15 | import static org.hamcrest.CoreMatchers.containsString; 16 | import static org.hamcrest.CoreMatchers.equalTo; 17 | import static org.junit.Assert.assertThat; 18 | import static play.test.Helpers.*; 19 | 20 | public class IntegrationTest extends WithApplication { 21 | 22 | @Override 23 | protected Application provideApplication() { 24 | return new GuiceApplicationBuilder().build(); 25 | } 26 | 27 | @Test 28 | public void testList() { 29 | PostRepository repository = app.injector().instanceOf(PostRepository.class); 30 | repository.create(new PostData("title", "body")); 31 | 32 | Http.RequestBuilder request = new Http.RequestBuilder() 33 | .method(GET) 34 | .uri("/v1/posts"); 35 | 36 | Result result = route(app, request); 37 | final String body = contentAsString(result); 38 | assertThat(body, containsString("body")); 39 | } 40 | 41 | @Test 42 | public void testTimeoutOnUpdate() { 43 | PostRepository repository = app.injector().instanceOf(PostRepository.class); 44 | repository.create(new PostData("title", "body")); 45 | 46 | JsonNode json = Json.toJson(new PostResource("1", "http://localhost:9000/v1/posts/1", "some title", "somebody")); 47 | 48 | Http.RequestBuilder request = new Http.RequestBuilder() 49 | .method(PUT) 50 | .bodyJson(json) 51 | .uri("/v1/posts/1"); 52 | 53 | Result result = route(app, request); 54 | assertThat(result.status(), equalTo(GATEWAY_TIMEOUT)); 55 | } 56 | 57 | @Test 58 | public void testCircuitBreakerOnShow() { 59 | PostRepository repository = app.injector().instanceOf(PostRepository.class); 60 | repository.create(new PostData("title", "body")); 61 | 62 | Http.RequestBuilder request = new Http.RequestBuilder() 63 | .method(GET) 64 | .uri("/v1/posts/1"); 65 | 66 | Result result = route(app, request); 67 | assertThat(result.status(), equalTo(SERVICE_UNAVAILABLE)); 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/v1/post/PostResourceHandler.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import com.palominolabs.http.url.UrlBuilder; 4 | import play.libs.concurrent.HttpExecutionContext; 5 | import play.mvc.Http; 6 | 7 | import javax.inject.Inject; 8 | import java.nio.charset.CharacterCodingException; 9 | import java.util.Optional; 10 | import java.util.concurrent.CompletionStage; 11 | import java.util.stream.Stream; 12 | 13 | /** 14 | * Handles presentation of Post resources, which map to JSON. 15 | */ 16 | public class PostResourceHandler { 17 | 18 | private final PostRepository repository; 19 | private final HttpExecutionContext ec; 20 | 21 | @Inject 22 | public PostResourceHandler(PostRepository repository, HttpExecutionContext ec) { 23 | this.repository = repository; 24 | this.ec = ec; 25 | } 26 | 27 | public CompletionStage> find(Http.Request request) { 28 | return repository.list().thenApplyAsync(postDataStream -> { 29 | return postDataStream.map(data -> new PostResource(data, link(request, data))); 30 | }, ec.current()); 31 | } 32 | 33 | public CompletionStage create(Http.Request request, PostResource resource) { 34 | final PostData data = new PostData(resource.getTitle(), resource.getBody()); 35 | return repository.create(data).thenApplyAsync(savedData -> { 36 | return new PostResource(savedData, link(request, savedData)); 37 | }, ec.current()); 38 | } 39 | 40 | public CompletionStage> lookup(Http.Request request,String id) { 41 | return repository.get(Long.parseLong(id)).thenApplyAsync(optionalData -> { 42 | return optionalData.map(data -> new PostResource(data, link(request, data))); 43 | }, ec.current()); 44 | } 45 | 46 | public CompletionStage> update(Http.Request request,String id, PostResource resource) { 47 | final PostData data = new PostData(resource.getTitle(), resource.getBody()); 48 | return repository.update(Long.parseLong(id), data).thenApplyAsync(optionalData -> { 49 | return optionalData.map(op -> new PostResource(op, link(request, op))); 50 | }, ec.current()); 51 | } 52 | 53 | private String link(Http.Request request, PostData data) { 54 | final String[] hostPort = request.host().split(":"); 55 | String host = hostPort[0]; 56 | int port = (hostPort.length == 2) ? Integer.parseInt(hostPort[1]) : -1; 57 | final String scheme = request.secure() ? "https" : "http"; 58 | try { 59 | return UrlBuilder.forHost(scheme, host, port) 60 | .pathSegments("v1", "posts", data.id.toString()) 61 | .toUrlString(); 62 | } catch (CharacterCodingException e) { 63 | throw new IllegalStateException(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/v1/post/JPAPostRepository.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import net.jodah.failsafe.CircuitBreaker; 4 | import net.jodah.failsafe.Failsafe; 5 | import play.db.jpa.JPAApi; 6 | 7 | import javax.inject.Inject; 8 | import javax.inject.Singleton; 9 | import javax.persistence.EntityManager; 10 | import javax.persistence.TypedQuery; 11 | import java.sql.SQLException; 12 | import java.util.Optional; 13 | import java.util.concurrent.CompletionStage; 14 | import java.util.function.Function; 15 | import java.util.stream.Stream; 16 | 17 | import static java.util.concurrent.CompletableFuture.supplyAsync; 18 | 19 | /** 20 | * A repository that provides a non-blocking API with a custom execution context 21 | * and circuit breaker. 22 | */ 23 | @Singleton 24 | public class JPAPostRepository implements PostRepository { 25 | 26 | private final JPAApi jpaApi; 27 | private final PostExecutionContext ec; 28 | private final CircuitBreaker circuitBreaker = new CircuitBreaker().withFailureThreshold(1).withSuccessThreshold(3); 29 | 30 | @Inject 31 | public JPAPostRepository(JPAApi api, PostExecutionContext ec) { 32 | this.jpaApi = api; 33 | this.ec = ec; 34 | } 35 | 36 | @Override 37 | public CompletionStage> list() { 38 | return supplyAsync(() -> wrap(em -> select(em)), ec); 39 | } 40 | 41 | @Override 42 | public CompletionStage create(PostData postData) { 43 | return supplyAsync(() -> wrap(em -> insert(em, postData)), ec); 44 | } 45 | 46 | @Override 47 | public CompletionStage> get(Long id) { 48 | return supplyAsync(() -> wrap(em -> Failsafe.with(circuitBreaker).get(() -> lookup(em, id))), ec); 49 | } 50 | 51 | @Override 52 | public CompletionStage> update(Long id, PostData postData) { 53 | return supplyAsync(() -> wrap(em -> Failsafe.with(circuitBreaker).get(() -> modify(em, id, postData))), ec); 54 | } 55 | 56 | private T wrap(Function function) { 57 | return jpaApi.withTransaction(function); 58 | } 59 | 60 | private Optional lookup(EntityManager em, Long id) throws SQLException { 61 | throw new SQLException("Call this to cause the circuit breaker to trip"); 62 | //return Optional.ofNullable(em.find(PostData.class, id)); 63 | } 64 | 65 | private Stream select(EntityManager em) { 66 | TypedQuery query = em.createQuery("SELECT p FROM PostData p", PostData.class); 67 | return query.getResultList().stream(); 68 | } 69 | 70 | private Optional modify(EntityManager em, Long id, PostData postData) throws InterruptedException { 71 | final PostData data = em.find(PostData.class, id); 72 | if (data != null) { 73 | data.title = postData.title; 74 | data.body = postData.body; 75 | } 76 | Thread.sleep(10000L); 77 | return Optional.ofNullable(data); 78 | } 79 | 80 | private PostData insert(EntityManager em, PostData postData) { 81 | return em.merge(postData); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | # These settings are synced to GitHub by https://probot.github.io/apps/settings/ 2 | repository: 3 | homepage: "https://developer.lightbend.com/start/?group=play" 4 | topics: playframework, example, example-project, sample, sample-app, jvm, webapp 5 | private: false 6 | has_issues: true 7 | # We don't need projects in sample projects 8 | has_projects: false 9 | # We don't need wiki in sample projects 10 | has_wiki: false 11 | has_downloads: true 12 | default_branch: 2.7.x 13 | allow_squash_merge: true 14 | allow_merge_commit: false 15 | allow_rebase_merge: false 16 | 17 | teams: 18 | - name: core 19 | permission: admin 20 | - name: integrators 21 | permission: write 22 | - name: write-bots 23 | permission: write 24 | 25 | branches: 26 | - name: "[0-9].*.x" 27 | protection: 28 | # We don't require reviews for sample applications because they are mainly 29 | # updated by template-control, which is an automated process 30 | required_pull_request_reviews: null 31 | # Required. Require status checks to pass before merging. Set to null to disable 32 | required_status_checks: 33 | # Required. The list of status checks to require in order to merge into this branch 34 | contexts: ["Travis CI - Pull Request", "typesafe-cla-validator"] 35 | 36 | # Labels: tailored list of labels to be used by sample applications 37 | labels: 38 | - color: f9d0c4 39 | name: "closed:declined" 40 | - color: f9d0c4 41 | name: "closed:duplicated" 42 | oldname: duplicate 43 | - color: f9d0c4 44 | name: "closed:invalid" 45 | oldname: invalid 46 | - color: f9d0c4 47 | name: "closed:question" 48 | oldname: question 49 | - color: f9d0c4 50 | name: "closed:wontfix" 51 | oldname: wontfix 52 | - color: 7057ff 53 | name: "good first issue" 54 | - color: 7057ff 55 | name: "Hacktoberfest" 56 | - color: 7057ff 57 | name: "help wanted" 58 | - color: cceecc 59 | name: "status:backlog" 60 | oldname: backlog 61 | - color: b60205 62 | name: "status:block-merge" 63 | oldname: block-merge 64 | - color: b60205 65 | name: "status:blocked" 66 | - color: 0e8a16 67 | name: "status:in-progress" 68 | - color: 0e8a16 69 | name: "status:merge-when-green" 70 | oldname: merge-when-green 71 | - color: fbca04 72 | name: "status:needs-backport" 73 | - color: fbca04 74 | name: "status:needs-forwardport" 75 | - color: fbca04 76 | name: "status:needs-info" 77 | - color: fbca04 78 | name: "status:needs-verification" 79 | - color: 0e8a16 80 | name: "status:ready" 81 | - color: fbca04 82 | name: "status:to-review" 83 | oldname: review 84 | - color: c5def5 85 | name: "topic:build/tests" 86 | - color: c5def5 87 | name: "topic:dev-environment" 88 | - color: c5def5 89 | name: "topic:documentation" 90 | - color: c5def5 91 | name: "topic:jdk-next" 92 | - color: b60205 93 | name: "type:defect" 94 | oldname: bug 95 | - color: 0052cc 96 | name: "type:feature" 97 | - color: 0052cc 98 | name: "type:improvement" 99 | oldname: enhancement 100 | - color: 0052cc 101 | name: "type:updates" 102 | - color: bf0d92 103 | name: "type:template-control" 104 | oldname: template-control 105 | -------------------------------------------------------------------------------- /app/v1/post/PostAction.java: -------------------------------------------------------------------------------- 1 | package v1.post; 2 | 3 | import com.codahale.metrics.Meter; 4 | import com.codahale.metrics.MetricRegistry; 5 | import com.codahale.metrics.Timer; 6 | import net.jodah.failsafe.FailsafeException; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import play.libs.concurrent.Futures; 10 | import play.libs.concurrent.HttpExecutionContext; 11 | import play.mvc.Http; 12 | import play.mvc.Result; 13 | import play.mvc.Results; 14 | 15 | import javax.inject.Inject; 16 | import javax.inject.Singleton; 17 | import java.util.concurrent.CompletionException; 18 | import java.util.concurrent.CompletionStage; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | import static com.codahale.metrics.MetricRegistry.name; 22 | import static java.util.concurrent.CompletableFuture.completedFuture; 23 | import static play.mvc.Http.Status.*; 24 | 25 | public class PostAction extends play.mvc.Action.Simple { 26 | private final Logger logger = LoggerFactory.getLogger("application.PostAction"); 27 | 28 | private final Meter requestsMeter; 29 | private final Timer responsesTimer; 30 | private final HttpExecutionContext ec; 31 | private final Futures futures; 32 | 33 | @Singleton 34 | @Inject 35 | public PostAction(MetricRegistry metrics, HttpExecutionContext ec, Futures futures) { 36 | this.ec = ec; 37 | this.futures = futures; 38 | this.requestsMeter = metrics.meter("requestsMeter"); 39 | this.responsesTimer = metrics.timer(name(PostAction.class, "responsesTimer")); 40 | } 41 | 42 | public CompletionStage call(Http.Request request) { 43 | if (logger.isTraceEnabled()) { 44 | logger.trace("call: request = " + request); 45 | } 46 | 47 | requestsMeter.mark(); 48 | if (request.accepts("application/json")) { 49 | final Timer.Context time = responsesTimer.time(); 50 | return futures.timeout(doCall(request), 1L, TimeUnit.SECONDS).exceptionally(e -> { 51 | return (Results.status(GATEWAY_TIMEOUT, views.html.timeout.render())); 52 | }).whenComplete((r, e) -> time.close()); 53 | } else { 54 | return completedFuture( 55 | status(NOT_ACCEPTABLE, "We only accept application/json") 56 | ); 57 | } 58 | } 59 | 60 | private CompletionStage doCall(Http.Request request) { 61 | return delegate.call(request).handleAsync((result, e) -> { 62 | if (e != null) { 63 | if (e instanceof CompletionException) { 64 | Throwable completionException = e.getCause(); 65 | if (completionException instanceof FailsafeException) { 66 | logger.error("Circuit breaker is open!", completionException); 67 | return Results.status(SERVICE_UNAVAILABLE, "Service has timed out"); 68 | } else { 69 | logger.error("Direct exception " + e.getMessage(), e); 70 | return internalServerError(); 71 | } 72 | } else { 73 | logger.error("Unknown exception " + e.getMessage(), e); 74 | return internalServerError(); 75 | } 76 | } else { 77 | return result; 78 | } 79 | }, ec.current()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Statement of Purpose 4 | 5 | The laws of most jurisdictions throughout the world automatically confer 6 | exclusive Copyright and Related Rights (defined below) upon the creator and 7 | subsequent owner(s) (each and all, an "owner") of an original work of 8 | authorship and/or a database (each, a "Work"). 9 | 10 | Certain owners wish to permanently relinquish those rights to a Work for the 11 | purpose of contributing to a commons of creative, cultural and scientific 12 | works ("Commons") that the public can reliably and without fear of later 13 | claims of infringement build upon, modify, incorporate in other works, reuse 14 | and redistribute as freely as possible in any form whatsoever and for any 15 | purposes, including without limitation commercial purposes. These owners may 16 | contribute to the Commons to promote the ideal of a free culture and the 17 | further production of creative, cultural and scientific works, or to gain 18 | reputation or greater distribution for their Work in part through the use and 19 | efforts of others. 20 | 21 | For these and/or other purposes and motivations, and without any expectation 22 | of additional consideration or compensation, the person associating CC0 with a 23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright 24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work 25 | and publicly distribute the Work under its terms, with knowledge of his or her 26 | Copyright and Related Rights in the Work and the meaning and intended legal 27 | effect of CC0 on those rights. 28 | 29 | 1. Copyright and Related Rights. A Work made available under CC0 may be 30 | protected by copyright and related or neighboring rights ("Copyright and 31 | Related Rights"). Copyright and Related Rights include, but are not limited 32 | to, the following: 33 | 34 | i. the right to reproduce, adapt, distribute, perform, display, communicate, 35 | and translate a Work; 36 | 37 | ii. moral rights retained by the original author(s) and/or performer(s); 38 | 39 | iii. publicity and privacy rights pertaining to a person's image or likeness 40 | depicted in a Work; 41 | 42 | iv. rights protecting against unfair competition in regards to a Work, 43 | subject to the limitations in paragraph 4(a), below; 44 | 45 | v. rights protecting the extraction, dissemination, use and reuse of data in 46 | a Work; 47 | 48 | vi. database rights (such as those arising under Directive 96/9/EC of the 49 | European Parliament and of the Council of 11 March 1996 on the legal 50 | protection of databases, and under any national implementation thereof, 51 | including any amended or successor version of such directive); and 52 | 53 | vii. other similar, equivalent or corresponding rights throughout the world 54 | based on applicable law or treaty, and any national implementations thereof. 55 | 56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, 57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and 58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright 59 | and Related Rights and associated claims and causes of action, whether now 60 | known or unknown (including existing as well as future claims and causes of 61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum 62 | duration provided by applicable law or treaty (including future time 63 | extensions), (iii) in any current or future medium and for any number of 64 | copies, and (iv) for any purpose whatsoever, including without limitation 65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes 66 | the Waiver for the benefit of each member of the public at large and to the 67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver 68 | shall not be subject to revocation, rescission, cancellation, termination, or 69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work 70 | by the public as contemplated by Affirmer's express Statement of Purpose. 71 | 72 | 3. Public License Fallback. Should any part of the Waiver for any reason be 73 | judged legally invalid or ineffective under applicable law, then the Waiver 74 | shall be preserved to the maximum extent permitted taking into account 75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver 76 | is so judged Affirmer hereby grants to each affected person a royalty-free, 77 | non transferable, non sublicensable, non exclusive, irrevocable and 78 | unconditional license to exercise Affirmer's Copyright and Related Rights in 79 | the Work (i) in all territories worldwide, (ii) for the maximum duration 80 | provided by applicable law or treaty (including future time extensions), (iii) 81 | in any current or future medium and for any number of copies, and (iv) for any 82 | purpose whatsoever, including without limitation commercial, advertising or 83 | promotional purposes (the "License"). The License shall be deemed effective as 84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the 85 | License for any reason be judged legally invalid or ineffective under 86 | applicable law, such partial invalidity or ineffectiveness shall not 87 | invalidate the remainder of the License, and in such case Affirmer hereby 88 | affirms that he or she will not (i) exercise any of his or her remaining 89 | Copyright and Related Rights in the Work or (ii) assert any associated claims 90 | and causes of action with respect to the Work, in either case contrary to 91 | Affirmer's express Statement of Purpose. 92 | 93 | 4. Limitations and Disclaimers. 94 | 95 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 96 | surrendered, licensed or otherwise affected by this document. 97 | 98 | b. Affirmer offers the Work as-is and makes no representations or warranties 99 | of any kind concerning the Work, express, implied, statutory or otherwise, 100 | including without limitation warranties of title, merchantability, fitness 101 | for a particular purpose, non infringement, or the absence of latent or 102 | other defects, accuracy, or the present or absence of errors, whether or not 103 | discoverable, all to the greatest extent permissible under applicable law. 104 | 105 | c. Affirmer disclaims responsibility for clearing rights of other persons 106 | that may apply to the Work or any use thereof, including without limitation 107 | any person's Copyright and Related Rights in the Work. Further, Affirmer 108 | disclaims responsibility for obtaining any necessary consents, permissions 109 | or other rights required for any use of the Work. 110 | 111 | d. Affirmer understands and acknowledges that Creative Commons is not a 112 | party to this document and has no duty or obligation with respect to this 113 | CC0 or use of the Work. 114 | 115 | For more information, please see 116 | 117 | --------------------------------------------------------------------------------