├── .gitignore ├── .mvn ├── jvm.config ├── maven.config └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .settings.xml ├── .travis.yml ├── LICENSE ├── README.md ├── RELEASE.md ├── mvnw ├── pom.xml ├── src ├── config │ ├── bom.xml │ ├── eclipse-java-style.xml │ └── pomSortOrder.xml ├── etc │ └── header.txt ├── main │ └── java │ │ └── feign │ │ └── error │ │ ├── AnnotationErrorDecoder.java │ │ ├── ErrorCodes.java │ │ ├── ErrorHandling.java │ │ ├── ExceptionGenerator.java │ │ ├── FeignExceptionConstructor.java │ │ ├── MethodErrorHandler.java │ │ ├── ResponseBody.java │ │ └── ResponseHeaders.java └── test │ └── java │ └── feign │ └── error │ ├── AbstractAnnotationErrorDecoderTest.java │ ├── AnnotationErrorDecoderClassInheritanceTest.java │ ├── AnnotationErrorDecoderExceptionConstructorsTest.java │ ├── AnnotationErrorDecoderIllegalInterfacesTest.java │ ├── AnnotationErrorDecoderInheritanceTest.java │ ├── AnnotationErrorDecoderNoAnnotationTest.java │ ├── AnnotationErrorDecoderPriorityTest.java │ └── TestPojo.java └── travis └── publish.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target 3 | *.iml -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFeign/feign-annotation-error-decoder/546752425238f3d42d0ceec91d5c5af05841803e/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip -------------------------------------------------------------------------------- /.settings.xml: -------------------------------------------------------------------------------- 1 | 16 | 20 | 21 | 22 | sonatype 23 | ${env.SONATYPE_USER} 24 | ${env.SONATYPE_PASSWORD} 25 | 26 | 27 | bintray 28 | ${env.BINTRAY_USER} 29 | ${env.BINTRAY_KEY} 30 | 31 | 32 | jfrog-snapshots 33 | ${env.BINTRAY_USER} 34 | ${env.BINTRAY_KEY} 35 | 36 | 37 | github.com 38 | ${env.GH_USER} 39 | ${env.GH_TOKEN} 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Run `travis lint` when changing this file to avoid breaking the build. 2 | # Default JDK is really old: 1.8.0_31; Trusty's is less old: 1.8.0_51 3 | # https://docs.travis-ci.com/user/ci-environment/#Virtualization-environments 4 | dist: trusty 5 | sudo: false 6 | language: java 7 | jdk: oraclejdk8 8 | before_install: 9 | # Parameters used during release 10 | - git config user.name "$GH_USER" 11 | - git config user.email "$GH_USER_EMAIL" 12 | # setup https authentication credentials, used by ./mvnw release:prepare 13 | - git config credential.helper "store --file=.git/credentials" 14 | - echo "https://$GH_TOKEN:@github.com" > .git/credentials 15 | 16 | install: 17 | # Override default travis to use the maven wrapper 18 | - ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip=true -B -V 19 | 20 | script: 21 | - ./travis/publish.sh 22 | 23 | cache: 24 | directories: 25 | - $HOME/.m2 26 | 27 | 28 | matrix: 29 | include: 30 | - os: linux 31 | jdk: oraclejdk8 32 | addons: 33 | apt: 34 | packages: 35 | - oracle-java8-installer 36 | #removing openjdk8 from matrix for now as it causes issues on release 37 | # - os: linux 38 | # jdk: openjdk8 39 | # - os: linux 40 | # jdk: openjdk11 41 | 42 | # Don't build release tags. This avoids publish conflicts because the version commit exists both on master and the release tag. 43 | # See https://github.com/travis-ci/travis-ci/issues/1532 44 | branches: 45 | except: 46 | - /^[0-9]/ 47 | 48 | env: 49 | global: 50 | # Ex. travis encrypt BINTRAY_USER=your_github_account 51 | - secure: "UGCb+uE9a/hGVEPlAUM/iFgGYxnjJJ79nhl8a/RHsUJQI0/hGUwYkjELCVM3D9ck0hZI6xTjk/fr2JwTlAghmBYun8K9xKhGYnUShwCGwFBZzGRxLcN2Hfv2y4jSgUG59lRVxAFJFjXaH2wBooNmRRm/rjQpqdKiVissx6fUWq2B+zKUKQofXZlCi7gXTNeyQS4ROeDk3O+Q7uVLZ6ut39JSTSOl1t3AGBwJJ+Rz8d3kbLshM1T04MnRR7BRpDknWBc2b+7cbfNSRsQ8F7gbYce/lZSz5/WlE6c+RXNLztCf4AbPdkrJx5I6WRdCD34Hleo1zqTy2JOHneYJGKfupeqrvglFDibnJmsSpaOhgcGPCl5vi2MI/B0FiSyjtsdxgW9+ZaR3um3+6bBYfBznmPq379gCQcbxOX2+VlItSJHcOqH651F5akp58Uw7qO3bYYlj07pmZvZz//PaZf6F/h0LxLUGqn0esMBxLYsLb6nk8/DR5EL/69goR8qYkV17VHgTPNGT7YB7lQ+lQGzq9q7m9hT3lZj57ZjOrcHKTc0e9AA/8hOpMIegaeTHhRbrOUMQFWsqHke73BPKFvrJYEi54H4P1LatDCB1aQXoYuXsujR7idS6JGDW1kJy5ljppPjhzT9DYs4ypYI37yswSTrsQtwFysYC1FLVuklJCJU=" 52 | # # Ex. travis encrypt BINTRAY_KEY=xxx-https://bintray.com/profile/edit-xxx --add 53 | - secure: "XpunNYBzavq6waWQFr0G6ixR1egdqjGq+EbIjGb3h/AvHkOPA6NAgthOgyZFnB3xSOTP6M8SVRFPZyC69zcA69n8Np1vfo1eKZjq6mKG+gpxh19x4zqhd57dlt1TITmqiuPqShwIfcDLWI8Tb8sQ4CiI71AGtFXo4c83Nll79eS+wxqwXqyGn643bt/7DjPeZx7GVKi1iippO+TJCxnBmlJEj9g2N/ynb2AE0ofmf66pCSVWUZQ7AF366j/pSWXe0Y8jLdMR9LkC1nvznjtxcM3Kc0SzYJqzWN/AzkkUndQBt30fLdTH1Se/TAMltaAXiYXHld7giJFAUY8RybIm6Zp21Gawd/MvHqsEg0KJ84OaIuxBAbWBKCn7Wp7r+VLqOEaJF7bzGc2BZgFCTcr2xN6Q4EIQboanKjEGQZ5DxaNC3gQeNTJRenUH+PAHrk6a1ZPaO24ymDYOaN9wyJo+ueJGXTCS8fjYZJNlTk93D/koftkUapvuU5rd+2w/Q4oL6D/7fPCyiH94C428+nEaYzTkpqibSU1tRG8zDxl+MkVTQ4t0dJfVH3Hz4eqXs+9mir69a2QmQuFoefSOr5fNa7m+Hx0/H0FvmzAqnrSkmlXXG6d3Y7YDUEPtgVeZ8CJ+qFLRalkWM9cV+7bDc+SWxM2vC0HsT6LNS+IHT36fYBQ=" 54 | # # Ex. travis encrypt GH_USER_EMAIL=for_github@domain.com --add 55 | - secure: "WJQvlc3K9KWUHz71qqlgux1xH11Cz/IY3QaNDU6Zg5bsBwDMCS03WwNw/4JfmH89u55sXEYlmtC6i38WrZbjJy2peNOP62FVP7zyPagehACJW71Q2uoOs6OPQDmQsh6n+sFOxEBbl4zc8nD6QgAt/X3n7MO7BcHreokUHHOPz7hQ8KNiF1zK2r4h8/98gInP5wbw8TemUDJgFhFJbWSIENg3tfBOgypb+pjOCViHwqm4gBs2/S9IYBBNAf415KHvz7QvIU49JQFMrhMj89hX/mbywWFcBfbTqXVT3El6V7f5gN2A77nMxWeaFfoYvG3BBr4fcuf8AaRgHtL0twTTS5tMGx45RnhQGjTFMFvEPRRglh78TMIcgO688rFJmQCi8IY7mLEvTIHvI7BXrAz+A1xuhGyLyteopdOJsZ4e7AAOqwvdef3JQXgR3LCTsaevJfXIenMl4Lb5Eh/LIcEaxpZCSH2nuMOMDfn1lw4L7sMxCC1QjEs+hnuKE72DDZOyyT7co5aZlvcvglHOEEWyAuwpy08+LH8NKOluFia3+g2WdhrFZoxd/vNDc6SSBbYnAPVtn+v36ucDuP6N8snATs3VU5yjWePzfCVpbnclwBvc+kmGSGXqDTdQlQXLRLF9aAY5sLyECc921E/Jesz0t34ZU5poGBER+tH1WDeZIG0=" 56 | # # Ex. travis encrypt GH_USER=your_github_account --add 57 | - secure: "g2NBlGFcPLtgPQByQGy9dequHtdVCs2tAx3lEIQJoYv7VTlv+sPHaLSn4/sSSPven9k4KCF9cMZ/mF4+TBJxfR+WhvbqVI+nL1js8dHw4ko7wGhNUMeZot0l6u44JtalNiYCA8+0sn8rrj9lisS/xE3kzpyXMVZ3CMEBBp5gghUUwjKTXJPnV/WcmTbari6MCCa8UVQ3G4J9prhjX9ZRFZSQGk+5MrRH+O/EqkThpEQaUDtOaXx3P8RMcO8KwpPs8GUD++Z9clnH2NTs24BRJ6oOdbyR+9KnmBIV/FOYCmSelBmBs5AznkPz3XRQfSW8CfFLepHkEWvjw9k1hHMvQTAtqz5ZJyvbVC0ztIK8O1q8bQAOBoHRkQyxWk5o/57SrwgSQTtYLjoAjsR4Et2Noab01qme8/Knd8XYhee46CnHtxpPq6dhX58CB9N0Tep4TJYz5pKfe5q8jAQO9ceaLiPAhnRNzpHN/2CksXTdbdp+/go9FU7sBs61q+JK29zbVQTNpgiLiNagoJ8ZP8JkVDklQWK++wCWb2PxiaTMgsGxfRt2qydnpLdA/qkUrov7vlNlt5EEXqSslo+jdMfSsDBhr442bYrUGzlzTAuZTqBk2hS9VXSktUvDwzdx84BRQ2iKyfmeeuHDWdzLeQ+C+gMtb+Z1j6RRN1Bzcxaja58=" 58 | # # Ex. travis encrypt GH_TOKEN=XXX-https://github.com/settings/tokens-XXX --add 59 | - secure: "SYm90I0vUc9i52aISvGEgjlW3ACrAE6orzE08b2PAvKJqzcZ+3FOKvWpgAPDypXr+6LYiYhtOrX2Yt3S6/XDpizDQPcaz09aRBG3AR9yzDuE3UQgazPtgd2cNQiMIoKiBfIMi2z5jJk0PpYNxi0n7cOXSKBmxKjXCAcD4PUAZzR4hCYph1qWBtsj82WMqXgC6BxlLUPYYrnPALnyfmDxsYB017e2AyGkk7ItLWF90ov87d+BbulknOQ5fXp5atkV/xgcrr73yATe4pniWr8c2HZy1jaeYqtFYDN4QVhgN3QBrtGIwKYZbamYLgL5OX2g5L5JWqaR8RICZVs/5bQecwcNlHph8yRoByc/cssZhLnPbMgIbeSE02YbJ+Xk+kEtEBhSv6jGWlicWX8cl+d5Z0QRBKl+c/QrIuA1p7ltk5S4cb0WedPWu/u90eJZUoAb3HKpquAgU2FTohNby/Je8L+P+QtpmqOMk5cM+kformomx1bYEw2RQj+hj+G2fE8lvuZtXA1n45KAiCN185YI4/1Sdo9guBKdUjgs6ig37pJkbhVSsAdbfUUeb9wCVN2nOf2E2P19ZZoAJ0Gkf/zWGuNiFHcvLBORpZ9oIb3o6TeSi1rj8zJiGNmBzBXHZ2JDfgzfaabnnxpwUHtHBB0HA3uyA/xMJWuyAzeeRl9TorA=" 60 | # # Ex. travis encrypt SONATYPE_USER=your_sonatype_account 61 | - secure: "JRkMiXYwDURgZFJg/pOT+jsd9JXq74tRUBaTbvvcvaOdpfL5tBjgdoQgu/xvDttcwF74v5ygOWrXBKM/Q4fLamMrX+Z2+s/fMawXgZC0DsIU3UWB4W0rg2IWW9ByLTRrEOmRs1kIIEG5IfpvwuviQPbIbeKdZL9yDmRikah4kWAy/cDiUF3oqieSfww8TSzkk1edh+LlWfiz3kyXFThV1kjN1emQxbRKR8onK9LqIBTsiaxuz0h+hJnUFvHIp13DzqMYzq4TE1LKerC3aj/GwAlbuJYnE0Qe++phEjVcr6tEVEkc2NbWfRywKFo0o7TqoEpHZI0olCRcwvRnUUU6OMlIHLa9N2P9u+LqJ4Y6Im+hcqIfPFG04BEww6fp6EkPWzGM2vv+uLADBEPT7Rxg95LWkC8JrFtRkT3JNah7O9LErLVmDW7cAh2lFeqaHgBWHXxqULdFrlh///pZIhQDClKvNF+fKWsFfPNqBEoa5a88dNDd5i3y10+XqIeo8BQNYUGDF4PmaOrxIcOPEmlAfaIR8ZI4U/t4LuxM6v57fKw6vAhc5bzC7aYOSBE/fOmJ72PGAQDpi1ufseVPAtaQb/M3pgz1Cy8fbGoASF08yI72LzkNhgnbSSyWXMTr19r7O3iyTC67V3ENdFNvZmnQXQdJ3p54eTHDs0Ev8nqxV/g=" 62 | # # Ex. travis encrypt SONATYPE_PASSWORD=your_sonatype_password 63 | - secure: "FhyPYnFzModdYtBmvoI2H8RUig8MoJLRcEZXXYKaDvTKuUzMai5mEEZVt7hVNvIDEk/mqhziTL6bQ++sgZ7mzxRKcpxM3Z3+6fLFvibpV+IMt4C5hXiDZBgDrZGbM4aA2XWhXBHq37x/aOOQsIMHna7kv3IAnyw+KoAX0Hfj2X2914VxmUDMiobjwNIGMk9LUS+YeI8jYcssB4Dp+6QzpmuoVzxkd5paEOKE9GwP5BXRo2QaPu4BEK6op2dV4aG7E1GJenj+3bJfVGgl5/EGXI1KTLp0QZMRwYH3BiwVh5VVuHeNlv3R38y4bAoi3JuovqcsHBzkA9hic5IzrCkyTQIpq8k7upxPI+W9LDuPGjM24i6aWA8sO948UBMZ9Upvh8Cwxyt76tiOdujOXhbCzgXfnrnPkxDC6lmBDNH6raA6kIej80cA4Wrg/h/b7R5W9iRzAER2qzer2Vrn9Db/VSMwFy+UqC4ySznygZ6OzE0UBYF3oG2LXRHP0o96pjsiTdm+c3c5Rp1sSosrVnROCiurcppx4Z7sMTPBb4QVfzPnbcWwStiyAVp6oIs1hjBVJFs/uZS1R8YH3fGJWgOq5qyha+Q+T10M6vplJXAhknLuG7GL98S+LCERKBPuikT0dPaEQVBqNnGHmNl/W6YJ4oAggacx377kR8JDDCVcAz0=" -------------------------------------------------------------------------------- /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 | Annotation Error Decoder 2 | ========================= 3 | [![Join the chat at https://gitter.im/OpenFeign/feign](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OpenFeign/feign?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![Build Status](https://travis-ci.org/OpenFeign/feign-annotation-error-decoder.svg?branch=master)](https://travis-ci.org/OpenFeign/feign-annotation-error-decoder) 5 | [![Download](https://api.bintray.com/packages/openfeign/maven/feign-annotation-error-decoder/images/download.svg) ](https://bintray.com/openfeign/maven/feign-annotation-error-decoder/_latestVersion) 6 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign/feign-annotation-error-decoder/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign/feign-annotation-error-decoder) 7 | 8 | This module allows to annotate Feign's interfaces with annotations to generate Exceptions based on error codes 9 | 10 | To use AnnotationErrorDecoder with Feign, add the Annotation Error Decoder module to your classpath. Then, configure 11 | Feign to use the AnnotationErrorDecoder: 12 | 13 | ```java 14 | GitHub github = Feign.builder() 15 | .errorDecoder( 16 | AnnotationErrorDecoder.builderFor(GitHub.class).build() 17 | ) 18 | .target(GitHub.class, "https://api.github.com"); 19 | ``` 20 | 21 | ## Leveraging the annotations and priority order 22 | For annotation decoding to work, the class must be annotated with `@ErrorHandling` tags. 23 | The tags are valid in both the class level as well as method level. They will be treated from 'most specific' to 24 | 'least specific' in the following order: 25 | * A code specific exception defined on the method 26 | * A code specific exception defined on the class 27 | * The default exception of the method 28 | * The default exception of the class 29 | 30 | ```java 31 | @ErrorHandling(codeSpecific = 32 | { 33 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class), 34 | @ErrorCodes( codes = {403}, generate = ForbiddenException.class), 35 | @ErrorCodes( codes = {404}, generate = UnknownItemException.class), 36 | }, 37 | defaultException = ClassLevelDefaultException.class 38 | ) 39 | interface GitHub { 40 | 41 | @ErrorHandling(codeSpecific = 42 | { 43 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class), 44 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class), 45 | }, 46 | defaultException = FailedToGetContributorsException.class 47 | ) 48 | @RequestLine("GET /repos/{owner}/{repo}/contributors") 49 | List contributors(@Param("owner") String owner, @Param("repo") String repo); 50 | } 51 | ``` 52 | In the above example, error responses to 'contributors' would hence be mapped as follows by status codes: 53 | 54 | | Code | Exception | Reason | 55 | | ----------- | -------------------------------- | --------------------- | 56 | | 401 | `UnAuthorizedException` | from Class definition | 57 | | 403 | `ForbiddenException` | from Class definition | 58 | | 404 | `NonExistenRepoException` | from Method definition, note that the class generic exception won't be thrown here | 59 | | 502,503,504 | `RetryAfterCertainTimeException` | from method definition. Note that you can have multiple error codes generate the same type of exception | 60 | | Any Other | `FailedToGetContributorsException` | from Method default | 61 | 62 | For a class level default exception to be thrown, the method must not have a `defaultException` defined, nor must the error code 63 | be mapped at either the method or class level. 64 | 65 | If the return code cannot be mapped to any code and no default exceptions have been configured, then the decoder will 66 | drop to a default decoder (by default, the standard one provided by feign). You can change the default drop-into decoder 67 | as follows: 68 | 69 | ```java 70 | GitHub github = Feign.builder() 71 | .errorDecoder( 72 | AnnotationErrorDecoder.builderFor(GitHub.class) 73 | .withDefaultDecoder(new MyOtherErrorDecoder()) 74 | .build() 75 | ) 76 | .target(GitHub.class, "https://api.github.com"); 77 | ``` 78 | 79 | 80 | ## Complex Exceptions 81 | 82 | Any exception can be used if they have a default constructor: 83 | 84 | ```java 85 | class DefaultConstructorException extends Exception {} 86 | ``` 87 | 88 | However, if you want to have parameters (such as the feign.Request object or response body or response headers), you have to annotate its 89 | constructor appropriately (the body annotation is optional, provided there aren't paramters which will clash) 90 | 91 | All the following examples are valid exceptions: 92 | ```java 93 | class JustBody extends Exception { 94 | 95 | @FeignExceptionConstructor 96 | public JustBody(String body) { 97 | 98 | } 99 | } 100 | class JustRequest extends Exception { 101 | 102 | @FeignExceptionConstructor 103 | public JustRequest(Request request) { 104 | 105 | } 106 | } 107 | class RequestAndResponseBody extends Exception { 108 | 109 | @FeignExceptionConstructor 110 | public RequestAndResponseBody(Request request, String body) { 111 | 112 | } 113 | } 114 | //Headers must be of type Map> 115 | class BodyAndHeaders extends Exception { 116 | 117 | @FeignExceptionConstructor 118 | public BodyAndHeaders(@ResponseBody String body, @ResponseHeaders Map> headers) { 119 | 120 | } 121 | } 122 | class RequestAndResponseBodyAndHeaders extends Exception { 123 | 124 | @FeignExceptionConstructor 125 | public RequestAndResponseBodyAndHeaders(Request request, @ResponseBody String body, @ResponseHeaders Map> headers) { 126 | 127 | } 128 | } 129 | class JustHeaders extends Exception { 130 | 131 | @FeignExceptionConstructor 132 | public JustHeaders(@ResponseHeaders Map> headers) { 133 | 134 | } 135 | } 136 | ``` 137 | 138 | If you want to have the body decoded, you'll need to pass a decoder at construction time (just as for normal responses): 139 | 140 | ```java 141 | GitHub github = Feign.builder() 142 | .errorDecoder( 143 | AnnotationErrorDecoder.builderFor(GitHub.class) 144 | .withResponseBodyDecoder(new JacksonDecoder()) 145 | .build() 146 | ) 147 | .target(GitHub.class, "https://api.github.com"); 148 | ``` 149 | 150 | This will enable you to create exceptions where the body is a complex pojo: 151 | 152 | ```java 153 | class ComplexPojoException extends Exception { 154 | 155 | @FeignExceptionConstructor 156 | public ComplexPojoException(GithubExceptionResponse body) { 157 | if (body != null) { 158 | // extract data 159 | } else { 160 | // fallback code 161 | } 162 | } 163 | } 164 | //The pojo can then be anything you'd like provided the decoder can manage it 165 | class GithubExceptionResponse { 166 | public String message; 167 | public int githubCode; 168 | public List urlsForHelp; 169 | } 170 | ``` 171 | 172 | It's worth noting that at setup/startup time, the generators are checked with a null value of the body. 173 | If you don't do the null-checker, you'll get an NPE and startup will fail. 174 | 175 | 176 | ## Inheriting from other interface definitions 177 | You can create a client interface that inherits from a different one. However, there are some limitations that 178 | you should be aware of (for most cases, these shouldn't be an issue): 179 | * The inheritance is not natural java inheritance of annotations - as these don't work on interfaces 180 | * Instead, the error looks at the class and if it finds the `@ErrorHandling` annotation, it uses that one. 181 | * If not, it will look at *all* the interfaces the main interface `extends` - but it does so in the order the 182 | java API gives it - so order is not guaranteed. 183 | * If it finds the annotation in one of those parents, it uses that definition, without looking at any other 184 | * That means that if more than one interface was extended which contained the `@ErrorHandling` annotation, we can't 185 | really guarantee which one of the parents will be selected and you should really do handling at the child interface 186 | * so far, the java API seems to return in order of definition after the `extends`, but it's a really bad practice 187 | if you have to depend on that... so our suggestion: don't. 188 | 189 | That means that as long as you only ever extend from a base interface (where you may decide that all 404's are "NotFoundException", for example) 190 | then you should be ok. But if you get complex in polymorphism, all bets are off - so don't go crazy! 191 | 192 | Example: 193 | In the following code: 194 | * The base `FeignClientBase` interface defines a default set of exceptions at class level 195 | * the `GitHub1` and `GitHub2` interfaces will inherit the class-level error handling, which means that 196 | any 401/403/404 will be handled correctly (provided the method doesn't specify a more specific exception) 197 | * the `GitHub3` interface however, by defining its own error handling, will handle all 401's, but not the 198 | 403/404's since there's no merging/etc (not really in the plan to implement either...) 199 | ```java 200 | 201 | @ErrorHandling(codeSpecific = 202 | { 203 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class), 204 | @ErrorCodes( codes = {403}, generate = ForbiddenException.class), 205 | @ErrorCodes( codes = {404}, generate = UnknownItemException.class), 206 | }, 207 | defaultException = ClassLevelDefaultException.class 208 | ) 209 | interface FeignClientBase {} 210 | 211 | interface GitHub1 extends FeignClientBase { 212 | 213 | @ErrorHandling(codeSpecific = 214 | { 215 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class), 216 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class), 217 | }, 218 | defaultException = FailedToGetContributorsException.class 219 | ) 220 | @RequestLine("GET /repos/{owner}/{repo}/contributors") 221 | List contributors(@Param("owner") String owner, @Param("repo") String repo); 222 | } 223 | 224 | interface GitHub2 extends FeignClientBase { 225 | 226 | @ErrorHandling(codeSpecific = 227 | { 228 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class), 229 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class), 230 | }, 231 | defaultException = FailedToGetContributorsException.class 232 | ) 233 | @RequestLine("GET /repos/{owner}/{repo}/contributors") 234 | List contributors(@Param("owner") String owner, @Param("repo") String repo); 235 | } 236 | 237 | @ErrorHandling(codeSpecific = 238 | { 239 | @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class) 240 | }, 241 | defaultException = ClassLevelDefaultException.class 242 | ) 243 | interface GitHub3 extends FeignClientBase { 244 | 245 | @ErrorHandling(codeSpecific = 246 | { 247 | @ErrorCodes( codes = {404}, generate = NonExistentRepoException.class), 248 | @ErrorCodes( codes = {502, 503, 504}, generate = RetryAfterCertainTimeException.class), 249 | }, 250 | defaultException = FailedToGetContributorsException.class 251 | ) 252 | @RequestLine("GET /repos/{owner}/{repo}/contributors") 253 | List contributors(@Param("owner") String owner, @Param("repo") String repo); 254 | } 255 | ``` -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Feign Annotation Error Decoder Release Process 2 | 3 | This repo uses [semantic versions](http://semver.org/). Please keep this in mind when choosing version numbers. 4 | 5 | 1. **Alert others you are releasing** 6 | 7 | There should be no commits made to master while the release is in progress (about 10 minutes). Before you start 8 | a release, alert others on [gitter](https://gitter.im/OpenFeign/feign) so that they don't accidentally merge 9 | anything. If they do, and the build fails because of that, you'll have to recreate the release tag described below. 10 | 11 | 1. **Push a git tag** 12 | 13 | The tag should be of the format `release-N.M.L`, for example `release-8.18.0`. 14 | 15 | You can do this either from the command line or via the github UI by creating a release. 16 | 17 | 1. **Wait for Travis CI** 18 | 19 | This part is controlled by [`travis/publish.sh`](travis/publish.sh). It creates a couple commits, bumps the version, 20 | publishes artifacts, syncs to Maven Central. 21 | 22 | ## Credentials 23 | 24 | Credentials of various kind are needed for the release process to work. If you notice something 25 | failing due to unauthorized, re-encrypt them using instructions at the bottom of the `.travis.yml` 26 | 27 | Ex You'll see comments like this: 28 | ```yaml 29 | env: 30 | global: 31 | # Ex. travis encrypt BINTRAY_USER=your_github_account 32 | - secure: "VeTO... 33 | ``` 34 | 35 | To re-encrypt, you literally run the commands with relevant values and replace the "secure" key with the output: 36 | 37 | ```bash 38 | $ travis encrypt BINTRAY_USER=adrianmole 39 | Please add the following to your .travis.yml file: 40 | 41 | secure: "mQnECL+dXc5l9wCYl/wUz+AaYFGt/1G31NAZcTLf2RbhKo8mUenc4hZNjHCEv+4ZvfYLd/NoTNMhTCxmtBMz1q4CahPKLWCZLoRD1ExeXwRymJPIhxZUPzx9yHPHc5dmgrSYOCJLJKJmHiOl9/bJi123456=" 42 | ``` -------------------------------------------------------------------------------- /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 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # traverses directory structure from process work directory to filesystem root 188 | # first directory with .mvn subdirectory is considered project base directory 189 | find_maven_basedir() { 190 | local basedir=$(pwd) 191 | local wdir=$(pwd) 192 | while [ "$wdir" != '/' ] ; do 193 | if [ -d "$wdir"/.mvn ] ; then 194 | basedir=$wdir 195 | break 196 | fi 197 | wdir=$(cd "$wdir/.."; pwd) 198 | done 199 | echo "${basedir}" 200 | } 201 | 202 | # concatenates all lines of a file 203 | concat_lines() { 204 | if [ -f "$1" ]; then 205 | echo "$(tr -s '\n' ' ' < "$1")" 206 | fi 207 | } 208 | 209 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 210 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 211 | 212 | # For Cygwin, switch paths to Windows format before running java 213 | if $cygwin; then 214 | [ -n "$M2_HOME" ] && 215 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 216 | [ -n "$JAVA_HOME" ] && 217 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 218 | [ -n "$CLASSPATH" ] && 219 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 220 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 221 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 222 | fi 223 | 224 | # Provide a "standardized" way to retrieve the CLI args that will 225 | # work with both Windows and non-Windows executions. 226 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 227 | export MAVEN_CMD_LINE_ARGS 228 | 229 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 230 | 231 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@ 232 | exec "$JAVACMD" \ 233 | $MAVEN_OPTS \ 234 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 235 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 236 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 237 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | 21 | io.github.openfeign 22 | parent 23 | 10.7.0 24 | 25 | 26 | feign-annotation-error-decoder 27 | 1.3.1-SNAPSHOT 28 | Feign Annotation Error Decoder 29 | Feign Annotation Error Decoder 30 | https://github.com/OpenFeign/feign-annotation-error-decoder 31 | 2017 32 | 33 | 34 | OpenFeign 35 | https://github.com/openfeign 36 | 37 | 38 | 39 | 40 | The Apache Software License, Version 2.0 41 | http://www.apache.org/licenses/LICENSE-2.0.txt 42 | repo 43 | 44 | 45 | 46 | 47 | https://github.com/OpenFeign/feign-annotation-error-decoder 48 | scm:git:https://github.com/OpenFeign/feign-annotation-error-decoder.git 49 | scm:git:https://github.com/OpenFeign/feign-annotation-error-decoder.git 50 | HEAD 51 | 52 | 53 | 54 | 55 | saintf 56 | Fernando Saint-Jean 57 | fsaintjean@gmail.com 58 | 59 | 60 | 61 | 62 | 63 | bintray 64 | https://api.bintray.com/maven/openfeign/maven/feign-annotation-error-decoder/;publish=1 65 | 66 | 67 | jfrog-snapshots 68 | http://oss.jfrog.org/artifactory/oss-snapshot-local 69 | 70 | 71 | 72 | 73 | Github 74 | https://github.com/openfeign/feign-annotation-error-decoder/issues 75 | 76 | 77 | 78 | 79 | ${project.groupId} 80 | feign-core 81 | ${project.parent.version} 82 | provided 83 | 84 | 85 | 86 | ${project.groupId} 87 | feign-core 88 | ${project.parent.version} 89 | test-jar 90 | test 91 | 92 | 93 | 94 | com.squareup.okhttp3 95 | mockwebserver 96 | test 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | maven-jar-plugin 105 | ${maven-jar-plugin.version} 106 | 107 | 108 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 109 | 110 | 111 | 112 | 113 | maven-compiler-plugin 114 | 115 | 116 | 117 | default-compile 118 | compile 119 | 120 | compile 121 | 122 | 123 | ${main.java.version} 124 | ${main.java.version} 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | org.codehaus.mojo 135 | animal-sniffer-maven-plugin 136 | ${animal-sniffer-maven-plugin.version} 137 | 138 | 139 | org.codehaus.mojo.signature 140 | ${main.signature.artifact} 141 | 1.0 142 | 143 | 144 | 145 | 146 | 147 | check 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | maven-install-plugin 156 | ${maven-install-plugin.version} 157 | 158 | true 159 | 160 | 161 | 162 | 163 | maven-release-plugin 164 | ${maven-release-plugin.version} 165 | 166 | false 167 | release 168 | true 169 | @{project.version} 170 | 171 | 172 | 173 | 174 | io.zipkin.centralsync-maven-plugin 175 | centralsync-maven-plugin 176 | ${centralsync-maven-plugin.version} 177 | 178 | openfeign 179 | maven 180 | feign-annotation-error-decoder 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | release 189 | 190 | 191 | 192 | 193 | maven-source-plugin 194 | ${maven-source-plugin.version} 195 | 196 | 197 | attach-sources 198 | 199 | jar 200 | 201 | 202 | 203 | 204 | 205 | 206 | maven-javadoc-plugin 207 | ${maven-javadoc-plugin.version} 208 | 209 | false 210 | 211 | 212 | 213 | attach-javadocs 214 | 215 | jar 216 | 217 | package 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /src/config/bom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 4.0.0 19 | 20 | ${model.groupId} 21 | ${model.artifactId} 22 | ${model.version} 23 | ${model.name} 24 | pom 25 | Bill of material 26 | #if ($model.url) 27 | 28 | ${model.url}#end 29 | #if ($model.licenses && !$model.licenses.isEmpty()) 30 | 31 | #foreach($l in $model.licenses) 32 | 33 | 34 | ${l.name} 35 | ${l.url} 36 | ${l.distribution} 37 | #end 38 | 39 | 40 | #end 41 | 42 | #if ($model.developers && !$model.developers.isEmpty()) 43 | #foreach($d in $model.developers) 44 | 45 | 46 | ${d.id} 47 | ${d.name}#if($d.email) 48 | 49 | ${d.email}#end#if($d.url) 50 | 51 | ${d.url}#end#if($d.organization) 52 | 53 | ${d.organization}#end#if($d.organizationUrl) 54 | 55 | ${d.organizationUrl}#end 56 | 57 | #end 58 | 59 | 60 | #end 61 | 62 | 63 | #foreach($d in $model.dependencyManagement.dependencies) 64 | 65 | 66 | ${d.groupId} 67 | ${d.artifactId} 68 | ${d.version}#if( $d.scope && $!d.scope != '' ) 69 | 70 | ${d.scope}#end#if( $d.type && $!d.type != '' && $!d.type != 'jar' && $!d.type != 'bundle') 71 | 72 | ${d.type}#end#if( $d.classifier && $!d.classifier != '' ) 73 | 74 | ${d.classifier}#end#if( $d.exclusions && $d.exclusions.size() > 0 ) 75 | 76 | #foreach( $e in $d.exclusions ) 77 | 78 | 79 | ${e.groupId} 80 | ${e.artifactId} 81 | #end 82 | 83 | #end 84 | 85 | #end 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/config/eclipse-java-style.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | -------------------------------------------------------------------------------- /src/config/pomSortOrder.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | -------------------------------------------------------------------------------- /src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright ${license.git.copyrightYears} The Feign Authors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 4 | in compliance with the License. You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License 9 | is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 10 | or implied. See the License for the specific language governing permissions and limitations under 11 | the License. 12 | -------------------------------------------------------------------------------- /src/main/java/feign/error/AnnotationErrorDecoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Response; 17 | import feign.codec.Decoder; 18 | import feign.codec.ErrorDecoder; 19 | import java.lang.reflect.Method; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.Optional; 23 | import static feign.Feign.configKey; 24 | 25 | public class AnnotationErrorDecoder implements ErrorDecoder { 26 | 27 | private final Map errorHandlerMap; 28 | private final ErrorDecoder defaultDecoder; 29 | 30 | 31 | AnnotationErrorDecoder(Map errorHandlerMap, 32 | ErrorDecoder defaultDecoder) { 33 | this.errorHandlerMap = errorHandlerMap; 34 | this.defaultDecoder = defaultDecoder; 35 | } 36 | 37 | @Override 38 | public Exception decode(String methodKey, Response response) { 39 | if (errorHandlerMap.containsKey(methodKey)) { 40 | return errorHandlerMap.get(methodKey).decode(response); 41 | } 42 | return defaultDecoder.decode(methodKey, response); 43 | } 44 | 45 | 46 | public static AnnotationErrorDecoder.Builder builderFor(Class apiType) { 47 | return new Builder(apiType); 48 | } 49 | 50 | public static class Builder { 51 | private final Class apiType; 52 | private ErrorDecoder defaultDecoder = new ErrorDecoder.Default(); 53 | private Decoder responseBodyDecoder = new Decoder.Default(); 54 | 55 | 56 | public Builder(Class apiType) { 57 | this.apiType = apiType; 58 | } 59 | 60 | public Builder withDefaultDecoder(ErrorDecoder defaultDecoder) { 61 | this.defaultDecoder = defaultDecoder; 62 | return this; 63 | } 64 | 65 | public Builder withResponseBodyDecoder(Decoder responseBodyDecoder) { 66 | this.responseBodyDecoder = responseBodyDecoder; 67 | return this; 68 | } 69 | 70 | public AnnotationErrorDecoder build() { 71 | Map errorHandlerMap = generateErrorHandlerMapFromApi(apiType); 72 | return new AnnotationErrorDecoder(errorHandlerMap, defaultDecoder); 73 | } 74 | 75 | Map generateErrorHandlerMapFromApi(Class apiType) { 76 | 77 | ExceptionGenerator classLevelDefault = new ExceptionGenerator.Builder() 78 | .withResponseBodyDecoder(responseBodyDecoder) 79 | .withExceptionType(ErrorHandling.NO_DEFAULT.class) 80 | .build(); 81 | Map classLevelStatusCodeDefinitions = 82 | new HashMap(); 83 | 84 | Optional classLevelErrorHandling = 85 | readErrorHandlingIncludingInherited(apiType); 86 | if (classLevelErrorHandling.isPresent()) { 87 | ErrorHandlingDefinition classErrorHandlingDefinition = 88 | readAnnotation(classLevelErrorHandling.get(), responseBodyDecoder); 89 | classLevelDefault = classErrorHandlingDefinition.defaultThrow; 90 | classLevelStatusCodeDefinitions = classErrorHandlingDefinition.statusCodesMap; 91 | } 92 | 93 | Map methodErrorHandlerMap = 94 | new HashMap(); 95 | for (Method method : apiType.getMethods()) { 96 | if (method.isAnnotationPresent(ErrorHandling.class)) { 97 | ErrorHandlingDefinition methodErrorHandling = 98 | readAnnotation(method.getAnnotation(ErrorHandling.class), responseBodyDecoder); 99 | ExceptionGenerator methodDefault = methodErrorHandling.defaultThrow; 100 | if (methodDefault.getExceptionType().equals(ErrorHandling.NO_DEFAULT.class)) { 101 | methodDefault = classLevelDefault; 102 | } 103 | 104 | MethodErrorHandler methodErrorHandler = 105 | new MethodErrorHandler(methodErrorHandling.statusCodesMap, 106 | classLevelStatusCodeDefinitions, methodDefault); 107 | 108 | methodErrorHandlerMap.put(configKey(apiType, method), methodErrorHandler); 109 | } 110 | } 111 | 112 | return methodErrorHandlerMap; 113 | } 114 | 115 | Optional readErrorHandlingIncludingInherited(Class apiType) { 116 | if (apiType.isAnnotationPresent(ErrorHandling.class)) { 117 | return Optional.of(apiType.getAnnotation(ErrorHandling.class)); 118 | } 119 | for (Class parentInterface : apiType.getInterfaces()) { 120 | Optional errorHandling = 121 | readErrorHandlingIncludingInherited(parentInterface); 122 | if (errorHandling.isPresent()) { 123 | return errorHandling; 124 | } 125 | } 126 | // Finally, if there's a superclass that isn't Object check if the superclass has anything 127 | if (!apiType.isInterface() && !apiType.getSuperclass().equals(Object.class)) { 128 | return readErrorHandlingIncludingInherited(apiType.getSuperclass()); 129 | } 130 | return Optional.empty(); 131 | } 132 | 133 | static ErrorHandlingDefinition readAnnotation(ErrorHandling errorHandling, 134 | Decoder responseBodyDecoder) { 135 | ExceptionGenerator defaultException = new ExceptionGenerator.Builder() 136 | .withResponseBodyDecoder(responseBodyDecoder) 137 | .withExceptionType(errorHandling.defaultException()) 138 | .build(); 139 | Map statusCodesDefinition = 140 | new HashMap(); 141 | 142 | for (ErrorCodes statusCodeDefinition : errorHandling.codeSpecific()) { 143 | for (int statusCode : statusCodeDefinition.codes()) { 144 | if (statusCodesDefinition.containsKey(statusCode)) { 145 | throw new IllegalStateException( 146 | "Status Code [" + statusCode + "] " + 147 | "has already been declared to throw [" 148 | + statusCodesDefinition.get(statusCode).getExceptionType().getName() + "] " + 149 | "and [" + statusCodeDefinition.generate() + "] - dupe definition"); 150 | } 151 | statusCodesDefinition.put(statusCode, 152 | new ExceptionGenerator.Builder() 153 | .withResponseBodyDecoder(responseBodyDecoder) 154 | .withExceptionType(statusCodeDefinition.generate()) 155 | .build()); 156 | } 157 | } 158 | 159 | return new ErrorHandlingDefinition(defaultException, statusCodesDefinition); 160 | } 161 | 162 | private static class ErrorHandlingDefinition { 163 | private final ExceptionGenerator defaultThrow; 164 | private final Map statusCodesMap; 165 | 166 | 167 | private ErrorHandlingDefinition(ExceptionGenerator defaultThrow, 168 | Map statusCodesMap) { 169 | this.defaultThrow = defaultThrow; 170 | this.statusCodesMap = statusCodesMap; 171 | } 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/main/java/feign/error/ErrorCodes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | public @interface ErrorCodes { 17 | int[] codes(); 18 | 19 | Class generate(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/feign/error/ErrorHandling.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Response; 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Inherited; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | @Inherited 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target({ElementType.TYPE, ElementType.METHOD}) 26 | public @interface ErrorHandling { 27 | ErrorCodes[] codeSpecific() default {}; 28 | 29 | Class defaultException() default NO_DEFAULT.class; 30 | 31 | final class NO_DEFAULT extends Exception { 32 | @FeignExceptionConstructor 33 | public NO_DEFAULT(@ResponseBody Response response) { 34 | super("Endpoint responded with " + response.status() + ", reason: " + response.reason()); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/feign/error/ExceptionGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Request; 17 | import feign.Response; 18 | import feign.Types; 19 | import feign.codec.DecodeException; 20 | import feign.codec.Decoder; 21 | import java.io.IOException; 22 | import java.lang.annotation.Annotation; 23 | import java.lang.reflect.Constructor; 24 | import java.lang.reflect.InvocationTargetException; 25 | import java.lang.reflect.Type; 26 | import java.util.Arrays; 27 | import java.util.Collection; 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | import static feign.Util.checkState; 31 | 32 | class ExceptionGenerator { 33 | 34 | private static final Response TEST_RESPONSE; 35 | 36 | static { 37 | Map> testHeaders = new HashMap>(); 38 | testHeaders.put("TestHeader", Arrays.asList("header-value")); 39 | 40 | TEST_RESPONSE = Response.builder() 41 | .status(500) 42 | .body((Response.Body) null) 43 | .headers(testHeaders) 44 | .request(Request.create(Request.HttpMethod.GET, "http://test", testHeaders, 45 | Request.Body.empty(), null)) 46 | .build(); 47 | } 48 | 49 | private final Integer bodyIndex; 50 | private final Integer requestIndex; 51 | private final Integer headerMapIndex; 52 | private final Integer numOfParams; 53 | private final Type bodyType; 54 | private final Class exceptionType; 55 | private final Decoder bodyDecoder; 56 | 57 | ExceptionGenerator(Integer bodyIndex, Integer requestIndex, Integer headerMapIndex, 58 | Integer numOfParams, Type bodyType, 59 | Class exceptionType, Decoder bodyDecoder) { 60 | this.bodyIndex = bodyIndex; 61 | this.requestIndex = requestIndex; 62 | this.headerMapIndex = headerMapIndex; 63 | this.numOfParams = numOfParams; 64 | this.bodyType = bodyType; 65 | this.exceptionType = exceptionType; 66 | this.bodyDecoder = bodyDecoder; 67 | } 68 | 69 | 70 | Exception createException(Response response) throws InvocationTargetException, 71 | NoSuchMethodException, InstantiationException, IllegalAccessException { 72 | 73 | Class[] paramClasses = new Class[numOfParams]; 74 | Object[] paramValues = new Object[numOfParams]; 75 | if (bodyIndex >= 0) { 76 | paramClasses[bodyIndex] = Types.getRawType(bodyType); 77 | paramValues[bodyIndex] = resolveBody(response); 78 | } 79 | if (requestIndex >= 0) { 80 | paramClasses[requestIndex] = Request.class; 81 | paramValues[requestIndex] = response.request(); 82 | } 83 | if (headerMapIndex >= 0) { 84 | paramValues[headerMapIndex] = response.headers(); 85 | paramClasses[headerMapIndex] = Map.class; 86 | } 87 | return exceptionType.getConstructor(paramClasses) 88 | .newInstance(paramValues); 89 | 90 | } 91 | 92 | Class getExceptionType() { 93 | return exceptionType; 94 | } 95 | 96 | private Object resolveBody(Response response) { 97 | if (bodyType instanceof Class && ((Class) bodyType).isInstance(response)) { 98 | return response; 99 | } 100 | try { 101 | return bodyDecoder.decode(response, bodyType); 102 | } catch (IOException e) { 103 | // How do we log this? 104 | return null; 105 | } catch (DecodeException e) { 106 | // How do we log this? 107 | return null; 108 | } 109 | } 110 | 111 | static class Builder { 112 | private Class exceptionType; 113 | private Decoder responseBodyDecoder; 114 | 115 | public Builder withExceptionType(Class exceptionType) { 116 | this.exceptionType = exceptionType; 117 | return this; 118 | } 119 | 120 | public Builder withResponseBodyDecoder(Decoder bodyDecoder) { 121 | this.responseBodyDecoder = bodyDecoder; 122 | return this; 123 | } 124 | 125 | public ExceptionGenerator build() { 126 | Constructor constructor = getConstructor(exceptionType); 127 | Type[] parameterTypes = constructor.getGenericParameterTypes(); 128 | Annotation[][] parametersAnnotations = constructor.getParameterAnnotations(); 129 | 130 | Integer bodyIndex = -1; 131 | Integer requestIndex = -1; 132 | Integer headerMapIndex = -1; 133 | Integer numOfParams = parameterTypes.length; 134 | Type bodyType = null; 135 | 136 | for (int i = 0; i < parameterTypes.length; i++) { 137 | Annotation[] paramAnnotations = parametersAnnotations[i]; 138 | boolean foundAnnotation = false; 139 | for (Annotation annotation : paramAnnotations) { 140 | if (annotation.annotationType().equals(ResponseHeaders.class)) { 141 | checkState(headerMapIndex == -1, 142 | "Cannot have two parameters tagged with @ResponseHeaders"); 143 | checkState(Types.getRawType(parameterTypes[i]).equals(Map.class), 144 | "Response Header map must be of type Map, but was %s", parameterTypes[i]); 145 | headerMapIndex = i; 146 | foundAnnotation = true; 147 | break; 148 | } 149 | } 150 | if (!foundAnnotation) { 151 | if (parameterTypes[i].equals(Request.class)) { 152 | checkState(requestIndex == -1, 153 | "Cannot have two parameters either without annotations or with object of type feign.Request"); 154 | requestIndex = i; 155 | } else { 156 | checkState(bodyIndex == -1, 157 | "Cannot have two parameters either without annotations or with @ResponseBody annotation"); 158 | bodyIndex = i; 159 | bodyType = parameterTypes[i]; 160 | } 161 | } 162 | } 163 | 164 | ExceptionGenerator generator = new ExceptionGenerator( 165 | bodyIndex, 166 | requestIndex, 167 | headerMapIndex, 168 | numOfParams, 169 | bodyType, 170 | exceptionType, 171 | responseBodyDecoder); 172 | 173 | validateGeneratorCanBeUsedToGenerateExceptions(generator); 174 | return generator; 175 | } 176 | 177 | private void validateGeneratorCanBeUsedToGenerateExceptions(ExceptionGenerator generator) { 178 | try { 179 | generator.createException(TEST_RESPONSE); 180 | } catch (Exception e) { 181 | throw new IllegalStateException( 182 | "Cannot generate exception - check constructor parameter types (are headers Map> or is something causing an exception on construction?)", 183 | e); 184 | } 185 | } 186 | 187 | private Constructor getConstructor(Class exceptionClass) { 188 | Constructor preferredConstructor = null; 189 | for (Constructor constructor : exceptionClass.getConstructors()) { 190 | 191 | FeignExceptionConstructor exceptionConstructor = 192 | constructor.getAnnotation(FeignExceptionConstructor.class); 193 | if (exceptionConstructor == null) { 194 | continue; 195 | } 196 | Class[] parameterTypes = constructor.getParameterTypes(); 197 | if (parameterTypes.length == 0) { 198 | continue; 199 | } 200 | if (preferredConstructor == null) { 201 | preferredConstructor = (Constructor) constructor; 202 | } else { 203 | throw new IllegalStateException( 204 | "Too many constructors marked with @FeignExceptionConstructor"); 205 | } 206 | } 207 | 208 | if (preferredConstructor == null) { 209 | try { 210 | return exceptionClass.getConstructor(); 211 | } catch (NoSuchMethodException e) { 212 | throw new IllegalStateException( 213 | "Cannot find any suitable constructor in class [" + exceptionClass.getName() 214 | + "] - did you forget to mark one with @FeignExceptionConstructor or at least have a public default constructor?", 215 | e); 216 | } 217 | } 218 | return preferredConstructor; 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /src/main/java/feign/error/FeignExceptionConstructor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Target({ElementType.CONSTRUCTOR}) 23 | public @interface FeignExceptionConstructor { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/feign/error/MethodErrorHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Response; 17 | import java.lang.reflect.InvocationTargetException; 18 | import java.util.Map; 19 | 20 | class MethodErrorHandler { 21 | 22 | private final Map methodLevelExceptionsByCode; 23 | private final Map classLevelExceptionsByCode; 24 | private final ExceptionGenerator defaultException; 25 | 26 | MethodErrorHandler(Map methodLevelExceptionsByCode, 27 | Map classLevelExceptionsByCode, 28 | ExceptionGenerator defaultException) { 29 | this.methodLevelExceptionsByCode = methodLevelExceptionsByCode; 30 | this.classLevelExceptionsByCode = classLevelExceptionsByCode; 31 | this.defaultException = defaultException; 32 | } 33 | 34 | 35 | public Exception decode(Response response) { 36 | ExceptionGenerator constructorDefinition = getConstructorDefinition(response); 37 | return createException(constructorDefinition, response); 38 | } 39 | 40 | private ExceptionGenerator getConstructorDefinition(Response response) { 41 | if (methodLevelExceptionsByCode.containsKey(response.status())) { 42 | return methodLevelExceptionsByCode.get(response.status()); 43 | } 44 | if (classLevelExceptionsByCode.containsKey(response.status())) { 45 | return classLevelExceptionsByCode.get(response.status()); 46 | } 47 | return defaultException; 48 | } 49 | 50 | protected Exception createException(ExceptionGenerator constructorDefinition, Response response) { 51 | try { 52 | return constructorDefinition.createException(response); 53 | } catch (IllegalAccessException e) { 54 | throw new IllegalStateException("Cannot access constructor", e); 55 | } catch (InstantiationException e) { 56 | throw new IllegalStateException("Cannot instantiate exception with constructor", e); 57 | } catch (InvocationTargetException e) { 58 | throw new IllegalStateException("Cannot invoke constructor", e); 59 | } catch (NoSuchMethodException e) { 60 | throw new IllegalStateException("Constructor does not exist", e); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/feign/error/ResponseBody.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Target({ElementType.PARAMETER}) 23 | public @interface ResponseBody { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/feign/error/ResponseHeaders.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import java.lang.annotation.ElementType; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | @Retention(RetentionPolicy.RUNTIME) 22 | @Target({ElementType.PARAMETER}) 23 | public @interface ResponseHeaders { 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AbstractAnnotationErrorDecoderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Request; 17 | import feign.Response; 18 | import java.nio.charset.StandardCharsets; 19 | import java.util.Collection; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import static feign.Feign.configKey; 23 | 24 | public abstract class AbstractAnnotationErrorDecoderTest { 25 | 26 | 27 | 28 | public abstract Class interfaceAtTest(); 29 | 30 | String feignConfigKey(String methodName) throws NoSuchMethodException { 31 | return configKey(interfaceAtTest(), interfaceAtTest().getMethod(methodName)); 32 | } 33 | 34 | Response testResponse(int status) { 35 | return testResponse(status, "default Response body"); 36 | } 37 | 38 | Response testResponse(int status, String body) { 39 | return testResponse(status, body, new HashMap>()); 40 | } 41 | 42 | Response testResponse(int status, String body, Map> headers) { 43 | return Response.builder() 44 | .status(status) 45 | .body(body, StandardCharsets.UTF_8) 46 | .headers(headers) 47 | .request(Request.create(Request.HttpMethod.GET, "http://test", headers, 48 | Request.Body.empty(), null)) 49 | .build(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderClassInheritanceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1NotFoundException; 18 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.UnauthenticatedOrUnauthorizedException; 19 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method2NotFoundException; 20 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ServeErrorException; 21 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelNotFoundException; 22 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method1DefaultException; 23 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.Method3DefaultException; 24 | import feign.error.AnnotationErrorDecoderClassInheritanceTest.ParentInterfaceWithErrorHandling.ClassLevelDefaultException; 25 | import java.util.Arrays; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.junit.runners.Parameterized; 29 | import org.junit.runners.Parameterized.Parameter; 30 | import org.junit.runners.Parameterized.Parameters; 31 | 32 | @RunWith(Parameterized.class) 33 | public class AnnotationErrorDecoderClassInheritanceTest extends 34 | AbstractAnnotationErrorDecoderTest { 35 | 36 | @Override 37 | public Class interfaceAtTest() { 38 | return GrandChild.class; 39 | } 40 | 41 | @Parameters( 42 | name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})") 43 | public static Iterable data() { 44 | return Arrays.asList(new Object[][] { 45 | {"Test Code Specific At Method", 404, "method1Test", Method1NotFoundException.class}, 46 | {"Test Code Specific At Method", 401, "method1Test", 47 | UnauthenticatedOrUnauthorizedException.class}, 48 | {"Test Code Specific At Method", 404, "method2Test", Method2NotFoundException.class}, 49 | {"Test Code Specific At Method", 500, "method2Test", ServeErrorException.class}, 50 | {"Test Code Specific At Method", 503, "method2Test", ServeErrorException.class}, 51 | {"Test Code Specific At Class", 403, "method1Test", 52 | UnauthenticatedOrUnauthorizedException.class}, 53 | {"Test Code Specific At Class", 403, "method2Test", 54 | UnauthenticatedOrUnauthorizedException.class}, 55 | {"Test Code Specific At Class", 404, "method3Test", ClassLevelNotFoundException.class}, 56 | {"Test Code Specific At Class", 403, "method3Test", 57 | UnauthenticatedOrUnauthorizedException.class}, 58 | {"Test Default At Method", 504, "method1Test", Method1DefaultException.class}, 59 | {"Test Default At Method", 504, "method3Test", Method3DefaultException.class}, 60 | {"Test Default At Class", 504, "method2Test", ClassLevelDefaultException.class}, 61 | }); 62 | } 63 | 64 | @Parameter // first data value (0) is default 65 | public String testType; 66 | 67 | @Parameter(1) 68 | public int errorCode; 69 | 70 | @Parameter(2) 71 | public String method; 72 | 73 | @Parameter(3) 74 | public Class expectedExceptionClass; 75 | 76 | @Test 77 | public void test() throws Exception { 78 | AnnotationErrorDecoder decoder = 79 | AnnotationErrorDecoder.builderFor(GrandChild.class).build(); 80 | 81 | assertThat(decoder.decode(feignConfigKey(method), testResponse(errorCode)).getClass()) 82 | .isEqualTo(expectedExceptionClass); 83 | } 84 | 85 | @ErrorHandling(codeSpecific = { 86 | @ErrorCodes(codes = {404}, generate = ClassLevelNotFoundException.class), 87 | @ErrorCodes(codes = {403}, generate = UnauthenticatedOrUnauthorizedException.class) 88 | }, 89 | defaultException = ClassLevelDefaultException.class) 90 | interface ParentInterfaceWithErrorHandling { 91 | @ErrorHandling(codeSpecific = { 92 | @ErrorCodes(codes = {404}, generate = Method1NotFoundException.class), 93 | @ErrorCodes(codes = {401}, generate = UnauthenticatedOrUnauthorizedException.class) 94 | }, 95 | defaultException = Method1DefaultException.class) 96 | void method1Test(); 97 | 98 | @ErrorHandling(codeSpecific = { 99 | @ErrorCodes(codes = {404}, generate = Method2NotFoundException.class), 100 | @ErrorCodes(codes = {500, 503}, generate = ServeErrorException.class) 101 | }) 102 | void method2Test(); 103 | 104 | @ErrorHandling( 105 | defaultException = Method3DefaultException.class) 106 | void method3Test(); 107 | 108 | class ClassLevelDefaultException extends Exception { 109 | } 110 | class Method1DefaultException extends Exception { 111 | } 112 | class Method3DefaultException extends Exception { 113 | } 114 | class Method1NotFoundException extends Exception { 115 | } 116 | class Method2NotFoundException extends Exception { 117 | } 118 | class ClassLevelNotFoundException extends Exception { 119 | } 120 | class UnauthenticatedOrUnauthorizedException extends Exception { 121 | } 122 | class ServeErrorException extends Exception { 123 | } 124 | } 125 | 126 | abstract class Child implements ParentInterfaceWithErrorHandling { 127 | } 128 | 129 | abstract class GrandChild extends Child { 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderExceptionConstructorsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Request; 17 | import feign.codec.Decoder; 18 | import feign.optionals.OptionalDecoder; 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Parameterized; 22 | import org.junit.runners.Parameterized.Parameters; 23 | import org.junit.runners.Parameterized.Parameter; 24 | import java.util.*; 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors; 27 | import static feign.error.AnnotationErrorDecoderExceptionConstructorsTest.TestClientInterfaceWithDifferentExceptionConstructors.*; 28 | 29 | @RunWith(Parameterized.class) 30 | public class AnnotationErrorDecoderExceptionConstructorsTest extends 31 | AbstractAnnotationErrorDecoderTest { 32 | 33 | 34 | private static final String NO_BODY = "NO BODY"; 35 | private static final Object NULL_BODY = null; 36 | private static final String NON_NULL_BODY = "A GIVEN BODY"; 37 | private static final feign.Request REQUEST = feign.Request.create(feign.Request.HttpMethod.GET, 38 | "http://test", Collections.emptyMap(), Request.Body.empty(), null); 39 | private static final feign.Request NO_REQUEST = null; 40 | private static final Map> NON_NULL_HEADERS = 41 | new HashMap>(); 42 | private static final Map> NO_HEADERS = null; 43 | 44 | 45 | @Override 46 | public Class interfaceAtTest() { 47 | return TestClientInterfaceWithDifferentExceptionConstructors.class; 48 | } 49 | 50 | @Parameters( 51 | name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})") 52 | public static Iterable data() { 53 | return Arrays.asList(new Object[][] { 54 | {"Test Default Constructor", 500, DefaultConstructorException.class, NO_REQUEST, NO_BODY, 55 | NO_HEADERS}, 56 | {"test Default Constructor", 501, DeclaredDefaultConstructorException.class, NO_REQUEST, 57 | NO_BODY, 58 | NO_HEADERS}, 59 | {"test Default Constructor", 502, 60 | DeclaredDefaultConstructorWithOtherConstructorsException.class, NO_REQUEST, NO_BODY, 61 | NO_HEADERS}, 62 | {"test Declared Constructor", 503, DefinedConstructorWithNoAnnotationForBody.class, 63 | NO_REQUEST, 64 | NON_NULL_BODY, NO_HEADERS}, 65 | {"test Declared Constructor", 504, DefinedConstructorWithAnnotationForBody.class, 66 | NO_REQUEST, NON_NULL_BODY, NO_HEADERS}, 67 | {"test Declared Constructor", 505, DefinedConstructorWithAnnotationForBodyAndHeaders.class, 68 | NO_REQUEST, NON_NULL_BODY, NON_NULL_HEADERS}, 69 | {"test Declared Constructor", 506, 70 | DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder.class, NO_REQUEST, 71 | NON_NULL_BODY, 72 | NON_NULL_HEADERS}, 73 | {"test Declared Constructor", 507, DefinedConstructorWithAnnotationForHeaders.class, 74 | NO_REQUEST, NO_BODY, NON_NULL_HEADERS}, 75 | {"test Declared Constructor", 508, 76 | DefinedConstructorWithAnnotationForHeadersButNotForBody.class, NO_REQUEST, 77 | NON_NULL_BODY, 78 | NON_NULL_HEADERS}, 79 | {"test Declared Constructor", 509, 80 | DefinedConstructorWithAnnotationForNonSupportedBody.class, NO_REQUEST, NULL_BODY, 81 | NO_HEADERS}, 82 | {"test Declared Constructor", 510, 83 | DefinedConstructorWithAnnotationForOptionalBody.class, NO_REQUEST, 84 | Optional.of(NON_NULL_BODY), 85 | NO_HEADERS}, 86 | {"test Declared Constructor", 511, 87 | DefinedConstructorWithRequest.class, REQUEST, NO_BODY, 88 | NO_HEADERS}, 89 | {"test Declared Constructor", 512, 90 | DefinedConstructorWithRequestAndResponseBody.class, REQUEST, NON_NULL_BODY, 91 | NO_HEADERS}, 92 | {"test Declared Constructor", 513, 93 | DefinedConstructorWithRequestAndAnnotationForResponseBody.class, REQUEST, NON_NULL_BODY, 94 | NO_HEADERS}, 95 | {"test Declared Constructor", 514, 96 | DefinedConstructorWithRequestAndResponseHeadersAndResponseBody.class, REQUEST, 97 | NON_NULL_BODY, 98 | NON_NULL_HEADERS}, 99 | {"test Declared Constructor", 515, 100 | DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody.class, REQUEST, 101 | Optional.of(NON_NULL_BODY), 102 | NON_NULL_HEADERS} 103 | }); 104 | } 105 | 106 | @Parameter // first data value (0) is default 107 | public String testName; 108 | 109 | @Parameter(1) 110 | public int errorCode; 111 | 112 | @Parameter(2) 113 | public Class expectedExceptionClass; 114 | 115 | @Parameter(3) 116 | public Object expectedRequest; 117 | 118 | @Parameter(4) 119 | public Object expectedBody; 120 | 121 | @Parameter(5) 122 | public Map> expectedHeaders; 123 | 124 | @Test 125 | public void test() throws Exception { 126 | AnnotationErrorDecoder decoder = AnnotationErrorDecoder 127 | .builderFor(TestClientInterfaceWithDifferentExceptionConstructors.class) 128 | .withResponseBodyDecoder(new OptionalDecoder(new Decoder.Default())) 129 | .build(); 130 | 131 | Exception genericException = decoder.decode(feignConfigKey("method1Test"), 132 | testResponse(errorCode, NON_NULL_BODY, NON_NULL_HEADERS)); 133 | 134 | assertThat(genericException).isInstanceOf(expectedExceptionClass); 135 | 136 | ParametersException exception = (ParametersException) genericException; 137 | assertThat(exception.body()).isEqualTo(expectedBody); 138 | assertThat(exception.headers()).isEqualTo(expectedHeaders); 139 | } 140 | 141 | @Test 142 | public void testIfExceptionIsNotInTheList() throws Exception { 143 | AnnotationErrorDecoder decoder = AnnotationErrorDecoder 144 | .builderFor(TestClientInterfaceWithDifferentExceptionConstructors.class) 145 | .withResponseBodyDecoder(new OptionalDecoder(new Decoder.Default())) 146 | .build(); 147 | 148 | Exception genericException = decoder.decode(feignConfigKey("method1Test"), 149 | testResponse(-1, NON_NULL_BODY, NON_NULL_HEADERS)); 150 | 151 | assertThat(genericException) 152 | .isInstanceOf(ErrorHandling.NO_DEFAULT.class) 153 | .hasMessage("Endpoint responded with -1, reason: null"); 154 | } 155 | 156 | interface TestClientInterfaceWithDifferentExceptionConstructors { 157 | 158 | @ErrorHandling(codeSpecific = { 159 | @ErrorCodes(codes = {500}, generate = DefaultConstructorException.class), 160 | @ErrorCodes(codes = {501}, generate = DeclaredDefaultConstructorException.class), 161 | @ErrorCodes(codes = {502}, 162 | generate = DeclaredDefaultConstructorWithOtherConstructorsException.class), 163 | @ErrorCodes(codes = {503}, generate = DefinedConstructorWithNoAnnotationForBody.class), 164 | @ErrorCodes(codes = {504}, generate = DefinedConstructorWithAnnotationForBody.class), 165 | @ErrorCodes(codes = {505}, 166 | generate = DefinedConstructorWithAnnotationForBodyAndHeaders.class), 167 | @ErrorCodes(codes = {506}, 168 | generate = DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder.class), 169 | @ErrorCodes(codes = {507}, generate = DefinedConstructorWithAnnotationForHeaders.class), 170 | @ErrorCodes(codes = {508}, 171 | generate = DefinedConstructorWithAnnotationForHeadersButNotForBody.class), 172 | @ErrorCodes(codes = {509}, 173 | generate = DefinedConstructorWithAnnotationForNonSupportedBody.class), 174 | @ErrorCodes(codes = {510}, 175 | generate = DefinedConstructorWithAnnotationForOptionalBody.class), 176 | @ErrorCodes(codes = {511}, 177 | generate = DefinedConstructorWithRequest.class), 178 | @ErrorCodes(codes = {512}, 179 | generate = DefinedConstructorWithRequestAndResponseBody.class), 180 | @ErrorCodes(codes = {513}, 181 | generate = DefinedConstructorWithRequestAndAnnotationForResponseBody.class), 182 | @ErrorCodes(codes = {514}, 183 | generate = DefinedConstructorWithRequestAndResponseHeadersAndResponseBody.class), 184 | @ErrorCodes(codes = {515}, 185 | generate = DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody.class) 186 | }) 187 | void method1Test(); 188 | 189 | class ParametersException extends Exception { 190 | public Object body() { 191 | return NO_BODY; 192 | } 193 | 194 | public feign.Request request() { 195 | return null; 196 | } 197 | 198 | public Map> headers() { 199 | return null; 200 | } 201 | } 202 | class DefaultConstructorException extends ParametersException { 203 | } 204 | 205 | class DeclaredDefaultConstructorException extends ParametersException { 206 | public DeclaredDefaultConstructorException() {} 207 | } 208 | 209 | class DeclaredDefaultConstructorWithOtherConstructorsException extends ParametersException { 210 | public DeclaredDefaultConstructorWithOtherConstructorsException() {} 211 | 212 | public DeclaredDefaultConstructorWithOtherConstructorsException(TestPojo testPojo) { 213 | throw new UnsupportedOperationException("Should not be called"); 214 | } 215 | 216 | public DeclaredDefaultConstructorWithOtherConstructorsException(Throwable cause) { 217 | throw new UnsupportedOperationException("Should not be called"); 218 | } 219 | 220 | public DeclaredDefaultConstructorWithOtherConstructorsException(String message, 221 | Throwable cause) { 222 | throw new UnsupportedOperationException("Should not be called"); 223 | } 224 | } 225 | 226 | class DefinedConstructorWithNoAnnotationForBody extends ParametersException { 227 | String body; 228 | 229 | public DefinedConstructorWithNoAnnotationForBody() { 230 | throw new UnsupportedOperationException("Should not be called"); 231 | } 232 | 233 | @FeignExceptionConstructor 234 | public DefinedConstructorWithNoAnnotationForBody(String body) { 235 | this.body = body; 236 | } 237 | 238 | public DefinedConstructorWithNoAnnotationForBody(TestPojo testPojo) { 239 | throw new UnsupportedOperationException("Should not be called"); 240 | } 241 | 242 | @Override 243 | public Object body() { 244 | return body; 245 | } 246 | 247 | } 248 | 249 | class DefinedConstructorWithRequest extends ParametersException { 250 | feign.Request request; 251 | 252 | public DefinedConstructorWithRequest() { 253 | throw new UnsupportedOperationException("Should not be called"); 254 | } 255 | 256 | @FeignExceptionConstructor 257 | public DefinedConstructorWithRequest(feign.Request request) { 258 | this.request = request; 259 | } 260 | 261 | public DefinedConstructorWithRequest(TestPojo testPojo) { 262 | throw new UnsupportedOperationException("Should not be called"); 263 | } 264 | 265 | @Override 266 | public feign.Request request() { 267 | return request; 268 | } 269 | 270 | } 271 | 272 | class DefinedConstructorWithRequestAndResponseBody extends ParametersException { 273 | feign.Request request; 274 | String body; 275 | 276 | public DefinedConstructorWithRequestAndResponseBody() { 277 | throw new UnsupportedOperationException("Should not be called"); 278 | } 279 | 280 | @FeignExceptionConstructor 281 | public DefinedConstructorWithRequestAndResponseBody(feign.Request request, String body) { 282 | this.request = request; 283 | this.body = body; 284 | } 285 | 286 | public DefinedConstructorWithRequestAndResponseBody(TestPojo testPojo) { 287 | throw new UnsupportedOperationException("Should not be called"); 288 | } 289 | 290 | @Override 291 | public feign.Request request() { 292 | return request; 293 | } 294 | 295 | @Override 296 | public String body() { 297 | return body; 298 | } 299 | } 300 | 301 | class DefinedConstructorWithRequestAndAnnotationForResponseBody extends ParametersException { 302 | feign.Request request; 303 | String body; 304 | 305 | public DefinedConstructorWithRequestAndAnnotationForResponseBody() { 306 | throw new UnsupportedOperationException("Should not be called"); 307 | } 308 | 309 | @FeignExceptionConstructor 310 | public DefinedConstructorWithRequestAndAnnotationForResponseBody(feign.Request request, 311 | @ResponseBody String body) { 312 | this.request = request; 313 | this.body = body; 314 | } 315 | 316 | public DefinedConstructorWithRequestAndAnnotationForResponseBody(TestPojo testPojo) { 317 | throw new UnsupportedOperationException("Should not be called"); 318 | } 319 | 320 | @Override 321 | public feign.Request request() { 322 | return request; 323 | } 324 | 325 | @Override 326 | public String body() { 327 | return body; 328 | } 329 | } 330 | 331 | class DefinedConstructorWithRequestAndResponseHeadersAndResponseBody 332 | extends ParametersException { 333 | feign.Request request; 334 | String body; 335 | Map headers; 336 | 337 | public DefinedConstructorWithRequestAndResponseHeadersAndResponseBody() { 338 | throw new UnsupportedOperationException("Should not be called"); 339 | } 340 | 341 | @FeignExceptionConstructor 342 | public DefinedConstructorWithRequestAndResponseHeadersAndResponseBody(feign.Request request, 343 | @ResponseHeaders Map headers, 344 | @ResponseBody String body) { 345 | this.request = request; 346 | this.body = body; 347 | this.headers = headers; 348 | } 349 | 350 | public DefinedConstructorWithRequestAndResponseHeadersAndResponseBody(TestPojo testPojo) { 351 | throw new UnsupportedOperationException("Should not be called"); 352 | } 353 | 354 | @Override 355 | public feign.Request request() { 356 | return request; 357 | } 358 | 359 | @Override 360 | public Map headers() { 361 | return headers; 362 | } 363 | 364 | @Override 365 | public String body() { 366 | return body; 367 | } 368 | } 369 | 370 | class DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody 371 | extends ParametersException { 372 | feign.Request request; 373 | Optional body; 374 | Map headers; 375 | 376 | public DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody() { 377 | throw new UnsupportedOperationException("Should not be called"); 378 | } 379 | 380 | @FeignExceptionConstructor 381 | public DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody( 382 | feign.Request request, 383 | @ResponseHeaders Map headers, 384 | @ResponseBody Optional body) { 385 | this.request = request; 386 | this.body = body; 387 | this.headers = headers; 388 | } 389 | 390 | public DefinedConstructorWithRequestAndResponseHeadersAndOptionalResponseBody( 391 | TestPojo testPojo) { 392 | throw new UnsupportedOperationException("Should not be called"); 393 | } 394 | 395 | @Override 396 | public feign.Request request() { 397 | return request; 398 | } 399 | 400 | @Override 401 | public Map headers() { 402 | return headers; 403 | } 404 | 405 | @Override 406 | public Object body() { 407 | return body; 408 | } 409 | } 410 | 411 | class DefinedConstructorWithAnnotationForBody extends ParametersException { 412 | String body; 413 | 414 | public DefinedConstructorWithAnnotationForBody() { 415 | throw new UnsupportedOperationException("Should not be called"); 416 | } 417 | 418 | @FeignExceptionConstructor 419 | public DefinedConstructorWithAnnotationForBody(@ResponseBody String body) { 420 | this.body = body; 421 | } 422 | 423 | @Override 424 | public Object body() { 425 | return body; 426 | } 427 | } 428 | 429 | class DefinedConstructorWithAnnotationForOptionalBody extends ParametersException { 430 | Optional body; 431 | 432 | public DefinedConstructorWithAnnotationForOptionalBody() { 433 | throw new UnsupportedOperationException("Should not be called"); 434 | } 435 | 436 | @FeignExceptionConstructor 437 | public DefinedConstructorWithAnnotationForOptionalBody(@ResponseBody Optional body) { 438 | this.body = body; 439 | } 440 | 441 | @Override 442 | public Object body() { 443 | return body; 444 | } 445 | } 446 | 447 | class DefinedConstructorWithAnnotationForNonSupportedBody extends ParametersException { 448 | TestPojo body; 449 | 450 | @FeignExceptionConstructor 451 | public DefinedConstructorWithAnnotationForNonSupportedBody(@ResponseBody TestPojo body) { 452 | this.body = body; 453 | } 454 | 455 | @Override 456 | public Object body() { 457 | return body; 458 | } 459 | } 460 | 461 | class DefinedConstructorWithAnnotationForBodyAndHeaders extends ParametersException { 462 | String body; 463 | Map> headers; 464 | 465 | @FeignExceptionConstructor 466 | public DefinedConstructorWithAnnotationForBodyAndHeaders(@ResponseBody String body, 467 | @ResponseHeaders Map> headers) { 468 | this.body = body; 469 | this.headers = headers; 470 | } 471 | 472 | @Override 473 | public Object body() { 474 | return body; 475 | } 476 | 477 | @Override 478 | public Map> headers() { 479 | return headers; 480 | } 481 | } 482 | 483 | class DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder extends ParametersException { 484 | String body; 485 | Map> headers; 486 | 487 | @FeignExceptionConstructor 488 | public DefinedConstructorWithAnnotationForBodyAndHeadersSecondOrder( 489 | @ResponseHeaders Map> headers, @ResponseBody String body) { 490 | this.body = body; 491 | this.headers = headers; 492 | } 493 | 494 | @Override 495 | public Object body() { 496 | return body; 497 | } 498 | 499 | @Override 500 | public Map> headers() { 501 | return headers; 502 | } 503 | } 504 | 505 | class DefinedConstructorWithAnnotationForHeaders extends ParametersException { 506 | Map> headers; 507 | 508 | @FeignExceptionConstructor 509 | public DefinedConstructorWithAnnotationForHeaders( 510 | @ResponseHeaders Map> headers) { 511 | this.headers = headers; 512 | } 513 | 514 | @Override 515 | public Map> headers() { 516 | return headers; 517 | } 518 | } 519 | 520 | class DefinedConstructorWithAnnotationForHeadersButNotForBody extends ParametersException { 521 | String body; 522 | Map> headers; 523 | 524 | @FeignExceptionConstructor 525 | public DefinedConstructorWithAnnotationForHeadersButNotForBody( 526 | @ResponseHeaders Map> headers, String body) { 527 | this.body = body; 528 | this.headers = headers; 529 | } 530 | 531 | @Override 532 | public Object body() { 533 | return body; 534 | } 535 | 536 | @Override 537 | public Map> headers() { 538 | return headers; 539 | } 540 | } 541 | } 542 | } 543 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderIllegalInterfacesTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.junit.runner.Request; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Parameterized; 21 | import org.junit.runners.Parameterized.Parameters; 22 | import org.junit.runners.Parameterized.Parameter; 23 | import java.util.Arrays; 24 | import java.util.Collection; 25 | import java.util.Map; 26 | import static org.assertj.core.api.Assertions.assertThat; 27 | import static org.assertj.core.api.Assertions.fail; 28 | 29 | @RunWith(Parameterized.class) 30 | public class AnnotationErrorDecoderIllegalInterfacesTest { 31 | 32 | @Parameters( 33 | name = "{index}: When building interface ({0}) should return exception type ({1}) with message ({2})") 34 | public static Iterable data() { 35 | return Arrays.asList(new Object[][] { 36 | {IllegalTestClientInterfaceWithTooManyMappingsToSingleCode.class, 37 | IllegalStateException.class, "Status Code [404] has already been declared"}, 38 | {IllegalTestClientInterfaceWithExceptionWithTooManyConstructors.class, 39 | IllegalStateException.class, "Too many constructors"}, 40 | {IllegalTestClientInterfaceWithExceptionWithTooManyBodyParams.class, 41 | IllegalStateException.class, "Cannot have two parameters either without"}, 42 | {IllegalTestClientInterfaceWithExceptionWithTooManyHeaderParams.class, 43 | IllegalStateException.class, "Cannot have two parameters tagged"}, 44 | {IllegalTestClientInterfaceWithExceptionWithBadHeaderParams.class, 45 | IllegalStateException.class, "Cannot generate exception - check constructor"}, 46 | {IllegalTestClientInterfaceWithExceptionWithBadHeaderObjectParam.class, 47 | IllegalStateException.class, "Response Header map must be of type Map"}, 48 | {IllegalTestClientInterfaceWithExceptionWithTooManyRequestParams.class, 49 | IllegalStateException.class, "Cannot have two parameters either without"} 50 | }); 51 | } 52 | 53 | @Parameter // first data value (0) is default 54 | public Class testInterface; 55 | 56 | @Parameter(1) 57 | public Class expectedExceptionClass; 58 | 59 | @Parameter(2) 60 | public String messageStart; 61 | 62 | @Test 63 | public void test() throws Exception { 64 | try { 65 | AnnotationErrorDecoder.builderFor(testInterface).build(); 66 | fail("Should have thrown exception"); 67 | } catch (Exception e) { 68 | assertThat(e.getClass()).isEqualTo(expectedExceptionClass); 69 | assertThat(e.getMessage()).startsWith(messageStart); 70 | } 71 | } 72 | 73 | interface IllegalTestClientInterfaceWithTooManyMappingsToSingleCode { 74 | @ErrorHandling(codeSpecific = { 75 | @ErrorCodes(codes = {404}, generate = Exception.class), 76 | @ErrorCodes(codes = {404}, generate = Exception.class) 77 | }) 78 | void method1Test(); 79 | } 80 | 81 | interface IllegalTestClientInterfaceWithExceptionWithTooManyConstructors { 82 | @ErrorHandling(codeSpecific = { 83 | @ErrorCodes(codes = {404}, generate = BadException.class) 84 | }) 85 | void method1Test(); 86 | 87 | class BadException extends Exception { 88 | 89 | @FeignExceptionConstructor 90 | public BadException(String body) { 91 | 92 | } 93 | 94 | @FeignExceptionConstructor 95 | public BadException(String body, @ResponseHeaders Map> headers) { 96 | 97 | } 98 | } 99 | } 100 | 101 | interface IllegalTestClientInterfaceWithExceptionWithTooManyBodyParams { 102 | @ErrorHandling(codeSpecific = { 103 | @ErrorCodes(codes = {404}, generate = BadException.class) 104 | }) 105 | void method1Test(); 106 | 107 | class BadException extends Exception { 108 | 109 | @FeignExceptionConstructor 110 | public BadException(String body, @ResponseBody String otherBody) { 111 | 112 | } 113 | } 114 | } 115 | 116 | interface IllegalTestClientInterfaceWithExceptionWithTooManyRequestParams { 117 | @ErrorHandling(codeSpecific = { 118 | @ErrorCodes(codes = {404}, generate = BadException.class) 119 | }) 120 | void method1Test(); 121 | 122 | class BadException extends Exception { 123 | 124 | @FeignExceptionConstructor 125 | public BadException(Request request1, Request request2) { 126 | 127 | } 128 | } 129 | } 130 | 131 | interface IllegalTestClientInterfaceWithExceptionWithTooManyHeaderParams { 132 | 133 | @ErrorHandling(codeSpecific = { 134 | @ErrorCodes(codes = {404}, generate = BadException.class) 135 | }) 136 | void method1Test(); 137 | 138 | class BadException extends Exception { 139 | 140 | @FeignExceptionConstructor 141 | public BadException(@ResponseHeaders Map> headers1, 142 | @ResponseHeaders Map> headers2) { 143 | 144 | } 145 | } 146 | } 147 | 148 | interface IllegalTestClientInterfaceWithExceptionWithBadHeaderParams { 149 | 150 | @ErrorHandling(codeSpecific = { 151 | @ErrorCodes(codes = {404}, generate = BadException.class) 152 | }) 153 | void method1Test(); 154 | 155 | class BadException extends Exception { 156 | 157 | @FeignExceptionConstructor 158 | public BadException(@ResponseHeaders Map headers1) { 159 | headers1.get(3); 160 | } 161 | } 162 | } 163 | 164 | interface IllegalTestClientInterfaceWithExceptionWithBadHeaderObjectParam { 165 | 166 | @ErrorHandling(codeSpecific = { 167 | @ErrorCodes(codes = {404}, generate = BadException.class) 168 | }) 169 | void method1Test(); 170 | 171 | class BadException extends Exception { 172 | 173 | @FeignExceptionConstructor 174 | public BadException(@ResponseHeaders TestPojo headers1) {} 175 | } 176 | } 177 | 178 | 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderInheritanceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.ClassLevelDefaultException; 17 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.ClassLevelNotFoundException; 18 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.Method1DefaultException; 19 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.Method1NotFoundException; 20 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.Method2NotFoundException; 21 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.Method3DefaultException; 22 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.ServeErrorException; 23 | import static feign.error.AnnotationErrorDecoderInheritanceTest.TestClientInterfaceWithExceptionPriority.UnauthenticatedOrUnauthorizedException; 24 | import static org.assertj.core.api.Assertions.assertThat; 25 | import java.util.Arrays; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.junit.runners.Parameterized; 29 | import org.junit.runners.Parameterized.Parameter; 30 | import org.junit.runners.Parameterized.Parameters; 31 | 32 | @RunWith(Parameterized.class) 33 | public class AnnotationErrorDecoderInheritanceTest extends 34 | AbstractAnnotationErrorDecoderTest { 35 | 36 | @Override 37 | public Class interfaceAtTest() { 38 | return TestClientInterfaceWithExceptionPriority.class; 39 | } 40 | 41 | @Parameters( 42 | name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})") 43 | public static Iterable data() { 44 | return Arrays.asList(new Object[][] { 45 | {"Test Code Specific At Method", 404, "method1Test", Method1NotFoundException.class}, 46 | {"Test Code Specific At Method", 401, "method1Test", 47 | UnauthenticatedOrUnauthorizedException.class}, 48 | {"Test Code Specific At Method", 404, "method2Test", Method2NotFoundException.class}, 49 | {"Test Code Specific At Method", 500, "method2Test", ServeErrorException.class}, 50 | {"Test Code Specific At Method", 503, "method2Test", ServeErrorException.class}, 51 | {"Test Code Specific At Class", 403, "method1Test", 52 | UnauthenticatedOrUnauthorizedException.class}, 53 | {"Test Code Specific At Class", 403, "method2Test", 54 | UnauthenticatedOrUnauthorizedException.class}, 55 | {"Test Code Specific At Class", 404, "method3Test", ClassLevelNotFoundException.class}, 56 | {"Test Code Specific At Class", 403, "method3Test", 57 | UnauthenticatedOrUnauthorizedException.class}, 58 | {"Test Default At Method", 504, "method1Test", Method1DefaultException.class}, 59 | {"Test Default At Method", 504, "method3Test", Method3DefaultException.class}, 60 | {"Test Default At Class", 504, "method2Test", ClassLevelDefaultException.class}, 61 | }); 62 | } 63 | 64 | @Parameter // first data value (0) is default 65 | public String testType; 66 | 67 | @Parameter(1) 68 | public int errorCode; 69 | 70 | @Parameter(2) 71 | public String method; 72 | 73 | @Parameter(3) 74 | public Class expectedExceptionClass; 75 | 76 | @Test 77 | public void test() throws Exception { 78 | AnnotationErrorDecoder decoder = 79 | AnnotationErrorDecoder.builderFor(TestClientInterfaceWithExceptionPriority.class).build(); 80 | 81 | assertThat(decoder.decode(feignConfigKey(method), testResponse(errorCode)).getClass()) 82 | .isEqualTo(expectedExceptionClass); 83 | } 84 | 85 | 86 | @ErrorHandling(codeSpecific = { 87 | @ErrorCodes(codes = {404}, generate = ClassLevelNotFoundException.class), 88 | @ErrorCodes(codes = {403}, generate = UnauthenticatedOrUnauthorizedException.class) 89 | }, 90 | defaultException = ClassLevelDefaultException.class) 91 | interface TopLevelInterface { 92 | @ErrorHandling(codeSpecific = { 93 | @ErrorCodes(codes = {404}, generate = Method1NotFoundException.class), 94 | @ErrorCodes(codes = {401}, generate = UnauthenticatedOrUnauthorizedException.class) 95 | }, 96 | defaultException = Method1DefaultException.class) 97 | void method1Test(); 98 | 99 | class ClassLevelDefaultException extends Exception { 100 | } 101 | class Method1DefaultException extends Exception { 102 | } 103 | class Method3DefaultException extends Exception { 104 | } 105 | class Method1NotFoundException extends Exception { 106 | } 107 | class Method2NotFoundException extends Exception { 108 | } 109 | class ClassLevelNotFoundException extends Exception { 110 | } 111 | class UnauthenticatedOrUnauthorizedException extends Exception { 112 | } 113 | class ServeErrorException extends Exception { 114 | } 115 | 116 | } 117 | 118 | interface SecondTopLevelInterface { 119 | } 120 | interface SecondLevelInterface extends SecondTopLevelInterface, TopLevelInterface { 121 | } 122 | 123 | interface TestClientInterfaceWithExceptionPriority extends SecondLevelInterface { 124 | 125 | @ErrorHandling(codeSpecific = { 126 | @ErrorCodes(codes = {404}, generate = Method2NotFoundException.class), 127 | @ErrorCodes(codes = {500, 503}, generate = ServeErrorException.class) 128 | }) 129 | void method2Test(); 130 | 131 | @ErrorHandling( 132 | defaultException = Method3DefaultException.class) 133 | void method3Test(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderNoAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import feign.Response; 17 | import feign.codec.ErrorDecoder; 18 | import org.junit.Test; 19 | import static feign.error.AnnotationErrorDecoderNoAnnotationTest.*; 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | public class AnnotationErrorDecoderNoAnnotationTest 23 | extends AbstractAnnotationErrorDecoderTest { 24 | 25 | @Override 26 | public Class interfaceAtTest() { 27 | return TestClientInterfaceWithNoAnnotations.class; 28 | } 29 | 30 | @Test 31 | public void delegatesToDefaultErrorDecoder() throws Exception { 32 | 33 | ErrorDecoder defaultErrorDecoder = new ErrorDecoder() { 34 | @Override 35 | public Exception decode(String methodKey, Response response) { 36 | return new DefaultErrorDecoderException(); 37 | } 38 | }; 39 | 40 | AnnotationErrorDecoder decoder = 41 | AnnotationErrorDecoder.builderFor(TestClientInterfaceWithNoAnnotations.class) 42 | .withDefaultDecoder(defaultErrorDecoder) 43 | .build(); 44 | 45 | assertThat(decoder.decode(feignConfigKey("method1Test"), testResponse(502)).getClass()) 46 | .isEqualTo(DefaultErrorDecoderException.class); 47 | } 48 | 49 | interface TestClientInterfaceWithNoAnnotations { 50 | void method1Test(); 51 | } 52 | 53 | static class DefaultErrorDecoderException extends Exception { 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/feign/error/AnnotationErrorDecoderPriorityTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.junit.runners.Parameterized; 19 | import org.junit.runners.Parameterized.Parameters; 20 | import org.junit.runners.Parameterized.Parameter; 21 | import java.util.Arrays; 22 | import static org.assertj.core.api.Assertions.assertThat; 23 | import static feign.error.AnnotationErrorDecoderPriorityTest.TestClientInterfaceWithExceptionPriority.*; 24 | 25 | @RunWith(Parameterized.class) 26 | public class AnnotationErrorDecoderPriorityTest extends 27 | AbstractAnnotationErrorDecoderTest { 28 | 29 | @Override 30 | public Class interfaceAtTest() { 31 | return TestClientInterfaceWithExceptionPriority.class; 32 | } 33 | 34 | @Parameters( 35 | name = "{0}: When error code ({1}) on method ({2}) should return exception type ({3})") 36 | public static Iterable data() { 37 | return Arrays.asList(new Object[][] { 38 | {"Test Code Specific At Method", 404, "method1Test", Method1NotFoundException.class}, 39 | {"Test Code Specific At Method", 401, "method1Test", 40 | UnauthenticatedOrUnauthorizedException.class}, 41 | {"Test Code Specific At Method", 404, "method2Test", Method2NotFoundException.class}, 42 | {"Test Code Specific At Method", 500, "method2Test", ServeErrorException.class}, 43 | {"Test Code Specific At Method", 503, "method2Test", ServeErrorException.class}, 44 | {"Test Code Specific At Class", 403, "method1Test", 45 | UnauthenticatedOrUnauthorizedException.class}, 46 | {"Test Code Specific At Class", 403, "method2Test", 47 | UnauthenticatedOrUnauthorizedException.class}, 48 | {"Test Code Specific At Class", 404, "method3Test", ClassLevelNotFoundException.class}, 49 | {"Test Code Specific At Class", 403, "method3Test", 50 | UnauthenticatedOrUnauthorizedException.class}, 51 | {"Test Default At Method", 504, "method1Test", Method1DefaultException.class}, 52 | {"Test Default At Method", 504, "method3Test", Method3DefaultException.class}, 53 | {"Test Default At Class", 504, "method2Test", ClassLevelDefaultException.class}, 54 | }); 55 | } 56 | 57 | @Parameter // first data value (0) is default 58 | public String testType; 59 | 60 | @Parameter(1) 61 | public int errorCode; 62 | 63 | @Parameter(2) 64 | public String method; 65 | 66 | @Parameter(3) 67 | public Class expectedExceptionClass; 68 | 69 | @Test 70 | public void test() throws Exception { 71 | AnnotationErrorDecoder decoder = 72 | AnnotationErrorDecoder.builderFor(TestClientInterfaceWithExceptionPriority.class).build(); 73 | 74 | assertThat(decoder.decode(feignConfigKey(method), testResponse(errorCode)).getClass()) 75 | .isEqualTo(expectedExceptionClass); 76 | } 77 | 78 | 79 | @ErrorHandling(codeSpecific = { 80 | @ErrorCodes(codes = {404}, generate = ClassLevelNotFoundException.class), 81 | @ErrorCodes(codes = {403}, generate = UnauthenticatedOrUnauthorizedException.class) 82 | }, 83 | defaultException = ClassLevelDefaultException.class) 84 | interface TestClientInterfaceWithExceptionPriority { 85 | @ErrorHandling(codeSpecific = { 86 | @ErrorCodes(codes = {404}, generate = Method1NotFoundException.class), 87 | @ErrorCodes(codes = {401}, generate = UnauthenticatedOrUnauthorizedException.class) 88 | }, 89 | defaultException = Method1DefaultException.class) 90 | void method1Test(); 91 | 92 | @ErrorHandling(codeSpecific = { 93 | @ErrorCodes(codes = {404}, generate = Method2NotFoundException.class), 94 | @ErrorCodes(codes = {500, 503}, generate = ServeErrorException.class) 95 | }) 96 | void method2Test(); 97 | 98 | @ErrorHandling( 99 | defaultException = Method3DefaultException.class) 100 | void method3Test(); 101 | 102 | 103 | 104 | class ClassLevelDefaultException extends Exception { 105 | } 106 | class Method1DefaultException extends Exception { 107 | } 108 | class Method3DefaultException extends Exception { 109 | } 110 | class Method1NotFoundException extends Exception { 111 | } 112 | class Method2NotFoundException extends Exception { 113 | } 114 | class ClassLevelNotFoundException extends Exception { 115 | } 116 | class UnauthenticatedOrUnauthorizedException extends Exception { 117 | } 118 | class ServeErrorException extends Exception { 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/test/java/feign/error/TestPojo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017-2019 The Feign Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package feign.error; 15 | 16 | public class TestPojo { 17 | public String aString; 18 | public int anInt; 19 | } 20 | -------------------------------------------------------------------------------- /travis/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright 2017-2019 The Feign Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed under the License 11 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 | # or implied. See the License for the specific language governing permissions and limitations under 13 | # the License. 14 | # 15 | 16 | # taken from OpenZipkin 17 | 18 | set -euo pipefail 19 | set -x 20 | 21 | build_started_by_tag() { 22 | if [ "${TRAVIS_TAG}" == "" ]; then 23 | echo "[Publishing] This build was not started by a tag, publishing snapshot" 24 | return 1 25 | else 26 | echo "[Publishing] This build was started by the tag ${TRAVIS_TAG}, publishing release" 27 | return 0 28 | fi 29 | } 30 | 31 | is_pull_request() { 32 | if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then 33 | echo "[Not Publishing] This is a Pull Request" 34 | return 0 35 | else 36 | echo "[Publishing] This is not a Pull Request" 37 | return 1 38 | fi 39 | } 40 | 41 | is_travis_branch_master() { 42 | if [ "${TRAVIS_BRANCH}" = master ]; then 43 | echo "[Publishing] Travis branch is master" 44 | return 0 45 | else 46 | echo "[Not Publishing] Travis branch is not master" 47 | return 1 48 | fi 49 | } 50 | 51 | check_travis_branch_equals_travis_tag() { 52 | #Weird comparison comparing branch to tag because when you 'git push --tags' 53 | #the branch somehow becomes the tag value 54 | #github issue: https://github.com/travis-ci/travis-ci/issues/1675 55 | if [ "${TRAVIS_BRANCH}" != "${TRAVIS_TAG}" ]; then 56 | echo "Travis branch does not equal Travis tag, which it should, bailing out." 57 | echo " github issue: https://github.com/travis-ci/travis-ci/issues/1675" 58 | exit 1 59 | else 60 | echo "[Publishing] Branch (${TRAVIS_BRANCH}) same as Tag (${TRAVIS_TAG})" 61 | fi 62 | } 63 | 64 | check_release_tag() { 65 | tag="${TRAVIS_TAG}" 66 | if [[ "$tag" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then 67 | echo "Build started by version tag $tag. During the release process tags like this" 68 | echo "are created by the 'release' Maven plugin. Nothing to do here." 69 | exit 0 70 | elif [[ ! "$tag" =~ ^release-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then 71 | echo "You must specify a tag of the format 'release-0.0.0' to release this project." 72 | echo "The provided tag ${tag} doesn't match that. Aborting." 73 | exit 1 74 | fi 75 | } 76 | 77 | print_project_version() { 78 | ./mvnw help:evaluate -N -Dexpression=project.version|sed -n '/^[0-9]/p' 79 | } 80 | 81 | is_release_commit() { 82 | project_version="$(print_project_version)" 83 | if [[ "$project_version" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then 84 | echo "Build started by release commit $project_version. Will synchronize to maven central." 85 | return 0 86 | else 87 | return 1 88 | fi 89 | } 90 | 91 | release_version() { 92 | echo "${TRAVIS_TAG}" | sed 's/^release-//' 93 | } 94 | 95 | safe_checkout_master() { 96 | # We need to be on a branch for release:perform to be able to create commits, and we want that branch to be master. 97 | # But we also want to make sure that we build and release exactly the tagged version, so we verify that the remote 98 | # master is where our tag is. 99 | git checkout -B master 100 | git fetch origin master:origin/master 101 | commit_local_master="$(git show --pretty='format:%H' master)" 102 | commit_remote_master="$(git show --pretty='format:%H' origin/master)" 103 | if [ "$commit_local_master" != "$commit_remote_master" ]; then 104 | echo "Master on remote 'origin' has commits since the version under release, aborting" 105 | exit 1 106 | fi 107 | } 108 | 109 | javadoc_to_gh_pages() { 110 | version="$(print_project_version)" 111 | rm -rf javadoc-builddir 112 | builddir="javadoc-builddir/$version" 113 | 114 | # Collect javadoc for all modules 115 | for jar in $(find . -name "*${version}-javadoc.jar"); do 116 | module="$(echo "$jar" | sed "s~.*/\(.*\)-${version}-javadoc.jar~\1~")" 117 | this_builddir="$builddir/$module" 118 | if [ -d "$this_builddir" ]; then 119 | # Skip modules we've already processed. 120 | # We may find multiple instances of the same javadoc jar because of, for instance, 121 | # integration tests copying jars around. 122 | continue 123 | fi 124 | mkdir -p "$this_builddir" 125 | unzip "$jar" -d "$this_builddir" 126 | # Build a simple module-level index 127 | echo "
  • ${module}
  • " >> "${builddir}/index.html" 128 | done 129 | 130 | # Update gh-pages 131 | git fetch origin gh-pages:gh-pages 132 | git checkout gh-pages 133 | rm -rf "$version" 134 | mv "javadoc-builddir/$version" ./ 135 | rm -rf "javadoc-builddir" 136 | 137 | # Update simple version-level index 138 | if ! grep "$version" index.html 2>/dev/null; then 139 | echo "
  • ${version}
  • " >> index.html 140 | fi 141 | 142 | # Ensure links are ordered by versions, latest on top 143 | sort -rV index.html > index.html.sorted 144 | mv index.html.sorted index.html 145 | 146 | git add "$version" 147 | git add index.html 148 | git commit -m "Automatically updated javadocs for $version" 149 | git push origin gh-pages 150 | } 151 | 152 | #---------------------- 153 | # MAIN 154 | #---------------------- 155 | 156 | if ! is_pull_request && build_started_by_tag; then 157 | check_travis_branch_equals_travis_tag 158 | check_release_tag 159 | fi 160 | 161 | # skip license on travis due to #1512 162 | ./mvnw install -nsu -Dlicense.skip=true -Dgpg.skip=true 163 | 164 | # formatter errors: 165 | if [ -z $(git status --porcelain) ]; 166 | then 167 | echo "No changes detected, all good" 168 | else 169 | echo "The following files have formatting changes:" 170 | git status --porcelain 171 | echo "" 172 | echo "Please run 'mvn clean install' locally to format files" 173 | exit 1 174 | fi 175 | 176 | # If we are on a pull request, our only job is to run tests, which happened above via ./mvnw install 177 | if is_pull_request; then 178 | true 179 | 180 | # If we are on master, we will deploy the latest snapshot or release version 181 | # - If a release commit fails to deploy for a transient reason, delete the broken version from bintray and click rebuild 182 | elif is_travis_branch_master; then 183 | ./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -DskipTests -Dgpg.skip=true deploy 184 | 185 | # If the deployment succeeded, sync it to Maven Central. Note: this needs to be done once per project, not module, hence -N 186 | if is_release_commit; then 187 | ./mvnw --batch-mode -s ./.settings.xml -nsu -Dgpg.skip=true -N io.zipkin.centralsync-maven-plugin:centralsync-maven-plugin:sync 188 | # javadoc_to_gh_pages 189 | fi 190 | 191 | # If we are on a release tag, the following will update any version references and push a version tag for deployment. 192 | elif build_started_by_tag; then 193 | safe_checkout_master 194 | # skip license on travis due to #1512 195 | ./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -DreleaseVersion="$(release_version)" -Darguments="-DskipTests -Dlicense.skip=true -Dgpg.skip=true" release:prepare 196 | fi 197 | --------------------------------------------------------------------------------