{"id":20173268,"url":"https://github.com/teedjay/playground-rest","last_synced_at":"2025-07-17T03:35:26.059Z","repository":{"id":73156879,"uuid":"105017481","full_name":"teedjay/playground-rest","owner":"teedjay","description":"Testable REST API's using JEE7 with  jax-rs, jax-b and beans validation.","archived":false,"fork":false,"pushed_at":"2017-11-08T09:08:29.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T04:41:54.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teedjay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-27T12:48:36.000Z","updated_at":"2017-10-04T16:32:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9720a2d-1e45-468d-a8f1-98ad4e510077","html_url":"https://github.com/teedjay/playground-rest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/teedjay/playground-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teedjay%2Fplayground-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teedjay%2Fplayground-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teedjay%2Fplayground-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teedjay%2Fplayground-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teedjay","download_url":"https://codeload.github.com/teedjay/playground-rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teedjay%2Fplayground-rest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265563093,"owners_count":23788644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T01:34:34.410Z","updated_at":"2025-07-17T03:35:26.003Z","avatar_url":"https://github.com/teedjay.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# playground-rest\nExamples using JEE7 standards like jax-rs and beans validation to make simple REST \nresources and showing ways to test and run these.\n\nTech demonstrated in this demo : \n- [x] Anemic objects as data-structures for input / output to REST API\n- [x] Automatic mapping between data and JSON / XML using JAX-RS\n- [x] Automatic Validation of input / output data with Beans Validation\n- [x] Automatic description of REST API (WADL for API and XSD for data) \n- [x] CDI for injection of business services\n- [x] Logging to internal Payara log (DebugResource.java)\n- [x] Logging to external log using SLF4J (ExampleResource.java) \n- [x] Unit testing by injecting mocks using mockito (ExampleResourceTest.java)\n- [x] Unit testing of Beans Validation constraints (UserTest.java)\n- [x] Integration testing REST API with RESTAssured and Arquillian using Payara container (UsersResourceIT.java)\n- [x] Mocked service using a CDI producer (MockTestResourceUsingMockitoIT)\n\nThe ```User.java``` shows how anemic objects can work at the API level to transport\nand validate data structures.  They should not be used inside your domain model and \nbusiness logic directly but mapped to real domain objects at the API level.  \n\n## How to build artifacts\nMake sure you have Java 8 and Maven 3 installed and available from the command line.\n```\njava -version   =\u003e should be Java 8\nmvn -version    =\u003e should be Maven 3\nmvn clean package\n```\n\nThe built war file will be available under target as shown below and can be deployed to any JEE7 application server.\n```\ntarget/rest-1.0-SNAPSHOT.war\n```\n\n## Unit Testing and Integration Testing\nMaven defaults to SureFire for running unit tests.  For integration testing we would \nlike to use the FailSafe plugin (see pom.xml for configuration).\n\nBy convention all test classes ending in *IT.java will be run in the verify phase of Maven using FailSafe plugin.\n\n```\nmvn clean test    =\u003e runs all unit tests\nmvn clean verify  =\u003e run all tests including integration tests \n```\n\nNote for Mac-users : Running the full ```mvn clean verify``` should take around 14 seconds on a MacBook Pro,\nif you experience 30 seconds make sure your hostname resolves to localhost for both IP4 and IP6 in \nyour ```etc/hosts``` settings.  Follow these [instructions](https://thoeni.io/post/macos-sierra-java/). \n\n## How to run on different appservers\nThis application runs on any JEE7 application server, \njust copy the war file to your favorite application server or use one of the methods below.\n\n### Using Payara Micro\nDownload the latest [Payara Micro](http://www.payara.fish/downloads) jar file and start it with the war file we just buildt like this.\n```\njava -jar payara-micro-4.1.2.173.jar --deploy target/rest-1.0-SNAPSHOT.war\n```\n\nPayara Micro will cluster automatically so if you want to run more instances (or start on other ports) use the ```--port``` option.\n```\njava -jar payara-micro-4.1.2.173.jar --deploy target/rest-1.0-SNAPSHOT.war --port 8081\n```\n\n### Using Payara MicroProfile\nPayara MicroProfile is a scaled down appserver compatible with Eclipse MicroProfile.\nIt only supports a subset of JEE features like JAX-RS + CDI + JSON-P, but this is\nusually enough to build microservices and might be an option.  It runs the same way :\n```\njava -jar payara-microprofile-1.0-4.1.2.172.jar --deploy target/rest-1.0-SNAPSHOT.war\n```\n\n## Logging with Payara\nPayara Micro uses Java Util Logging (JUL) internally and defaults to console output.\nTo redirect JUL logging to file just use the logToFile command lone option like this : \n```\njava -jar payara-micro-4.1.2.173.jar --deploy target/rest-1.0-SNAPSHOT.war --logToFile ./payara-system.log\n```\n\nTake a look at the DebugResource.class on how to use JUL for logging in your own code.\n\n### Adding support for external logging (using SLF4J and Logback)\nIf you want your application logging separate from the Payara system logs,\nit is possible to use SLF4J or other logging frameworks.\n\nTake a look at the ExampleResource on how to enable SLF4J / Logback.\n\n## Importing the REST API using Postman\nYou can import the full REST API by importing the WADL definition into Postman.\n\nThe WADL is exposed by JAX-RS as default and it describes all the REST API functions.\nThe WADL also links to a XSD file that defines input/output objects of the API. \n\nJust start the server and import WADL from this url :  [.../rest/application.wadl](http://localhost:8080/rest-1.0-SNAPSHOT/rest/application.wadl)\n\nNow you can crate a new HTTP POST request to the example resource :\n```\nhttp://localhost:8080/rest-1.0-SNAPSHOT/rest/example\n```\n\nTo see the data formats used by the api look at this url [.../rest/application.wadl/xsd0.xsd](localhost:8080/rest-1.0-SNAPSHOT/rest/application.wadl/xsd0.xsd).\n\nMake sure you use correct Content-Type application/json when POST'ing JSON and use this example data :\n```\n{\n\t\"name\" : \"ole\",\n\t\"age\" : 78,\n\t\"address\" : \"oslo\"\n}\n```\n\nYou will get a response back with the same data, but formatted as XML or JSON.\nNote that the text element has been added by the REST call and has a fixed text.\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?\u003e\n\u003cuser\u003e\n    \u003cname\u003eole\u003c/name\u003e\n    \u003cage\u003e78\u003c/age\u003e\n    \u003caddress\u003eoslo\u003c/address\u003e\n    \u003ctext\u003eThis text is from the fixed text service\u003c/text\u003e\n\u003c/user\u003e\n```\n\n## Testing using CURL\nTo post the same query as the Postman example use this curl command :\n```\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\":\"ole\",\"age\":78,\"address\":\"oslo\"}' http://localhost:8080/rest-1.0-SNAPSHOT/rest/example\n```\n\n## XML and JSON response\nThe JAX-RS / JAX-WS features of JEE7 will support both XML and JSON response out of the box.\nIn our example XML is set as default response but the client can ask for JSON using normal accept header :  \n```\ncurl -X POST -H \"Content-Type: application/json\" -H \"Accept: application/json\" -d '{\"name\":\"ole\",\"age\":78,\"address\":\"oslo\"}' http://localhost:8080/rest-1.0-SNAPSHOT/rest/example\n```\nThe response will be like this :\n```\n{\n    \"name\" : \"ole\",\n    \"age\" : 78,\n    \"address\" : \"oslo\",\n    \"text\" : \"This text is from the fixed text service\"\n}\n```\n\n## Debugging\nA debug resource is available that returns all CDI beans in the system, use browser or curl to HTTP GET this.\n```\ncurl -i http://localhost:8080/rest-1.0-SNAPSHOT/rest/debug\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteedjay%2Fplayground-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteedjay%2Fplayground-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteedjay%2Fplayground-rest/lists"}