├── .gitignore ├── LICENSE ├── README.md ├── eclipse └── eclipse-code-formatter.xml ├── pom.xml ├── spring-boot-actuator-support ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── alibaba │ └── boot │ └── actuate │ └── endpoint │ └── condition │ ├── CompatibleConditionalOnEnabledEndpoint.java │ └── CompatibleOnEnabledEndpointCondition.java └── spring-boot-web-support ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── alibaba │ │ └── boot │ │ └── web │ │ ├── autoconfigure │ │ ├── ContentNegotiationManagerConfiguration.java │ │ ├── ExclusiveViewResolverConfiguration.java │ │ └── SpeedupWebMvcAutoConfiguration.java │ │ ├── condition │ │ ├── ConditionalOnPropertyPrefix.java │ │ └── OnPropertyPrefixCondition.java │ │ ├── filter │ │ ├── NoopOrderedHiddenHttpMethodFilter.java │ │ └── NoopOrderedHttpPutFormContentFilter.java │ │ └── util │ │ ├── ViewResolverUtils.java │ │ └── WebSupportUtils.java └── resources │ └── META-INF │ └── spring.factories └── test ├── java ├── boot │ └── BootApplication.java └── com │ └── alibaba │ └── boot │ └── web │ ├── AbstractSpringBootTest.java │ ├── autoconfigure │ ├── ContentNegotiationManagerConfigurationDisabledTest.java │ ├── ContentNegotiationManagerConfigurationTest.java │ ├── ExclusiveViewResolverConfigurationDisabledTest.java │ ├── ExclusiveViewResolverConfigurationTest.java │ ├── SpeedupWebMvcAutoConfigurationDisabledTest.java │ └── SpeedupWebMvcAutoConfigurationTest.java │ ├── filter │ ├── NoopOrderedHiddenHttpMethodFilterTest.java │ └── NoopOrderedHttpPutFormContentFilterTest.java │ └── util │ ├── ViewResolverUtilsTest.java │ └── WebSupportUtilsTest.java └── resources ├── application-disabled.properties └── application-enabled.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.war 15 | *.ear 16 | *.zip 17 | *.tar.gz 18 | *.rar 19 | 20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 21 | hs_err_pid* 22 | 23 | # eclipse ignore 24 | .settings/ 25 | .project 26 | .classpath 27 | .factorypath 28 | 29 | # idea ignore 30 | .idea/ 31 | *.ipr 32 | *.iml 33 | *.iws 34 | target 35 | 36 | # temp ignore 37 | *.log 38 | *.cache 39 | *.diff 40 | *.patch 41 | *.tmp 42 | 43 | # system ignore 44 | .DS_Store 45 | Thumbs.db 46 | 47 | # Maven ignore 48 | .flattened-pom.xml 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 [yyyy] [name of copyright owner] 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. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-support 2 | The support project for Spring Boot 3 | -------------------------------------------------------------------------------- /eclipse/eclipse-code-formatter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 9 | 12 | 15 | 18 | 20 | 23 | 25 | 28 | 31 | 32 | 35 | 38 | 41 | 44 | 46 | 47 | 49 | 52 | 55 | 58 | 61 | 63 | 65 | 66 | 68 | 70 | 71 | 73 | 76 | 79 | 82 | 84 | 86 | 87 | 90 | 93 | 96 | 99 | 101 | 104 | 107 | 109 | 111 | 113 | 116 | 119 | 122 | 125 | 128 | 131 | 134 | 137 | 140 | 141 | 144 | 146 | 148 | 151 | 154 | 157 | 160 | 163 | 164 | 166 | 167 | 170 | 173 | 176 | 179 | 182 | 185 | 188 | 191 | 193 | 196 | 199 | 201 | 204 | 207 | 209 | 211 | 214 | 217 | 220 | 223 | 226 | 229 | 232 | 234 | 237 | 239 | 242 | 244 | 245 | 248 | 251 | 254 | 256 | 259 | 262 | 265 | 268 | 270 | 273 | 276 | 279 | 282 | 285 | 288 | 290 | 292 | 295 | 298 | 300 | 302 | 304 | 307 | 309 | 312 | 315 | 318 | 321 | 324 | 326 | 329 | 331 | 332 | 334 | 337 | 340 | 343 | 346 | 349 | 351 | 354 | 357 | 359 | 362 | 365 | 368 | 370 | 372 | 375 | 376 | 379 | 382 | 385 | 387 | 390 | 392 | 393 | 396 | 399 | 402 | 405 | 408 | 411 | 413 | 415 | 418 | 421 | 424 | 425 | 428 | 431 | 432 | 435 | 438 | 441 | 444 | 446 | 449 | 452 | 455 | 456 | 458 | 461 | 464 | 465 | 468 | 471 | 474 | 477 | 478 | 480 | 483 | 486 | 488 | 491 | 494 | 495 | 498 | 501 | 502 | 503 | 506 | 508 | 511 | 513 | 516 | 519 | 522 | 525 | 528 | 531 | 533 | 535 | 538 | 541 | 544 | 547 | 550 | 553 | 556 | 559 | 561 | 563 | 566 | 569 | 572 | 575 | 578 | 581 | 583 | 586 | 589 | 591 | 593 | 596 | 599 | 602 | 604 | 606 | 609 | 611 | 614 | 617 | 620 | 623 | 625 | 628 | 631 | 633 | 635 | 638 | 640 | 642 | 644 | 647 | 650 | 653 | 654 | 657 | 660 | 663 | 666 | 668 | 671 | 674 | 677 | 680 | 682 | 685 | 687 | 689 | 691 | 694 | 697 | 700 | 703 | 706 | 709 | 712 | 715 | 718 | 721 | 723 | 726 | 729 | 730 | 733 | 736 | 738 | 741 | 742 | 745 | 747 | 748 | 751 | 754 | 755 | 756 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | spring-boot-web-support 8 | spring-boot-actuator-support 9 | 10 | 11 | 12 | org.sonatype.oss 13 | oss-parent 14 | 7 15 | 16 | 17 | com.alibaba.boot 18 | spring-boot-support 19 | ${revision} 20 | Alibaba :: Spring Boot Support :: POM 21 | pom 22 | 23 | 24 | UTF-8 25 | UTF-8 26 | 1.8 27 | 1.8 28 | 3.0.1 29 | 2.19.1 30 | 3.1.0 31 | 1.2.5 32 | 1.0.0-SNAPSHOT 33 | 34 | 3.1.0 35 | 36 | 2.3.4.RELEASE 37 | 38 | 3.0.2 39 | 3.6.0 40 | 3.0.1 41 | 1.5 42 | 2.5.3 43 | 44 | 45 | 46 | git@github.com:alibaba/spring-boot-support.git 47 | git@github.com:alibaba/spring-boot-support.git 48 | https://github.com/alibaba/spring-boot-support 49 | 50 | 51 | 52 | 53 | mercyblitz 54 | 小马哥 55 | https://github.com/mercyblitz 56 | mercyblitz@gmail.com 57 | 58 | 59 | 60 | 61 | 62 | Apache License, Version 2.0 63 | http://www.apache.org/licenses/LICENSE-2.0 64 | repo 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | javax.servlet 73 | javax.servlet-api 74 | ${servlet-api.version} 75 | provided 76 | true 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-dependencies 84 | ${spring.boot.version} 85 | pom 86 | import 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | src/main/resources/ 97 | false 98 | 99 | 100 | ../ 101 | META-INF/ 102 | false 103 | 104 | NOTICE 105 | LICENSE 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-jar-plugin 115 | ${maven-jar-plugin.version} 116 | 117 | 118 | true 119 | true 120 | 121 | true 122 | true 123 | 124 | 125 | ${project.version} 126 | ${project.version} 127 | 128 | 129 | 130 | 131 | 132 | 133 | org.apache.maven.plugins 134 | maven-compiler-plugin 135 | ${maven-compiler-plugin.version} 136 | 137 | true 138 | ${java.source.version} 139 | ${java.target.version} 140 | ${project.build.sourceEncoding} 141 | 142 | 143 | 144 | 145 | org.apache.maven.plugins 146 | maven-source-plugin 147 | ${maven-source-plugin.version} 148 | 149 | 150 | attach-sources 151 | 152 | jar 153 | 154 | 155 | 156 | 157 | 158 | 159 | org.apache.maven.plugins 160 | maven-enforcer-plugin 161 | 162 | 163 | enforce-rules 164 | 165 | enforce 166 | 167 | 168 | 169 | 170 | [1.8,) 171 | 172 | 173 | project.name 174 | 175 | 176 | project.description 177 | 178 | 179 | true 180 | 181 | 182 | 183 | 184 | 185 | 186 | org.codehaus.mojo 187 | flatten-maven-plugin 188 | ${flatten-maven-plugin.version} 189 | 190 | true 191 | resolveCiFriendliesOnly 192 | 193 | 194 | 195 | flatten 196 | process-resources 197 | 198 | flatten 199 | 200 | 201 | 202 | flatten.clean 203 | clean 204 | 205 | clean 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | sona 217 | https://oss.sonatype.org/content/repositories/snapshots/ 218 | 219 | 220 | sona 221 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 222 | 223 | 224 | 225 | 226 | 227 | release 228 | 229 | 230 | 231 | org.apache.maven.plugins 232 | maven-javadoc-plugin 233 | 234 | 235 | package 236 | 237 | jar 238 | 239 | 240 | 241 | 242 | 243 | org.apache.maven.plugins 244 | maven-gpg-plugin 245 | 246 | 247 | verify 248 | 249 | sign 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | spring-boot-2.0 261 | 262 | 2.0.9.RELEASE 263 | 264 | 265 | 266 | 267 | 268 | spring-boot-2.1 269 | 270 | 2.1.15.RELEASE 271 | 272 | 273 | 274 | 275 | 276 | spring-boot-2.2 277 | 278 | 2.2.8.RELEASE 279 | 280 | 281 | 282 | -------------------------------------------------------------------------------- /spring-boot-actuator-support/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alibaba.boot 7 | spring-boot-support 8 | ${revision} 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | com.alibaba.boot 14 | spring-boot-actuator-support 15 | ${revision} 16 | Alibaba :: Spring Boot Support :: Actuator 17 | jar 18 | 19 | 20 | 21 | 22 | javax.servlet 23 | javax.servlet-api 24 | provided 25 | true 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | true 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-actuator 37 | true 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-autoconfigure 43 | true 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /spring-boot-actuator-support/src/main/java/com/alibaba/boot/actuate/endpoint/condition/CompatibleConditionalOnEnabledEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.actuate.endpoint.condition; 18 | 19 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 20 | import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension; 21 | import org.springframework.context.annotation.Conditional; 22 | 23 | import java.lang.annotation.Documented; 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | /** 30 | * {@link Conditional} that checks whether or not an endpoint is enabled, which is compatible with 31 | * org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint ([2.0.x, 2.2.x]) 32 | * org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint 33 | * 34 | * @see CompatibleOnEnabledEndpointCondition 35 | * @since 1.0.0 36 | */ 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Target({ElementType.METHOD, ElementType.TYPE}) 39 | @Documented 40 | @Conditional(CompatibleOnEnabledEndpointCondition.class) 41 | public @interface CompatibleConditionalOnEnabledEndpoint { 42 | 43 | /** 44 | * The endpoint type that should be checked. Inferred when the return type of the 45 | * {@code @Bean} method is either an {@link Endpoint @Endpoint} or an 46 | * {@link EndpointExtension @EndpointExtension}. 47 | * 48 | * @return the endpoint type to check 49 | */ 50 | Class endpoint() default Void.class; 51 | } 52 | -------------------------------------------------------------------------------- /spring-boot-actuator-support/src/main/java/com/alibaba/boot/actuate/endpoint/condition/CompatibleOnEnabledEndpointCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.actuate.endpoint.condition; 18 | 19 | import org.springframework.beans.BeanUtils; 20 | import org.springframework.context.annotation.Condition; 21 | import org.springframework.context.annotation.ConditionContext; 22 | import org.springframework.context.annotation.Conditional; 23 | import org.springframework.core.type.AnnotatedTypeMetadata; 24 | import org.springframework.util.ClassUtils; 25 | 26 | import java.util.stream.Stream; 27 | 28 | /** 29 | * {@link Conditional} that checks whether or not an endpoint is enabled, which is compatible with 30 | * org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnEnabledEndpointCondition 31 | * and org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnAvailableEndpointCondition 32 | * 33 | * @see CompatibleConditionalOnEnabledEndpoint 34 | * @since 1.0.0 35 | */ 36 | class CompatibleOnEnabledEndpointCondition implements Condition { 37 | 38 | static String[] CONDITION_CLASS_NAMES = { 39 | "org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnAvailableEndpointCondition", // 2.2.0+ 40 | "org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnEnabledEndpointCondition" // [2.0.0 , 2.2.x] 41 | }; 42 | 43 | 44 | @Override 45 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { 46 | ClassLoader classLoader = context.getClassLoader(); 47 | 48 | Condition condition = Stream.of(CONDITION_CLASS_NAMES) // Iterate class names 49 | .filter(className -> ClassUtils.isPresent(className, classLoader)) // Search class existing or not by name 50 | .findFirst() // Find the first candidate 51 | .map(className -> ClassUtils.resolveClassName(className, classLoader)) // Resolve class name to Class 52 | .filter(Condition.class::isAssignableFrom) // Accept the Condition implementation 53 | .map(BeanUtils::instantiateClass) // Instantiate Class to be instance 54 | .map(Condition.class::cast) // Cast the instance to be Condition one 55 | .orElse(NegativeCondition.INSTANCE); // Or else get a negative condition 56 | 57 | return condition.matches(context, metadata); 58 | } 59 | 60 | private static class NegativeCondition implements Condition { 61 | 62 | static final NegativeCondition INSTANCE = new NegativeCondition(); 63 | 64 | @Override 65 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { 66 | return false; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring-boot-web-support/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-web-support 2 | An support project for Spring Boot Web 3 | 4 | 5 | 6 | ## Dependencies & Compatibility 7 | 8 | | Dependencies | Compatibility | 9 | | -------------- | ------------- | 10 | | Java | 1.7 + | 11 | | Servlet | 3.0 + | 12 | | Spring Boot | 1.4 + | 13 | | [Alibaba Spring WebMVC Support](https://github.com/alibaba/spring-webmvc-support) | 1.0.0 + | 14 | | [Alibaba Spring Context Support](https://github.com/alibaba/spring-context-support) | 1.0.0 + | 15 | 16 | 17 | ## Downstream Projects 18 | 19 | * [Alibaba Spring WebMVC Support](https://github.com/alibaba/spring-webmvc-support) 20 | * [Alibaba Spring Context Support](https://github.com/alibaba/spring-context-support) 21 | 22 | 23 | 24 | 25 | 26 | ## Release version 27 | 28 | ````xml 29 | 30 | 31 | ...... 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | ${spring-boot.version} 38 | 39 | 40 | 41 | 42 | com.alibaba.boot 43 | spring-boot-web-support 44 | 1.0.0.RELEASE 45 | 46 | 47 | ...... 48 | 49 | 50 | ```` 51 | 52 | 53 | 54 | If your project failed to resolve the dependency, try to add the following repository: 55 | ```xml 56 | 57 | 58 | sonatype-nexus 59 | https://oss.sonatype.org/content/repositories/releases 60 | 61 | true 62 | 63 | 64 | 65 | ``` 66 | 67 | 68 | 69 | 70 | ## Documents 71 | 72 | TODO -------------------------------------------------------------------------------- /spring-boot-web-support/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | com.alibaba.boot 7 | spring-boot-support 8 | ${revision} 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | com.alibaba.boot 14 | spring-boot-web-support 15 | ${revision} 16 | Alibaba :: Spring Boot Support :: Web 17 | jar 18 | 19 | 20 | 21 | 1.0.0.RELEASE 22 | 23 | 24 | 25 | 26 | 27 | 28 | javax.servlet 29 | javax.servlet-api 30 | provided 31 | true 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | true 39 | 40 | 41 | 42 | 43 | org.springframework 44 | spring-context 45 | true 46 | 47 | 48 | 49 | org.springframework 50 | spring-context-support 51 | true 52 | 53 | 54 | 55 | org.springframework 56 | spring-webmvc 57 | true 58 | 59 | 60 | 61 | com.alibaba.spring 62 | spring-webmvc-support 63 | ${spring-webmvc-support.version} 64 | 65 | 66 | 67 | 68 | junit 69 | junit 70 | test 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-starter-test 76 | test 77 | 78 | 79 | 80 | org.thymeleaf 81 | thymeleaf-spring5 82 | test 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/autoconfigure/ContentNegotiationManagerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.condition.ConditionalOnPropertyPrefix; 4 | import com.alibaba.spring.util.PropertySourcesUtils; 5 | import com.alibaba.spring.web.servlet.config.annotation.ConfigurableContentNegotiationManagerWebMvcConfigurer; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.core.env.ConfigurableEnvironment; 12 | import org.springframework.web.accept.ContentNegotiationManager; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 14 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import static com.alibaba.boot.web.util.WebSupportUtils.CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX; 20 | 21 | /** 22 | * {@link ContentNegotiationManager} {@link Configuration} 23 | * 24 | * @author Mercy 25 | * @see ContentNegotiationManager 26 | * @since 2017.03.29 27 | */ 28 | 29 | @ConditionalOnWebApplication 30 | @ConditionalOnBean(WebMvcConfigurationSupport.class) 31 | @ConditionalOnPropertyPrefix({CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX}) 32 | @AutoConfigureAfter(name = { 33 | "org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration", // compatible with Spring Boot 1.x 34 | "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration" // compatible with Spring Boot 2.0 35 | }) 36 | public class ContentNegotiationManagerConfiguration { 37 | 38 | @Bean 39 | public WebMvcConfigurer configurableContentNegotiationManagerWebMvcConfigurer(ConfigurableEnvironment environment) { 40 | 41 | Map properties = new HashMap(); 42 | 43 | Map subProperties = PropertySourcesUtils.getSubProperties(environment.getPropertySources(), 44 | CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX); 45 | 46 | for (Map.Entry entry : subProperties.entrySet()) { 47 | properties.put(entry.getKey(), entry.getValue().toString()); 48 | } 49 | 50 | return new ConfigurableContentNegotiationManagerWebMvcConfigurer(properties); 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/autoconfigure/ExclusiveViewResolverConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.spring.web.context.ExclusiveViewResolverApplicationListener; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.servlet.ViewResolver; 10 | 11 | import static com.alibaba.boot.web.util.WebSupportUtils.VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME; 12 | 13 | /** 14 | * Exclusive {@link ViewResolver} {@link Configuration} 15 | * 16 | * @author Mercy 17 | * @see ViewResolver 18 | * @see Configuration 19 | * @since 2017.03.23 20 | */ 21 | @ConditionalOnWebApplication 22 | @ConditionalOnProperty(VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME) 23 | public class ExclusiveViewResolverConfiguration { 24 | 25 | @Bean 26 | public ExclusiveViewResolverApplicationListener exclusiveViewResolverApplicationListener 27 | (@Value("${" + VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME + "}") String exclusiveViewResolverBeanName) { 28 | 29 | ExclusiveViewResolverApplicationListener applicationListener = 30 | new ExclusiveViewResolverApplicationListener(exclusiveViewResolverBeanName); 31 | 32 | return applicationListener; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/autoconfigure/SpeedupWebMvcAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.filter.NoopOrderedHiddenHttpMethodFilter; 4 | import com.alibaba.boot.web.filter.NoopOrderedHttpPutFormContentFilter; 5 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 6 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 7 | import org.springframework.boot.autoconfigure.AutoConfigureOrder; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 12 | import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; 13 | import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.core.Ordered; 16 | import org.springframework.web.filter.HiddenHttpMethodFilter; 17 | import org.springframework.web.filter.HttpPutFormContentFilter; 18 | import org.springframework.web.servlet.DispatcherServlet; 19 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 20 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 21 | 22 | import javax.servlet.Servlet; 23 | 24 | import static com.alibaba.boot.web.util.WebSupportUtils.NOOP_HIDDEN_HTTP_METHOD_FILTER_ENABLED_PROPERTY_NAME; 25 | import static com.alibaba.boot.web.util.WebSupportUtils.NOOP_HTTP_PUT_FORM_CONTENT_FILTER_ENABLED_PROPERTY_NAME; 26 | 27 | /** 28 | * Speed up {@link WebMvcAutoConfiguration} , auto configure before {@link WebMvcAutoConfiguration} and 29 | * after {@link DispatcherServletAutoConfiguration} , which speeds up execution time and improves performances. 30 | * 31 | * @author Mercy 32 | * @see WebMvcAutoConfiguration 33 | * @see DispatcherServletAutoConfiguration 34 | * @since 2017.04.11 35 | */ 36 | @ConditionalOnWebApplication 37 | @ConditionalOnClass({Servlet.class, DispatcherServlet.class, 38 | WebMvcConfigurerAdapter.class}) 39 | @ConditionalOnMissingBean(WebMvcConfigurationSupport.class) 40 | @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10) 41 | @AutoConfigureBefore(name = { 42 | "org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration", // compatible with Spring Boot 1.x 43 | "org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration" // compatible with Spring Boot 2.0 44 | }) 45 | @AutoConfigureAfter(name = { 46 | "org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration", // compatible with Spring Boot 1.x 47 | "org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration" // compatible with Spring Boot 2.0 48 | }) 49 | public class SpeedupWebMvcAutoConfiguration { 50 | 51 | @Bean 52 | @ConditionalOnProperty(value = NOOP_HIDDEN_HTTP_METHOD_FILTER_ENABLED_PROPERTY_NAME, havingValue = "true") 53 | @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) 54 | public NoopOrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() { 55 | return new NoopOrderedHiddenHttpMethodFilter(); 56 | } 57 | 58 | /** 59 | * spring.mvc.formcontent.putfilter property since 1.4.1.RELEASE 60 | */ 61 | @Bean 62 | @ConditionalOnProperty(value = {NOOP_HTTP_PUT_FORM_CONTENT_FILTER_ENABLED_PROPERTY_NAME}, havingValue = "true") 63 | @ConditionalOnMissingBean(HttpPutFormContentFilter.class) 64 | public NoopOrderedHttpPutFormContentFilter httpPutFormContentFilter() { 65 | return new NoopOrderedHttpPutFormContentFilter(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/condition/ConditionalOnPropertyPrefix.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.condition; 2 | 3 | import org.springframework.context.annotation.Conditional; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * {@link Conditional} that checks if the prefix of properties are found in environment.. 12 | * 13 | * @author Mercy 14 | * @see OnPropertyPrefixCondition 15 | * @since 2017.03.29 16 | */ 17 | @Retention(RetentionPolicy.RUNTIME) 18 | @Target({ElementType.TYPE, ElementType.METHOD}) 19 | @Conditional(OnPropertyPrefixCondition.class) 20 | public @interface ConditionalOnPropertyPrefix { 21 | 22 | /** 23 | * The prefix values of properties. 24 | *

25 | * The prefix automatically ends 26 | * with a dot if not specified. 27 | * 28 | * @return prefix values of properties. 29 | */ 30 | String[] value(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/condition/OnPropertyPrefixCondition.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.condition; 2 | 3 | import org.springframework.boot.autoconfigure.condition.ConditionOutcome; 4 | import org.springframework.boot.autoconfigure.condition.SpringBootCondition; 5 | import org.springframework.context.annotation.Condition; 6 | import org.springframework.context.annotation.ConditionContext; 7 | import org.springframework.core.annotation.AnnotationAttributes; 8 | import org.springframework.core.env.ConfigurableEnvironment; 9 | import org.springframework.core.env.EnumerablePropertySource; 10 | import org.springframework.core.env.MutablePropertySources; 11 | import org.springframework.core.env.PropertySource; 12 | import org.springframework.core.type.AnnotatedTypeMetadata; 13 | 14 | import java.util.Arrays; 15 | 16 | /** 17 | * {@link Condition} that checks if the prefix of properties are found in environment. 18 | * 19 | * @author Mercy 20 | * @see SpringBootCondition 21 | * @see ConditionalOnPropertyPrefix 22 | * @since 2017.03.29 23 | */ 24 | public class OnPropertyPrefixCondition extends SpringBootCondition { 25 | 26 | @Override 27 | public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { 28 | 29 | AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap( 30 | metadata.getAnnotationAttributes(ConditionalOnPropertyPrefix.class.getName())); 31 | 32 | String[] prefixValues = annotationAttributes.getStringArray("value"); 33 | 34 | ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment(); 35 | 36 | boolean matched = false; 37 | 38 | for (String prefix : prefixValues) { 39 | 40 | if (startsWith(environment, prefix)) { 41 | matched = true; 42 | break; 43 | } 44 | 45 | } 46 | 47 | return matched ? ConditionOutcome.match() : ConditionOutcome.noMatch("The prefix values " + 48 | Arrays.asList(prefixValues) + " were not found in Environment!"); 49 | 50 | } 51 | 52 | private boolean startsWith(ConfigurableEnvironment environment, String prefix) { 53 | 54 | final String actualPrefix = prefix.endsWith(".") ? prefix : prefix + "."; 55 | 56 | boolean started = false; 57 | 58 | MutablePropertySources mutablePropertySources = environment.getPropertySources(); 59 | 60 | for (PropertySource propertySource : mutablePropertySources) { 61 | 62 | if (propertySource instanceof EnumerablePropertySource) { 63 | 64 | EnumerablePropertySource source = EnumerablePropertySource.class.cast(propertySource); 65 | 66 | String[] propertyNames = source.getPropertyNames(); 67 | 68 | for (String propertyName : propertyNames) { 69 | 70 | if (propertyName.startsWith(actualPrefix)) { 71 | started = true; 72 | break; 73 | } 74 | 75 | } 76 | 77 | } 78 | 79 | } 80 | 81 | return started; 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/filter/NoopOrderedHiddenHttpMethodFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.filter; 2 | 3 | import org.springframework.core.Ordered; 4 | import org.springframework.web.filter.HiddenHttpMethodFilter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | /** 10 | * {@link Ordered} No-Operation {@link HiddenHttpMethodFilter} 11 | * 12 | * @author Mercy 13 | * @see HiddenHttpMethodFilter 14 | * @since 2017.03.21 15 | */ 16 | public final class NoopOrderedHiddenHttpMethodFilter extends HiddenHttpMethodFilter implements Ordered { 17 | 18 | private int order = -10000; 19 | 20 | protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { 21 | 22 | return true; 23 | 24 | } 25 | 26 | public void setOrder(int order) { 27 | this.order = order; 28 | } 29 | 30 | @Override 31 | public int getOrder() { 32 | return order; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/filter/NoopOrderedHttpPutFormContentFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.filter; 2 | 3 | import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; 4 | import org.springframework.core.Ordered; 5 | import org.springframework.web.filter.HttpPutFormContentFilter; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | /** 11 | * {@link Ordered} No-Operation {@link HttpPutFormContentFilter} 12 | * 13 | * @author Mercy 14 | * @see HttpPutFormContentFilter 15 | * @see WebMvcAutoConfiguration#httpPutFormContentFilter() 16 | * @since 2017.03.21 17 | */ 18 | public final class NoopOrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements Ordered { 19 | 20 | private int order = -9900; 21 | 22 | protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { 23 | 24 | return true; 25 | 26 | } 27 | 28 | public void setOrder(int order) { 29 | this.order = order; 30 | } 31 | 32 | @Override 33 | public int getOrder() { 34 | return order; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/util/ViewResolverUtils.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.util; 2 | 3 | import org.springframework.web.servlet.ViewResolver; 4 | 5 | /** 6 | * {@link ViewResolver} Utilities 7 | * 8 | * @author Mercy 9 | * @see ViewResolver 10 | * @since 2017.03.22 11 | */ 12 | public class ViewResolverUtils { 13 | 14 | /** 15 | * The bean name of InternalResourceViewResolver 16 | */ 17 | public static final String INTERNAL_RESOURCE_VIEW_RESOLVER_BEAN_NAME = "defaultViewResolver"; 18 | 19 | /** 20 | * The bean name of org.springframework.web.servlet.view.velocity.VelocityViewResolver 21 | */ 22 | public static final String VELOCITY_VIEW_RESOLVER_BEAN_NAME = "velocityViewResolver"; 23 | 24 | /** 25 | * The bean name of org.thymeleaf.spring5.view.ThymeleafViewResolver 26 | */ 27 | public static final String THYMELEAF_VIEW_RESOLVER_BEAN_NAME = "thymeleafViewResolver"; 28 | 29 | /** 30 | * The bean name of org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver 31 | */ 32 | public static final String FREEMARKER_VIEW_RESOLVER_BEAN_NAME = "freeMarkerViewResolver"; 33 | 34 | /** 35 | * The bean name of org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver 36 | */ 37 | public static final String GROOVY_MARKUP_VIEW_RESOLVER_BEAN_NAME = "groovyMarkupViewResolver"; 38 | 39 | /** 40 | * The bean name of org.springframework.boot.web.servlet.view.MustacheViewResolver 41 | */ 42 | public static final String MUSTACHE_VIEW_RESOLVER_BEAN_NAME = "mustacheViewResolver"; 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/java/com/alibaba/boot/web/util/WebSupportUtils.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.util; 2 | 3 | import com.alibaba.boot.web.filter.NoopOrderedHiddenHttpMethodFilter; 4 | import com.alibaba.boot.web.filter.NoopOrderedHttpPutFormContentFilter; 5 | import org.springframework.web.accept.ContentNegotiationManager; 6 | import org.springframework.web.servlet.ViewResolver; 7 | 8 | /** 9 | * Web Support Utilities 10 | * 11 | * @author Mercy 12 | * @since 2017.03.29 13 | */ 14 | public abstract class WebSupportUtils { 15 | 16 | /** 17 | * The prefix of property name 18 | */ 19 | public static final String PROPERTY_NAME_PREFIX = "web-support."; 20 | 21 | /** 22 | * The prefix of property name of {@link ContentNegotiationManager} 23 | */ 24 | public static final String CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX = PROPERTY_NAME_PREFIX + 25 | "content-negotiation-manager"; 26 | 27 | /** 28 | * The property name of exclusive bean name of {@link ViewResolver}s. 29 | */ 30 | public static final String VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME = PROPERTY_NAME_PREFIX 31 | + "exclusive-view-resolver"; 32 | 33 | /** 34 | * The property name of class name of {@link NoopOrderedHiddenHttpMethodFilter} 35 | */ 36 | public static final String NOOP_HIDDEN_HTTP_METHOD_FILTER_ENABLED_PROPERTY_NAME = 37 | PROPERTY_NAME_PREFIX + "noop.httpmethod.hiddenfilter.enabled"; 38 | 39 | /** 40 | * The property name of class name of {@link NoopOrderedHttpPutFormContentFilter} 41 | */ 42 | public static final String NOOP_HTTP_PUT_FORM_CONTENT_FILTER_ENABLED_PROPERTY_NAME = 43 | PROPERTY_NAME_PREFIX + "noop.formcontent.putfilter.enabled"; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Register EnableAutoConfiguration 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | com.alibaba.boot.web.autoconfigure.ExclusiveViewResolverConfiguration,\ 4 | com.alibaba.boot.web.autoconfigure.ContentNegotiationManagerConfiguration,\ 5 | com.alibaba.boot.web.autoconfigure.SpeedupWebMvcAutoConfiguration -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/boot/BootApplication.java: -------------------------------------------------------------------------------- 1 | package boot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * Spring Boot Application 9 | * 10 | * @author Mercy 11 | * @see SpringBootApplication 12 | * @since 2017.03.29 13 | */ 14 | @EnableAutoConfiguration 15 | public class BootApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(BootApplication.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/AbstractSpringBootTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web; 2 | 3 | import boot.BootApplication; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | /** 11 | * {@link AbstractSpringBootTest} 12 | * 13 | * @author Mercy 14 | * @version 1.0.0 15 | * @see AbstractSpringBootTest 16 | * @since 1.0.0 2016-07-18 17 | */ 18 | 19 | @RunWith(SpringRunner.class) 20 | @SpringBootTest(classes = BootApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 21 | public abstract class AbstractSpringBootTest { 22 | 23 | @Autowired 24 | protected ApplicationContext applicationContext; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/ContentNegotiationManagerConfigurationDisabledTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.spring.util.BeanUtils; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ActiveProfiles; 9 | import org.springframework.web.accept.ContentNegotiationManager; 10 | import org.springframework.web.accept.ContentNegotiationStrategy; 11 | import org.springframework.web.accept.HeaderContentNegotiationStrategy; 12 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * {@link ContentNegotiationManagerConfiguration} Test 18 | * 19 | * @author Mercy 20 | * @see ContentNegotiationManagerConfiguration 21 | * @since 2017.03.29 22 | */ 23 | @ActiveProfiles("disabled") 24 | public class ContentNegotiationManagerConfigurationDisabledTest extends AbstractSpringBootTest { 25 | 26 | @Autowired 27 | private ContentNegotiatingViewResolver contentNegotiatingViewResolver; 28 | 29 | @Test 30 | public void testContentNegotiationManagerConfigurationOnDisabled() { 31 | 32 | Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ContentNegotiationManagerConfiguration.class)); 33 | 34 | ContentNegotiationManager contentNegotiationManager = 35 | contentNegotiatingViewResolver.getContentNegotiationManager(); 36 | 37 | List strategies = contentNegotiationManager.getStrategies(); 38 | 39 | Assert.assertEquals(1, strategies.size()); 40 | Assert.assertTrue(contains(HeaderContentNegotiationStrategy.class, strategies)); 41 | 42 | } 43 | 44 | private boolean contains(Class strategyClass, 45 | List strategies) { 46 | 47 | boolean contained = false; 48 | 49 | for (ContentNegotiationStrategy strategy : strategies) { 50 | 51 | contained = strategyClass.isInstance(strategy); 52 | 53 | if (contained) { 54 | break; 55 | } 56 | 57 | } 58 | 59 | return contained; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/ContentNegotiationManagerConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.spring.util.FieldUtils; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.test.context.ActiveProfiles; 10 | import org.springframework.web.accept.ContentNegotiationManager; 11 | import org.springframework.web.accept.ContentNegotiationStrategy; 12 | import org.springframework.web.accept.FixedContentNegotiationStrategy; 13 | import org.springframework.web.accept.HeaderContentNegotiationStrategy; 14 | import org.springframework.web.accept.ParameterContentNegotiationStrategy; 15 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 16 | 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | /** 21 | * {@link ContentNegotiationManagerConfiguration} Test 22 | * 23 | * @author Mercy 24 | * @see ContentNegotiationManagerConfiguration 25 | * @since 2017.03.29 26 | */ 27 | @ActiveProfiles("enabled") 28 | public class ContentNegotiationManagerConfigurationTest extends AbstractSpringBootTest { 29 | 30 | @Autowired 31 | private ContentNegotiationManagerConfiguration contentNegotiationManagerConfiguration; 32 | 33 | @Autowired 34 | private ContentNegotiatingViewResolver contentNegotiatingViewResolver; 35 | 36 | /** 37 | * spring.web-support.content-negotiation-manager.favorPathExtension = true 38 | * spring.web-support.content-negotiation-manager.favorParameter = true 39 | * spring.web-support.content-negotiation-manager.ignoreAcceptHeader = false 40 | * spring.web-support.content-negotiation-manager.useJaf = false 41 | * spring.web-support.content-negotiation-manager.parameterName = test-format 42 | * spring.web-support.content-negotiation-manager.mediaTypes.html = text/html 43 | * spring.web-support.content-negotiation-manager.mediaTypes.xml = text/xml 44 | * spring.web-support.content-negotiation-manager.mediaTypes.json = application/json 45 | * spring.web-support.content-negotiation-manager.mediaTypes.gif = image/gif 46 | * spring.web-support.content-negotiation-manager.mediaTypes.jpeg = image/jpeg 47 | * spring.web-support.content-negotiation-manager.defaultContentType = text/html 48 | */ 49 | @Test 50 | public void testContentNegotiationManagerConfiguration() { 51 | 52 | ContentNegotiationManager contentNegotiationManager = 53 | contentNegotiatingViewResolver.getContentNegotiationManager(); 54 | 55 | List strategies = contentNegotiationManager.getStrategies(); 56 | 57 | Assert.assertEquals(4, strategies.size()); 58 | Assert.assertTrue(contains(ParameterContentNegotiationStrategy.class, strategies)); 59 | Assert.assertTrue(contains(HeaderContentNegotiationStrategy.class, strategies)); 60 | Assert.assertTrue(contains(FixedContentNegotiationStrategy.class, strategies)); 61 | 62 | ContentNegotiationStrategy strategy = strategies.get(0); 63 | 64 | strategy = FieldUtils.getFieldValue(strategy, "delegate"); 65 | 66 | Map mediaTypesMap = FieldUtils.getFieldValue(strategy, "mediaTypes"); 67 | 68 | Assert.assertEquals("html", mediaTypesMap.get("html").getSubtype()); 69 | Assert.assertEquals("xml", mediaTypesMap.get("xml").getSubtype()); 70 | Assert.assertEquals("json", mediaTypesMap.get("json").getSubtype()); 71 | Assert.assertEquals("gif", mediaTypesMap.get("gif").getSubtype()); 72 | Assert.assertEquals("jpeg", mediaTypesMap.get("jpeg").getSubtype()); 73 | 74 | } 75 | 76 | private boolean contains(Class strategyClass, 77 | List strategies) { 78 | 79 | boolean contained = false; 80 | 81 | for (ContentNegotiationStrategy strategy : strategies) { 82 | 83 | contained = strategyClass.isInstance(strategy); 84 | 85 | if (contained) { 86 | break; 87 | } 88 | 89 | } 90 | 91 | return contained; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/ExclusiveViewResolverConfigurationDisabledTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.spring.util.BeanUtils; 5 | import com.alibaba.spring.web.context.ExclusiveViewResolverApplicationListener; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.springframework.test.context.ActiveProfiles; 9 | import org.springframework.web.servlet.ViewResolver; 10 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 11 | import org.thymeleaf.spring5.view.ThymeleafViewResolver; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * {@link ExclusiveViewResolverConfiguration} Disabled Test 17 | * 18 | * @author Mercy 19 | * @see ExclusiveViewResolverConfiguration 20 | * @since 2017.03.29 21 | */ 22 | @ActiveProfiles("disabled") 23 | public class ExclusiveViewResolverConfigurationDisabledTest extends AbstractSpringBootTest { 24 | 25 | @Test 26 | public void testExclusiveViewResolverConfigurationDisabled() { 27 | 28 | Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class)); 29 | Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class)); 30 | 31 | ContentNegotiatingViewResolver contentNegotiatingViewResolver = 32 | applicationContext.getBean(ContentNegotiatingViewResolver.class); 33 | 34 | Assert.assertNotNull(contentNegotiatingViewResolver); 35 | 36 | List viewResolvers = contentNegotiatingViewResolver.getViewResolvers(); 37 | 38 | Assert.assertTrue(viewResolvers.size() > 1); 39 | 40 | ThymeleafViewResolver thymeleafViewResolver = 41 | applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class); 42 | 43 | Assert.assertTrue(viewResolvers.contains(thymeleafViewResolver)); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/ExclusiveViewResolverConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.spring.util.BeanUtils; 5 | import com.alibaba.spring.web.context.ExclusiveViewResolverApplicationListener; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.springframework.test.context.ActiveProfiles; 9 | import org.springframework.web.servlet.ViewResolver; 10 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; 11 | import org.thymeleaf.spring5.view.ThymeleafViewResolver; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * {@link ExclusiveViewResolverConfiguration} Test 17 | * 18 | * @author Mercy 19 | * @see ExclusiveViewResolverConfiguration 20 | * @since 2017.03.29 21 | */ 22 | @ActiveProfiles("enabled") 23 | public class ExclusiveViewResolverConfigurationTest extends AbstractSpringBootTest { 24 | 25 | @Test 26 | public void testExclusiveViewResolverConfiguration() { 27 | 28 | Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class)); 29 | Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class)); 30 | 31 | ContentNegotiatingViewResolver contentNegotiatingViewResolver = 32 | applicationContext.getBean(ContentNegotiatingViewResolver.class); 33 | 34 | Assert.assertNotNull(contentNegotiatingViewResolver); 35 | 36 | List viewResolvers = contentNegotiatingViewResolver.getViewResolvers(); 37 | 38 | Assert.assertEquals(1, viewResolvers.size()); 39 | 40 | ThymeleafViewResolver thymeleafViewResolver = 41 | applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class); 42 | 43 | Assert.assertEquals(thymeleafViewResolver, viewResolvers.get(0)); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/SpeedupWebMvcAutoConfigurationDisabledTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.boot.web.filter.NoopOrderedHiddenHttpMethodFilter; 5 | import com.alibaba.boot.web.filter.NoopOrderedHttpPutFormContentFilter; 6 | import com.alibaba.spring.util.BeanUtils; 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | import org.springframework.test.context.ActiveProfiles; 10 | 11 | import javax.servlet.ServletException; 12 | import java.io.IOException; 13 | 14 | /** 15 | * {@link SpeedupWebMvcAutoConfiguration} Test with "disabled" profile 16 | * 17 | * @author Mercy 18 | * @see SpeedupWebMvcAutoConfiguration 19 | * @since 2017.04.11 20 | */ 21 | @ActiveProfiles("disabled") 22 | public class SpeedupWebMvcAutoConfigurationDisabledTest extends AbstractSpringBootTest { 23 | 24 | @Test 25 | public void testNoopOrderedHiddenHttpMethodFilter() throws ServletException, IOException { 26 | 27 | Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, NoopOrderedHiddenHttpMethodFilter.class)); 28 | 29 | } 30 | 31 | @Test 32 | public void testNoopOrderedHttpPutFormContentFilter() throws ServletException, IOException { 33 | 34 | Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, NoopOrderedHttpPutFormContentFilter.class)); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/autoconfigure/SpeedupWebMvcAutoConfigurationTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.autoconfigure; 2 | 3 | import com.alibaba.boot.web.AbstractSpringBootTest; 4 | import com.alibaba.boot.web.filter.NoopOrderedHiddenHttpMethodFilter; 5 | import com.alibaba.boot.web.filter.NoopOrderedHttpPutFormContentFilter; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.springframework.mock.web.MockFilterChain; 9 | import org.springframework.mock.web.MockHttpServletRequest; 10 | import org.springframework.mock.web.MockHttpServletResponse; 11 | import org.springframework.test.context.ActiveProfiles; 12 | 13 | import javax.servlet.ServletException; 14 | import javax.servlet.http.HttpServletRequestWrapper; 15 | import java.io.IOException; 16 | 17 | /** 18 | * {@link SpeedupWebMvcAutoConfiguration} Test 19 | * 20 | * @author Mercy 21 | * @see SpeedupWebMvcAutoConfiguration 22 | * @since 2017.04.11 23 | */ 24 | @ActiveProfiles("enabled") 25 | public class SpeedupWebMvcAutoConfigurationTest extends AbstractSpringBootTest { 26 | 27 | 28 | @Test 29 | public void testNoopOrderedHiddenHttpMethodFilter() throws ServletException, IOException { 30 | 31 | NoopOrderedHiddenHttpMethodFilter filter = applicationContext.getBean(NoopOrderedHiddenHttpMethodFilter.class); 32 | 33 | MockHttpServletRequest request = new MockHttpServletRequest(); 34 | request.setMethod("POST"); 35 | request.setParameter("_method", "action"); 36 | 37 | MockHttpServletResponse response = new MockHttpServletResponse(); 38 | 39 | MockFilterChain filterChain = new MockFilterChain(); 40 | 41 | filter.doFilter(request, response, filterChain); 42 | 43 | Assert.assertFalse(HttpServletRequestWrapper.class.isAssignableFrom(filterChain.getRequest().getClass())); 44 | Assert.assertTrue(MockHttpServletRequest.class.isAssignableFrom(filterChain.getRequest().getClass())); 45 | 46 | } 47 | 48 | @Test 49 | public void testNoopOrderedHttpPutFormContentFilter() throws ServletException, IOException { 50 | 51 | NoopOrderedHttpPutFormContentFilter filter = applicationContext.getBean(NoopOrderedHttpPutFormContentFilter.class); 52 | 53 | MockHttpServletRequest request = new MockHttpServletRequest(); 54 | request.setMethod("PUT"); 55 | 56 | MockHttpServletResponse response = new MockHttpServletResponse(); 57 | 58 | MockFilterChain filterChain = new MockFilterChain(); 59 | 60 | filter.doFilter(request, response, filterChain); 61 | 62 | Assert.assertFalse(HttpServletRequestWrapper.class.isAssignableFrom(filterChain.getRequest().getClass())); 63 | Assert.assertTrue(MockHttpServletRequest.class.isAssignableFrom(filterChain.getRequest().getClass())); 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/filter/NoopOrderedHiddenHttpMethodFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.filter; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.springframework.mock.env.MockEnvironment; 7 | import org.springframework.mock.web.MockFilterChain; 8 | import org.springframework.mock.web.MockFilterConfig; 9 | import org.springframework.mock.web.MockHttpServletRequest; 10 | import org.springframework.mock.web.MockHttpServletResponse; 11 | 12 | import javax.servlet.FilterChain; 13 | import javax.servlet.ServletException; 14 | import java.io.IOException; 15 | 16 | import static org.springframework.web.filter.OncePerRequestFilter.ALREADY_FILTERED_SUFFIX; 17 | 18 | /** 19 | * {@link com.alibaba.spring.web.filter.NoopHiddenHttpMethodFilter} Test 20 | * 21 | * @author Mercy 22 | * @see com.alibaba.spring.web.filter.NoopHiddenHttpMethodFilter 23 | * @since 2017.03.21 24 | */ 25 | public class NoopOrderedHiddenHttpMethodFilterTest { 26 | 27 | private static final String FILTER_NAME = "test-filter"; 28 | 29 | private static final String FILTERED_ATTRIBUTE_NAME = FILTER_NAME + ALREADY_FILTERED_SUFFIX; 30 | 31 | private MockEnvironment environment = new MockEnvironment(); 32 | 33 | private MockFilterConfig filterConfig = new MockFilterConfig(FILTER_NAME); 34 | 35 | private MockHttpServletRequest request = new MockHttpServletRequest(); 36 | 37 | private MockHttpServletResponse response = new MockHttpServletResponse(); 38 | 39 | private FilterChain filterChain = new MockFilterChain(); 40 | 41 | private NoopOrderedHiddenHttpMethodFilter filter = new NoopOrderedHiddenHttpMethodFilter(); 42 | 43 | @Before 44 | public void init() throws ServletException { 45 | 46 | filter.init(filterConfig); 47 | 48 | filter.setEnvironment(environment); 49 | 50 | } 51 | 52 | @Test 53 | public void testShouldNotFilter() throws ServletException { 54 | 55 | filter.setEnvironment(environment); 56 | 57 | Assert.assertTrue(filter.shouldNotFilter(request)); 58 | 59 | } 60 | 61 | @Test 62 | public void testOrder() { 63 | 64 | filter.setOrder(1); 65 | 66 | Assert.assertEquals(1, filter.getOrder()); 67 | 68 | } 69 | 70 | 71 | @Test 72 | public void testDoFilter() throws ServletException, IOException { 73 | 74 | filter.doFilter(request, response, filterChain); 75 | 76 | Assert.assertNull(request.getAttribute(FILTERED_ATTRIBUTE_NAME)); 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/filter/NoopOrderedHttpPutFormContentFilterTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.filter; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.springframework.mock.env.MockEnvironment; 7 | import org.springframework.mock.web.MockFilterChain; 8 | import org.springframework.mock.web.MockFilterConfig; 9 | import org.springframework.mock.web.MockHttpServletRequest; 10 | import org.springframework.mock.web.MockHttpServletResponse; 11 | 12 | import javax.servlet.FilterChain; 13 | import javax.servlet.ServletException; 14 | import java.io.IOException; 15 | 16 | import static org.springframework.web.filter.OncePerRequestFilter.ALREADY_FILTERED_SUFFIX; 17 | 18 | /** 19 | * {@link NoopOrderedHttpPutFormContentFilter} Test 20 | * 21 | * @author Mercy 22 | * @see NoopOrderedHttpPutFormContentFilter 23 | * @since 2017.03.21 24 | */ 25 | public class NoopOrderedHttpPutFormContentFilterTest { 26 | 27 | private static final String FILTER_NAME = "test-filter"; 28 | 29 | private static final String FILTERED_ATTRIBUTE_NAME = FILTER_NAME + ALREADY_FILTERED_SUFFIX; 30 | 31 | private MockEnvironment environment = new MockEnvironment(); 32 | 33 | private MockFilterConfig filterConfig = new MockFilterConfig(FILTER_NAME); 34 | 35 | private MockHttpServletRequest request = new MockHttpServletRequest(); 36 | 37 | private MockHttpServletResponse response = new MockHttpServletResponse(); 38 | 39 | private FilterChain filterChain = new MockFilterChain(); 40 | 41 | private NoopOrderedHttpPutFormContentFilter filter = new NoopOrderedHttpPutFormContentFilter(); 42 | 43 | @Before 44 | public void init() throws ServletException { 45 | 46 | filter.init(filterConfig); 47 | 48 | filter.setEnvironment(environment); 49 | 50 | } 51 | 52 | @Test 53 | public void testShouldNotFilter() throws ServletException { 54 | 55 | filter.setEnvironment(environment); 56 | 57 | Assert.assertTrue(filter.shouldNotFilter(request)); 58 | 59 | } 60 | 61 | @Test 62 | public void testOrder() { 63 | 64 | filter.setOrder(1); 65 | 66 | Assert.assertEquals(1, filter.getOrder()); 67 | 68 | } 69 | 70 | 71 | @Test 72 | public void testDoFilter() throws ServletException, IOException { 73 | 74 | 75 | filter.doFilter(request, response, filterChain); 76 | 77 | Assert.assertNull(request.getAttribute(FILTERED_ATTRIBUTE_NAME)); 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/util/ViewResolverUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.util; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import static com.alibaba.boot.web.util.ViewResolverUtils.FREEMARKER_VIEW_RESOLVER_BEAN_NAME; 7 | import static com.alibaba.boot.web.util.ViewResolverUtils.GROOVY_MARKUP_VIEW_RESOLVER_BEAN_NAME; 8 | import static com.alibaba.boot.web.util.ViewResolverUtils.INTERNAL_RESOURCE_VIEW_RESOLVER_BEAN_NAME; 9 | import static com.alibaba.boot.web.util.ViewResolverUtils.MUSTACHE_VIEW_RESOLVER_BEAN_NAME; 10 | import static com.alibaba.boot.web.util.ViewResolverUtils.THYMELEAF_VIEW_RESOLVER_BEAN_NAME; 11 | import static com.alibaba.boot.web.util.ViewResolverUtils.VELOCITY_VIEW_RESOLVER_BEAN_NAME; 12 | 13 | /** 14 | * {@link ViewResolverUtils} Test 15 | * 16 | * @author Mercy 17 | * @see ViewResolverUtils 18 | * @since 2017.04.11 19 | */ 20 | public class ViewResolverUtilsTest { 21 | 22 | @Test 23 | public void testConstants() { 24 | 25 | Assert.assertEquals("defaultViewResolver", INTERNAL_RESOURCE_VIEW_RESOLVER_BEAN_NAME); 26 | Assert.assertEquals("velocityViewResolver", VELOCITY_VIEW_RESOLVER_BEAN_NAME); 27 | Assert.assertEquals("thymeleafViewResolver", THYMELEAF_VIEW_RESOLVER_BEAN_NAME); 28 | Assert.assertEquals("freeMarkerViewResolver", FREEMARKER_VIEW_RESOLVER_BEAN_NAME); 29 | Assert.assertEquals("groovyMarkupViewResolver", GROOVY_MARKUP_VIEW_RESOLVER_BEAN_NAME); 30 | Assert.assertEquals("mustacheViewResolver", MUSTACHE_VIEW_RESOLVER_BEAN_NAME); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/java/com/alibaba/boot/web/util/WebSupportUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.boot.web.util; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import static com.alibaba.boot.web.util.WebSupportUtils.CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX; 7 | import static com.alibaba.boot.web.util.WebSupportUtils.NOOP_HIDDEN_HTTP_METHOD_FILTER_ENABLED_PROPERTY_NAME; 8 | import static com.alibaba.boot.web.util.WebSupportUtils.NOOP_HTTP_PUT_FORM_CONTENT_FILTER_ENABLED_PROPERTY_NAME; 9 | import static com.alibaba.boot.web.util.WebSupportUtils.PROPERTY_NAME_PREFIX; 10 | import static com.alibaba.boot.web.util.WebSupportUtils.VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME; 11 | 12 | /** 13 | * {@link WebSupportUtils} Test 14 | * 15 | * @author Mercy 16 | * @see WebSupportUtils 17 | * @since 2017.04.11 18 | */ 19 | public class WebSupportUtilsTest { 20 | 21 | @Test 22 | public void testConstants() { 23 | Assert.assertEquals("web-support.", PROPERTY_NAME_PREFIX); 24 | 25 | Assert.assertEquals("web-support.content-negotiation-manager", 26 | CONTENT_NEGOTIATION_MANAGER_PROPERTY_NAME_PREFIX); 27 | 28 | Assert.assertEquals("web-support.exclusive-view-resolver", 29 | VIEW_RESOLVERS_EXCLUSIVE_BEAN_NAME_PROPERTY_NAME); 30 | 31 | Assert.assertEquals("web-support.noop.httpmethod.hiddenfilter.enabled", 32 | NOOP_HIDDEN_HTTP_METHOD_FILTER_ENABLED_PROPERTY_NAME); 33 | 34 | Assert.assertEquals("web-support.noop.formcontent.putfilter.enabled", 35 | NOOP_HTTP_PUT_FORM_CONTENT_FILTER_ENABLED_PROPERTY_NAME); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/resources/application-disabled.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/spring-boot-support/15138e3c6bdbe14f22f1d89e32aae4c1b36ab021/spring-boot-web-support/src/test/resources/application-disabled.properties -------------------------------------------------------------------------------- /spring-boot-web-support/src/test/resources/application-enabled.properties: -------------------------------------------------------------------------------- 1 | web-support.exclusive-view-resolver=thymeleafViewResolver 2 | # ContentNegotiationManager 配置项 3 | web-support.content-negotiation-manager.favorPathExtension=true 4 | web-support.content-negotiation-manager.favorParameter=true 5 | web-support.content-negotiation-manager.ignoreAcceptHeader=false 6 | web-support.content-negotiation-manager.useJaf=false 7 | web-support.content-negotiation-manager.parameterName=test-format 8 | web-support.content-negotiation-manager.mediaTypes.html=text/html 9 | web-support.content-negotiation-manager.mediaTypes.xml=text/xml 10 | web-support.content-negotiation-manager.mediaTypes.json=application/json 11 | web-support.content-negotiation-manager.mediaTypes.gif=image/gif 12 | web-support.content-negotiation-manager.mediaTypes.jpeg=image/jpeg 13 | web-support.content-negotiation-manager.defaultContentType=text/html 14 | # 激活 NoopOrderedHiddenHttpMethodFilter 15 | web-support.noop.httpmethod.hiddenfilter.enabled=true 16 | # 激活 NoopOrderedHttpPutFormContentFilter 17 | web-support.noop.formcontent.putfilter.enabled=true --------------------------------------------------------------------------------