├── .gitignore
├── .mvn
└── wrapper
│ ├── MavenWrapperDownloader.java
│ └── maven-wrapper.properties
├── .travis.yml
├── LICENSE.md
├── README.md
├── checkstyle.xml
├── demos
├── spring-5-hibernate-validator-demo
│ ├── .gitignore
│ ├── README.md
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── demo
│ │ │ ├── AppConfig.java
│ │ │ ├── dto
│ │ │ └── DTO.java
│ │ │ └── service
│ │ │ ├── MyService.java
│ │ │ └── MyServiceImpl.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ └── service
│ │ └── MyServiceImplTest.java
├── spring-boot-auto-configuration-demo
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── demo
│ │ │ │ ├── DemoApplication.java
│ │ │ │ ├── component
│ │ │ │ └── MyComponent.java
│ │ │ │ ├── dto
│ │ │ │ └── DTO.java
│ │ │ │ └── service
│ │ │ │ ├── MyService.java
│ │ │ │ └── MyServiceImpl.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ └── DemoApplicationTests.java
└── spring-boot-web-auto-configuration-demo
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── demo
│ │ │ ├── DemoApplication.java
│ │ │ ├── component
│ │ │ └── MyComponent.java
│ │ │ ├── dto
│ │ │ └── DTO.java
│ │ │ └── service
│ │ │ ├── MyService.java
│ │ │ └── MyServiceImpl.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── example
│ └── demo
│ └── DemoApplicationTests.java
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── io
│ │ └── github
│ │ └── opensanca
│ │ ├── ServiceValidatorAutoConfiguration.java
│ │ ├── ServiceValidatorImport.java
│ │ ├── annotation
│ │ └── ServiceValidation.java
│ │ ├── aop
│ │ └── ServiceValidationAspectImpl.java
│ │ ├── exception
│ │ ├── ServiceValidationErrorCollection.java
│ │ └── ServiceValidationException.java
│ │ ├── matchers
│ │ ├── ServiceValidatorErrorMatcher.java
│ │ └── ServiceValidatorViolationsMatcher.java
│ │ └── mvc
│ │ └── ServiceValidatorExceptionHandlerController.java
└── resources
│ └── META-INF
│ └── spring.factories
└── test
└── java
└── io
└── github
└── opensanca
├── DemoSpringBootWebApp.java
├── ServiceValidationMockitoTest.java
└── ServiceValidationTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Java template
3 | # Compiled class file
4 | *.class
5 |
6 | # Log file
7 | *.log
8 |
9 | # BlueJ files
10 | *.ctxt
11 |
12 | # Mobile Tools for Java (J2ME)
13 | .mtj.tmp/
14 |
15 | # Package Files #
16 | *.jar
17 | *.war
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 | ### JetBrains template
26 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
27 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
28 |
29 | # User-specific stuff:
30 | .idea/**/workspace.xml
31 | .idea/**/tasks.xml
32 | .idea/dictionaries
33 |
34 | # Sensitive or high-churn files:
35 | .idea/**/dataSources/
36 | .idea/**/dataSources.ids
37 | .idea/**/dataSources.xml
38 | .idea/**/dataSources.local.xml
39 | .idea/**/sqlDataSources.xml
40 | .idea/**/dynamic.xml
41 | .idea/**/uiDesigner.xml
42 |
43 | # Gradle:
44 | .idea/**/gradle.xml
45 | .idea/**/libraries
46 |
47 | # CMake
48 | cmake-build-debug/
49 | cmake-build-release/
50 |
51 | # Mongo Explorer plugin:
52 | .idea/**/mongoSettings.xml
53 |
54 | ## File-based project format:
55 | *.iws
56 |
57 | ## Plugin-specific files:
58 |
59 | # IntelliJ
60 | out/
61 | .idea/
62 | service-validator.iml
63 |
64 | # mpeltonen/sbt-idea plugin
65 | .idea_modules/
66 |
67 | # JIRA plugin
68 | atlassian-ide-plugin.xml
69 |
70 | # Cursive Clojure plugin
71 | .idea/replstate.xml
72 |
73 | # Crashlytics plugin (for Android Studio and IntelliJ)
74 | com_crashlytics_export_strings.xml
75 | crashlytics.properties
76 | crashlytics-build.properties
77 | fabric.properties
78 | ### Gradle template
79 | .gradle
80 | /build/
81 |
82 | # Ignore Gradle GUI config
83 | gradle-app.setting
84 |
85 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
86 | !gradle-wrapper.jar
87 |
88 | # Cache of project
89 | .gradletasknamecache
90 |
91 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
92 | # gradle/wrapper/gradle-wrapper.properties
93 |
94 | target/
95 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | http://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.net.*;
21 | import java.io.*;
22 | import java.nio.channels.*;
23 | import java.util.Properties;
24 |
25 | public class MavenWrapperDownloader {
26 |
27 | /**
28 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
29 | */
30 | private static final String DEFAULT_DOWNLOAD_URL =
31 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
32 |
33 | /**
34 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
35 | * use instead of the default one.
36 | */
37 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
38 | ".mvn/wrapper/maven-wrapper.properties";
39 |
40 | /**
41 | * Path where the maven-wrapper.jar will be saved to.
42 | */
43 | private static final String MAVEN_WRAPPER_JAR_PATH =
44 | ".mvn/wrapper/maven-wrapper.jar";
45 |
46 | /**
47 | * Name of the property which should be used to override the default download url for the wrapper.
48 | */
49 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
50 |
51 | public static void main(String args[]) {
52 | System.out.println("- Downloader started");
53 | File baseDirectory = new File(args[0]);
54 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
55 |
56 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
57 | // wrapperUrl parameter.
58 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
59 | String url = DEFAULT_DOWNLOAD_URL;
60 | if(mavenWrapperPropertyFile.exists()) {
61 | FileInputStream mavenWrapperPropertyFileInputStream = null;
62 | try {
63 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64 | Properties mavenWrapperProperties = new Properties();
65 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
67 | } catch (IOException e) {
68 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69 | } finally {
70 | try {
71 | if(mavenWrapperPropertyFileInputStream != null) {
72 | mavenWrapperPropertyFileInputStream.close();
73 | }
74 | } catch (IOException e) {
75 | // Ignore ...
76 | }
77 | }
78 | }
79 | System.out.println("- Downloading from: : " + url);
80 |
81 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
82 | if(!outputFile.getParentFile().exists()) {
83 | if(!outputFile.getParentFile().mkdirs()) {
84 | System.out.println(
85 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
86 | }
87 | }
88 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
89 | try {
90 | downloadFileFromURL(url, outputFile);
91 | System.out.println("Done");
92 | System.exit(0);
93 | } catch (Throwable e) {
94 | System.out.println("- Error downloading");
95 | e.printStackTrace();
96 | System.exit(1);
97 | }
98 | }
99 |
100 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
101 | URL website = new URL(urlString);
102 | ReadableByteChannel rbc;
103 | rbc = Channels.newChannel(website.openStream());
104 | FileOutputStream fos = new FileOutputStream(destination);
105 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
106 | fos.close();
107 | rbc.close();
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [2018] [Opensanca.com.br]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Service Validation
2 |
3 | NullSafe and DTO validation for Bean Validation in service layer using Aspect.
4 |
5 | ## Build and Install
6 |
7 | [](https://travis-ci.org/opensanca/service-validator)
8 |
9 | ```bash
10 | $ ./mvnw clean install
11 | ```
12 | ## How to use
13 |
14 | ```xml
15 |
16 | io.github.opensanca
17 | service-validator
18 | 1.1.0
19 |
20 | ```
21 |
22 | ```groovy
23 | compile 'io.github.opensanca:service-validator:1.1.0'
24 | ```
25 | ### Spring Boot projects
26 |
27 | Service Validation provides a `ServiceValidationAutoConfiguration.class` that allowed Auto Configuration mechanism.
28 |
29 | >Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added.
30 | >https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html
31 |
32 | ### Non Spring Boot projects
33 |
34 | Service Validation provides a `ServiceValidatorImport.class` that allowed easy way configure it.
35 |
36 | ```java
37 | @ComponentScan(basePackages={"seu.pacote","io.github.opensanca"})
38 | ```
39 | OR
40 | ```java
41 | @Configuration
42 | @ComponentScan
43 | @Import(ServiceValidatorImport.class)
44 | public class AppConfig {
45 | //...
46 | }
47 | ```
48 |
49 | ### Extra configurations
50 |
51 | Because we use Bean Validation 1.1 [JSR 349](http://beanvalidation.org/1.1/), you have to ensure there is a
52 | provider for this specification available in your classpath, such as `Hibernate Validator` or `Apache BVal`. Note that if you are
53 | using a JEE-compliant application server like `WildFly` or `TomEE` you already have one.
54 |
55 | The absence of providers cause this error during Spring context startup:
56 |
57 | ```bazaar
58 | javax.validation.ValidationException:
59 | Unable to create a Configuration, because no Bean Validation provider could be found.
60 | Add a provider like Hibernate Validator (RI) to your classpath.
61 | ```
62 |
63 | OR
64 |
65 | ```bazaar
66 | ***************************
67 | APPLICATION FAILED TO START
68 | ***************************
69 |
70 | Description:
71 |
72 | The Bean Validation API is on the classpath but no implementation could be found
73 |
74 | Action:
75 |
76 | Add an implementation, such as Hibernate Validator, to the classpath
77 | ```
78 |
79 | Additionally, some Bean Validation providers may have dependencies of their own, like the Expression Language API,
80 | causing similar bootstrap errors like the following:
81 |
82 | ```bazaar
83 | Caused by: javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory'.
84 | Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead
85 | ```
86 |
87 | We recommended to use `Glassfish Web EL Implementation` in this case. Note that EL is also part of the JEE stack,
88 | so you can safely ignore this if you're running a full-fledged application server.
89 |
90 | ## Samples
91 |
92 | ```java
93 | public class DTO {
94 |
95 | @NotNull
96 | private String text;
97 |
98 | @Max(10)
99 | private Integer number;
100 |
101 | public void setNumber(Integer number) {
102 | this.number = number;
103 | }
104 |
105 | public void setText(String text) {
106 | this.text = text;
107 | }
108 | }
109 | ```
110 | Validate Javax Validations Constraints and NullSafe.
111 | ```java
112 | @Component
113 | public class MyComponent {
114 |
115 | @ServiceValidation
116 | public void doSomething(final DTO dto) {
117 |
118 | }
119 | }
120 | ```
121 | Validate Javax Validations Constraints only.
122 | ```java
123 | @Component
124 | public class MyComponent {
125 |
126 | @ServiceValidation(nullSafe = false)
127 | public void doSomething(final DTO dto) {
128 |
129 | }
130 | }
131 | ```
132 | Validate NullSafe arguments only.
133 | ```java
134 | @Component
135 | public class MyComponent {
136 |
137 | @ServiceValidation(javaxValidation = false)
138 | public void doSomething(final DTO dto) {
139 |
140 | }
141 | }
142 | ```
143 |
144 | #### Don't do this! ¬¬
145 |
146 | ```java
147 | @Component
148 | public class MyComponent {
149 |
150 | @ServiceValidation(nullSafe = false, javaxValidation = false) //Don't do this!
151 | public void youDontNeedThis(DTO dto) {
152 |
153 | }
154 | }
155 | ```
156 |
157 | ## Spring MVC
158 |
159 | There is an `@ExceptionHandler` bundled in this library that automatically
160 | translates `ServiceValidationException`'s to JSON. So you don't need to bother
161 | writing your own should you decide to leverage this exception as an interface
162 | with your API clients.
163 |
164 | ## Testing Violations
165 |
166 | ServiceValidator provides custom `org.hamcrest.Matchers` that allowed testing violations of
167 | `ServiceValidationErrorCollection.class`.
168 |
169 | + errorCollectionHasSize
170 | + errorCollectionHasViolation
171 |
172 | ```java
173 | import static io.github.opensanca.matchers.ServiceValidatorErrorMatcher.errorCollectionHasSize;
174 | import static io.github.opensanca.matchers.ServiceValidatorViolationsMatcher.errorCollectionHasViolation;
175 |
176 | @RunWith(SpringRunner.class)
177 | public class CoolTest {
178 |
179 | @Rule
180 | public ExpectedException exception = ExpectedException.none();
181 |
182 | @Test
183 | public void someCoolTest() {
184 | exception.expect(ServiceValidationException.class);
185 | exception.expect(errorCollectionHasSize(1));
186 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be null"));
187 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be empty"));
188 | //
189 | }
190 | }
191 | ```
192 |
--------------------------------------------------------------------------------
/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
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 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .gradle/
3 | *.iml
4 | build/
5 | .out/
6 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/README.md:
--------------------------------------------------------------------------------
1 | # Spring 5
2 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.example'
2 | version '1.0-SNAPSHOT'
3 |
4 | apply plugin: 'java'
5 | apply plugin: 'application'
6 | apply plugin: 'com.github.johnrengelman.shadow'
7 |
8 | sourceCompatibility = 1.8
9 | targetCompatibility = 1.8
10 | mainClassName = 'Main'
11 |
12 | repositories {
13 | mavenCentral()
14 | mavenLocal()
15 | }
16 |
17 | dependencies {
18 | compile group: 'org.springframework', name: 'spring-webmvc', version: '5.0.1.RELEASE'
19 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.2'
20 |
21 | compile group: 'io.github.opensanca', name: 'service-validator', version: '1.1.0-SNAPSHOT'
22 |
23 | compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.4.2.Final'
24 | compile group: 'org.glassfish.web', name: 'el-impl', version: '2.2'
25 |
26 |
27 | testCompile group: 'junit', name: 'junit', version: '4.12'
28 | testCompile group: 'org.springframework', name: 'spring-test', version: '5.0.1.RELEASE'
29 | }
30 |
31 | buildscript {
32 | repositories {
33 | jcenter()
34 | }
35 | dependencies {
36 | classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
37 | }
38 | }
39 |
40 | shadowJar {
41 | mergeServiceFiles()
42 | }
43 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/opensanca/service-validator/1fb98ad650a9972e6f0c15dcbdcf485c3d25a27b/demos/spring-5-hibernate-validator-demo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Mar 25 16:25:16 BRT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
7 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/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 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/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 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'spring-5-demo'
2 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/src/main/java/com/example/demo/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import io.github.opensanca.ServiceValidatorImport;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.annotation.ComponentScan;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.context.annotation.Import;
8 |
9 | @Configuration
10 | @ComponentScan
11 | @Import(ServiceValidatorImport.class)
12 | public class AppConfig {
13 |
14 | public static void main (String[] args) throws Exception {
15 | new AnnotationConfigApplicationContext(AppConfig.class);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/src/main/java/com/example/demo/dto/DTO.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.dto;
2 |
3 | import javax.validation.constraints.Max;
4 | import javax.validation.constraints.NotNull;
5 |
6 | public class DTO {
7 |
8 | @NotNull
9 | private String text;
10 |
11 | @Max(10)
12 | private Integer number;
13 |
14 | public void setNumber(Integer number) {
15 | this.number = number;
16 | }
17 |
18 | public void setText(String text) {
19 | this.text = text;
20 | }
21 |
22 | public String getText () {
23 | return text;
24 | }
25 |
26 | public Integer getNumber () {
27 | return number;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/src/main/java/com/example/demo/service/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 |
5 | /**
6 | * @author s2it_agomes
7 | * @version $Revision: $
8 | * $Id: $
9 | * @since 25/03/18 16:23
10 | */
11 | public interface MyService {
12 |
13 | DTO getDto(DTO dto);
14 | }
15 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/src/main/java/com/example/demo/service/MyServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 | import io.github.opensanca.annotation.ServiceValidation;
5 | import org.springframework.stereotype.Service;
6 |
7 | /**
8 | * @author s2it_agomes
9 | * @version $Revision: $
10 | * $Id: $
11 | * @since 25/03/18 16:22
12 | */
13 | @Service
14 | public class MyServiceImpl implements MyService {
15 |
16 | @Override
17 | @ServiceValidation
18 | public DTO getDto (final DTO dto){
19 | return dto;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/demos/spring-5-hibernate-validator-demo/src/test/java/com/example/demo/service/MyServiceImplTest.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.AppConfig;
4 | import com.example.demo.dto.DTO;
5 | import io.github.opensanca.exception.ServiceValidationException;
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.test.context.ContextConfiguration;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | /**
14 | * @author s2it_agomes
15 | * @since 25/03/18 16:49
16 | * @version $Revision: $
17 | * $Id: $
18 | *
19 | */
20 | @RunWith(SpringRunner.class)
21 | @ContextConfiguration(classes= AppConfig.class)
22 | public class MyServiceImplTest {
23 |
24 | @Autowired
25 | private MyService myService;
26 |
27 | @Test(expected = ServiceValidationException.class)
28 | public void shouldValidateWhenAttributeIsNull(){
29 |
30 | myService.getDto(null);
31 | }
32 |
33 | @Test(expected = ServiceValidationException.class)
34 | public void shouldValidateWhenModelIsInvalid(){
35 |
36 | myService.getDto(new DTO());
37 | }
38 |
39 | @Test
40 | public void everythingFine(){
41 |
42 | final DTO dto = new DTO();
43 | dto.setNumber(1);
44 | dto.setText("test");
45 |
46 | final DTO result = myService.getDto(dto);
47 | Assert.assertEquals(result.getNumber(), dto.getNumber());
48 | Assert.assertEquals(result.getText(), dto.getText());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/opensanca/service-validator/1fb98ad650a9972e6f0c15dcbdcf485c3d25a27b/demos/spring-boot-auto-configuration-demo/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example
7 | spring-boot-auto-configuration-demo
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | spring-boot-auto-configuration-demo
12 | Demo Spring Boot Auto Configuration for Service Validator
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.10.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter
31 |
32 |
33 |
34 | io.github.opensanca
35 | service-validator
36 | 1.1.0-SNAPSHOT
37 |
38 |
39 | org.hibernate
40 | hibernate-validator
41 | 5.4.2.Final
42 |
43 |
44 | org.glassfish.web
45 | el-impl
46 | 2.2
47 |
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-test
52 | test
53 |
54 |
55 |
56 |
57 |
58 |
59 | org.springframework.boot
60 | spring-boot-maven-plugin
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/java/com/example/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class DemoApplication {
8 |
9 | public static void main (String[] args) {
10 | SpringApplication.run(DemoApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/java/com/example/demo/component/MyComponent.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.component;
2 |
3 | import com.example.demo.dto.DTO;
4 | import io.github.opensanca.annotation.ServiceValidation;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class MyComponent {
9 |
10 | @ServiceValidation
11 | public void doSomething (DTO dto) {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/java/com/example/demo/dto/DTO.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.dto;
2 |
3 | import javax.validation.constraints.Max;
4 | import javax.validation.constraints.NotNull;
5 |
6 | public class DTO {
7 |
8 | @NotNull
9 | String text;
10 |
11 | @Max(10)
12 | Integer number;
13 |
14 | public void setNumber (Integer number) {
15 | this.number = number;
16 | }
17 |
18 | public void setText (String text) {
19 | this.text = text;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/java/com/example/demo/service/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 |
5 | public interface MyService {
6 |
7 | void doSomething (DTO dto);
8 | }
9 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/java/com/example/demo/service/MyServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 | import io.github.opensanca.annotation.ServiceValidation;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class MyServiceImpl implements MyService {
9 |
10 | @Override
11 | @ServiceValidation
12 | public void doSomething (DTO dto) {
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.level.org.springframework:DEBUG
--------------------------------------------------------------------------------
/demos/spring-boot-auto-configuration-demo/src/test/java/com/example/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import com.example.demo.component.MyComponent;
4 | import com.example.demo.dto.DTO;
5 | import com.example.demo.service.MyService;
6 | import io.github.opensanca.exception.ServiceValidationException;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | @SpringBootTest
14 | @RunWith(SpringRunner.class)
15 | public class DemoApplicationTests {
16 |
17 | @Autowired
18 | private MyComponent component;
19 |
20 | @Autowired
21 | private MyService service;
22 |
23 | @Test(expected = ServiceValidationException.class)
24 | public void shouldValidateWithAInterfaceProxy () {
25 |
26 | service.doSomething(new DTO());
27 | }
28 |
29 | @Test(expected = ServiceValidationException.class)
30 | public void shouldValidateWithAComponent () {
31 |
32 | component.doSomething(new DTO());
33 | }
34 |
35 | @Test
36 | public void shouldValidateAComponentWithCorrectDto () {
37 |
38 | DTO dto = new DTO();
39 | dto.setNumber(2);
40 | dto.setText("TEST");
41 | component.doSomething(dto);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/opensanca/service-validator/1fb98ad650a9972e6f0c15dcbdcf485c3d25a27b/demos/spring-boot-web-auto-configuration-demo/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
2 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.example
7 | spring-boot-web-auto-configuration-demo
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | spring-boot-web-auto-configuration-demo
12 | Demo Spring Boot Auto Configuration for Service Validator
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.10.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 |
35 | io.github.opensanca
36 | service-validator
37 | 1.1.0-SNAPSHOT
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-test
43 | test
44 |
45 |
46 |
47 |
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-maven-plugin
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/java/com/example/demo/DemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class DemoApplication {
8 |
9 | public static void main (String[] args) {
10 | SpringApplication.run(DemoApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/java/com/example/demo/component/MyComponent.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.component;
2 |
3 | import com.example.demo.dto.DTO;
4 | import io.github.opensanca.annotation.ServiceValidation;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class MyComponent {
9 |
10 | @ServiceValidation
11 | public void doSomething (DTO dto) {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/java/com/example/demo/dto/DTO.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.dto;
2 |
3 | import javax.validation.constraints.Max;
4 | import javax.validation.constraints.NotNull;
5 |
6 | public class DTO {
7 |
8 | @NotNull
9 | String text;
10 |
11 | @Max(10)
12 | Integer number;
13 |
14 | public void setNumber (Integer number) {
15 | this.number = number;
16 | }
17 |
18 | public void setText (String text) {
19 | this.text = text;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/java/com/example/demo/service/MyService.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 |
5 | public interface MyService {
6 |
7 | void doSomething (DTO dto);
8 | }
9 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/java/com/example/demo/service/MyServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.demo.service;
2 |
3 | import com.example.demo.dto.DTO;
4 | import io.github.opensanca.annotation.ServiceValidation;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class MyServiceImpl implements MyService {
9 |
10 | @Override
11 | @ServiceValidation
12 | public void doSomething (DTO dto) {
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.level.org.springframework:DEBUG
--------------------------------------------------------------------------------
/demos/spring-boot-web-auto-configuration-demo/src/test/java/com/example/demo/DemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import com.example.demo.component.MyComponent;
4 | import com.example.demo.dto.DTO;
5 | import com.example.demo.service.MyService;
6 | import io.github.opensanca.exception.ServiceValidationException;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | @SpringBootTest
14 | @RunWith(SpringRunner.class)
15 | public class DemoApplicationTests {
16 |
17 | @Autowired
18 | private MyComponent component;
19 |
20 | @Autowired
21 | private MyService service;
22 |
23 | @Test(expected = ServiceValidationException.class)
24 | public void shouldValidateWithAInterfaceProxy () {
25 |
26 | service.doSomething(new DTO());
27 | }
28 |
29 | @Test(expected = ServiceValidationException.class)
30 | public void shouldValidateWithAComponent () {
31 |
32 | component.doSomething(new DTO());
33 | }
34 |
35 | @Test
36 | public void shouldValidateAComponentWithCorrectDto () {
37 |
38 | DTO dto = new DTO();
39 | dto.setNumber(2);
40 | dto.setText("TEST");
41 | component.doSomething(dto);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Mingw, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | ##########################################################################################
204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
205 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
206 | ##########################################################################################
207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
208 | if [ "$MVNW_VERBOSE" = true ]; then
209 | echo "Found .mvn/wrapper/maven-wrapper.jar"
210 | fi
211 | else
212 | if [ "$MVNW_VERBOSE" = true ]; then
213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
214 | fi
215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
216 | while IFS="=" read key value; do
217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
218 | esac
219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
220 | if [ "$MVNW_VERBOSE" = true ]; then
221 | echo "Downloading from: $jarUrl"
222 | fi
223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
224 |
225 | if command -v wget > /dev/null; then
226 | if [ "$MVNW_VERBOSE" = true ]; then
227 | echo "Found wget ... using wget"
228 | fi
229 | wget "$jarUrl" -O "$wrapperJarPath"
230 | elif command -v curl > /dev/null; then
231 | if [ "$MVNW_VERBOSE" = true ]; then
232 | echo "Found curl ... using curl"
233 | fi
234 | curl -o "$wrapperJarPath" "$jarUrl"
235 | else
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Falling back to using Java to download"
238 | fi
239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
240 | if [ -e "$javaClass" ]; then
241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
242 | if [ "$MVNW_VERBOSE" = true ]; then
243 | echo " - Compiling MavenWrapperDownloader.java ..."
244 | fi
245 | # Compiling the Java class
246 | ("$JAVA_HOME/bin/javac" "$javaClass")
247 | fi
248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
249 | # Running the downloader
250 | if [ "$MVNW_VERBOSE" = true ]; then
251 | echo " - Running MavenWrapperDownloader.java ..."
252 | fi
253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
254 | fi
255 | fi
256 | fi
257 | fi
258 | ##########################################################################################
259 | # End of extension
260 | ##########################################################################################
261 |
262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
263 | if [ "$MVNW_VERBOSE" = true ]; then
264 | echo $MAVEN_PROJECTBASEDIR
265 | fi
266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
267 |
268 | # For Cygwin, switch paths to Windows format before running java
269 | if $cygwin; then
270 | [ -n "$M2_HOME" ] &&
271 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
272 | [ -n "$JAVA_HOME" ] &&
273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
274 | [ -n "$CLASSPATH" ] &&
275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
276 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
278 | fi
279 |
280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
281 |
282 | exec "$JAVACMD" \
283 | $MAVEN_OPTS \
284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
287 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
126 | )
127 |
128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
130 | if exist %WRAPPER_JAR% (
131 | echo Found %WRAPPER_JAR%
132 | ) else (
133 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
134 | echo Downloading from: %DOWNLOAD_URL%
135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
136 | echo Finished downloading %WRAPPER_JAR%
137 | )
138 | @REM End of extension
139 |
140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
141 | if ERRORLEVEL 1 goto error
142 | goto end
143 |
144 | :error
145 | set ERROR_CODE=1
146 |
147 | :end
148 | @endlocal & set ERROR_CODE=%ERROR_CODE%
149 |
150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
154 | :skipRcPost
155 |
156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
158 |
159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
160 |
161 | exit /B %ERROR_CODE%
162 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | io.github.opensanca
5 | service-validator
6 | 1.1.1-SNAPSHOT
7 | jar
8 | Service Validator
9 |
10 | NullSafe and DTO validation for Javax Validation in service layer using Aspect
11 |
12 | https://github.com/opensanca/service-validator
13 |
14 |
15 | andrelugomes
16 | André Luis Gomes
17 | andrelugomes@gmail.com
18 |
19 |
20 |
21 | git@github.com:opensanca/service-validator.git
22 | scm:git:git@github.com:opensanca/service-validator.git
23 | scm:git:git@github.com:opensanca/service-validator.git
24 | HEAD
25 |
26 |
27 |
28 | The Apache License, Version 2.0
29 | http://www.apache.org/licenses/LICENSE-2.0.txt
30 |
31 |
32 |
33 |
34 | sonatype-nexus-snapshots
35 | Sonatype Nexus snapshot repository
36 | https://oss.sonatype.org/content/repositories/snapshots
37 |
38 |
39 | sonatype-nexus-staging
40 | Sonatype Nexus release repository
41 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
42 |
43 |
44 |
45 | 1.8
46 | 3.5.1
47 | 2.2.1
48 | 2.9.1
49 | 2.5
50 | 2.5.2
51 | 3.0.0
52 | 1.5
53 | 1.6.7
54 | 3.9.0
55 |
56 | 4.3.15.RELEASE
57 | 1.5.10.RELEASE
58 | 1.3
59 | 1.8.8
60 | 1.1.0.Final
61 | 2.2
62 | 2.2
63 | 1.10.19
64 |
65 |
66 |
67 | org.aspectj
68 | aspectjweaver
69 | ${aspectjweaver.version}
70 |
71 |
72 | javax.validation
73 | validation-api
74 | ${validation-api.version}
75 |
76 |
77 | javax.el
78 | el-api
79 | ${el-api.version}
80 |
81 |
82 |
83 | org.springframework
84 | spring-context
85 | ${spring.version}
86 | compile
87 |
88 |
89 | org.springframework
90 | spring-web
91 | ${spring.version}
92 | compile
93 |
94 |
95 | org.hamcrest
96 | hamcrest-all
97 | ${hamcrest-all.version}
98 | compile
99 |
100 |
101 |
102 | org.springframework.boot
103 | spring-boot-starter-test
104 | ${spring-boot.version}
105 | test
106 |
107 |
108 | org.springframework.boot
109 | spring-boot-starter-web
110 | ${spring-boot.version}
111 | test
112 |
113 |
114 | org.glassfish.web
115 | el-impl
116 | ${el-impl.version}
117 | test
118 |
119 |
120 | org.mockito
121 | mockito-all
122 | ${mockito-all.version}
123 | test
124 |
125 |
126 |
127 |
128 |
129 |
130 | maven-compiler-plugin
131 | ${maven-compiler-plugin.version}
132 |
133 | UTF-8
134 | ${java.version}
135 | ${java.version}
136 |
137 |
138 |
139 | org.apache.maven.plugins
140 | maven-source-plugin
141 | ${maven-source-plugin.version}
142 |
143 |
144 | attach-sources
145 |
146 | jar-no-fork
147 |
148 |
149 |
150 |
151 |
152 | org.apache.maven.plugins
153 | maven-javadoc-plugin
154 | ${maven-javadoc-plugin.version}
155 |
156 |
157 | attach-javadocs
158 |
159 | jar
160 |
161 |
162 |
163 |
164 |
165 | maven-resources-plugin
166 | ${maven-resources-plugin.version}
167 |
168 | UTF-8
169 |
170 |
171 |
172 | org.apache.maven.plugins
173 | maven-release-plugin
174 | ${maven-release-plugin.version}
175 |
176 |
177 | org.sonatype.plugins
178 | nexus-staging-maven-plugin
179 | ${nexus-staging-maven-plugin.version}
180 | true
181 |
182 | ossrh
183 | https://oss.sonatype.org/
184 | true
185 |
186 |
187 |
188 | org.apache.maven.plugins
189 | maven-checkstyle-plugin
190 | ${maven-checkstyle-plugin.version}
191 |
192 |
193 | validate
194 | validate
195 |
196 | checkstyle.xml
197 | UTF-8
198 | true
199 | true
200 |
201 |
202 | check
203 |
204 |
205 |
206 |
207 |
208 | org.apache.maven.plugins
209 | maven-pmd-plugin
210 | ${maven-pmd-plugin.version}
211 |
212 | false
213 | true
214 | true
215 |
216 |
217 |
218 |
219 | check
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 | org.apache.maven.plugins
231 | maven-checkstyle-plugin
232 | ${maven-checkstyle-plugin.version}
233 |
234 | checkstyle.xml
235 | UTF-8
236 | true
237 | true
238 | false
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 | sign-artifacts
247 |
248 |
249 | performRelease
250 | true
251 |
252 |
253 |
254 |
255 |
256 | org.apache.maven.plugins
257 | maven-gpg-plugin
258 | ${maven-gpg-plugin.version}
259 |
260 |
261 | sign-artifacts
262 | verify
263 |
264 | sign
265 |
266 |
267 | ${gpg.homedir}
268 | ${gpg.passphrase}
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/ServiceValidatorAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @ComponentScan("io.github.opensanca")
8 | public class ServiceValidatorAutoConfiguration {
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/ServiceValidatorImport.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
5 | import org.springframework.context.annotation.Import;
6 |
7 | @Configuration
8 | @EnableAspectJAutoProxy
9 | @Import(ServiceValidatorAutoConfiguration.class)
10 | public class ServiceValidatorImport {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/annotation/ServiceValidation.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.METHOD)
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface ServiceValidation {
11 |
12 | boolean nullSafe() default true;
13 | boolean javaxValidation() default true;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/aop/ServiceValidationAspectImpl.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.aop;
2 |
3 | import io.github.opensanca.annotation.ServiceValidation;
4 | import io.github.opensanca.exception.ServiceValidationErrorCollection;
5 | import io.github.opensanca.exception.ServiceValidationException;
6 | import org.aspectj.lang.JoinPoint;
7 | import org.aspectj.lang.annotation.Aspect;
8 | import org.aspectj.lang.annotation.Before;
9 | import org.aspectj.lang.annotation.Pointcut;
10 | import org.aspectj.lang.reflect.MethodSignature;
11 | import org.springframework.stereotype.Component;
12 |
13 | import javax.validation.ConstraintViolation;
14 | import javax.validation.Validation;
15 | import javax.validation.Validator;
16 | import javax.validation.ValidatorFactory;
17 | import java.lang.reflect.Method;
18 | import java.lang.reflect.Parameter;
19 | import java.util.Set;
20 |
21 | @Aspect
22 | @Component
23 | public class ServiceValidationAspectImpl {
24 |
25 | public static final String NULLSAFE_VIOLATION_MESSAGE = "Method arguments cannot be null!";
26 |
27 | public ServiceValidationAspectImpl() { }
28 |
29 | @Pointcut("@annotation(serviceValidation)")
30 | public void annotationPointCutDefinition(final ServiceValidation serviceValidation) { }
31 |
32 | @Before("annotationPointCutDefinition(serviceValidation)")
33 | public void valid(final JoinPoint joinPoint, final ServiceValidation serviceValidation) {
34 |
35 | ServiceValidationErrorCollection errors = new ServiceValidationErrorCollection();
36 | Object[] args = joinPoint.getArgs();
37 |
38 | if (serviceValidation.nullSafe()) {
39 | for (int argIndex = 0; argIndex < args.length; argIndex++) {
40 |
41 | if (args[argIndex] == null) {
42 | String parameterName = resolveParameterName(joinPoint, argIndex);
43 | errors.addError(parameterName, NULLSAFE_VIOLATION_MESSAGE);
44 | }
45 | }
46 | }
47 |
48 | if (serviceValidation.javaxValidation()) {
49 | for (int argIndex = 0; argIndex < args.length; argIndex++) {
50 |
51 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
52 | Validator validator = factory.getValidator();
53 | Object arg = args[argIndex];
54 |
55 | if (arg != null) {
56 | Set> violations = validator.validate(arg);
57 | if (!violations.isEmpty()) {
58 | String parameterName = resolveParameterName(joinPoint, argIndex);
59 | for (ConstraintViolation violation : violations) {
60 | String valuePath = String.format("%s.%s", parameterName, violation.getPropertyPath());
61 | errors.addError(valuePath, violation.getMessage());
62 | }
63 | }
64 | }
65 |
66 | }
67 | }
68 |
69 | if (!errors.isEmpty()) {
70 | throw new ServiceValidationException(errors);
71 | }
72 | }
73 |
74 | private String resolveParameterName(final JoinPoint joinPoint, final int argIndex) {
75 | if (!(joinPoint.getSignature() instanceof MethodSignature)) {
76 | return String.format("args[%s]", argIndex);
77 | }
78 | MethodSignature signature = (MethodSignature) joinPoint.getSignature();
79 | Method method = signature.getMethod();
80 | Parameter[] parameters = method.getParameters();
81 | return parameters[argIndex].getType().getSimpleName();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/exception/ServiceValidationErrorCollection.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.exception;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | public class ServiceValidationErrorCollection extends HashMap> {
8 |
9 | public void addError(final String valuePath, final String errorMessage) {
10 | if (!containsKey(valuePath)) {
11 | put(valuePath, new ArrayList<>());
12 | }
13 | get(valuePath).add(errorMessage);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/exception/ServiceValidationException.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.exception;
2 |
3 |
4 | /**
5 | * Thrown when one or more parameters of
6 | * an annotated method is invalid, i.e.
7 | * is null or do not pass JSR-303 validation.
8 | */
9 | public class ServiceValidationException extends RuntimeException {
10 |
11 | private ServiceValidationErrorCollection errors;
12 |
13 | public ServiceValidationException(final ServiceValidationErrorCollection errors) {
14 | this.errors = errors;
15 | }
16 |
17 | public ServiceValidationErrorCollection getErrors() {
18 | return errors;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/matchers/ServiceValidatorErrorMatcher.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.matchers;
2 |
3 | import io.github.opensanca.exception.ServiceValidationErrorCollection;
4 | import io.github.opensanca.exception.ServiceValidationException;
5 | import org.hamcrest.Description;
6 | import org.hamcrest.TypeSafeMatcher;
7 |
8 | public class ServiceValidatorErrorMatcher extends TypeSafeMatcher {
9 |
10 | private Integer expectedSize;
11 | private ServiceValidationErrorCollection errors;
12 |
13 | public ServiceValidatorErrorMatcher(final Integer expectedSize) {
14 | this.expectedSize = expectedSize;
15 | }
16 |
17 | public static ServiceValidatorErrorMatcher errorCollectionHasSize(final Integer expectedSize) {
18 | return new ServiceValidatorErrorMatcher(expectedSize);
19 | }
20 |
21 | @Override
22 | protected boolean matchesSafely(final ServiceValidationException e) {
23 | errors = e.getErrors();
24 | return errors.size() == expectedSize;
25 | }
26 |
27 | @Override
28 | public void describeTo(final Description description) {
29 | description.appendValue(expectedSize).appendText(" was not found instead of ").appendValue(errors.size());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/matchers/ServiceValidatorViolationsMatcher.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.matchers;
2 |
3 | import java.util.List;
4 |
5 | import io.github.opensanca.exception.ServiceValidationException;
6 | import org.hamcrest.Description;
7 | import org.hamcrest.TypeSafeMatcher;
8 | import org.springframework.util.CollectionUtils;
9 |
10 | public class ServiceValidatorViolationsMatcher extends TypeSafeMatcher {
11 |
12 | private String key;
13 | private String value;
14 | private List constraints;
15 | private boolean hasErrorKey;
16 | private boolean hasErrorValue;
17 |
18 | public ServiceValidatorViolationsMatcher(final String key, final String value) {
19 | this.key = key;
20 | this.value = value;
21 | this.hasErrorKey = false;
22 | this.hasErrorValue = false;
23 | }
24 |
25 | public static ServiceValidatorViolationsMatcher errorCollectionHasViolation(final String key, final String value) {
26 | return new ServiceValidatorViolationsMatcher(key, value);
27 | }
28 |
29 | @Override
30 | protected boolean matchesSafely(final ServiceValidationException e) {
31 | constraints = e.getErrors().get(key);
32 | if (CollectionUtils.isEmpty(constraints)) {
33 | hasErrorKey = true;
34 | return false;
35 | } else {
36 | final boolean isValidationOk = constraints.contains(value);
37 | hasErrorValue = !isValidationOk;
38 | return isValidationOk;
39 | }
40 | }
41 |
42 | @Override
43 | public void describeTo(final Description description) {
44 | if (hasErrorKey) {
45 | description.appendValue(key.toString()).appendText(" key not found.");
46 | }
47 | if (hasErrorValue) {
48 | description.appendText("Found ").appendValue(constraints).appendText(" instead of ").appendValue(value);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/io/github/opensanca/mvc/ServiceValidatorExceptionHandlerController.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca.mvc;
2 |
3 | import io.github.opensanca.exception.ServiceValidationErrorCollection;
4 | import io.github.opensanca.exception.ServiceValidationException;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.web.bind.annotation.ControllerAdvice;
7 | import org.springframework.web.bind.annotation.ExceptionHandler;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 | import org.springframework.web.bind.annotation.ResponseStatus;
10 |
11 | @ControllerAdvice
12 | public class ServiceValidatorExceptionHandlerController {
13 |
14 | @ExceptionHandler(ServiceValidationException.class)
15 | @ResponseStatus(HttpStatus.BAD_REQUEST)
16 | public @ResponseBody ServiceValidationErrorCollection handleException(final ServiceValidationException ex) {
17 | return ex.getErrors();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.github.opensanca.ServiceValidatorAutoConfiguration
--------------------------------------------------------------------------------
/src/test/java/io/github/opensanca/DemoSpringBootWebApp.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca;
2 |
3 | import java.util.Locale;
4 |
5 | import javax.validation.constraints.NotNull;
6 |
7 | import io.github.opensanca.annotation.ServiceValidation;
8 | import org.hibernate.validator.constraints.NotEmpty;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.SpringApplication;
11 | import org.springframework.boot.autoconfigure.SpringBootApplication;
12 | import org.springframework.boot.context.event.ApplicationReadyEvent;
13 | import org.springframework.context.ApplicationListener;
14 | import org.springframework.stereotype.Component;
15 | import org.springframework.stereotype.Controller;
16 | import org.springframework.stereotype.Service;
17 | import org.springframework.web.bind.annotation.GetMapping;
18 |
19 | @SpringBootApplication
20 | public class DemoSpringBootWebApp implements ApplicationListener {
21 | public static void main(String[] args) {
22 | SpringApplication.run(DemoSpringBootWebApp.class, args);
23 | }
24 |
25 | @Override
26 | public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
27 | Locale.setDefault(Locale.ENGLISH);
28 | }
29 | }
30 |
31 | class DTO {
32 |
33 | @NotNull
34 | @NotEmpty
35 | private String text;
36 |
37 | public void setText(String text) {
38 | this.text = text;
39 | }
40 |
41 | public String getText() {
42 | return text;
43 | }
44 | }
45 |
46 | @Component
47 | class MyComponent {
48 |
49 | @ServiceValidation
50 | public DTO defaultValidation(final DTO dto) {
51 | return dto;
52 | }
53 |
54 | @ServiceValidation(nullSafe = false)
55 | public DTO nullSafeFalse(final DTO dto) {
56 | return dto;
57 | }
58 |
59 | @ServiceValidation(javaxValidation = false)
60 | public DTO javaxValidationFalse(final DTO dto) {
61 | return dto;
62 | }
63 |
64 | @ServiceValidation(nullSafe = false, javaxValidation = false)
65 | public DTO dontDoThat(final DTO dto) {
66 | return dto;
67 | }
68 | }
69 |
70 | interface MyService {
71 |
72 | DTO doSomething(DTO dto);
73 |
74 | void doSomethingElse(DTO dto1, DTO dto2, DTO dto3);
75 |
76 | String getStringByName(String name);
77 |
78 | Long getLong(Long number, String string);
79 | }
80 |
81 | @Service
82 | class MyServiceImpl implements MyService {
83 |
84 | @Autowired
85 | private MyComponent component;
86 |
87 | @Override
88 | @ServiceValidation
89 | public DTO doSomething(final DTO dto) {
90 | return dto;
91 | }
92 |
93 | @Override
94 | @ServiceValidation
95 | public void doSomethingElse(DTO dto1, DTO dto2, DTO dto3) {}
96 |
97 | @Override
98 | @ServiceValidation
99 | public String getStringByName(String name) {
100 | return name;
101 | }
102 |
103 | @Override
104 | @ServiceValidation
105 | public Long getLong(Long number, String string) {
106 | return number + Long.valueOf(string);
107 | }
108 | }
109 |
110 | @Controller
111 | class MyController {
112 |
113 | @Autowired
114 | private MyService service;
115 |
116 | @GetMapping("/test")
117 | public void test() {
118 | DTO dto1 = null;
119 | DTO dto2 = new DTO();
120 | DTO dto3 = new DTO();
121 | dto3.setText("TEST");
122 | this.service.doSomethingElse(dto1, dto2, dto3);
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/src/test/java/io/github/opensanca/ServiceValidationMockitoTest.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca;
2 |
3 | import io.github.opensanca.aop.ServiceValidationAspectImpl;
4 | import io.github.opensanca.exception.ServiceValidationException;
5 | import org.junit.Before;
6 | import org.junit.Rule;
7 | import org.junit.Test;
8 | import org.junit.rules.ExpectedException;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.InjectMocks;
11 | import org.mockito.Mock;
12 | import org.mockito.MockitoAnnotations;
13 | import org.mockito.runners.MockitoJUnitRunner;
14 | import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
15 |
16 | import static io.github.opensanca.aop.ServiceValidationAspectImpl.NULLSAFE_VIOLATION_MESSAGE;
17 | import static io.github.opensanca.matchers.ServiceValidatorErrorMatcher.errorCollectionHasSize;
18 | import static io.github.opensanca.matchers.ServiceValidatorViolationsMatcher.errorCollectionHasViolation;
19 |
20 | @RunWith(MockitoJUnitRunner.class)
21 | public class ServiceValidationMockitoTest {
22 |
23 | @Rule
24 | public ExpectedException exception = ExpectedException.none();
25 |
26 | @InjectMocks
27 | private MyComponent component;
28 |
29 | @InjectMocks
30 | private MyService service = new MyServiceImpl();
31 |
32 | @Mock
33 | private ServiceValidationAspectImpl serviceValidationAspect;
34 |
35 | @Before
36 | public void setup() {
37 | MockitoAnnotations.initMocks(this);
38 | ServiceValidationAspectImpl aspect = new ServiceValidationAspectImpl();
39 |
40 | AspectJProxyFactory componentFactory = new AspectJProxyFactory(component);
41 | componentFactory.addAspect(aspect);
42 | component = componentFactory.getProxy();
43 |
44 | AspectJProxyFactory serviceFactory = new AspectJProxyFactory(service);
45 | serviceFactory.addAspect(aspect);
46 | service = serviceFactory.getProxy();
47 | }
48 |
49 | @Test
50 | public void shouldValidateJavax() {
51 | exception.expect(ServiceValidationException.class);
52 | exception.expect(errorCollectionHasSize(1));
53 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be null"));
54 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be empty"));
55 |
56 | component.defaultValidation(new DTO());
57 | }
58 |
59 | @Test
60 | public void shouldValidateNullForJavaTypes() {
61 | exception.expect(ServiceValidationException.class);
62 | exception.expect(errorCollectionHasSize(1));
63 | exception.expect(errorCollectionHasViolation("String", NULLSAFE_VIOLATION_MESSAGE));
64 |
65 | service.getStringByName(null);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/io/github/opensanca/ServiceValidationTest.java:
--------------------------------------------------------------------------------
1 | package io.github.opensanca;
2 |
3 | import static io.github.opensanca.aop.ServiceValidationAspectImpl.NULLSAFE_VIOLATION_MESSAGE;
4 | import static io.github.opensanca.matchers.ServiceValidatorErrorMatcher.errorCollectionHasSize;
5 | import static io.github.opensanca.matchers.ServiceValidatorViolationsMatcher.errorCollectionHasViolation;
6 | import static org.assertj.core.api.Assertions.assertThat;
7 | import static org.hamcrest.Matchers.containsInAnyOrder;
8 | import static org.hamcrest.Matchers.hasSize;
9 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
10 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
11 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
12 |
13 | import io.github.opensanca.exception.ServiceValidationException;
14 | import org.junit.Before;
15 | import org.junit.Rule;
16 | import org.junit.Test;
17 | import org.junit.rules.ExpectedException;
18 | import org.junit.runner.RunWith;
19 | import org.springframework.beans.factory.annotation.Autowired;
20 | import org.springframework.boot.test.context.SpringBootTest;
21 | import org.springframework.test.context.junit4.SpringRunner;
22 | import org.springframework.test.web.servlet.MockMvc;
23 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
24 | import org.springframework.web.context.WebApplicationContext;
25 |
26 | @SpringBootTest
27 | @RunWith(SpringRunner.class)
28 | public class ServiceValidationTest {
29 |
30 | @Rule
31 | public ExpectedException exception = ExpectedException.none();
32 |
33 | @Autowired
34 | private MyComponent component;
35 |
36 | @Autowired
37 | private MyService service;
38 |
39 | @Autowired
40 | private WebApplicationContext ctx;
41 |
42 | private MockMvc mockMvc;
43 |
44 | @Before
45 | public void setup() {
46 | this.mockMvc = MockMvcBuilders.webAppContextSetup(this.ctx).build();
47 | }
48 |
49 | @Test
50 | public void shouldValidateJavax() {
51 | exception.expect(ServiceValidationException.class);
52 | exception.expect(errorCollectionHasSize(1));
53 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be null"));
54 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be empty"));
55 |
56 | component.defaultValidation(new DTO());
57 | }
58 |
59 | @Test
60 | public void shouldValidateNullSafe() {
61 | exception.expect(ServiceValidationException.class);
62 | exception.expect(errorCollectionHasSize(1));
63 | exception.expect(errorCollectionHasViolation("DTO", NULLSAFE_VIOLATION_MESSAGE));
64 |
65 | component.defaultValidation(null);
66 | }
67 |
68 | @Test
69 | public void shouldValidateJavaxAndNullByDefault() {
70 | DTO dto = new DTO();
71 | dto.setText("TEST");
72 | DTO result = component.defaultValidation(dto);
73 |
74 | assertThat(result.getText()).isEqualToIgnoringCase("TEST");
75 | }
76 |
77 | @Test
78 | public void shouldNotValidateNullJustJavax() {
79 | DTO dto = new DTO();
80 | dto.setText("TEST");
81 | DTO result = component.nullSafeFalse(dto);
82 |
83 | assertThat(result).isInstanceOf(DTO.class);
84 | assertThat(result.getText()).isNotNull();
85 | }
86 |
87 | @Test
88 | public void shouldNotValidateNullJustJavaxPassingNull() {
89 | DTO result = component.nullSafeFalse(null);
90 |
91 | assertThat(result).isNull();
92 | }
93 |
94 | @Test
95 | public void shouldNotValidateJavaxJustNull() {
96 | DTO dto = new DTO();
97 | DTO result = component.javaxValidationFalse(dto);
98 |
99 | assertThat(result.getText()).isNull();
100 | }
101 |
102 | @Test
103 | public void shouldValidateNullForJavaTypes() {
104 | exception.expect(ServiceValidationException.class);
105 | exception.expect(errorCollectionHasSize(1));
106 | exception.expect(errorCollectionHasViolation("String", NULLSAFE_VIOLATION_MESSAGE));
107 |
108 | service.getStringByName(null);
109 | }
110 |
111 | @Test
112 | public void shouldValidateNullForMultiplesJavaTypes() {
113 | exception.expect(ServiceValidationException.class);
114 | exception.expect(errorCollectionHasSize(1));
115 | exception.expect(errorCollectionHasViolation("Long", NULLSAFE_VIOLATION_MESSAGE));
116 |
117 | service.getLong(null, "2");
118 | }
119 |
120 | @Test
121 | public void shouldCombineNullAndJavaxErrors() {
122 | exception.expect(ServiceValidationException.class);
123 | exception.expect(errorCollectionHasSize(2));
124 | exception.expect(errorCollectionHasViolation("DTO", NULLSAFE_VIOLATION_MESSAGE));
125 | exception.expect(errorCollectionHasViolation("DTO.text", "may not be null"));
126 |
127 | DTO invalidDTO = new DTO();
128 | DTO validDTO = new DTO();
129 | validDTO.setText("TEST");
130 | service.doSomethingElse(null, invalidDTO, validDTO);
131 | }
132 |
133 | @Test
134 | public void shouldJsonifyServiceValidationException() throws Exception {
135 | this.mockMvc.perform(get("/test"))
136 | .andExpect(status().isBadRequest())
137 | .andExpect(jsonPath("DTO").isArray())
138 | .andExpect(jsonPath("DTO[0]").value(NULLSAFE_VIOLATION_MESSAGE))
139 | .andExpect(jsonPath("$['DTO.text']").isArray())
140 | .andExpect(jsonPath("$['DTO.text']", hasSize(2)))
141 | .andExpect(jsonPath("$['DTO.text']", containsInAnyOrder("may not be null","may not be empty")));
142 | }
143 |
144 | }
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------