Microservice should be in it's own group. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/750916a9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/750916a9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/750916a9
Branch: refs/heads/master Commit: 750916a91bb1b06953a366695a7edb54cafd6c42 Parents: 495c648 Author: JamesBognar <[email protected]> Authored: Fri Sep 8 19:27:47 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Fri Sep 8 19:27:47 2017 -0400 ---------------------------------------------------------------------- juneau-examples/juneau-examples-rest/pom.xml | 2 +- juneau-microservice/.project | 31 + juneau-microservice/.settings/.gitignore | 2 + .../.settings/org.eclipse.wst.html.core.prefs | 43 + .../juneau-microservice-server/.classpath | 26 + .../juneau-microservice-server/.gitignore | 3 + .../juneau-microservice-server/.project | 29 + .../juneau-microservice-server/Dockerfile | 29 + .../juneau-microservice-server/pom.xml | 108 + .../juneau/microservice/Microservice.java | 631 +++ .../apache/juneau/microservice/Resource.java | 74 + .../juneau/microservice/ResourceGroup.java | 75 + .../juneau/microservice/ResourceJena.java | 46 + .../juneau/microservice/ResourceJenaGroup.java | 89 + .../juneau/microservice/RestMicroservice.java | 644 +++ .../juneau/microservice/doc-files/build1.png | Bin 0 -> 2633 bytes .../juneau/microservice/doc-files/build2.png | Bin 0 -> 8634 bytes .../microservice/doc-files/helloworld1.png | Bin 0 -> 14050 bytes .../microservice/doc-files/instructions1.png | Bin 0 -> 44658 bytes .../microservice/doc-files/instructions2.png | Bin 0 -> 54971 bytes .../microservice/doc-files/instructions3.png | Bin 0 -> 20755 bytes .../microservice/doc-files/instructions4.png | Bin 0 -> 28672 bytes .../microservice/doc-files/instructions5.png | Bin 0 -> 8894 bytes .../microservice/doc-files/instructions6.png | Bin 0 -> 22345 bytes .../juneau/microservice/doc-files/manifest1.png | Bin 0 -> 10493 bytes .../org/apache/juneau/microservice/package.html | 1038 +++++ .../microservice/resources/ConfigEdit.html | 39 + .../microservice/resources/ConfigResource.java | 212 + .../resources/DirectoryResource.java | 375 ++ .../resources/LogEntryFormatter.java | 266 ++ .../microservice/resources/LogParser.java | 228 ++ .../microservice/resources/LogsResource.java | 348 ++ .../resources/SampleRootResource.java | 29 + .../resources/ShutdownResource.java | 52 + .../juneau/microservice/resources/package.html | 31 + .../src/test/java/.gitignore | 12 + .../juneau-microservice-template/.classpath | 26 + .../juneau-microservice-template/.gitignore | 3 + .../juneau-microservice-template/.project | 29 + .../META-INF/MANIFEST.MF | 29 + .../juneau-microservice-template/build.xml | 55 + .../dependency-reduced-pom.xml | 66 + .../juneau-microservice-template/jetty.xml | 58 + .../microservice.cfg | 118 + .../juneau-microservice-template/pom.xml | 107 + .../microservice/sample/HelloWorldResource.java | 35 + .../microservice/sample/RootResources.java | 41 + .../microservice/sample/nls/Messages.properties | 19 + .../src/test/java/.gitignore | 12 + .../juneau-microservice-test/.classpath | 31 + .../juneau-microservice-test/.gitignore | 3 + .../juneau-microservice-test/.project | 23 + .../juneau-microservice-test/jetty.xml | 58 + .../juneau-microservice-test.cfg | 58 + .../juneau-microservice-test.launch | 18 + .../juneau-microservice-test/pom.xml | 85 + .../juneau/rest/test/AcceptCharsetResource.java | 94 + .../test/BeanContextPropertiesResource.java | 44 + .../apache/juneau/rest/test/BpiResource.java | 140 + .../rest/test/CallbackStringsResource.java | 53 + .../rest/test/CharsetEncodingsResource.java | 75 + .../juneau/rest/test/ClientFuturesResource.java | 35 + .../juneau/rest/test/ClientVersionResource.java | 93 + .../apache/juneau/rest/test/ConfigResource.java | 38 + .../juneau/rest/test/ContentResource.java | 81 + .../java/org/apache/juneau/rest/test/DTO2s.java | 138 + .../rest/test/DefaultContentTypesResource.java | 141 + .../rest/test/ErrorConditionsResource.java | 135 + .../juneau/rest/test/FormDataResource.java | 75 + .../apache/juneau/rest/test/GroupsResource.java | 87 + .../apache/juneau/rest/test/GzipResource.java | 111 + .../juneau/rest/test/HeadersResource.java | 243 ++ .../juneau/rest/test/HtmlDocLinksResource.java | 255 ++ .../juneau/rest/test/HtmlDocResource.java | 186 + .../juneau/rest/test/InheritanceResource.java | 328 ++ .../apache/juneau/rest/test/InterfaceProxy.java | 191 + .../rest/test/InterfaceProxyResource.java | 738 ++++ .../org/apache/juneau/rest/test/LargePojo.java | 45 + .../juneau/rest/test/LargePojosResource.java | 39 + .../juneau/rest/test/MessagesResource.java | 62 + .../juneau/rest/test/NlsPropertyResource.java | 71 + .../apache/juneau/rest/test/NlsResource.java | 197 + .../juneau/rest/test/NoParserInputResource.java | 57 + .../juneau/rest/test/OnPostCallResource.java | 110 + .../juneau/rest/test/OnPreCallResource.java | 95 + .../rest/test/OptionsWithoutNlsResource.java | 44 + .../rest/test/OverlappingMethodsResource.java | 146 + .../apache/juneau/rest/test/ParamsResource.java | 419 ++ .../juneau/rest/test/ParsersResource.java | 151 + .../apache/juneau/rest/test/PathResource.java | 69 + .../juneau/rest/test/PathVariablesResource.java | 48 + .../apache/juneau/rest/test/PathsResource.java | 70 + .../juneau/rest/test/PropertiesResource.java | 106 + .../apache/juneau/rest/test/QueryResource.java | 63 + .../rest/test/RequestBeanProxyResource.java | 50 + .../juneau/rest/test/RestClient2Resource.java | 36 + .../juneau/rest/test/RestHooksInitResource.java | 274 ++ .../juneau/rest/test/RestHooksResource.java | 189 + .../java/org/apache/juneau/rest/test/Root.java | 84 + .../juneau/rest/test/SerializersResource.java | 143 + .../juneau/rest/test/StaticFilesResource.java | 36 + .../org/apache/juneau/rest/test/TestUtils.java | 98 + .../rest/test/ThirdPartyProxyResource.java | 1737 ++++++++ .../rest/test/TransformsParentResource.java | 26 + .../juneau/rest/test/TransformsResource.java | 114 + .../apache/juneau/rest/test/UrisResource.java | 118 + .../juneau/rest/test/UrlContentResource.java | 59 + .../apache/juneau/rest/test/pojos/ABean.java | 24 + .../juneau/rest/test/pojos/Constants.java | 25 + .../rest/test/pojos/ImplicitSwappedPojo.java | 35 + .../juneau/rest/test/pojos/SwappedPojo.java | 20 + .../juneau/rest/test/pojos/SwappedPojoSwap.java | 35 + .../apache/juneau/rest/test/pojos/TestEnum.java | 17 + .../juneau/rest/test/pojos/TypedBean.java | 17 + .../juneau/rest/test/pojos/TypedBeanImpl.java | 25 + .../rest/test/HtmlPropertiesResource.properties | 31 + .../rest/test/Messages2Resource.properties | 16 + .../rest/test/MessagesResource.properties | 16 + .../rest/test/NlsPropertyResource.properties | 16 + .../juneau/rest/test/NlsResource.properties | 71 + .../juneau/rest/test/ParamsResource.properties | 15 + .../rest/test/ParamsResource_ja_JP.properties | 15 + .../org/apache/juneau/rest/test/xdocs/test.txt | 13 + .../juneau/rest/test/xdocs/xdocs/test.txt | 13 + .../juneau/rest/test/AcceptCharsetTest.java | 125 + .../rest/test/BeanContextPropertiesTest.java | 34 + .../org/apache/juneau/rest/test/BpiTest.java | 253 ++ .../juneau/rest/test/CallbackStringsTest.java | 50 + .../juneau/rest/test/CharsetEncodingsTest.java | 110 + .../juneau/rest/test/ClientFuturesTest.java | 44 + .../juneau/rest/test/ClientVersionTest.java | 77 + .../org/apache/juneau/rest/test/ConfigTest.java | 57 + .../apache/juneau/rest/test/ContentTest.java | 450 +++ .../java/org/apache/juneau/rest/test/DTOs.java | 138 + .../rest/test/DefaultContentTypesTest.java | 427 ++ .../juneau/rest/test/ErrorConditionsTest.java | 210 + .../apache/juneau/rest/test/FormDataTest.java | 135 + .../org/apache/juneau/rest/test/GroupsTest.java | 109 + .../org/apache/juneau/rest/test/GzipTest.java | 340 ++ .../apache/juneau/rest/test/HeadersTest.java | 261 ++ .../juneau/rest/test/HtmlDocLinksTest.java | 337 ++ .../apache/juneau/rest/test/HtmlDocTest.java | 291 ++ .../juneau/rest/test/InheritanceTest.java | 116 + .../juneau/rest/test/InterfaceProxyTest.java | 833 ++++ .../juneau/rest/test/JacocoDummyTest.java | 38 + .../apache/juneau/rest/test/LargePojosTest.java | 84 + .../apache/juneau/rest/test/MessagesTest.java | 44 + .../juneau/rest/test/NlsPropertyTest.java | 43 + .../org/apache/juneau/rest/test/NlsTest.java | 97 + .../juneau/rest/test/NoParserInputTest.java | 61 + .../apache/juneau/rest/test/OnPostCallTest.java | 121 + .../apache/juneau/rest/test/OnPreCallTest.java | 61 + .../juneau/rest/test/OptionsWithoutNlsTest.java | 45 + .../rest/test/OverlappingMethodsTest.java | 170 + .../org/apache/juneau/rest/test/ParamsTest.java | 855 ++++ .../apache/juneau/rest/test/ParsersTest.java | 138 + .../org/apache/juneau/rest/test/PathTest.java | 41 + .../juneau/rest/test/PathVariableTest.java | 51 + .../org/apache/juneau/rest/test/PathsTest.java | 817 ++++ .../apache/juneau/rest/test/PropertiesTest.java | 43 + .../org/apache/juneau/rest/test/QueryTest.java | 60 + .../juneau/rest/test/RequestBeanProxyTest.java | 2017 +++++++++ .../apache/juneau/rest/test/RestClientTest.java | 190 + .../juneau/rest/test/RestHooksInitTest.java | 112 + .../apache/juneau/rest/test/RestHooksTest.java | 72 + .../apache/juneau/rest/test/RestTestcase.java | 89 + .../apache/juneau/rest/test/RestUtilsTest.java | 189 + .../juneau/rest/test/SerializersTest.java | 130 + .../juneau/rest/test/StaticFilesTest.java | 53 + .../juneau/rest/test/TestMicroservice.java | 136 + .../juneau/rest/test/ThirdPartyProxyTest.java | 3814 ++++++++++++++++++ .../apache/juneau/rest/test/TransformsTest.java | 63 + .../org/apache/juneau/rest/test/UrisTest.java | 432 ++ .../apache/juneau/rest/test/UrlContentTest.java | 65 + .../juneau/rest/test/UrlPathPatternTest.java | 40 + .../org/apache/juneau/rest/test/_TestSuite.java | 84 + juneau-microservice/pom.xml | 40 + juneau-releng/juneau-all/pom.xml | 2 +- juneau-rest/.DS_Store | Bin 0 -> 6148 bytes .../juneau-microservice-template/.classpath | 26 - .../juneau-microservice-template/.gitignore | 3 - .../juneau-microservice-template/.project | 29 - .../META-INF/MANIFEST.MF | 29 - .../juneau-microservice-template/build.xml | 55 - .../dependency-reduced-pom.xml | 66 - .../juneau-microservice-template/jetty.xml | 58 - .../microservice.cfg | 118 - .../juneau-microservice-template/pom.xml | 107 - .../microservice/sample/HelloWorldResource.java | 35 - .../microservice/sample/RootResources.java | 41 - .../microservice/sample/nls/Messages.properties | 19 - .../src/test/java/.gitignore | 12 - juneau-rest/juneau-microservice/.classpath | 26 - juneau-rest/juneau-microservice/.gitignore | 3 - juneau-rest/juneau-microservice/.project | 26 - juneau-rest/juneau-microservice/Dockerfile | 29 - juneau-rest/juneau-microservice/pom.xml | 108 - .../juneau/microservice/Microservice.java | 631 --- .../apache/juneau/microservice/Resource.java | 74 - .../juneau/microservice/ResourceGroup.java | 75 - .../juneau/microservice/ResourceJena.java | 46 - .../juneau/microservice/ResourceJenaGroup.java | 89 - .../juneau/microservice/RestMicroservice.java | 644 --- .../juneau/microservice/doc-files/build1.png | Bin 2633 -> 0 bytes .../juneau/microservice/doc-files/build2.png | Bin 8634 -> 0 bytes .../microservice/doc-files/helloworld1.png | Bin 14050 -> 0 bytes .../microservice/doc-files/instructions1.png | Bin 44658 -> 0 bytes .../microservice/doc-files/instructions2.png | Bin 54971 -> 0 bytes .../microservice/doc-files/instructions3.png | Bin 20755 -> 0 bytes .../microservice/doc-files/instructions4.png | Bin 28672 -> 0 bytes .../microservice/doc-files/instructions5.png | Bin 8894 -> 0 bytes .../microservice/doc-files/instructions6.png | Bin 22345 -> 0 bytes .../juneau/microservice/doc-files/manifest1.png | Bin 10493 -> 0 bytes .../org/apache/juneau/microservice/package.html | 1038 ----- .../microservice/resources/ConfigEdit.html | 39 - .../microservice/resources/ConfigResource.java | 212 - .../resources/DirectoryResource.java | 375 -- .../resources/LogEntryFormatter.java | 266 -- .../microservice/resources/LogParser.java | 228 -- .../microservice/resources/LogsResource.java | 348 -- .../resources/SampleRootResource.java | 29 - .../resources/ShutdownResource.java | 52 - .../juneau/microservice/resources/package.html | 31 - .../src/test/java/.gitignore | 12 - juneau-rest/juneau-rest-test/.classpath | 31 - juneau-rest/juneau-rest-test/.gitignore | 3 - juneau-rest/juneau-rest-test/.project | 22 - juneau-rest/juneau-rest-test/jetty.xml | 58 - .../juneau-microservice-test.launch | 18 + .../juneau-rest-test/juneau-rest-test.cfg | 58 - .../juneau-rest-test/juneau-rest-test.launch | 18 - juneau-rest/juneau-rest-test/pom.xml | 85 - .../juneau/rest/test/AcceptCharsetResource.java | 94 - .../test/BeanContextPropertiesResource.java | 44 - .../apache/juneau/rest/test/BpiResource.java | 140 - .../rest/test/CallbackStringsResource.java | 53 - .../rest/test/CharsetEncodingsResource.java | 75 - .../juneau/rest/test/ClientFuturesResource.java | 35 - .../juneau/rest/test/ClientVersionResource.java | 93 - .../apache/juneau/rest/test/ConfigResource.java | 38 - .../juneau/rest/test/ContentResource.java | 81 - .../java/org/apache/juneau/rest/test/DTO2s.java | 138 - .../rest/test/DefaultContentTypesResource.java | 141 - .../rest/test/ErrorConditionsResource.java | 135 - .../juneau/rest/test/FormDataResource.java | 75 - .../apache/juneau/rest/test/GroupsResource.java | 87 - .../apache/juneau/rest/test/GzipResource.java | 111 - .../juneau/rest/test/HeadersResource.java | 243 -- .../juneau/rest/test/HtmlDocLinksResource.java | 255 -- .../juneau/rest/test/HtmlDocResource.java | 186 - .../juneau/rest/test/InheritanceResource.java | 328 -- .../apache/juneau/rest/test/InterfaceProxy.java | 191 - .../rest/test/InterfaceProxyResource.java | 738 ---- .../org/apache/juneau/rest/test/LargePojo.java | 45 - .../juneau/rest/test/LargePojosResource.java | 39 - .../juneau/rest/test/MessagesResource.java | 62 - .../juneau/rest/test/NlsPropertyResource.java | 71 - .../apache/juneau/rest/test/NlsResource.java | 197 - .../juneau/rest/test/NoParserInputResource.java | 57 - .../juneau/rest/test/OnPostCallResource.java | 110 - .../juneau/rest/test/OnPreCallResource.java | 95 - .../rest/test/OptionsWithoutNlsResource.java | 44 - .../rest/test/OverlappingMethodsResource.java | 146 - .../apache/juneau/rest/test/ParamsResource.java | 419 -- .../juneau/rest/test/ParsersResource.java | 151 - .../apache/juneau/rest/test/PathResource.java | 69 - .../juneau/rest/test/PathVariablesResource.java | 48 - .../apache/juneau/rest/test/PathsResource.java | 70 - .../juneau/rest/test/PropertiesResource.java | 106 - .../apache/juneau/rest/test/QueryResource.java | 63 - .../rest/test/RequestBeanProxyResource.java | 50 - .../juneau/rest/test/RestClient2Resource.java | 36 - .../juneau/rest/test/RestHooksInitResource.java | 274 -- .../juneau/rest/test/RestHooksResource.java | 189 - .../java/org/apache/juneau/rest/test/Root.java | 84 - .../juneau/rest/test/SerializersResource.java | 143 - .../juneau/rest/test/StaticFilesResource.java | 36 - .../org/apache/juneau/rest/test/TestUtils.java | 98 - .../rest/test/ThirdPartyProxyResource.java | 1737 -------- .../rest/test/TransformsParentResource.java | 26 - .../juneau/rest/test/TransformsResource.java | 114 - .../apache/juneau/rest/test/UrisResource.java | 118 - .../juneau/rest/test/UrlContentResource.java | 59 - .../apache/juneau/rest/test/pojos/ABean.java | 24 - .../juneau/rest/test/pojos/Constants.java | 25 - .../rest/test/pojos/ImplicitSwappedPojo.java | 35 - .../juneau/rest/test/pojos/SwappedPojo.java | 20 - .../juneau/rest/test/pojos/SwappedPojoSwap.java | 35 - .../apache/juneau/rest/test/pojos/TestEnum.java | 17 - .../juneau/rest/test/pojos/TypedBean.java | 17 - .../juneau/rest/test/pojos/TypedBeanImpl.java | 25 - .../rest/test/HtmlPropertiesResource.properties | 31 - .../rest/test/Messages2Resource.properties | 16 - .../rest/test/MessagesResource.properties | 16 - .../rest/test/NlsPropertyResource.properties | 16 - .../juneau/rest/test/NlsResource.properties | 71 - .../juneau/rest/test/ParamsResource.properties | 15 - .../rest/test/ParamsResource_ja_JP.properties | 15 - .../org/apache/juneau/rest/test/xdocs/test.txt | 13 - .../juneau/rest/test/xdocs/xdocs/test.txt | 13 - .../juneau/rest/test/AcceptCharsetTest.java | 125 - .../rest/test/BeanContextPropertiesTest.java | 34 - .../org/apache/juneau/rest/test/BpiTest.java | 253 -- .../juneau/rest/test/CallbackStringsTest.java | 50 - .../juneau/rest/test/CharsetEncodingsTest.java | 110 - .../juneau/rest/test/ClientFuturesTest.java | 44 - .../juneau/rest/test/ClientVersionTest.java | 77 - .../org/apache/juneau/rest/test/ConfigTest.java | 57 - .../apache/juneau/rest/test/ContentTest.java | 450 --- .../java/org/apache/juneau/rest/test/DTOs.java | 138 - .../rest/test/DefaultContentTypesTest.java | 427 -- .../juneau/rest/test/ErrorConditionsTest.java | 210 - .../apache/juneau/rest/test/FormDataTest.java | 135 - .../org/apache/juneau/rest/test/GroupsTest.java | 109 - .../org/apache/juneau/rest/test/GzipTest.java | 340 -- .../apache/juneau/rest/test/HeadersTest.java | 261 -- .../juneau/rest/test/HtmlDocLinksTest.java | 337 -- .../apache/juneau/rest/test/HtmlDocTest.java | 291 -- .../juneau/rest/test/InheritanceTest.java | 116 - .../juneau/rest/test/InterfaceProxyTest.java | 833 ---- .../juneau/rest/test/JacocoDummyTest.java | 38 - .../apache/juneau/rest/test/LargePojosTest.java | 84 - .../apache/juneau/rest/test/MessagesTest.java | 44 - .../juneau/rest/test/NlsPropertyTest.java | 43 - .../org/apache/juneau/rest/test/NlsTest.java | 97 - .../juneau/rest/test/NoParserInputTest.java | 61 - .../apache/juneau/rest/test/OnPostCallTest.java | 121 - .../apache/juneau/rest/test/OnPreCallTest.java | 61 - .../juneau/rest/test/OptionsWithoutNlsTest.java | 45 - .../rest/test/OverlappingMethodsTest.java | 170 - .../org/apache/juneau/rest/test/ParamsTest.java | 855 ---- .../apache/juneau/rest/test/ParsersTest.java | 138 - .../org/apache/juneau/rest/test/PathTest.java | 41 - .../juneau/rest/test/PathVariableTest.java | 51 - .../org/apache/juneau/rest/test/PathsTest.java | 817 ---- .../apache/juneau/rest/test/PropertiesTest.java | 43 - .../org/apache/juneau/rest/test/QueryTest.java | 60 - .../juneau/rest/test/RequestBeanProxyTest.java | 2017 --------- .../apache/juneau/rest/test/RestClientTest.java | 190 - .../juneau/rest/test/RestHooksInitTest.java | 112 - .../apache/juneau/rest/test/RestHooksTest.java | 72 - .../apache/juneau/rest/test/RestTestcase.java | 89 - .../apache/juneau/rest/test/RestUtilsTest.java | 189 - .../juneau/rest/test/SerializersTest.java | 130 - .../juneau/rest/test/StaticFilesTest.java | 53 - .../juneau/rest/test/TestMicroservice.java | 136 - .../juneau/rest/test/ThirdPartyProxyTest.java | 3814 ------------------ .../apache/juneau/rest/test/TransformsTest.java | 63 - .../org/apache/juneau/rest/test/UrisTest.java | 432 -- .../apache/juneau/rest/test/UrlContentTest.java | 65 - .../juneau/rest/test/UrlPathPatternTest.java | 40 - .../org/apache/juneau/rest/test/_TestSuite.java | 84 - juneau-rest/pom.xml | 3 - pom.xml | 1 + 354 files changed, 28488 insertions(+), 28352 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-examples/juneau-examples-rest/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-examples/juneau-examples-rest/pom.xml b/juneau-examples/juneau-examples-rest/pom.xml index 306cf57..a952ad0 100644 --- a/juneau-examples/juneau-examples-rest/pom.xml +++ b/juneau-examples/juneau-examples-rest/pom.xml @@ -48,7 +48,7 @@ <dependencies> <dependency> <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> + <artifactId>juneau-microservice-server</artifactId> <version>${project.version}</version> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/.project ---------------------------------------------------------------------- diff --git a/juneau-microservice/.project b/juneau-microservice/.project new file mode 100644 index 0000000..474be51 --- /dev/null +++ b/juneau-microservice/.project @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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 * + * * + * 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. * + *************************************************************************************************************************** +--> +<projectDescription> + <name>juneau-rest</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + </natures> +</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/.settings/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice/.settings/.gitignore b/juneau-microservice/.settings/.gitignore new file mode 100644 index 0000000..9976760 --- /dev/null +++ b/juneau-microservice/.settings/.gitignore @@ -0,0 +1,2 @@ +/org.eclipse.core.resources.prefs +/org.eclipse.m2e.core.prefs http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/.settings/org.eclipse.wst.html.core.prefs ---------------------------------------------------------------------- diff --git a/juneau-microservice/.settings/org.eclipse.wst.html.core.prefs b/juneau-microservice/.settings/org.eclipse.wst.html.core.prefs new file mode 100644 index 0000000..57fb737 --- /dev/null +++ b/juneau-microservice/.settings/org.eclipse.wst.html.core.prefs @@ -0,0 +1,43 @@ +attrDuplicate=2 +attrInvalidName=2 +attrInvalidValue=2 +attrNameMismatch=2 +attrNamesToIgnore= +attrUndefName=2 +attrUndefValue=2 +attrValueEqualsMissing=2 +attrValueMismatch=1 +attrValueUnclosed=2 +cdataInvalidContent=2 +cdataUnclosed=1 +commentInvalidContent=2 +commentUnclosed=1 +docDoctypeUnclosed=1 +docDuplicateTag=1 +docInvalidChar=2 +docInvalidContent=2 +eclipse.preferences.version=1 +elemCoexistence=2 +elemDuplicate=2 +elemEndInvalidCase=1 +elemInvalidContent=2 +elemInvalidDirective=1 +elemInvalidEmptyTag=2 +elemInvalidName=1 +elemInvalidText=2 +elemMissingEnd=2 +elemMissingStart=2 +elemStartInvalidCase=2 +elemUnclosedEndTag=1 +elemUnclosedStartTag=1 +elemUnknownName=2 +elemUnnecessaryEnd=2 +elementNamesToIgnore=jc,jd,jt,jk,js,jf,jsa,jsf,jsm,jss,ja,xt,xa,xc,xs,xv,mk,mv,cc,cs,ck,ce,cv,l,properties,ua,uk,un,us +ignoreAttrNames=false +ignoreElementNames=true +piInvalidContent=2 +piUnclosed=1 +piUndefined=2 +refInvalidContent=2 +resourceNotFound=2 +use-project-settings=true http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/.classpath ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/.classpath b/juneau-microservice/juneau-microservice-server/.classpath new file mode 100644 index 0000000..b4c1fc3 --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/.classpath @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" output="target/test-classes" path="src/test/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" output="target/classes" path="src/main/java"> + <attributes> + <attribute name="optional" value="true"/> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> + <attributes> + <attribute name="maven.pomderived" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="output" path="target/classes"/> +</classpath> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/.gitignore b/juneau-microservice/juneau-microservice-server/.gitignore new file mode 100644 index 0000000..d274d47 --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/.gitignore @@ -0,0 +1,3 @@ +/target/ +/.settings/ +/.DS_Store http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/.project ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/.project b/juneau-microservice/juneau-microservice-server/.project new file mode 100644 index 0000000..ffcf1ba --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/.project @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>juneau-microservice-service</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.m2e.core.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.m2e.core.maven2Nature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature> + </natures> +</projectDescription> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/Dockerfile ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/Dockerfile b/juneau-microservice/juneau-microservice-server/Dockerfile new file mode 100755 index 0000000..462b0da --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/Dockerfile @@ -0,0 +1,29 @@ +# *************************************************************************************************************************** +# * 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 +# * +# * 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. +# *************************************************************************************************************************** + +# Dockerfile for creating a Juneau microservice container + +FROM ubuntu + +# Change this to whatever port you wish to use. +EXPOSE 10000 + +# Install Java +apt-get update +apt-get install default-jre + +# Copy our jar +copy build/microservice.jar / + +ENTRYPOINT [] +CMD /bin/sh -c "java -jar microservice.jar 10000" http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/pom.xml b/juneau-microservice/juneau-microservice-server/pom.xml new file mode 100644 index 0000000..d10c107 --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/pom.xml @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * 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 * + * * + * 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. * + *************************************************************************************************************************** +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest</artifactId> + <version>6.3.2-incubating-SNAPSHOT</version> + </parent> + + <artifactId>juneau-microservice-server</artifactId> + <name>Apache Juneau Microservice Server</name> + <description>API for creating standalone executable jars that can be used to start lightweight configurable REST interfaces.</description> + + <properties> + <!-- Skip javadoc generation since we generate them in the aggregate pom --> + <maven.javadoc.skip>true</maven.javadoc.skip> + <jetty.version>9.4.6.v20170531</jetty.version> + + <!-- Java 8 required because Jetty requires it. --> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-rest-client</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.juneau</groupId> + <artifactId>juneau-marshall-rdf</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-security</artifactId> + <version>${jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + <version>${jetty.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-xml</artifactId> + <version>${jetty.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <mainClass>org.apache.juneau.microservice.RestMicroservice</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Microservice.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Microservice.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Microservice.java new file mode 100755 index 0000000..1e7ca26 --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Microservice.java @@ -0,0 +1,631 @@ +// *************************************************************************************************************************** +// * 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 * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.microservice; + +import static org.apache.juneau.internal.IOUtils.*; + +import java.io.*; +import java.net.*; +import java.util.*; +import java.util.jar.*; + +import org.apache.juneau.*; +import org.apache.juneau.ini.*; +import org.apache.juneau.internal.*; +import org.apache.juneau.svl.*; +import org.apache.juneau.svl.vars.*; +import org.apache.juneau.utils.*; + +/** + * Parent class for all microservices. + * + * <p> + * A microservice defines a simple API for starting and stopping simple Java services contained in executable jars. + * + * <p> + * The general command for invoking these services is... + * <p class='bcode'> + * java -jar mymicroservice.jar [mymicroservice.cfg] + * </p> + * + * <p> + * Your microservice class must be specified as the <jk>Main-Class</jk> entry in the manifest file of your microservice + * jar file. + * + * <h6 class='topic'>Microservice Configuration</h6> + * + * This class defines the following method for accessing configuration for your microservice: + * <ul class='spaced-list'> + * <li> + * {@link #getArgs()} - The command-line arguments passed to the jar file. + * <li> + * {@link #getConfig()} - An external INI-style configuration file. + * <li> + * {@link #getManifest()} - The manifest file for the main jar file. + * </ul> + * + * <h6 class='topic'>Entry point Method</h6> + * + * Subclasses must implement a static void main method as the entry point for the microservice. + * Typically, this method will simply consist of the following... + * <p class='bcode'> + * <jk>public static void</jk> main(String[] args) <jk>throws</jk> Exception { + * <jk>new</jk> MyMicroservice(args).start(); + * } + * </p> + * + * <h6 class='topic'>Lifecycle Methods</h6> + * + * Subclasses must implement the following lifecycle methods: + * <ul class='spaced-list'> + * <li> + * {@link #start()} - Gets executed during startup. + * <li> + * {@link #stop()} - Gets executed when 'exit' is typed in the console or an external shutdown signal is received. + * <li> + * {@link #kill()} - Can be used to forcibly shut down the service. Doesn't get called during normal operation. + * </ul> + * + * <h6 class='topic'>Lifecycle Listener Methods</h6> + * + * Subclasses can optionally implement the following event listener methods: + * <ul class='spaced-list'> + * <li> + * {@link #onStart()} - Gets executed before {@link #start()}. + * <li> + * {@link #onStop()} - Gets executed before {@link #stop()}. + * <li> + * {@link #onConfigSave(ConfigFile)} - Gets executed after a config file has been saved. + * <li> + * {@link #onConfigChange(ConfigFile, Set)} - Gets executed after a config file has been modified. + * </ul> + * + * <h6 class='topic'>Other Methods</h6> + * + * Subclasses can optionally override the following methods to provide customized behavior: + * <ul class='spaced-list'> + * <li> + * {@link #createVarResolver()} - Creates the {@link VarResolver} used to resolve variables in the config file + * returned by {@link #getConfig()}. + * </ul> + */ +public abstract class Microservice { + + private static Args args; + private static ConfigFile cf; + private static ManifestFile mf; + + private String cfPath; + + /** + * Constructor. + * + * @param args Command line arguments. + * @throws Exception + */ + protected Microservice(String...args) throws Exception { + Microservice.args = new Args(args); + } + + /** + * Specifies the path of the config file for this microservice. + * + * <p> + * If you do not specify the config file location, we attempt to resolve it through the following methods: + * <ol> + * <li>The first argument in the command line arguments passed in through the constructor. + * <li>The value of the <code>Main-ConfigFile</code> entry in the manifest file. + * <li>A config file in the same location and with the same name as the executable jar file. + * (e.g. <js>"java -jar myjar.jar"</js> will look for <js>"myjar.cfg"</js>). + * </ol> + * + * <p> + * If this path does not exist, a {@link FileNotFoundException} will be thrown from the {@link #start()} command. + * + * @param cfPath The absolute or relative path of the config file. + * @param create Create the file if it doesn't exist. + * @return This object (for method chaining). + * @throws IOException If config file does not exist at the specified location or could not be read or created. + */ + public Microservice setConfig(String cfPath, boolean create) throws IOException { + File f = new File(cfPath); + if (! f.exists()) { + if (! create) + throw new FileNotFoundException("Could not locate config file at '"+f.getAbsolutePath()+"'"); + if (! f.createNewFile()) + throw new FileNotFoundException("Could not create config file at '"+f.getAbsolutePath()+"'"); + } + this.cfPath = cfPath; + return this; + } + + /** + * Specifies the config file for this microservice. + * + * <p> + * Note that if you use this method instead of {@link #setConfig(String,boolean)}, the config file will not use + * the variable resolver constructed from {@link #createVarResolver()}. + * + * @param cf The config file for this application, or <jk>null</jk> if no config file is needed. + */ + public static void setConfig(ConfigFile cf) { + Microservice.cf = cf; + } + + /** + * Specifies the manifest file of the jar file this microservice is contained within. + * + * <p> + * If you do not specify the manifest file, we attempt to resolve it through the following methods: + * <ol> + * <li>Looking on the file system for a file at <js>"META-INF/MANIFEST.MF"</js>. + * This is primarily to allow for running microservices from within eclipse workspaces where the manifest file + * is located in the project root. + * <li>Using the class loader for this class to find the file at the URL <js>"META-INF/MANIFEST.MF"</js>. + * </ol> + * + * @param mf The manifest file of this microservice. + */ + public static void setManifest(Manifest mf) { + Microservice.mf = new ManifestFile(mf); + } + + /** + * Convenience method for specifying the manifest contents directly. + * + * @param contents The lines in the manifest file. + * @return This object (for method chaining). + * @throws IOException + */ + public Microservice setManifestContents(String...contents) throws IOException { + String s = StringUtils.join(contents, "\n") + "\n"; + Microservice.mf = new ManifestFile(new Manifest(new ByteArrayInputStream(s.getBytes("UTF-8")))); + return this; + } + + /** + * Same as {@link #setManifest(Manifest)} except specified through a {@link File} object. + * + * @param f The manifest file of this microservice. + * @throws IOException If a problem occurred while trying to read the manifest file. + */ + public static void setManifest(File f) throws IOException { + Microservice.mf = new ManifestFile(f); + } + + /** + * Same as {@link #setManifest(Manifest)} except finds and loads the manifest file of the jar file that the + * specified class is contained within. + * + * @param c The class whose jar file contains the manifest to use for this microservice. + * @throws IOException If a problem occurred while trying to read the manifest file. + */ + public static void setManifest(Class<?> c) throws IOException { + Microservice.mf = new ManifestFile(c); + } + + /** + * Creates the {@link VarResolver} used to resolve variables in the config file returned by {@link #getConfig()}. + * + * <p> + * The default implementation resolves the following variables: + * <ul> + * <li><code>$S{key}</code>, <code>$S{key,default}</code> - System properties. + * <li><code>$E{key}</code>, <code>$E{key,default}</code> - Environment variables. + * <li><code>$C{key}</code>, <code>$C{key,default}</code> - Config file entries. + * <li><code>$MF{key}</code>, <code>$MF{key,default}</code> - Manifest file entries. + * <li><code>$ARG{key}</code>, <code>$ARG{key,default}</code> - Command-line arguments. + * <li><code>$IF{boolArg,thenValue}</code>, <code>$IF{boolArg,thenValue,elseValue}</code> - If-block logic. + * <li><code>$SW{stringArg,pattern,thenVal...}</code>, + * <code>$SW{stringArg,pattern,thenVal,elseVal...}</code> - Switch-block logic. + * </ul> + * + * <p> + * Subclasses can override this method to provide their own variables. + * + * <h5 class='section'>Example:</h5> + * <p class='bcode'> + * <jd>/** + * * Augment default var resolver with a custom $B{...} variable that simply wraps strings inside square brackets. + * * /</jd> + * <ja>@Override</ja> <jc>// Microservice</jc> + * <jk>protected</jk> StringVarResolver createVarResolver() { + * <jk>return super</jk>.createVarResolver() + * .addVar(<js>"B"</js>, + * <jk>new</jk> StringVarWithDefault() { + * <ja>@Override</ja> <jc>// StringVar</jc> + * <jk>public</jk> String resolve(String varVal) { + * <jk>return</jk> <js>'['</js> + varVal + <js>']'</js>; + * } + * } + * ); + * } + * </p> + * <p class='bcode'> + * <cc># Example config file</cc> + * <cs>[MySection]</cs> + * <ck>myEntry</ck> = $B{foo} + * </p> + * <p class='bcode'> + * <jc>// Example java code</jc> + * String myentry = getConfig().getString(<js>"MySection/myEntry"</js>); <jc>// == "[foo]"</js> + * </p> + * + * @return A new {@link VarResolver}. + */ + protected VarResolverBuilder createVarResolver() { + VarResolverBuilder b = new VarResolverBuilder() + .defaultVars() + .vars(ConfigFileVar.class, ManifestFileVar.class, ArgsVar.class, SwitchVar.class, IfVar.class) + .contextObject(ManifestFileVar.SESSION_manifest, mf) + .contextObject(ArgsVar.SESSION_args, args); + if (cf != null) + b.contextObject(ConfigFileVar.SESSION_config, cf); + return b; + } + + /** + * Returns the command-line arguments passed into the application. + * + * <p> + * This method can be called from the class constructor. + * + * <p> + * See {@link Args} for details on using this method. + * + * @return The command-line arguments passed into the application. + */ + protected static Args getArgs() { + return args; + } + + /** + * Returns the external INI-style configuration file that can be used to configure your microservice. + * + * <p> + * The config file location is determined in the following order: + * <ol class='spaced-list'> + * <li> + * The first argument passed to the microservice jar. + * <li> + * The <code>Main-ConfigFile</code> entry in the microservice jar manifest file. + * <li> + * The name of the microservice jar with a <js>".cfg"</js> suffix (e.g. + * <js>"mymicroservice.jar"</js>-><js>"mymicroservice.cfg"</js>). + * </ol> + * + * <p> + * If all methods for locating the config file fail, then this method returns <jk>null</jk>. + * + * <p> + * Subclasses can set their own config file by calling the {@link #setConfig(ConfigFile)} method. + * + * <p> + * String variables defined by {@link #createVarResolver()} are automatically resolved when using this method. + * + * <p> + * This method can be called from the class constructor. + * + * <h5 class='section'>Example:</h5> + * <p class='bcode'> + * <cc>#--------------------------</cc> + * <cc># My section</cc> + * <cc>#--------------------------</cc> + * <cs>[MySection]</cs> + * + * <cc># An integer</cc> + * <ck>anInt</ck> = 1 + * + * <cc># A boolean</cc> + * <ck>aBoolean</ck> = true + * + * <cc># An int array</cc> + * <ck>anIntArray</ck> = 1,2,3 + * + * <cc># A POJO that can be converted from a String</cc> + * <ck>aURL</ck> = http://foo + * + * <cc># A POJO that can be converted from JSON</cc> + * <ck>aBean</ck> = {foo:'bar',baz:123} + * + * <cc># A system property</cc> + * <ck>locale</ck> = $S{java.locale, en_US} + * + * <cc># An environment variable</cc> + * <ck>path</ck> = $E{PATH, unknown} + * + * <cc># A manifest file entry</cc> + * <ck>mainClass</ck> = $MF{Main-Class} + * + * <cc># Another value in this config file</cc> + * <ck>sameAsAnInt</ck> = $C{MySection/anInt} + * + * <cc># A command-line argument in the form "myarg=foo"</cc> + * <ck>myArg</ck> = $ARG{myarg} + * + * <cc># The first command-line argument</cc> + * <ck>firstArg</ck> = $ARG{0} + * + * <cc># Look for system property, or env var if that doesn't exist, or command-line arg if that doesn't exist.</cc> + * <ck>nested</ck> = $S{mySystemProperty,$E{MY_ENV_VAR,$ARG{0}}} + * + * <cc># A POJO with embedded variables</cc> + * <ck>aBean2</ck> = {foo:'$ARG{0}',baz:$C{MySection/anInt}} + * </p> + * + * <p class='bcode'> + * <jc>// Java code for accessing config entries above.</jc> + * ConfigFile cf = getConfig(); + * + * <jk>int</jk> anInt = cf.getInt(<js>"MySection/anInt"</js>); + * <jk>boolean</jk> aBoolean = cf.getBoolean(<js>"MySection/aBoolean"</js>); + * <jk>int</jk>[] anIntArray = cf.getObject(<jk>int</jk>[].<jk>class</jk>, <js>"MySection/anIntArray"</js>); + * URL aURL = cf.getObject(URL.<jk>class</jk>, <js>"MySection/aURL"</js>); + * MyBean aBean = cf.getObject(MyBean.<jk>class</jk>, <js>"MySection/aBean"</js>); + * Locale locale = cf.getObject(Locale.<jk>class</jk>, <js>"MySection/locale"</js>); + * String path = cf.getString(<js>"MySection/path"</js>); + * String mainClass = cf.getString(<js>"MySection/mainClass"</js>); + * <jk>int</jk> sameAsAnInt = cf.getInt(<js>"MySection/sameAsAnInt"</js>); + * String myArg = cf.getString(<js>"MySection/myArg"</js>); + * String firstArg = cf.getString(<js>"MySection/firstArg"</js>); + * </p> + * + * @return The config file for this application, or <jk>null</jk> if no config file is configured. + */ + protected static ConfigFile getConfig() { + return cf; + } + + /** + * Returns the main jar manifest file contents as a simple {@link ObjectMap}. + * + * <p> + * This map consists of the contents of {@link Manifest#getMainAttributes()} with the keys and entries converted to + * simple strings. + * <p> + * This method can be called from the class constructor. + * + * <h5 class='section'>Example:</h5> + * <p class='bcode'> + * <jc>// Get Main-Class from manifest file.</jc> + * String mainClass = Microservice.<jsm>getManifest</jsm>().getString(<js>"Main-Class"</js>, <js>"unknown"</js>); + * + * <jc>// Get Rest-Resources from manifest file.</jc> + * String[] restResources = Microservice.<jsm>getManifest</jsm>().getStringArray(<js>"Rest-Resources"</js>); + * </p> + * + * @return The manifest file from the main jar, or <jk>null</jk> if the manifest file could not be retrieved. + */ + protected static ManifestFile getManifest() { + return mf; + } + + + //-------------------------------------------------------------------------------- + // Abstract lifecycle methods. + //-------------------------------------------------------------------------------- + + /** + * Start this application. + * + * <p> + * Default implementation simply calls {@link #onStart()}. + * + * <p> + * Overridden methods MUST call this method FIRST so that the {@link #onStart()} method is called. + * + * @return This object (for method chaining). + * @throws Exception + */ + public Microservice start() throws Exception { + + // -------------------------------------------------------------------------------- + // Try to get the manifest file if it wasn't already set. + // -------------------------------------------------------------------------------- + if (mf == null) { + Manifest m = new Manifest(); + + // If running within an eclipse workspace, need to get it from the file system. + File f = new File("META-INF/MANIFEST.MF"); + if (f.exists()) { + try { + m.read(new FileInputStream(f)); + } catch (IOException e) { + System.err.println("Problem detected in MANIFEST.MF. Contents below:\n" + read(f)); + throw e; + } + } else { + // Otherwise, read from manifest file in the jar file containing the main class. + URLClassLoader cl = (URLClassLoader)getClass().getClassLoader(); + URL url = cl.findResource("META-INF/MANIFEST.MF"); + if (url != null) { + try { + m.read(url.openStream()); + } catch (IOException e) { + System.err.println("Problem detected in MANIFEST.MF. Contents below:\n" + read(url.openStream())); + throw e; + } + } + } + mf = new ManifestFile(m); + } + + // -------------------------------------------------------------------------------- + // Resolve the config file if the path was specified. + // -------------------------------------------------------------------------------- + ConfigFileBuilder cfb = new ConfigFileBuilder(); + if (cfPath != null) + cf = cfb.build(cfPath).getResolving(createVarResolver().build()); + + // -------------------------------------------------------------------------------- + // Find config file. + // Can either be passed in as first parameter, or we discover it using + // the 'sun.java.command' system property. + // -------------------------------------------------------------------------------- + if (cf == null) { + if (args.hasArg(0)) + cfPath = args.getArg(0); + else if (mf.containsKey("Main-ConfigFile")) + cfPath = mf.getString("Main-ConfigFile"); + else { + String cmd = System.getProperty("sun.java.command", "not_found").split("\\s+")[0]; + if (cmd.endsWith(".jar")) + cfPath = cmd.replace(".jar", ".cfg"); + } + + if (cfPath == null) { + System.err.println("Running class ["+getClass().getSimpleName()+"] without a config file."); + cf = cfb.build(); + } else { + System.out.println("Running class ["+getClass().getSimpleName()+"] using config file ["+cfPath+"]"); + cf = cfb.build(cfPath).getResolving(createVarResolver().build()); + } + } + + if (cfPath != null) + System.setProperty("juneau.configFile", cfPath); + + // -------------------------------------------------------------------------------- + // Set system properties. + // -------------------------------------------------------------------------------- + Set<String> spKeys = cf.getSectionKeys("SystemProperties"); + if (spKeys != null) + for (String key : spKeys) + System.setProperty(key, cf.get("SystemProperties", key)); + + // -------------------------------------------------------------------------------- + // Add a config file change listener. + // -------------------------------------------------------------------------------- + cf.addListener(new ConfigFileListener() { + @Override /* ConfigFileListener */ + public void onSave(ConfigFile cf) { + onConfigSave(cf); + } + @Override /* ConfigFileListener */ + public void onChange(ConfigFile cf, Set<String> changes) { + onConfigChange(cf, changes); + } + }); + + // -------------------------------------------------------------------------------- + // Add exit listeners. + // -------------------------------------------------------------------------------- + new Thread() { + @Override /* Thread */ + public void run() { + Console c = System.console(); + if (c == null) + System.out.println("No available console."); + else { + while (true) { + String l = c.readLine("\nEnter 'exit' to exit.\n"); + if (l == null || l.equals("exit")) { + Microservice.this.stop(); + break; + } + } + } + } + }.start(); + Runtime.getRuntime().addShutdownHook( + new Thread() { + @Override /* Thread */ + public void run() { + Microservice.this.stop(); + } + } + ); + onStart(); + return this; + } + + /** + * Joins the application with the current thread. + * + * <p> + * Default implementation is a no-op. + * + * @return This object (for method chaining). + * @throws Exception + */ + public Microservice join() throws Exception { + return this; + } + + /** + * Stop this application. + * + * <p> + * Default implementation simply calls {@link #onStop()}. + * + * <p> + * Overridden methods MUST call this method LAST so that the {@link #onStop()} method is called. + * + * @return This object (for method chaining). + */ + public Microservice stop() { + onStop(); + return this; + } + + /** + * Kill the JVM by calling <code>System.exit(2);</code>. + */ + public void kill() { + // This triggers the shutdown hook. + System.exit(2); + } + + + //-------------------------------------------------------------------------------- + // Lifecycle listener methods. + // Subclasses can override these methods to run code on certain events. + //-------------------------------------------------------------------------------- + + /** + * Called at the beginning of the {@link #start()} call. + * + * <p> + * Subclasses can override this method to hook into the lifecycle of this application. + */ + protected void onStart() {} + + /** + * Called at the end of the {@link #stop()} call. + * + * <p> + * Subclasses can override this method to hook into the lifecycle of this application. + */ + protected void onStop() {} + + /** + * Called if the {@link ConfigFile#save()} is called on the config file. + * + * <p> + * Subclasses can override this method to listen for config file changes. + * + * @param cf The config file. + */ + protected void onConfigSave(ConfigFile cf) {} + + /** + * Called if one or more changes occur in the config file. + * + * <p> + * Subclasses can override this method to listen for config file changes. + * + * @param cf The config file. + * @param changes The list of keys in the config file being changed. + */ + protected void onConfigChange(ConfigFile cf, Set<String> changes) {} +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Resource.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Resource.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Resource.java new file mode 100755 index 0000000..0579d4b --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/Resource.java @@ -0,0 +1,74 @@ +// *************************************************************************************************************************** +// * 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 * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.microservice; + +import static org.apache.juneau.rest.annotation.HookEvent.*; +import static javax.servlet.http.HttpServletResponse.*; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.svl.vars.*; + +/** + * Superclass for all REST resources. + * + * <p> + * In additional to the functionality of the {@link RestServletDefault} group, + * augments the {@link RestContext#getVarResolver()} method with the following additional variable types: + * <ul class='spaced-list'> + * <li> + * <code class='snippet'>$ARG{...}</code> - Command line arguments pulled from {@link Microservice#getArgs()}. + * + * <h6 class='figure'>Example:</h6> + * <p class='bcode'> + * String firstArg = request.getVarResolver().resolve(<js>"$ARG{0}"</js>); <jc>// First argument.</jc> + * String namedArg = request.getVarResolver().resolve(<js>"$ARG{myarg}"</js>); <jc>// Named argument (e.g. "myarg=foo"). </jc> + * </p> + * <li> + * <code class='snippet'>$MF{...}</code> - Manifest file entries pulled from {@link Microservice#getManifest()}. + * + * <h6 class='figure'>Example:</h6> + * <p class='bcode'> + * String mainClass = request.getVarResolver().resolve(<js>"$MF{Main-Class}"</js>); <jc>// Main class. </jc> + * </p> + * </ul> + */ +@SuppressWarnings("serial") +@RestResource( + htmldoc=@HtmlDoc( + links={ + "up: request:/..", + "options: servlet:/?method=OPTIONS" + }, + stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}" + ), + config="$S{juneau.configFile}" +) +public abstract class Resource extends RestServletDefault { + + /** + * Add <code>$ARGS</code> and <code>$MF</code> variable resolvers. + * + * @param config The resource config. + * @throws Exception + */ + @RestHook(INIT) + public void addConfigVars(RestConfig config) throws Exception { + if (Microservice.getArgs() == null || Microservice.getConfig() == null) + throw new RestException(SC_INTERNAL_SERVER_ERROR, "Attempting to use Resource class outside of RestMicroservice."); + config + .addVars(ArgsVar.class, ManifestFileVar.class) + .addVarContextObject(ArgsVar.SESSION_args, Microservice.getArgs()) + .addVarContextObject(ManifestFileVar.SESSION_manifest, Microservice.getManifest()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceGroup.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceGroup.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceGroup.java new file mode 100755 index 0000000..f3293cc --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceGroup.java @@ -0,0 +1,75 @@ +// *************************************************************************************************************************** +// * 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 * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.microservice; + +import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.rest.annotation.HookEvent.*; + +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.svl.vars.*; + +/** + * Superclass for all REST resource groups. + * + * <p> + * In additional to the functionality of the {@link RestServletGroupDefault} group, + * augments the {@link RestContext#getVarResolver()} method with the following additional variable types: + * <ul class='spaced-list'> + * <li> + * <jk>$ARG{...}</jk> - Command line arguments. + * <br>Resolves values from {@link Microservice#getArgs()}. + * + * <h6>Example:</h6> + * <p class='bcode'> + * String firstArg = request.getVarResolver().resolve(<js>"$ARG{0}"</js>); <jc>// First argument.</jc> + * String namedArg = request.getVarResolver().resolve(<js>"$ARG{myarg}"</js>); <jc>// Named argument (e.g. "myarg=foo"). </jc> + * </p> + * <li> + * <jk>$MF{...}</jk> - Manifest file entries. + * + * <h6>Example:</h6> + * <p class='bcode'> + * String mainClass = request.getVarResolver().resolve(<js>"$MF{Main-Class}"</js>); <jc>// Main class. </jc> + * </p> + * </ul> + */ +@SuppressWarnings("serial") +@RestResource( + htmldoc=@HtmlDoc( + links={ + "up: request:/..", + "options: servlet:/?method=OPTIONS" + }, + stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}" + ), + config="$S{juneau.configFile}" +) +public abstract class ResourceGroup extends RestServletGroupDefault { + + /** + * Initializes the registry URL and rest clent. + * + * @param config The resource config. + * @throws Exception + */ + @RestHook(INIT) + public void addConfigVars(RestConfig config) throws Exception { + if (Microservice.getArgs() == null || Microservice.getConfig() == null) + throw new RestException(SC_INTERNAL_SERVER_ERROR, "Attempting to use ResourceGroup class outside of RestMicroservice."); + config + .addVars(ArgsVar.class, ManifestFileVar.class) + .addVarContextObject(ArgsVar.SESSION_args, Microservice.getArgs()) + .addVarContextObject(ManifestFileVar.SESSION_manifest, Microservice.getManifest()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJena.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJena.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJena.java new file mode 100755 index 0000000..fdbddde --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJena.java @@ -0,0 +1,46 @@ +// *************************************************************************************************************************** +// * 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 * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.microservice; + +import org.apache.juneau.jena.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; + +/** + * Superclass for all REST resources with RDF support. + */ +@SuppressWarnings("serial") +@RestResource( + htmldoc=@HtmlDoc( + links={ + "up: request:/..", + "options: servlet:/?method=OPTIONS" + }, + stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}" + ), + config="$S{juneau.configFile}", + serializers={ + RdfSerializer.Xml.class, + RdfSerializer.XmlAbbrev.class, + RdfSerializer.Turtle.class, + RdfSerializer.NTriple.class, + RdfSerializer.N3.class + }, + parsers={ + RdfParser.Xml.class, + RdfParser.Turtle.class, + RdfParser.NTriple.class, + RdfParser.N3.class + } +) +public abstract class ResourceJena extends RestServletDefault {} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/750916a9/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJenaGroup.java ---------------------------------------------------------------------- diff --git a/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJenaGroup.java b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJenaGroup.java new file mode 100644 index 0000000..50f2075 --- /dev/null +++ b/juneau-microservice/juneau-microservice-server/src/main/java/org/apache/juneau/microservice/ResourceJenaGroup.java @@ -0,0 +1,89 @@ +// *************************************************************************************************************************** +// * 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 * +// * * +// * http://www.apache.org/licenses/LICENSE-2.0 * +// * * +// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * +// * specific language governing permissions and limitations under the License. * +// *************************************************************************************************************************** +package org.apache.juneau.microservice; + +import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.rest.annotation.HookEvent.*; + +import org.apache.juneau.jena.*; +import org.apache.juneau.rest.*; +import org.apache.juneau.rest.annotation.*; +import org.apache.juneau.svl.vars.*; + +/** + * Superclass for all REST resource groups. + * + * <p> + * In additional to the functionality of the {@link RestServletGroupDefault} group, + * augments the {@link RestContext#getVarResolver()} method with the following additional variable types: + * <ul class='spaced-list'> + * <li> + * <jk>$ARG{...}</jk> - Command line arguments. + * <br>Resolves values from {@link Microservice#getArgs()}. + * + * <h6>Example:</h6> + * <p class='bcode'> + * String firstArg = request.getVarResolver().resolve(<js>"$ARG{0}"</js>); <jc>// First argument.</jc> + * String namedArg = request.getVarResolver().resolve(<js>"$ARG{myarg}"</js>); <jc>// Named argument (e.g. "myarg=foo"). </jc> + * </p> + * <li> + * <jk>$MF{...}</jk> - Manifest file entries. + * + * <h6>Example:</h6> + * <p class='bcode'> + * String mainClass = request.getVarResolver().resolve(<js>"$MF{Main-Class}"</js>); <jc>// Main class. </jc> + * </p> + * </ul> + */ +@SuppressWarnings("serial") +@RestResource( + htmldoc=@HtmlDoc( + links={ + "up: request:/..", + "options: servlet:/?method=OPTIONS" + }, + stylesheet="$C{REST/stylesheet,servlet:/styles/devops.css}" + ), + config="$S{juneau.configFile}", + serializers={ + RdfSerializer.Xml.class, + RdfSerializer.XmlAbbrev.class, + RdfSerializer.Turtle.class, + RdfSerializer.NTriple.class, + RdfSerializer.N3.class + }, + parsers={ + RdfParser.Xml.class, + RdfParser.Turtle.class, + RdfParser.NTriple.class, + RdfParser.N3.class + } +) +public abstract class ResourceJenaGroup extends RestServletGroupDefault { + + /** + * Add <code>$ARGS</code> and <code>$MF</code> variable resolvers. + * + * @param config The resource config. + * @throws Exception + */ + @RestHook(INIT) + public void addConfigVars(RestConfig config) throws Exception { + if (Microservice.getArgs() == null || Microservice.getConfig() == null) + throw new RestException(SC_INTERNAL_SERVER_ERROR, "Attempting to use ResourceJenaGroup class outside of RestMicroservice."); + config + .addVars(ArgsVar.class, ManifestFileVar.class) + .addVarContextObject(ArgsVar.SESSION_args, Microservice.getArgs()) + .addVarContextObject(ManifestFileVar.SESSION_manifest, Microservice.getManifest()); + } +}
