├── .editorconfig ├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── AUTHORS ├── LICENSE ├── LICENSE.header ├── README.md ├── build-logic ├── build.gradle.kts ├── buildscript-gradle.lockfile ├── gradle.lockfile ├── gradle.properties ├── settings-gradle.lockfile ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── local │ └── maven-publish.gradle.kts ├── build.gradle.kts ├── buildscript-gradle.lockfile ├── gradle.lockfile ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom-j2cl-test.xml ├── settings-gradle.lockfile ├── settings.gradle.kts └── src ├── j2cl-test ├── java │ └── org │ │ └── gwtproject │ │ └── http │ │ └── client │ │ ├── RequestBuilderTest.java │ │ ├── RequestTest.java │ │ ├── RequestTestBase.java │ │ ├── ResponseTest.java │ │ ├── URLTest.java │ │ └── UrlBuilderTest.java └── webapp │ └── WEB-INF │ └── web.xml ├── main ├── java │ └── org │ │ └── gwtproject │ │ └── http │ │ └── client │ │ ├── Header.java │ │ ├── Request.java │ │ ├── RequestBuilder.java │ │ ├── RequestCallback.java │ │ ├── RequestException.java │ │ ├── RequestTimeoutException.java │ │ ├── Response.java │ │ ├── ResponseImpl.java │ │ ├── StringValidator.java │ │ ├── URL.java │ │ ├── UrlBuilder.java │ │ └── package-info.java └── resources │ ├── META-INF │ └── gwt │ │ └── mainModule │ └── org │ └── gwtproject │ └── http │ └── HTTP.gwt.xml ├── test ├── java │ └── org │ │ └── gwtproject │ │ └── http │ │ ├── HTTPSuite.java │ │ ├── client │ │ ├── RequestBuilderTest.java │ │ ├── RequestTest.java │ │ ├── RequestTestBase.java │ │ ├── ResponseTest.java │ │ ├── URLTest.java │ │ └── UrlBuilderTest.java │ │ └── server │ │ ├── RequestBuilderTestServlet.java │ │ ├── RequestTestServlet.java │ │ └── ResponseTestServlet.java └── resources │ └── org │ └── gwtproject │ └── http │ ├── RequestBuilderTest.gwt.xml │ ├── RequestTest.gwt.xml │ └── ResponseTest.gwt.xml └── testFixtures └── java └── org └── gwtproject └── http └── shared └── RequestBuilderTestConstants.java /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | continuation_indent_size = 4 11 | 12 | [*.{kt,kts}] 13 | indent_size = 4 14 | continuation_indent_size = 4 15 | 16 | [gradlew.bat] 17 | end_of_line = crlf 18 | -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | concurrency: 6 | group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} 7 | cancel-in-progress: true 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | java_version: [ 8, 11, 17 ] 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - name: Setup Java 20 | uses: actions/setup-java@v2 21 | with: 22 | distribution: 'temurin' 23 | java-version: ${{ matrix.java_version }} 24 | 25 | - name: Get Maven version 26 | run: mvn --version |head -1 > mvn-version 27 | 28 | - name: Cache Maven dependencies (for J2Cl tests) 29 | id: cache-maven-dependencies 30 | uses: actions/cache@v2 31 | with: 32 | path: ~/.m2/repository/ 33 | key: mvn-deps-${{ hashFiles('mvn-version') }}-${{ hashFiles('pom-j2cl-test.xml') }} 34 | 35 | - name: Build with Gradle 36 | uses: gradle/gradle-build-action@v1 37 | with: 38 | arguments: :build-logic:build build -Pj2clTest.webdriver=chrome 39 | distributions-cache-enabled: true 40 | dependencies-cache-enabled: true 41 | dependencies-cache-key: '**/*gradle.lockfile' 42 | dependencies-cache-exact: ${{ github.ref == 'refs/heads/master' }} 43 | cache-read-only: ${{ github.ref != 'refs/heads/master' }} 44 | 45 | - name: Before Maven cache 46 | if: steps.cache-maven-dependencies.outputs.cache-hit != 'true' 47 | run: shopt -s globstar && rm -rf ~/.m2/repository/**/*-SNAPSHOT/ ~/.m2/repository/org/gwtproject/**/LOCAL/ 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # NOTE: we don't include IDE-specific files (e.g. IntelliJ's *.iml and .idea/) on-purpose. 2 | # Those patterns should go in a global gitignore or repository-specific excludes. 3 | # See http://www.gwtproject.org/makinggwtbetter.html#global_gitignore 4 | 5 | .gradle/ 6 | build/ 7 | 8 | # Used for j2cl tests 9 | target/ 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of GWT Project authors for copyright purposes. 2 | 3 | # Names should be added to this file as one of 4 | # Organization's name 5 | # Individual's name 6 | 7 | # Please keep the list sorted. 8 | 9 | Google, Inc. 10 | Johannes Barop 11 | Thomas Broyer 12 | Vaadin Ltd. 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /LICENSE.header: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright $YEAR The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GWT HTTP 2 | ======== 3 | 4 | A future-proof port of the `com.google.gwt.http.HTTP` GWT module, 5 | with no dependency on `gwt-user` (besides the Java Runtime Emulation), 6 | to prepare for GWT 3 / J2Cl. 7 | 8 | Browser compatibility 9 | --------------------- 10 | 11 | The code should be compatible with all evergreen browsers, 12 | and Internet Explorer 10 and 11. 13 | 14 | Migrating from `c.g.g.http.HTTP` 15 | -------------------------------- 16 | 17 | 1. Add the dependency to your build. 18 | 19 | For Maven: 20 | 21 | ```xml 22 | 23 | org.gwtproject.http 24 | gwt-http 25 | ${gwtHttpVersion} 26 | 27 | ``` 28 | 29 | For Gradle: 30 | 31 | ```gradle 32 | compile "org.gwtproject.http:gwt-http:${gwtHttpVersion}" 33 | ``` 34 | 35 | 2. Update your GWT module to use 36 | 37 | ```xml 38 | 39 | ``` 40 | 41 | (either change from `com.google.gwt.http.HTTP`, 42 | or add it if you inherited it transitively from another GWT module) 43 | 44 | 3. Change your `import`s in your Java source files: 45 | 46 | ```java 47 | import org.gwtproject.http.client.RequestBuilder; 48 | import org.gwtproject.http.client.URL; 49 | import org.gwtproject.http.client.UrlBuilder; 50 | ``` 51 | -------------------------------------------------------------------------------- /build-logic/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-gradle-plugin` 3 | `kotlin-dsl` 4 | alias(libs.plugins.spotless) 5 | } 6 | buildscript { 7 | dependencyLocking { 8 | lockAllConfigurations() 9 | } 10 | } 11 | dependencyLocking { 12 | lockAllConfigurations() 13 | } 14 | repositories { 15 | mavenCentral() 16 | } 17 | spotless { 18 | kotlinGradle { 19 | target("**/*.gradle.kts") 20 | ktlint(libs.versions.ktlint.get()) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /build-logic/buildscript-gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | com.diffplug.durian:durian-collect:1.2.0=classpath 5 | com.diffplug.durian:durian-core:1.2.0=classpath 6 | com.diffplug.durian:durian-io:1.2.0=classpath 7 | com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:6.3.0=classpath 8 | com.diffplug.spotless:spotless-lib-extra:2.23.0=classpath 9 | com.diffplug.spotless:spotless-lib:2.23.0=classpath 10 | com.diffplug.spotless:spotless-plugin-gradle:6.3.0=classpath 11 | com.github.gundy:semver4j:0.16.4=classpath 12 | com.google.code.findbugs:jsr305:3.0.2=classpath 13 | com.google.code.gson:gson:2.8.6=classpath 14 | com.google.errorprone:error_prone_annotations:2.3.4=classpath 15 | com.google.guava:failureaccess:1.0.1=classpath 16 | com.google.guava:guava:29.0-jre=classpath 17 | com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=classpath 18 | com.google.j2objc:j2objc-annotations:1.3=classpath 19 | com.googlecode.concurrent-trees:concurrent-trees:2.6.1=classpath 20 | com.googlecode.javaewah:JavaEWAH:1.1.12=classpath 21 | de.undercouch:gradle-download-task:4.1.1=classpath 22 | org.checkerframework:checker-qual:2.11.1=classpath 23 | org.codehaus.groovy:groovy-xml:3.0.9=classpath 24 | org.codehaus.groovy:groovy:3.0.9=classpath 25 | org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r=classpath 26 | org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:2.1.7=classpath 27 | org.gradle.kotlin:gradle-kotlin-dsl-plugins:2.1.7=classpath 28 | org.jetbrains.intellij.deps:trove4j:1.0.20181211=classpath 29 | org.jetbrains.kotlin:kotlin-android-extensions:1.5.31=classpath 30 | org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.5.31=classpath 31 | org.jetbrains.kotlin:kotlin-build-common:1.5.31=classpath 32 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=classpath 33 | org.jetbrains.kotlin:kotlin-compiler-runner:1.5.31=classpath 34 | org.jetbrains.kotlin:kotlin-daemon-client:1.5.31=classpath 35 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=classpath 36 | org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=classpath 37 | org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=classpath 38 | org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31=classpath 39 | org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.5.31=classpath 40 | org.jetbrains.kotlin:kotlin-native-utils:1.5.31=classpath 41 | org.jetbrains.kotlin:kotlin-project-model:1.5.31=classpath 42 | org.jetbrains.kotlin:kotlin-sam-with-receiver:1.5.31=classpath 43 | org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=classpath 44 | org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=classpath 45 | org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=classpath 46 | org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=classpath 47 | org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=classpath 48 | org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=classpath 49 | org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=classpath 50 | org.jetbrains.kotlin:kotlin-stdlib:1.5.31=classpath 51 | org.jetbrains.kotlin:kotlin-tooling-metadata:1.5.31=classpath 52 | org.jetbrains.kotlin:kotlin-util-io:1.5.31=classpath 53 | org.jetbrains.kotlin:kotlin-util-klib:1.5.31=classpath 54 | org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=classpath 55 | org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=classpath 56 | org.jetbrains:annotations:13.0=classpath 57 | org.slf4j:slf4j-api:1.7.30=classpath 58 | empty= 59 | -------------------------------------------------------------------------------- /build-logic/gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | ch.qos.logback:logback-classic:1.2.9=spotless-1972455328 5 | ch.qos.logback:logback-core:1.2.9=spotless-1972455328 6 | com.github.shyiko.klob:klob:0.2.1=ktlint,spotless-1972455328 7 | com.pinterest.ktlint:ktlint-core:0.40.0=ktlint 8 | com.pinterest.ktlint:ktlint-core:0.44.0=spotless-1972455328 9 | com.pinterest.ktlint:ktlint-reporter-baseline:0.40.0=ktlint 10 | com.pinterest.ktlint:ktlint-reporter-baseline:0.44.0=spotless-1972455328 11 | com.pinterest.ktlint:ktlint-reporter-checkstyle:0.40.0=ktlint 12 | com.pinterest.ktlint:ktlint-reporter-checkstyle:0.44.0=spotless-1972455328 13 | com.pinterest.ktlint:ktlint-reporter-html:0.40.0=ktlint 14 | com.pinterest.ktlint:ktlint-reporter-html:0.44.0=spotless-1972455328 15 | com.pinterest.ktlint:ktlint-reporter-json:0.40.0=ktlint 16 | com.pinterest.ktlint:ktlint-reporter-json:0.44.0=spotless-1972455328 17 | com.pinterest.ktlint:ktlint-reporter-plain:0.40.0=ktlint 18 | com.pinterest.ktlint:ktlint-reporter-plain:0.44.0=spotless-1972455328 19 | com.pinterest.ktlint:ktlint-reporter-sarif:0.44.0=spotless-1972455328 20 | com.pinterest.ktlint:ktlint-ruleset-experimental:0.40.0=ktlint 21 | com.pinterest.ktlint:ktlint-ruleset-experimental:0.44.0=spotless-1972455328 22 | com.pinterest.ktlint:ktlint-ruleset-standard:0.40.0=ktlint 23 | com.pinterest.ktlint:ktlint-ruleset-standard:0.44.0=spotless-1972455328 24 | com.pinterest.ktlint:ktlint-ruleset-test:0.40.0=ktlint 25 | com.pinterest.ktlint:ktlint-ruleset-test:0.44.0=spotless-1972455328 26 | com.pinterest:ktlint:0.40.0=ktlint 27 | com.pinterest:ktlint:0.44.0=spotless-1972455328 28 | info.picocli:picocli:3.9.6=ktlint,spotless-1972455328 29 | io.github.detekt.sarif4k:sarif4k:0.0.1=spotless-1972455328 30 | io.github.microutils:kotlin-logging-jvm:2.1.21=spotless-1972455328 31 | net.java.dev.jna:jna:5.6.0=spotless-1972455328 32 | org.ec4j.core:ec4j-core:0.2.2=ktlint 33 | org.ec4j.core:ec4j-core:0.3.0=spotless-1972455328 34 | org.jetbrains.intellij.deps:trove4j:1.0.20181211=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath,ktlint,spotless-1972455328 35 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10=ktlint 36 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.31=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath 37 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.0=spotless-1972455328 38 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.4.10=ktlint 39 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.5.31=kotlinCompilerClasspath,kotlinKlibCommonizerClasspath 40 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.6.0=spotless-1972455328 41 | org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 42 | org.jetbrains.kotlin:kotlin-gradle-plugin-model:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 43 | org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.5.31=kotlinKlibCommonizerClasspath 44 | org.jetbrains.kotlin:kotlin-native-utils:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 45 | org.jetbrains.kotlin:kotlin-project-model:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 46 | org.jetbrains.kotlin:kotlin-reflect:1.4.10=ktlint 47 | org.jetbrains.kotlin:kotlin-reflect:1.5.31=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 48 | org.jetbrains.kotlin:kotlin-reflect:1.6.0=spotless-1972455328 49 | org.jetbrains.kotlin:kotlin-sam-with-receiver:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 50 | org.jetbrains.kotlin:kotlin-script-runtime:1.4.10=ktlint 51 | org.jetbrains.kotlin:kotlin-script-runtime:1.5.31=kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath 52 | org.jetbrains.kotlin:kotlin-script-runtime:1.6.0=spotless-1972455328 53 | org.jetbrains.kotlin:kotlin-scripting-common:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 54 | org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 55 | org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 56 | org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 57 | org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10=ktlint 58 | org.jetbrains.kotlin:kotlin-stdlib-common:1.5.31=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 59 | org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0=spotless-1972455328 60 | org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.0=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 61 | org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 62 | org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0=spotless-1972455328 63 | org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 64 | org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 65 | org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0=spotless-1972455328 66 | org.jetbrains.kotlin:kotlin-stdlib:1.4.10=ktlint 67 | org.jetbrains.kotlin:kotlin-stdlib:1.5.31=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 68 | org.jetbrains.kotlin:kotlin-stdlib:1.6.0=spotless-1972455328 69 | org.jetbrains.kotlin:kotlin-util-io:1.5.31=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 70 | org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 71 | org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0=kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest 72 | org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.1.0=spotless-1972455328 73 | org.jetbrains.kotlinx:kotlinx-serialization-core:1.1.0=spotless-1972455328 74 | org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.1.0=spotless-1972455328 75 | org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0=spotless-1972455328 76 | org.jetbrains:annotations:13.0=compileClasspath,compileOnly,compileOnlyDependenciesMetadata,embeddedKotlin,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,ktlint,spotless-1972455328,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath 77 | org.slf4j:slf4j-api:1.7.32=spotless-1972455328 78 | empty=annotationProcessor,apiDependenciesMetadata,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,ktlintReporter,ktlintRuleset,runtimeClasspath,runtimeOnlyDependenciesMetadata,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnly,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntimeOnlyDependenciesMetadata 79 | -------------------------------------------------------------------------------- /build-logic/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.jvm.target.validation.mode = IGNORE 2 | -------------------------------------------------------------------------------- /build-logic/settings-gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | empty=incomingCatalogForLibs0 5 | -------------------------------------------------------------------------------- /build-logic/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | buildscript { 2 | dependencyLocking { 3 | lockAllConfigurations() 4 | } 5 | } 6 | dependencyResolutionManagement { 7 | versionCatalogs { 8 | create("libs") { 9 | from(files("../gradle/libs.versions.toml")) 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /build-logic/src/main/kotlin/local/maven-publish.gradle.kts: -------------------------------------------------------------------------------- 1 | package local 2 | 3 | plugins { 4 | `java-base` 5 | `maven-publish` 6 | signing 7 | } 8 | 9 | java { 10 | withJavadocJar() 11 | withSourcesJar() 12 | } 13 | 14 | val sonatypeRepository = publishing.repositories.maven { 15 | name = "sonatype" 16 | setUrl( 17 | provider { 18 | if (isSnapshot) { 19 | uri("https://oss.sonatype.org/content/repositories/snapshots/") 20 | } else { 21 | uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") 22 | } 23 | } 24 | ) 25 | credentials { 26 | username = project.findProperty("ossrhUsername") as? String 27 | password = project.findProperty("ossrhPassword") as? String 28 | } 29 | } 30 | 31 | val mavenPublication = publishing.publications.create("maven") { 32 | from(components["java"]) 33 | 34 | if (isSnapshot) { 35 | version = "HEAD-SNAPSHOT" 36 | } 37 | 38 | pom { 39 | name.set(provider { "$groupId:$artifactId" }) 40 | description.set(provider { project.description ?: name.get() }) 41 | url.set("https://github.com/gwtproject/gwt-http") 42 | developers { 43 | developer { 44 | name.set("The GWT Project Authors") 45 | url.set("http://www.gwtproject.org") 46 | } 47 | } 48 | scm { 49 | connection.set("https://github.com/gwtproject/gwt-http.git") 50 | developerConnection.set("scm:git:ssh://github.com:gwtproject/gwt-http.git") 51 | url.set("https://github.com/gwtproject/gwt-http") 52 | } 53 | licenses { 54 | license { 55 | name.set("The Apache License, Version 2.0") 56 | url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") 57 | } 58 | } 59 | } 60 | } 61 | 62 | signing { 63 | useGpgCmd() 64 | isRequired = !isSnapshot 65 | sign(mavenPublication) 66 | } 67 | 68 | inline val Project.isSnapshot 69 | get() = version == Project.DEFAULT_VERSION 70 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import net.ltgt.gradle.errorprone.errorprone 2 | 3 | plugins { 4 | `java-library` 5 | id("local.maven-publish") 6 | alias(libs.plugins.errorprone) 7 | alias(libs.plugins.spotless) 8 | } 9 | 10 | buildscript { 11 | dependencyLocking { 12 | lockAllConfigurations() 13 | lockMode.set(LockMode.STRICT) 14 | } 15 | } 16 | dependencyLocking { 17 | lockAllConfigurations() 18 | lockMode.set(LockMode.STRICT) 19 | } 20 | 21 | group = "org.gwtproject.http" 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | errorprone(libs.errorprone.core) 29 | errorproneJavac(libs.errorprone.javac) 30 | 31 | implementation(libs.elemental2.dom) 32 | implementation(libs.elemental2.core) 33 | implementation(libs.jsinterop.base) 34 | 35 | testImplementation(libs.junit) 36 | testImplementation(libs.gwt.user) 37 | testImplementation(libs.gwt.dev) 38 | } 39 | 40 | java { 41 | sourceCompatibility = JavaVersion.VERSION_1_8 42 | } 43 | tasks.withType().configureEach { 44 | options.encoding = "UTF-8" 45 | options.compilerArgs.addAll(arrayOf("-Werror", "-Xlint:all")) 46 | if (JavaVersion.current().isJava9Compatible) { 47 | options.release.set(8) 48 | } 49 | options.errorprone.disable("StringSplitter") 50 | } 51 | 52 | sourceSets { 53 | test { 54 | java { 55 | // Code that is shared with J2Cl tests 56 | srcDir("src/testFixtures/java") 57 | } 58 | } 59 | } 60 | 61 | tasks { 62 | jar { 63 | from(sourceSets.main.map { it.allJava }) 64 | } 65 | 66 | test { 67 | val warDir = file("$buildDir/gwt/www-test") 68 | val workDir = file("$buildDir/gwt/work") 69 | val cacheDir = file("$buildDir/gwt/cache") 70 | outputs.dirs( 71 | mapOf( 72 | "war" to warDir, 73 | "work" to workDir, 74 | "cache" to cacheDir 75 | ) 76 | ) 77 | 78 | classpath += sourceSets.main.get().allJava.sourceDirectories + sourceSets.test.get().allJava.sourceDirectories 79 | include("**/*Suite.class") 80 | systemProperty( 81 | "gwt.args", 82 | """-ea -draftCompile -batch module -war "$warDir" -workDir "$workDir" -runStyle HtmlUnit:Chrome""" 83 | ) 84 | systemProperty("gwt.persistentunitcachedir", cacheDir) 85 | } 86 | 87 | javadoc { 88 | (options as CoreJavadocOptions).addBooleanOption("Xdoclint:all,-missing", true) 89 | if (JavaVersion.current().isJava9Compatible) { 90 | (options as CoreJavadocOptions).addBooleanOption("html5", true) 91 | } 92 | // Workaround for https://github.com/gradle/gradle/issues/5630 93 | (options as CoreJavadocOptions).addStringOption("sourcepath", "") 94 | } 95 | } 96 | 97 | spotless { 98 | java { 99 | target(sourceSets.map { it.allJava }, fileTree("src/j2cl-test/java") { include("**/*.java") }) 100 | googleJavaFormat(libs.versions.googleJavaFormat.get()) 101 | licenseHeaderFile("LICENSE.header") 102 | } 103 | kotlinGradle { 104 | ktlint(libs.versions.ktlint.get()) 105 | } 106 | } 107 | 108 | // 109 | // J2Cl tests 110 | // 111 | // Because there's only Maven tooling for J2Cl (and specifically tests), we publish 112 | // the JAR to the local Maven repository under a fixed (non-snapshot) version, and 113 | // then fork a Maven build. 114 | // 115 | val j2clTestPublication = publishing.publications.create("j2clTest") { 116 | from(components["java"]) 117 | version = "LOCAL" 118 | } 119 | tasks { 120 | val j2clTest by registering(Exec::class) { 121 | shouldRunAfter(test) 122 | dependsOn("publishJ2clTestPublicationToMavenLocal") 123 | inputs.files(sourceSets.main.map { it.runtimeClasspath }).withNormalizer(ClasspathNormalizer::class) 124 | // For the servlets 125 | inputs.files(compileTestJava).withNormalizer(ClasspathNormalizer::class) 126 | inputs.file("pom-j2cl-test.xml") 127 | inputs.dir("src/testFixtures") 128 | inputs.dir("src/j2cl-test") 129 | outputs.dir("target") 130 | 131 | val webdriver = findProperty("j2clTest.webdriver") ?: "htmlunit" 132 | inputs.property("webdriver", webdriver) 133 | 134 | commandLine("mvn", "-V", "-B", "-ntp", "-U", "-e", "-f", "pom-j2cl-test.xml", "verify", "-Dwebdriver=$webdriver") 135 | } 136 | 137 | check { 138 | dependsOn(j2clTest) 139 | } 140 | 141 | withType().configureEach { 142 | onlyIf { publication != j2clTestPublication } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /buildscript-gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | com.diffplug.durian:durian-collect:1.2.0=classpath 5 | com.diffplug.durian:durian-core:1.2.0=classpath 6 | com.diffplug.durian:durian-io:1.2.0=classpath 7 | com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:6.3.0=classpath 8 | com.diffplug.spotless:spotless-lib-extra:2.23.0=classpath 9 | com.diffplug.spotless:spotless-lib:2.23.0=classpath 10 | com.diffplug.spotless:spotless-plugin-gradle:6.3.0=classpath 11 | com.googlecode.concurrent-trees:concurrent-trees:2.6.1=classpath 12 | com.googlecode.javaewah:JavaEWAH:1.1.12=classpath 13 | net.ltgt.errorprone:net.ltgt.errorprone.gradle.plugin:2.0.2=classpath 14 | net.ltgt.gradle:gradle-errorprone-plugin:2.0.2=classpath 15 | org.codehaus.groovy:groovy-xml:3.0.9=classpath 16 | org.codehaus.groovy:groovy:3.0.9=classpath 17 | org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r=classpath 18 | org.slf4j:slf4j-api:1.7.30=classpath 19 | empty= 20 | -------------------------------------------------------------------------------- /gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | ant:ant:1.6.5=testCompileClasspath,testRuntimeClasspath 5 | ch.qos.logback:logback-classic:1.2.9=spotless-1972455328 6 | ch.qos.logback:logback-core:1.2.9=spotless-1972455328 7 | colt:colt:1.2.0=testCompileClasspath,testRuntimeClasspath 8 | com.github.ben-manes.caffeine:caffeine:2.8.8=annotationProcessor,errorprone,testAnnotationProcessor 9 | com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,errorprone,testAnnotationProcessor 10 | com.github.shyiko.klob:klob:0.2.1=ktlint,spotless-1972455328 11 | com.google.auto.service:auto-service-annotations:1.0-rc6=annotationProcessor,errorprone,testAnnotationProcessor 12 | com.google.auto.value:auto-value-annotations:1.7=annotationProcessor,errorprone,testAnnotationProcessor 13 | com.google.auto:auto-common:1.1.2=annotationProcessor,errorprone,testAnnotationProcessor 14 | com.google.code.findbugs:jFormatString:3.0.0=annotationProcessor,errorprone,testAnnotationProcessor 15 | com.google.code.findbugs:jsr305:1.3.9=testCompileClasspath,testRuntimeClasspath 16 | com.google.code.findbugs:jsr305:3.0.2=annotationProcessor,errorprone,googleJavaFormat1.7,spotless1972418317,testAnnotationProcessor 17 | com.google.code.gson:gson:2.6.2=testCompileClasspath,testRuntimeClasspath 18 | com.google.elemental2:elemental2-core:1.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath 19 | com.google.elemental2:elemental2-dom:1.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath 20 | com.google.elemental2:elemental2-promise:1.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath 21 | com.google.errorprone:error_prone_annotation:2.10.0=annotationProcessor,errorprone,testAnnotationProcessor 22 | com.google.errorprone:error_prone_annotations:2.10.0=annotationProcessor,errorprone,testAnnotationProcessor 23 | com.google.errorprone:error_prone_annotations:2.2.0=googleJavaFormat1.7,spotless1972418317 24 | com.google.errorprone:error_prone_check_api:2.10.0=annotationProcessor,errorprone,testAnnotationProcessor 25 | com.google.errorprone:error_prone_core:2.10.0=annotationProcessor,errorprone,testAnnotationProcessor 26 | com.google.errorprone:error_prone_type_annotations:2.10.0=annotationProcessor,errorprone,testAnnotationProcessor 27 | com.google.errorprone:javac-shaded:9+181-r4173-1=googleJavaFormat1.7,spotless1972418317 28 | com.google.errorprone:javac:9+181-r4173-1=errorproneJavac 29 | com.google.googlejavaformat:google-java-format:1.7=googleJavaFormat1.7,spotless1972418317 30 | com.google.guava:failureaccess:1.0.1=annotationProcessor,errorprone,googleJavaFormat1.7,spotless1972418317,testAnnotationProcessor 31 | com.google.guava:guava:27.0.1-jre=googleJavaFormat1.7,spotless1972418317 32 | com.google.guava:guava:30.1.1-jre=annotationProcessor,errorprone,testAnnotationProcessor 33 | com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,errorprone,googleJavaFormat1.7,spotless1972418317,testAnnotationProcessor 34 | com.google.gwt:gwt-dev:2.9.0=testCompileClasspath,testRuntimeClasspath 35 | com.google.gwt:gwt-user:2.9.0=testCompileClasspath,testRuntimeClasspath 36 | com.google.j2objc:j2objc-annotations:1.1=googleJavaFormat1.7,spotless1972418317 37 | com.google.j2objc:j2objc-annotations:1.3=annotationProcessor,errorprone,testAnnotationProcessor 38 | com.google.jsinterop:base:1.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath 39 | com.google.jsinterop:jsinterop-annotations:2.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath 40 | com.google.protobuf:protobuf-java:3.4.0=annotationProcessor,errorprone,testAnnotationProcessor 41 | com.ibm.icu:icu4j:63.1=testCompileClasspath,testRuntimeClasspath 42 | com.pinterest.ktlint:ktlint-core:0.40.0=ktlint 43 | com.pinterest.ktlint:ktlint-core:0.44.0=spotless-1972455328 44 | com.pinterest.ktlint:ktlint-reporter-baseline:0.40.0=ktlint 45 | com.pinterest.ktlint:ktlint-reporter-baseline:0.44.0=spotless-1972455328 46 | com.pinterest.ktlint:ktlint-reporter-checkstyle:0.40.0=ktlint 47 | com.pinterest.ktlint:ktlint-reporter-checkstyle:0.44.0=spotless-1972455328 48 | com.pinterest.ktlint:ktlint-reporter-html:0.40.0=ktlint 49 | com.pinterest.ktlint:ktlint-reporter-html:0.44.0=spotless-1972455328 50 | com.pinterest.ktlint:ktlint-reporter-json:0.40.0=ktlint 51 | com.pinterest.ktlint:ktlint-reporter-json:0.44.0=spotless-1972455328 52 | com.pinterest.ktlint:ktlint-reporter-plain:0.40.0=ktlint 53 | com.pinterest.ktlint:ktlint-reporter-plain:0.44.0=spotless-1972455328 54 | com.pinterest.ktlint:ktlint-reporter-sarif:0.44.0=spotless-1972455328 55 | com.pinterest.ktlint:ktlint-ruleset-experimental:0.40.0=ktlint 56 | com.pinterest.ktlint:ktlint-ruleset-experimental:0.44.0=spotless-1972455328 57 | com.pinterest.ktlint:ktlint-ruleset-standard:0.40.0=ktlint 58 | com.pinterest.ktlint:ktlint-ruleset-standard:0.44.0=spotless-1972455328 59 | com.pinterest.ktlint:ktlint-ruleset-test:0.40.0=ktlint 60 | com.pinterest.ktlint:ktlint-ruleset-test:0.44.0=spotless-1972455328 61 | com.pinterest:ktlint:0.40.0=ktlint 62 | com.pinterest:ktlint:0.44.0=spotless-1972455328 63 | commons-codec:commons-codec:1.10=testCompileClasspath,testRuntimeClasspath 64 | commons-collections:commons-collections:3.2.2=testCompileClasspath,testRuntimeClasspath 65 | commons-io:commons-io:2.4=testCompileClasspath,testRuntimeClasspath 66 | commons-logging:commons-logging:1.2=testCompileClasspath,testRuntimeClasspath 67 | info.picocli:picocli:3.9.6=ktlint,spotless-1972455328 68 | io.github.detekt.sarif4k:sarif4k:0.0.1=spotless-1972455328 69 | io.github.java-diff-utils:java-diff-utils:4.0=annotationProcessor,errorprone,testAnnotationProcessor 70 | io.github.microutils:kotlin-logging-jvm:2.1.21=spotless-1972455328 71 | javax.annotation:javax.annotation-api:1.2=testCompileClasspath,testRuntimeClasspath 72 | javax.servlet:javax.servlet-api:3.1.0=testCompileClasspath,testRuntimeClasspath 73 | javax.validation:validation-api:1.0.0.GA=testCompileClasspath,testRuntimeClasspath 74 | junit:junit:4.13.2=testCompileClasspath,testRuntimeClasspath 75 | net.java.dev.jna:jna:5.6.0=spotless-1972455328 76 | net.sourceforge.cssparser:cssparser:0.9.18=testCompileClasspath,testRuntimeClasspath 77 | net.sourceforge.htmlunit:htmlunit-core-js:2.17=testCompileClasspath,testRuntimeClasspath 78 | net.sourceforge.htmlunit:htmlunit:2.19=testCompileClasspath,testRuntimeClasspath 79 | net.sourceforge.nekohtml:nekohtml:1.9.22=testCompileClasspath,testRuntimeClasspath 80 | org.apache.commons:commons-lang3:3.4=testCompileClasspath,testRuntimeClasspath 81 | org.apache.httpcomponents:httpclient:4.5.1=testCompileClasspath,testRuntimeClasspath 82 | org.apache.httpcomponents:httpcore:4.4.3=testCompileClasspath,testRuntimeClasspath 83 | org.apache.httpcomponents:httpmime:4.5.1=testCompileClasspath,testRuntimeClasspath 84 | org.checkerframework:checker-qual:2.5.2=googleJavaFormat1.7,spotless1972418317 85 | org.checkerframework:checker-qual:3.8.0=annotationProcessor,errorprone,testAnnotationProcessor 86 | org.checkerframework:dataflow-errorprone:3.15.0=annotationProcessor,errorprone,testAnnotationProcessor 87 | org.codehaus.mojo:animal-sniffer-annotations:1.17=googleJavaFormat1.7,spotless1972418317 88 | org.ec4j.core:ec4j-core:0.2.2=ktlint 89 | org.ec4j.core:ec4j-core:0.3.0=spotless-1972455328 90 | org.eclipse.jetty.toolchain:jetty-schemas:3.1.M0=testCompileClasspath,testRuntimeClasspath 91 | org.eclipse.jetty.websocket:websocket-api:9.2.13.v20150730=testCompileClasspath,testRuntimeClasspath 92 | org.eclipse.jetty.websocket:websocket-client:9.2.13.v20150730=testCompileClasspath,testRuntimeClasspath 93 | org.eclipse.jetty.websocket:websocket-common:9.2.13.v20150730=testCompileClasspath,testRuntimeClasspath 94 | org.eclipse.jetty:apache-jsp:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 95 | org.eclipse.jetty:jetty-annotations:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 96 | org.eclipse.jetty:jetty-continuation:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 97 | org.eclipse.jetty:jetty-http:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 98 | org.eclipse.jetty:jetty-io:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 99 | org.eclipse.jetty:jetty-jndi:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 100 | org.eclipse.jetty:jetty-plus:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 101 | org.eclipse.jetty:jetty-security:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 102 | org.eclipse.jetty:jetty-server:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 103 | org.eclipse.jetty:jetty-servlet:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 104 | org.eclipse.jetty:jetty-servlets:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 105 | org.eclipse.jetty:jetty-util:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 106 | org.eclipse.jetty:jetty-webapp:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 107 | org.eclipse.jetty:jetty-xml:9.2.14.v20151106=testCompileClasspath,testRuntimeClasspath 108 | org.eclipse.jgit:org.eclipse.jgit:4.4.1.201607150455-r=annotationProcessor,errorprone,testAnnotationProcessor 109 | org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath 110 | org.jetbrains.intellij.deps:trove4j:1.0.20181211=ktlint,spotless-1972455328 111 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10=ktlint 112 | org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.0=spotless-1972455328 113 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.4.10=ktlint 114 | org.jetbrains.kotlin:kotlin-daemon-embeddable:1.6.0=spotless-1972455328 115 | org.jetbrains.kotlin:kotlin-reflect:1.4.10=ktlint 116 | org.jetbrains.kotlin:kotlin-reflect:1.6.0=spotless-1972455328 117 | org.jetbrains.kotlin:kotlin-script-runtime:1.4.10=ktlint 118 | org.jetbrains.kotlin:kotlin-script-runtime:1.6.0=spotless-1972455328 119 | org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10=ktlint 120 | org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0=spotless-1972455328 121 | org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0=spotless-1972455328 122 | org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0=spotless-1972455328 123 | org.jetbrains.kotlin:kotlin-stdlib:1.4.10=ktlint 124 | org.jetbrains.kotlin:kotlin-stdlib:1.6.0=spotless-1972455328 125 | org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.1.0=spotless-1972455328 126 | org.jetbrains.kotlinx:kotlinx-serialization-core:1.1.0=spotless-1972455328 127 | org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.1.0=spotless-1972455328 128 | org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0=spotless-1972455328 129 | org.jetbrains:annotations:13.0=ktlint,spotless-1972455328 130 | org.mortbay.jasper:apache-el:8.0.9.M3=testCompileClasspath,testRuntimeClasspath 131 | org.mortbay.jasper:apache-jsp:8.0.9.M3=testCompileClasspath,testRuntimeClasspath 132 | org.ow2.asm:asm-analysis:7.1=testCompileClasspath,testRuntimeClasspath 133 | org.ow2.asm:asm-commons:7.1=testCompileClasspath,testRuntimeClasspath 134 | org.ow2.asm:asm-tree:7.1=testCompileClasspath,testRuntimeClasspath 135 | org.ow2.asm:asm-util:7.1=testCompileClasspath,testRuntimeClasspath 136 | org.ow2.asm:asm:7.1=testCompileClasspath,testRuntimeClasspath 137 | org.pcollections:pcollections:2.1.2=annotationProcessor,errorprone,testAnnotationProcessor 138 | org.slf4j:slf4j-api:1.7.32=spotless-1972455328 139 | org.w3c.css:sac:1.3=testCompileClasspath,testRuntimeClasspath 140 | tapestry:tapestry:4.0.2=testCompileClasspath,testRuntimeClasspath 141 | xalan:serializer:2.7.2=testCompileClasspath,testRuntimeClasspath 142 | xalan:xalan:2.7.2=testCompileClasspath,testRuntimeClasspath 143 | xerces:xercesImpl:2.11.0=testCompileClasspath,testRuntimeClasspath 144 | xml-apis:xml-apis:1.4.01=testCompileClasspath,testRuntimeClasspath 145 | empty=ktlintReporter,ktlintRuleset,signatures 146 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | ktlint = "0.44.0" 3 | googleJavaFormat = "1.7" # last JDK-8-compatible version 4 | 5 | elemental2 = "1.1.0" 6 | gwt = "2.9.0" 7 | 8 | [libraries] 9 | errorprone-core = "com.google.errorprone:error_prone_core:2.10.0" # last JDK-8-compatible version 10 | errorprone-javac = "com.google.errorprone:javac:9+181-r4173-1" 11 | elemental2-core = { module = "com.google.elemental2:elemental2-core", version.ref = "elemental2" } 12 | elemental2-dom = { module = "com.google.elemental2:elemental2-dom", version.ref = "elemental2" } 13 | jsinterop-base = "com.google.jsinterop:base:1.0.0" 14 | 15 | junit = "junit:junit:4.13.2" 16 | gwt-user = { module = "com.google.gwt:gwt-user", version.ref = "gwt" } 17 | gwt-dev = { module = "com.google.gwt:gwt-dev", version.ref = "gwt" } 18 | 19 | [plugins] 20 | errorprone = "net.ltgt.errorprone:2.0.2" 21 | spotless = "com.diffplug.spotless:6.3.0" 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gwtproject/gwt-http/67df858dcca9c7a5d21e1eccd0c3a9fac0ce5a27/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /pom-j2cl-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.gwtproject.http 5 | gwt-http-j2cl-tests 6 | DO_NOT_DEPLOY 7 | 8 | 9 | UTF-8 10 | 1.8 11 | 1.8 12 | 13 | 8080 14 | 9999 15 | 16 | htmlunit 17 | 18 | 19 | 20 | 21 | vertispan-snapshots 22 | https://repo.vertispan.com/j2cl/ 23 | 24 | false 25 | 26 | 27 | true 28 | 29 | 30 | 31 | 32 | 33 | vertispan-snapshots 34 | https://repo.vertispan.com/j2cl/ 35 | 36 | false 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.gwtproject.http 47 | gwt-http 48 | LOCAL 49 | 50 | 51 | com.vertispan.j2cl 52 | junit-annotations 53 | 0.9-SNAPSHOT 54 | test 55 | 56 | 57 | com.vertispan.j2cl 58 | junit-emul 59 | 0.9-SNAPSHOT 60 | test 61 | 62 | 63 | com.vertispan.j2cl 64 | junit-emul 65 | 0.9-SNAPSHOT 66 | test 67 | sources 68 | 69 | 70 | 71 | 72 | src/testFixtures/java 73 | src/j2cl-test/java 74 | 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-surefire-plugin 79 | 2.22.2 80 | 81 | true 82 | 83 | 84 | 85 | com.vertispan.j2cl 86 | j2cl-maven-plugin 87 | 0.17-SNAPSHOT 88 | 89 | ${webdriver} 90 | ADVANCED 91 | 92 | http://localhost:${jetty.http.port}/ 93 | ${webdriver} 94 | 95 | 96 | 97 | 98 | j2cl-test 99 | integration-test 100 | 101 | test 102 | 103 | 104 | 105 | 106 | 107 | org.eclipse.jetty 108 | jetty-maven-plugin 109 | 9.4.45.v20220203 110 | 111 | 112 | jar 113 | 114 | 0 115 | STOP 116 | ${jetty.stop.port} 117 | build/classes/java/test 118 | src/j2cl-test/webapp 119 | 120 | 121 | 122 | start-jetty 123 | pre-integration-test 124 | 125 | start 126 | 127 | 128 | 129 | stop-jetty 130 | post-integration-test 131 | 132 | stop 133 | 134 | 135 | 136 | 137 | 138 | org.eclipse.jetty 139 | jetty-servlets 140 | 9.4.45.v20220203 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /settings-gradle.lockfile: -------------------------------------------------------------------------------- 1 | # This is a Gradle generated file for dependency locking. 2 | # Manual edits can break the build and are not advised. 3 | # This file is expected to be part of source control. 4 | empty=classpath,incomingCatalogForLibs0 5 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | includeBuild("build-logic") 3 | } 4 | 5 | rootProject.name = "gwt-http" 6 | 7 | buildscript { 8 | dependencyLocking { 9 | lockAllConfigurations() 10 | lockMode.set(LockMode.STRICT) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/RequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_DELETE_RESPONSE; 19 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_GET_RESPONSE; 20 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_HEAD_RESPONSE; 21 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_POST_RESPONSE; 22 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_PUT_RESPONSE; 23 | import static org.junit.Assert.assertEquals; 24 | import static org.junit.Assert.fail; 25 | 26 | import com.google.j2cl.junit.apt.J2clTestInput; 27 | import elemental2.promise.Promise; 28 | import org.junit.Test; 29 | 30 | /** Test cases for the {@link RequestBuilder} class. */ 31 | @J2clTestInput(RequestBuilderTest.class) 32 | public class RequestBuilderTest extends RequestTestBase { 33 | 34 | private static String getTestBaseURL() { 35 | return BASE_URL + "testRequestBuilder/"; 36 | } 37 | 38 | /** 39 | * Test method for {@link RequestBuilder#RequestBuilder(String, String)}. 40 | * 41 | *

Test Cases: 42 | * 43 | *

    44 | *
  • httpMethod == null 45 | *
  • httpMethod == "" 46 | *
  • url == null 47 | *
  • url == "" 48 | *
49 | */ 50 | @Test 51 | public void testRequestBuilderStringString() throws RequestException { 52 | try { 53 | new RequestBuilder((RequestBuilder.Method) null, null); 54 | fail("NullPointerException should have been thrown for construction with null method."); 55 | } catch (NullPointerException ex) { 56 | // purposely ignored 57 | } 58 | 59 | try { 60 | new RequestBuilder(RequestBuilder.GET, null); 61 | fail("NullPointerException should have been thrown for construction with null URL."); 62 | } catch (NullPointerException ex) { 63 | // purposely ignored 64 | } 65 | 66 | try { 67 | new RequestBuilder(RequestBuilder.GET, ""); 68 | fail("IllegalArgumentException should have been throw for construction with empty URL."); 69 | } catch (IllegalArgumentException ex) { 70 | // purposely ignored 71 | } 72 | } 73 | 74 | /** Test method for {@link RequestBuilder#RequestBuilder(String, String)}. */ 75 | @Test 76 | public void testRequestBuilderStringString_HTTPMethodRestrictionOverride() { 77 | new RequestBuilder(RequestBuilder.GET, "FOO"); 78 | 79 | class MyRequestBuilder extends RequestBuilder { 80 | MyRequestBuilder(String httpMethod, String url) { 81 | super(httpMethod, url); 82 | } 83 | } 84 | 85 | new MyRequestBuilder("HEAD", "FOO"); 86 | // should reach here without any exceptions being thrown 87 | } 88 | 89 | @Test(timeout = REQUEST_TIMEOUT) 90 | public Promise testSend_DELETE() throws RequestException { 91 | RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, getTestBaseURL()); 92 | return testSend(builder, SERVLET_DELETE_RESPONSE); 93 | } 94 | 95 | @Test(timeout = REQUEST_TIMEOUT) 96 | public Promise testSend_GET() throws RequestException { 97 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "send_GET"); 98 | return testSend(builder, SERVLET_GET_RESPONSE); 99 | } 100 | 101 | @Test(timeout = REQUEST_TIMEOUT) 102 | public Promise testSend_HEAD() throws RequestException { 103 | RequestBuilder builder = new RequestBuilder(RequestBuilder.HEAD, getTestBaseURL()); 104 | return testSend(builder, SERVLET_HEAD_RESPONSE); 105 | } 106 | 107 | @Test(timeout = REQUEST_TIMEOUT) 108 | public Promise testSend_POST() throws RequestException { 109 | RequestBuilder builder = 110 | new RequestBuilder(RequestBuilder.POST, getTestBaseURL() + "sendRequest_POST"); 111 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 112 | return testSend(builder, SERVLET_POST_RESPONSE); 113 | } 114 | 115 | @Test(timeout = REQUEST_TIMEOUT) 116 | public Promise testSend_PUT() throws RequestException { 117 | RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, getTestBaseURL()); 118 | builder.setHeader("Content-Type", "text/html"); 119 | builder.setRequestData("Put Me"); 120 | return testSend(builder, SERVLET_PUT_RESPONSE); 121 | } 122 | 123 | @Test(timeout = REQUEST_TIMEOUT) 124 | public Promise testSendRequest_DELETE() throws RequestException { 125 | RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, getTestBaseURL()); 126 | return testSendRequest(builder, null, SERVLET_DELETE_RESPONSE); 127 | } 128 | 129 | @Test(timeout = REQUEST_TIMEOUT) 130 | public Promise testSendRequest_GET() throws RequestException { 131 | RequestBuilder builder = 132 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "sendRequest_GET"); 133 | return testSendRequest(builder, null, SERVLET_GET_RESPONSE); 134 | } 135 | 136 | @Test(timeout = REQUEST_TIMEOUT) 137 | public Promise testSendRequest_HEAD() throws RequestException { 138 | RequestBuilder builder = new RequestBuilder(RequestBuilder.HEAD, getTestBaseURL()); 139 | return testSendRequest(builder, null, SERVLET_HEAD_RESPONSE); 140 | } 141 | 142 | @Test(timeout = REQUEST_TIMEOUT) 143 | public Promise testSendRequest_POST() throws RequestException { 144 | RequestBuilder builder = 145 | new RequestBuilder(RequestBuilder.POST, getTestBaseURL() + "sendRequest_POST"); 146 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 147 | return testSendRequest(builder, null, SERVLET_POST_RESPONSE); 148 | } 149 | 150 | @Test(timeout = REQUEST_TIMEOUT) 151 | public Promise testSendRequest_PUT() throws RequestException { 152 | RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, getTestBaseURL()); 153 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 154 | return testSendRequest(builder, "Put Me", SERVLET_PUT_RESPONSE); 155 | } 156 | 157 | @Test 158 | public void testSetCallback() { 159 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 160 | try { 161 | builder.setCallback(null); 162 | fail("Expected NullPointerException"); 163 | } catch (NullPointerException expected) { 164 | } 165 | } 166 | 167 | @Test 168 | public void testSetPassword() { 169 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 170 | try { 171 | builder.setPassword(null); 172 | fail("Expected NullPointerException"); 173 | } catch (NullPointerException expected) { 174 | } 175 | 176 | try { 177 | builder.setPassword(""); 178 | fail("Expected IllegalArgumentException"); 179 | } catch (IllegalArgumentException expected) { 180 | } 181 | } 182 | 183 | @Test 184 | public void testSetRequestData() { 185 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 186 | // Legal. 187 | builder.setRequestData(null); 188 | builder.setRequestData(""); 189 | } 190 | 191 | /** 192 | * Test method for {@link RequestBuilder#setHeader(String, String)}. 193 | * 194 | *

Test Cases: 195 | * 196 | *

    197 | *
  • name == null 198 | *
  • name == "" 199 | *
  • value == null 200 | *
  • value == "" 201 | *
202 | */ 203 | @Test(timeout = REQUEST_TIMEOUT) 204 | public Promise testSetRequestHeader() throws RequestException { 205 | RequestBuilder builder = 206 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setRequestHeader"); 207 | 208 | try { 209 | builder.setHeader(null, "bar"); 210 | fail("setRequestHeader(null, \"bar\")"); 211 | } catch (NullPointerException expected) { 212 | } 213 | 214 | try { 215 | builder.setHeader("", "bar"); 216 | fail("setRequestHeader(\"\", \"bar\")"); 217 | } catch (IllegalArgumentException expected) { 218 | } 219 | 220 | try { 221 | builder.setHeader("foo", null); 222 | fail("setRequestHeader(\"foo\", null)"); 223 | } catch (NullPointerException expected) { 224 | } 225 | 226 | try { 227 | builder.setHeader("foo", ""); 228 | fail("setRequestHeader(\"foo\", \"\")"); 229 | } catch (IllegalArgumentException expected) { 230 | } 231 | 232 | builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setRequestHeader"); 233 | builder.setHeader("Foo", "Bar"); 234 | builder.setHeader("Foo", "Bar1"); 235 | 236 | return sendRequest( 237 | builder, 238 | null, 239 | new RequestCallback() { 240 | @Override 241 | public void onError(Request request, Throwable exception) { 242 | fail(exception.getMessage()); 243 | } 244 | 245 | @Override 246 | public void onResponseReceived(Request request, Response response) { 247 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 248 | assertEquals(200, response.getStatusCode()); 249 | } 250 | }); 251 | } 252 | 253 | /** 254 | * Test method for {@link RequestBuilder#setTimeoutMillis(int)}. 255 | * 256 | *

Test Cases: 257 | * 258 | *

    259 | *
  • Timeout greater than the server's response time 260 | *
  • Timeout is less than the server's response time 261 | *
262 | */ 263 | @Test(timeout = REQUEST_TIMEOUT) 264 | public Promise testSetTimeout_noTimeout() throws RequestException { 265 | RequestBuilder builder = 266 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setTimeout/noTimeout"); 267 | builder.setTimeoutMillis(10000); 268 | return sendRequest( 269 | builder, 270 | null, 271 | new RequestCallback() { 272 | @Override 273 | public void onError(Request request, Throwable exception) { 274 | fail(exception.getMessage()); 275 | } 276 | 277 | @Override 278 | public void onResponseReceived(Request request, Response response) { 279 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 280 | assertEquals(200, response.getStatusCode()); 281 | } 282 | }); 283 | } 284 | 285 | /** 286 | * Test method for {@link RequestBuilder#setTimeoutMillis(int)}. 287 | * 288 | *

Test Cases: 289 | * 290 | *

    291 | *
  • Timeout greater than the server's response time 292 | *
  • Timeout is less than the server's response time 293 | *
294 | * 295 | *

XHR handling is synchronous in HtmlUnit at present (svn r5607). 296 | */ 297 | @Test(timeout = REQUEST_TIMEOUT) 298 | public Promise testSetTimeout_timeout() throws RequestException { 299 | if ("htmlunit".equals(System.getProperty("test.webdriver", "htmlunit"))) { 300 | // XHR handling is synchronous in HtmlUnit 301 | return Promise.resolve((Void) null); 302 | } 303 | RequestBuilder builder = 304 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setTimeout/timeout"); 305 | builder.setTimeoutMillis(2000); 306 | return sendRequest( 307 | builder, 308 | null, 309 | new RequestCallback() { 310 | @Override 311 | public void onError(Request request, Throwable exception) {} 312 | 313 | @Override 314 | public void onResponseReceived(Request request, Response response) { 315 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 316 | assertEquals(200, response.getStatusCode()); 317 | fail("Test did not timeout"); 318 | } 319 | }); 320 | } 321 | 322 | @Test 323 | public void testSetUser() { 324 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 325 | try { 326 | builder.setUser(null); 327 | fail("Expected NullPointerException"); 328 | } catch (NullPointerException expected) { 329 | } 330 | 331 | try { 332 | builder.setUser(""); 333 | fail("Expected IllegalArgumentException"); 334 | } catch (IllegalArgumentException expected) { 335 | } 336 | } 337 | 338 | /** 339 | * Helper method to test {@link RequestBuilder#send()}. 340 | * 341 | * @param builder the {@link RequestBuilder} 342 | * @param expectedResponse the expected response 343 | */ 344 | private Promise testSend(RequestBuilder builder, final String expectedResponse) 345 | throws RequestException { 346 | return withCallback( 347 | new RequestCallback() { 348 | @Override 349 | public void onError(Request request, Throwable exception) { 350 | fail(exception.getMessage()); 351 | } 352 | 353 | @Override 354 | public void onResponseReceived(Request request, Response response) { 355 | assertEquals(expectedResponse, response.getText()); 356 | assertEquals(200, response.getStatusCode()); 357 | } 358 | }, 359 | cb -> { 360 | builder.setCallback(cb); 361 | builder.send(); 362 | }); 363 | } 364 | 365 | /** 366 | * Helper method to test {@link RequestBuilder#sendRequest(String, RequestCallback)}. 367 | * 368 | * @param builder the {@link RequestBuilder} 369 | * @param requestData the data to request 370 | * @param expectedResponse the expected response 371 | */ 372 | private Promise testSendRequest( 373 | RequestBuilder builder, String requestData, final String expectedResponse) 374 | throws RequestException { 375 | return sendRequest( 376 | builder, 377 | requestData, 378 | new RequestCallback() { 379 | @Override 380 | public void onError(Request request, Throwable exception) { 381 | fail(exception.getMessage()); 382 | } 383 | 384 | @Override 385 | public void onResponseReceived(Request request, Response response) { 386 | assertEquals(expectedResponse, response.getText()); 387 | assertEquals(200, response.getStatusCode()); 388 | } 389 | }); 390 | } 391 | } 392 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/RequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertFalse; 20 | import static org.junit.Assert.assertTrue; 21 | import static org.junit.Assert.fail; 22 | 23 | import com.google.j2cl.junit.apt.J2clTestInput; 24 | import elemental2.dom.XMLHttpRequest; 25 | import elemental2.promise.Promise; 26 | import org.junit.Test; 27 | 28 | /** TODO: document me. */ 29 | @J2clTestInput(RequestTest.class) 30 | public class RequestTest extends RequestTestBase { 31 | 32 | private static String getTestBaseURL() { 33 | return BASE_URL + "testRequest/"; 34 | } 35 | 36 | /** Test method for {@link Request#cancel()}. */ 37 | @Test(timeout = REQUEST_TIMEOUT) 38 | public Promise testCancel() { 39 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "/cancel"); 40 | return new Promise<>( 41 | (resolve, reject) -> { 42 | try { 43 | Request request = 44 | builder.sendRequest( 45 | null, 46 | wrapCallback( 47 | new RequestCallback() { 48 | @Override 49 | public void onResponseReceived(Request request, Response response) { 50 | fail("Request was canceled - no response should be received"); 51 | } 52 | 53 | @Override 54 | public void onError(Request request, Throwable exception) { 55 | fail("Request was canceled - no timeout should occur"); 56 | } 57 | }, 58 | resolve, 59 | reject)); 60 | 61 | assertTrue(request.isPending()); 62 | request.cancel(); 63 | assertFalse(request.isPending()); 64 | 65 | resolve.onInvoke((Void) null); 66 | } catch (RequestException e) { 67 | fail(e.getMessage()); 68 | } 69 | }); 70 | } 71 | 72 | /** Test method for {@link Request#Request(XMLHttpRequest, int, RequestCallback)}. */ 73 | @Test 74 | public void testRequest() { 75 | RequestCallback callback = 76 | new RequestCallback() { 77 | @Override 78 | public void onResponseReceived(Request request, Response response) {} 79 | 80 | @Override 81 | public void onError(Request request, Throwable exception) {} 82 | }; 83 | 84 | try { 85 | new Request(null, 0, callback); 86 | fail(); 87 | } catch (NullPointerException ex) { 88 | // Success (The Request ctor explicitly throws an NPE). 89 | } 90 | 91 | try { 92 | new Request(new XMLHttpRequest(), -1, callback); 93 | fail(); 94 | } catch (IllegalArgumentException ex) { 95 | // Success. 96 | } 97 | 98 | try { 99 | new Request(new XMLHttpRequest(), -1, null); 100 | fail(); 101 | } catch (NullPointerException ex) { 102 | // Success (The Request ctor explicitly throws an NPE). 103 | } 104 | 105 | try { 106 | new Request(new XMLHttpRequest(), 0, callback); 107 | } catch (Throwable ex) { 108 | fail(ex.getMessage()); 109 | } 110 | } 111 | 112 | /** Test method for {@link Request#isPending()}. */ 113 | @Test(timeout = REQUEST_TIMEOUT) 114 | public Promise testIsPending() { 115 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "isPending"); 116 | return withCallback( 117 | new RequestCallback() { 118 | @Override 119 | public void onResponseReceived(Request request, Response response) {} 120 | 121 | @Override 122 | public void onError(Request request, Throwable exception) {} 123 | }, 124 | cb -> { 125 | try { 126 | Request request = builder.sendRequest(null, cb); 127 | 128 | assertTrue(request.isPending()); 129 | } catch (RequestException e) { 130 | fail(e.getMessage()); 131 | } 132 | }); 133 | } 134 | 135 | /* 136 | * Checks that the status code is correct when receiving a 204-No-Content. This needs special 137 | * handling in IE6-9. See http://code.google.com/p/google-web-toolkit/issues/detail?id=5031 138 | */ 139 | @Test(timeout = REQUEST_TIMEOUT) 140 | public Promise test204NoContent() { 141 | RequestBuilder builder = 142 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "204NoContent"); 143 | return sendRequest( 144 | builder, 145 | null, 146 | new RequestCallback() { 147 | 148 | @Override 149 | public void onResponseReceived(Request request, Response response) { 150 | assertEquals(204, response.getStatusCode()); 151 | } 152 | 153 | @Override 154 | public void onError(Request request, Throwable exception) { 155 | fail(exception.getMessage()); 156 | } 157 | }); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/RequestTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import elemental2.promise.Promise; 19 | import elemental2.promise.Promise.PromiseExecutorCallbackFn.RejectCallbackFn; 20 | import elemental2.promise.Promise.PromiseExecutorCallbackFn.ResolveCallbackFn; 21 | 22 | /** Base class for tests that send an http request. */ 23 | public abstract class RequestTestBase { 24 | protected static final String BASE_URL = 25 | System.getProperty("test.baseUrl", "http://localhost:8080/"); 26 | 27 | /** The timeout for request tests. */ 28 | protected static final int REQUEST_TIMEOUT = 15000; 29 | 30 | @FunctionalInterface 31 | protected interface Action { 32 | void accept(RequestCallback callback) throws Exception; 33 | } 34 | 35 | protected static Promise sendRequest( 36 | RequestBuilder builder, String requestData, RequestCallback callback) { 37 | return withCallback(callback, cb -> builder.sendRequest(requestData, cb)); 38 | } 39 | 40 | protected static Promise withCallback(RequestCallback callback, Action action) { 41 | return new Promise<>( 42 | (resolve, reject) -> { 43 | try { 44 | action.accept(wrapCallback(callback, resolve, reject)); 45 | } catch (Throwable throwable) { 46 | reject.onInvoke(throwable); 47 | } 48 | }); 49 | } 50 | 51 | protected static RequestCallback wrapCallback( 52 | RequestCallback callback, ResolveCallbackFn resolve, RejectCallbackFn reject) { 53 | return new RequestCallback() { 54 | @Override 55 | public void onResponseReceived(Request request, Response response) { 56 | try { 57 | callback.onResponseReceived(request, response); 58 | } catch (Throwable throwable) { 59 | reject.onInvoke(throwable); 60 | return; 61 | } 62 | resolve.onInvoke((Void) null); 63 | } 64 | 65 | @Override 66 | public void onError(Request request, Throwable exception) { 67 | try { 68 | callback.onError(request, exception); 69 | } catch (Throwable throwable) { 70 | reject.onInvoke(throwable); 71 | return; 72 | } 73 | resolve.onInvoke((Void) null); 74 | } 75 | }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/ResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertNotNull; 20 | import static org.junit.Assert.fail; 21 | 22 | import com.google.j2cl.junit.apt.J2clTestInput; 23 | import elemental2.dom.XMLHttpRequest; 24 | import elemental2.promise.Promise; 25 | import org.junit.Test; 26 | 27 | /** */ 28 | @J2clTestInput(ResponseTest.class) 29 | public class ResponseTest extends RequestTestBase { 30 | 31 | private static RequestBuilder getHTTPRequestBuilder() { 32 | return getHTTPRequestBuilder(getTestBaseURL()); 33 | } 34 | 35 | private static RequestBuilder getHTTPRequestBuilder(String testURL) { 36 | return new RequestBuilder(RequestBuilder.GET, testURL); 37 | } 38 | 39 | private static String getTestBaseURL() { 40 | return BASE_URL + "testResponse/"; 41 | } 42 | 43 | private static void raiseUnexpectedException(Throwable exception) { 44 | fail("Unexpected exception: " + exception.toString()); 45 | } 46 | 47 | /** Test method for {@link Response#getStatusCode()}. */ 48 | @Test(timeout = REQUEST_TIMEOUT) 49 | public Promise testGetStatusCode() { 50 | return executeTest( 51 | new RequestCallback() { 52 | @Override 53 | public void onError(Request request, Throwable exception) { 54 | fail(); 55 | } 56 | 57 | @Override 58 | public void onResponseReceived(Request request, Response response) { 59 | assertEquals(200, response.getStatusCode()); 60 | } 61 | }); 62 | } 63 | 64 | /** Test method for {@link Response#getStatusText()}. */ 65 | @Test(timeout = REQUEST_TIMEOUT) 66 | public Promise testGetStatusText() { 67 | return executeTest( 68 | new RequestCallback() { 69 | @Override 70 | public void onError(Request request, Throwable exception) { 71 | if (exception instanceof RuntimeException) { 72 | 73 | } else { 74 | raiseUnexpectedException(exception); 75 | } 76 | } 77 | 78 | @Override 79 | public void onResponseReceived(Request request, Response response) { 80 | assertEquals("OK", response.getStatusText()); 81 | } 82 | }); 83 | } 84 | 85 | @Test 86 | public void testGetHeadersOffline() { 87 | ResponseImpl resp = 88 | new ResponseImpl(new XMLHttpRequest()) { 89 | @Override 90 | protected boolean isResponseReady() { 91 | return true; 92 | } 93 | }; 94 | Header[] headers = resp.getHeaders(); 95 | assertNotNull(headers); 96 | assertEquals(0, headers.length); 97 | } 98 | 99 | private Promise executeTest(RequestBuilder builder, RequestCallback callback) { 100 | return sendRequest(builder, null, callback); 101 | } 102 | 103 | private Promise executeTest(RequestCallback callback) { 104 | return executeTest(getHTTPRequestBuilder(), callback); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/URLTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.fail; 20 | 21 | import com.google.j2cl.junit.apt.J2clTestInput; 22 | import org.junit.Test; 23 | 24 | /** Tests for the URL utility class. */ 25 | @J2clTestInput(URLTest.class) 26 | public class URLTest { 27 | 28 | private final String DECODED_URL = "http://www.foo \u00E9+bar.com/1_!~*'();/?@&=+$,#"; 29 | private final String DECODED_URL_COMPONENT = "-_.!~*'():/#?@ \u00E9+"; 30 | private final String ENCODED_URL = "http://www.foo%20%C3%A9+bar.com/1_!~*'();/?@&=+$,#"; 31 | private final String ENCODED_URL_COMPONENT = "-_.!~*'()%3A%2F%23%3F%40%20%C3%A9%2B"; 32 | private final String ENCODED_URL_COMPONENT_QS = "-_.!~*'()%3A%2F%23%3F%40+%C3%A9%2B"; 33 | 34 | /** Test method for {@link URL#decode(String)}. */ 35 | @Test 36 | public void testDecode() { 37 | try { 38 | URL.decode(null); 39 | fail("Expected NullPointerException"); 40 | } catch (NullPointerException ex) { 41 | // expected exception was thrown 42 | } 43 | 44 | assertEquals("", URL.decode("")); 45 | assertEquals(" ", URL.decode(" ")); 46 | 47 | String actualURL = URL.decode(ENCODED_URL); 48 | assertEquals(DECODED_URL, actualURL); 49 | } 50 | 51 | /** Test method for {@link URL#decodePathSegment(String)}. */ 52 | @Test 53 | public void testDecodePathSegment() { 54 | try { 55 | URL.decodePathSegment(null); 56 | fail("Expected NullPointerException"); 57 | } catch (NullPointerException ex) { 58 | // expected exception was thrown 59 | } 60 | 61 | assertEquals("", URL.decodePathSegment("")); 62 | assertEquals(" ", URL.decodePathSegment(" ")); 63 | assertEquals("+", URL.decodePathSegment("+")); 64 | assertEquals(" ", URL.decodePathSegment("%20")); 65 | 66 | String actualURLComponent = URL.decodePathSegment(ENCODED_URL_COMPONENT); 67 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 68 | } 69 | 70 | /** Test method for {@link URL#decodeQueryString(String)}. */ 71 | @Test 72 | public void testDecodeQueryString() { 73 | try { 74 | URL.decodeQueryString(null); 75 | fail("Expected NullPointerException"); 76 | } catch (NullPointerException ex) { 77 | // expected exception was thrown 78 | } 79 | 80 | try { 81 | // Malformed URI sequence 82 | URL.decodeQueryString("%E4"); 83 | fail("Expected JavaScriptException"); 84 | } catch (Exception expected) { 85 | assertEquals("java.lang.JsException", expected.getClass().getName()); 86 | } 87 | 88 | assertEquals("", URL.decodeQueryString("")); 89 | assertEquals(" ", URL.decodeQueryString(" ")); 90 | assertEquals(" ", URL.decodeQueryString("+")); 91 | assertEquals(" ", URL.decodeQueryString("%20")); 92 | 93 | String actualURLComponent = URL.decodeQueryString(ENCODED_URL_COMPONENT); 94 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 95 | 96 | actualURLComponent = URL.decodeQueryString(ENCODED_URL_COMPONENT_QS); 97 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 98 | } 99 | 100 | /** Test method for {@link URL#encode(String)}. */ 101 | public void testEncode() { 102 | try { 103 | URL.encode(null); 104 | fail("Expected NullPointerException"); 105 | } catch (NullPointerException ex) { 106 | // expected exception was thrown 107 | } 108 | 109 | assertEquals("", URL.encode("")); 110 | assertEquals("%20", URL.encode(" ")); 111 | 112 | String actualURL = URL.encode(DECODED_URL); 113 | assertEquals(ENCODED_URL, actualURL); 114 | } 115 | 116 | /** Test method for {@link URL#encodePathSegment(String)}. */ 117 | @Test 118 | public void testEncodePathSegment() { 119 | try { 120 | URL.encodePathSegment(null); 121 | fail("Expected NullPointerException"); 122 | } catch (NullPointerException ex) { 123 | // expected exception was thrown 124 | } 125 | 126 | assertEquals("", URL.encodePathSegment("")); 127 | assertEquals("%20", URL.encodePathSegment(" ")); 128 | 129 | String actualURLComponent = URL.encodePathSegment(DECODED_URL_COMPONENT); 130 | assertEquals(ENCODED_URL_COMPONENT, actualURLComponent); 131 | } 132 | 133 | /** Test method for {@link URL#encodeQueryString(String)}. */ 134 | @Test 135 | public void testEncodeQueryString() { 136 | try { 137 | URL.encodeQueryString(null); 138 | fail("Expected NullPointerException"); 139 | } catch (NullPointerException ex) { 140 | // expected exception was thrown 141 | } 142 | 143 | assertEquals("", URL.encodeQueryString("")); 144 | assertEquals("+", URL.encodeQueryString(" ")); 145 | 146 | String actualURLComponent = URL.encodeQueryString(DECODED_URL_COMPONENT); 147 | assertEquals(ENCODED_URL_COMPONENT_QS, actualURLComponent); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/j2cl-test/java/org/gwtproject/http/client/UrlBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | import static org.junit.Assert.assertTrue; 20 | import static org.junit.Assert.fail; 21 | 22 | import com.google.j2cl.junit.apt.J2clTestInput; 23 | import org.junit.Test; 24 | 25 | /** Test Case for {@link UrlBuilder}. */ 26 | @J2clTestInput(UrlBuilderTest.class) 27 | public class UrlBuilderTest { 28 | 29 | /** Test that the URL is encoded correctly. */ 30 | @Test 31 | public void testBuildStringEncode() { 32 | UrlBuilder builder = new UrlBuilder(); 33 | builder.setHost("google.com"); 34 | builder.setPath("path to file"); 35 | builder.setParameter("the key", "the value"); 36 | assertEquals("http://google.com/path%20to%20file?the+key=the+value", builder.buildString()); 37 | 38 | builder = new UrlBuilder(); 39 | builder.setHost("google.com"); 40 | builder.setPath("?not-query#not-hash"); 41 | builder.setParameter("not=value¬-next", "¬-next=pair"); 42 | builder.setParameter("#not-hash", "#not-hash"); 43 | builder.setHash("hash#in-hash"); 44 | assertEquals( 45 | "http://google.com/%3Fnot-query%23not-hash?not%3Dvalue%26not-next=%26not-next%3Dpair&%23not-hash=%23not-hash#hash%23in-hash", 46 | builder.buildString()); 47 | 48 | builder = new UrlBuilder(); 49 | builder.setHost("google.com"); 50 | builder.setPath("path"); 51 | builder.setHash("hash"); 52 | 53 | builder.setParameter("a_b", "a+b"); 54 | assertEquals("http://google.com/path?a_b=a%2Bb#hash", builder.buildString()); 55 | 56 | builder.setParameter("a_b", "a&b"); 57 | assertEquals("http://google.com/path?a_b=a%26b#hash", builder.buildString()); 58 | 59 | builder.setParameter("a_b", "a%b"); 60 | assertEquals("http://google.com/path?a_b=a%25b#hash", builder.buildString()); 61 | 62 | // Hash characters in the fragment should be encoded (issue #8396) 63 | builder.setHash("ha#sh#"); 64 | assertEquals("http://google.com/path?a_b=a%25b#ha%23sh%23", builder.buildString()); 65 | } 66 | 67 | @Test 68 | public void testBuildStringEntireUrl() { 69 | UrlBuilder builder = new UrlBuilder(); 70 | builder.setHost("google.com"); 71 | 72 | // Host only. 73 | assertEquals("http://google.com", builder.buildString()); 74 | 75 | // Host:Port 76 | builder.setPort(100); 77 | assertEquals("http://google.com:100", builder.buildString()); 78 | 79 | // Host:Port/Path 80 | builder.setPath("path/to/file"); 81 | assertEquals("http://google.com:100/path/to/file", builder.buildString()); 82 | 83 | // Host:Port/Path?Param 84 | builder.setParameter("key", "value"); 85 | assertEquals("http://google.com:100/path/to/file?key=value", builder.buildString()); 86 | 87 | // Host:Port/Path?Param#Hash 88 | builder.setHash("token"); 89 | assertEquals("http://google.com:100/path/to/file?key=value#token", builder.buildString()); 90 | } 91 | 92 | @Test 93 | public void testBuildStringEntireUrlWithReturns() { 94 | UrlBuilder builder = new UrlBuilder(); 95 | builder 96 | .setHost("google.com") 97 | .setPort(100) 98 | .setPath("path/to/file") 99 | .setParameter("key", "value") 100 | .setHash("token"); 101 | assertEquals("http://google.com:100/path/to/file?key=value#token", builder.buildString()); 102 | } 103 | 104 | @Test 105 | public void testBuildStringParts() { 106 | UrlBuilder builder = new UrlBuilder(); 107 | builder.setHost("google.com"); 108 | 109 | // Host only. 110 | assertEquals("http://google.com", builder.buildString()); 111 | 112 | // Host:Port 113 | builder.setPort(100); 114 | assertEquals("http://google.com:100", builder.buildString()); 115 | builder.setPort(UrlBuilder.PORT_UNSPECIFIED); 116 | 117 | // Host/Path 118 | builder.setPath("path/to/file"); 119 | assertEquals("http://google.com/path/to/file", builder.buildString()); 120 | builder.setPath(null); 121 | 122 | // Host?Param 123 | builder.setParameter("key", "value"); 124 | assertEquals("http://google.com?key=value", builder.buildString()); 125 | builder.removeParameter("key"); 126 | 127 | // Host#Hash 128 | builder.setHash("token"); 129 | assertEquals("http://google.com#token", builder.buildString()); 130 | builder.setHash(null); 131 | } 132 | 133 | @Test 134 | public void testSetHash() { 135 | UrlBuilder builder = new UrlBuilder(); 136 | builder.setHost("google.com"); 137 | 138 | // Hash not specified 139 | assertEquals("http://google.com", builder.buildString()); 140 | 141 | // # added if not present 142 | builder.setHash("myHash"); 143 | assertEquals("http://google.com#myHash", builder.buildString()); 144 | 145 | // Null hash 146 | builder.setHash(null); 147 | assertEquals("http://google.com", builder.buildString()); 148 | 149 | // # not added if present 150 | builder.setHash("#myHash2"); 151 | assertEquals("http://google.com#myHash2", builder.buildString()); 152 | } 153 | 154 | @Test 155 | public void testSetHost() { 156 | UrlBuilder builder = new UrlBuilder(); 157 | 158 | // Host not specified. 159 | assertEquals("http://", builder.buildString()); 160 | 161 | // Null host. 162 | builder.setHost(null); 163 | assertEquals("http://", builder.buildString()); 164 | 165 | // Empty host. 166 | builder.setHost(""); 167 | assertEquals("http://", builder.buildString()); 168 | 169 | // google.com 170 | builder.setHost("google.com"); 171 | assertEquals("http://google.com", builder.buildString()); 172 | 173 | // google.com:80 174 | builder.setHost("google.com:80"); 175 | assertEquals("http://google.com:80", builder.buildString()); 176 | 177 | // google.com:80 with overridden port. 178 | builder.setHost("google.com:80"); 179 | builder.setPort(1000); 180 | assertEquals("http://google.com:1000", builder.buildString()); 181 | 182 | // google.com:80 with overridden port in host. 183 | builder.setPort(1000); 184 | builder.setHost("google.com:80"); 185 | assertEquals("http://google.com:80", builder.buildString()); 186 | 187 | // Specify to many ports. 188 | // google.com:80:90 189 | try { 190 | builder.setHost("google.com:80:90"); 191 | fail("Expected IllegalArgumentException"); 192 | } catch (IllegalArgumentException e) { 193 | // Expected. 194 | } 195 | 196 | // Specify invalid port. 197 | // google.com:test 198 | try { 199 | builder.setHost("google.com:test"); 200 | fail("Expected IllegalArgumentException"); 201 | } catch (IllegalArgumentException e) { 202 | // Expected. 203 | } 204 | } 205 | 206 | @Test 207 | public void testSetParameter() { 208 | UrlBuilder builder = new UrlBuilder(); 209 | builder.setHost("google.com"); 210 | 211 | // Parameters not specified. 212 | assertEquals("http://google.com", builder.buildString()); 213 | 214 | // Simple parameter. 215 | builder.setParameter("key", "value"); 216 | assertEquals("http://google.com?key=value", builder.buildString()); 217 | 218 | // Remove simple parameter. 219 | builder.removeParameter("key"); 220 | assertEquals("http://google.com", builder.buildString()); 221 | 222 | // List parameter. 223 | builder.setParameter("key", "value0", "value1", "value2"); 224 | assertEquals("http://google.com?key=value0&key=value1&key=value2", builder.buildString()); 225 | 226 | // Remove list parameter. 227 | builder.removeParameter("key"); 228 | assertEquals("http://google.com", builder.buildString()); 229 | 230 | // Multiple parameters. 231 | builder.setParameter("key0", "value0", "value1", "value2"); 232 | builder.setParameter("key1", "simpleValue"); 233 | 234 | // The order of query params is not defined, so either URL is acceptable. 235 | String url = builder.buildString(); 236 | assertTrue( 237 | url.equals("http://google.com?key0=value0&key0=value1&key0=value2&key1=simpleValue") 238 | || url.equals( 239 | "http://google.com?key1=simpleValue&key0=value0&key0=value1&key0=value2")); 240 | 241 | // Empty list of multiple parameters. 242 | builder.setParameter("key0", "value0", "value1", "value2"); 243 | builder.setParameter("key1", "simpleValue"); 244 | assertTrue( 245 | url.equals("http://google.com?key0=value0&key0=value1&key0=value2&key1=simpleValue") 246 | || url.equals( 247 | "http://google.com?key1=simpleValue&key0=value0&key0=value1&key0=value2")); 248 | } 249 | 250 | @Test 251 | public void testSetParameterToNull() { 252 | UrlBuilder builder = new UrlBuilder(); 253 | builder.setHost("google.com"); 254 | 255 | try { 256 | builder.setParameter(null, "value"); 257 | fail("Expected IllegalArgumentException"); 258 | } catch (IllegalArgumentException e) { 259 | // Expected. 260 | } 261 | 262 | try { 263 | builder.setParameter(null); 264 | fail("Expected IllegalArgumentException"); 265 | } catch (IllegalArgumentException e) { 266 | // Expected. 267 | } 268 | 269 | try { 270 | builder.setParameter("key", new String[0]); 271 | fail("Expected IllegalArgumentException"); 272 | } catch (IllegalArgumentException e) { 273 | // Expected. 274 | } 275 | 276 | try { 277 | builder.setParameter("key", (String[]) null); 278 | fail("Expected IllegalArgumentException"); 279 | } catch (IllegalArgumentException e) { 280 | // Expected. 281 | } 282 | 283 | // Null values are okay. 284 | builder.setParameter("key", (String) null); 285 | assertEquals("http://google.com?key=", builder.buildString()); 286 | } 287 | 288 | @Test 289 | public void testSetPath() { 290 | UrlBuilder builder = new UrlBuilder(); 291 | builder.setHost("google.com"); 292 | 293 | // Path not specified. 294 | assertEquals("http://google.com", builder.buildString()); 295 | 296 | // Null path. 297 | builder.setPath(null); 298 | assertEquals("http://google.com", builder.buildString()); 299 | 300 | // Empty path. 301 | builder.setPath(""); 302 | assertEquals("http://google.com", builder.buildString()); 303 | 304 | // path/to/file.html 305 | builder.setPath("path/to/file.html"); 306 | assertEquals("http://google.com/path/to/file.html", builder.buildString()); 307 | 308 | // /path/to/file.html 309 | builder.setPath("/path/to/file.html"); 310 | assertEquals("http://google.com/path/to/file.html", builder.buildString()); 311 | } 312 | 313 | @Test 314 | public void testSetPort() { 315 | UrlBuilder builder = new UrlBuilder(); 316 | builder.setHost("google.com"); 317 | 318 | // Port not specified. 319 | assertEquals("http://google.com", builder.buildString()); 320 | 321 | // Port 1000. 322 | builder.setPort(1000); 323 | assertEquals("http://google.com:1000", builder.buildString()); 324 | 325 | // PORT_UNSPECIFIED. 326 | builder.setPort(UrlBuilder.PORT_UNSPECIFIED); 327 | assertEquals("http://google.com", builder.buildString()); 328 | } 329 | 330 | @Test 331 | public void testSetProtocol() { 332 | UrlBuilder builder = new UrlBuilder(); 333 | builder.setHost("google.com"); 334 | 335 | // Protocol not specified. 336 | assertEquals("http://google.com", builder.buildString()); 337 | 338 | // Null host. 339 | try { 340 | builder.setProtocol(null); 341 | fail("Expected IllegalArgumentException"); 342 | } catch (IllegalArgumentException e) { 343 | // Expected. 344 | } 345 | 346 | // Empty host. 347 | try { 348 | builder.setProtocol(""); 349 | fail("Expected IllegalArgumentException"); 350 | } catch (IllegalArgumentException e) { 351 | // Expected. 352 | } 353 | 354 | // ftp 355 | builder.setProtocol("ftp"); 356 | assertEquals("ftp://google.com", builder.buildString()); 357 | 358 | // tcp: 359 | builder.setProtocol("tcp:"); 360 | assertEquals("tcp://google.com", builder.buildString()); 361 | 362 | // http:/ 363 | builder.setProtocol("http:/"); 364 | assertEquals("http://google.com", builder.buildString()); 365 | 366 | // http:// 367 | builder.setProtocol("http://"); 368 | assertEquals("http://google.com", builder.buildString()); 369 | } 370 | } 371 | -------------------------------------------------------------------------------- /src/j2cl-test/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | CORS 4 | org.eclipse.jetty.servlets.CrossOriginFilter 5 | 6 | allowedMethods 7 | HEAD,GET,POST,PUT,DELETE 8 | 9 | 10 | allowedHeaders 11 | Foo,Authorization,Content-Type,Accept,Origin 12 | 13 | 14 | exposedHeaders 15 | header1,header2,header3 16 | 17 | 18 | 19 | CORS 20 | /* 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/Header.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** Class for describing an HTTP header. */ 19 | public abstract class Header { 20 | /** 21 | * Returns the name of the HTTP header. 22 | * 23 | * @return name of the HTTP header 24 | */ 25 | public abstract String getName(); 26 | 27 | /** 28 | * Returns the value of the HTTP header. 29 | * 30 | * @return value of the HTTP header 31 | */ 32 | public abstract String getValue(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import elemental2.dom.DomGlobal; 19 | import elemental2.dom.XMLHttpRequest; 20 | 21 | /** 22 | * An HTTP request that is waiting for a response. Requests can be queried for their pending status 23 | * or they can be canceled. 24 | */ 25 | public class Request { 26 | 27 | /** 28 | * Creates a {@link Response} instance for the given JavaScript XmlHttpRequest object. 29 | * 30 | * @param xmlHttpRequest xmlHttpRequest object for which we need a response 31 | * @return a {@link Response} object instance 32 | */ 33 | private static Response createResponse(final XMLHttpRequest xmlHttpRequest) { 34 | return new ResponseImpl(xmlHttpRequest); 35 | } 36 | 37 | /** The number of milliseconds to wait for this HTTP request to complete. */ 38 | private final int timeoutMillis; 39 | 40 | /** ID of the timer used to force HTTPRequest timeouts. Only meaningful if timeoutMillis > 0. */ 41 | private final double timerId; 42 | 43 | /** 44 | * JavaScript XmlHttpRequest object that this Java class wraps. This field is not final because we 45 | * transfer ownership of it to the HTTPResponse object and set this field to null. 46 | */ 47 | private XMLHttpRequest xmlHttpRequest; 48 | 49 | /** 50 | * Constructs an instance of the Request object. 51 | * 52 | * @param xmlHttpRequest JavaScript XmlHttpRequest object instance 53 | * @param timeoutMillis number of milliseconds to wait for a response 54 | * @param callback callback interface to use for notification 55 | * @throws IllegalArgumentException if timeoutMillis < 0 56 | * @throws NullPointerException if xmlHttpRequest, or callback are null 57 | */ 58 | Request(XMLHttpRequest xmlHttpRequest, int timeoutMillis, RequestCallback callback) { 59 | if (xmlHttpRequest == null) { 60 | throw new NullPointerException(); 61 | } 62 | 63 | if (callback == null) { 64 | throw new NullPointerException(); 65 | } 66 | 67 | if (timeoutMillis < 0) { 68 | throw new IllegalArgumentException(); 69 | } 70 | 71 | this.timeoutMillis = timeoutMillis; 72 | this.xmlHttpRequest = xmlHttpRequest; 73 | 74 | if (timeoutMillis > 0) { 75 | timerId = DomGlobal.setTimeout(args -> fireOnTimeout(callback), timeoutMillis); 76 | } else { 77 | timerId = 0; 78 | } 79 | } 80 | 81 | /** 82 | * Cancels a pending request. If the request has already been canceled or if it has timed out no 83 | * action is taken. 84 | */ 85 | public void cancel() { 86 | if (xmlHttpRequest == null) { 87 | return; 88 | } 89 | 90 | cancelTimer(); 91 | 92 | /* 93 | * There is a strange race condition that occurs on Mozilla when you cancel 94 | * a request while the response is coming in. It appears that in some cases 95 | * the onreadystatechange handler is still called after the handler function 96 | * has been deleted and during the call to XmlHttpRequest.abort(). So we 97 | * null the xmlHttpRequest here and that will prevent the 98 | * fireOnResponseReceived method from calling the callback function. 99 | * 100 | * Setting the onreadystatechange handler to null gives us the correct 101 | * behavior in Mozilla but crashes IE. That is why we have chosen to fixed 102 | * this in Java by nulling out our reference to the XmlHttpRequest object. 103 | */ 104 | final XMLHttpRequest xhr = xmlHttpRequest; 105 | xmlHttpRequest = null; 106 | 107 | // XXX: this clearOnReadyStateChange() was in com.google.gwt.http.client.Request, do we really 108 | // need it (and equivalent) here? 109 | // com.google.gwt.xhr.client.XMLHttpRequest has this note: 110 | /* 111 | * NOTE: Testing discovered that for some bizarre reason, on Mozilla, the 112 | * JavaScript XmlHttpRequest.onreadystatechange handler 113 | * function maybe still be called after it is deleted. The theory is that the 114 | * callback is cached somewhere. Setting it to null or an empty function does 115 | * seem to work properly, though. 116 | * 117 | * On IE, setting onreadystatechange to null (as opposed to an empty function) 118 | * sometimes throws an exception. 119 | * 120 | * End result: *always* set onreadystatechange to an empty function (never to 121 | * null). 122 | */ 123 | // xhr.clearOnReadyStateChange(); 124 | xhr.abort(); 125 | } 126 | 127 | /** 128 | * Returns true if this request is waiting for a response. 129 | * 130 | * @return true if this request is waiting for a response 131 | */ 132 | public boolean isPending() { 133 | if (xmlHttpRequest == null) { 134 | return false; 135 | } 136 | 137 | double readyState = xmlHttpRequest.readyState; 138 | 139 | /* 140 | * Because we are doing asynchronous requests it is possible that we can 141 | * call XmlHttpRequest.send and still have the XmlHttpRequest.getReadyState 142 | * method return the state as XmlHttpRequest.OPEN. That is why we include 143 | * open although it is nottechnically true since open implies that the 144 | * request has not been sent. 145 | */ 146 | return readyState == XMLHttpRequest.OPENED 147 | || readyState == XMLHttpRequest.HEADERS_RECEIVED 148 | || readyState == XMLHttpRequest.LOADING; 149 | } 150 | 151 | /* 152 | * Method called when the JavaScript XmlHttpRequest object's readyState 153 | * reaches 4 (LOADED). 154 | */ 155 | void fireOnResponseReceived(RequestCallback callback) { 156 | if (xmlHttpRequest == null) { 157 | // the request has timed out at this point 158 | return; 159 | } 160 | 161 | cancelTimer(); 162 | 163 | /* 164 | * We cannot use cancel here because it would clear the contents of the 165 | * JavaScript XmlHttpRequest object so we manually null out our reference to 166 | * the JavaScriptObject 167 | */ 168 | final XMLHttpRequest xhr = xmlHttpRequest; 169 | xmlHttpRequest = null; 170 | 171 | Response response = createResponse(xhr); 172 | callback.onResponseReceived(this, response); 173 | } 174 | 175 | /** Stops the current HTTPRequest timer if there is one. */ 176 | private void cancelTimer() { 177 | if (timeoutMillis > 0) { 178 | DomGlobal.clearTimeout(timerId); 179 | } 180 | } 181 | 182 | /* 183 | * Method called when this request times out. 184 | */ 185 | private void fireOnTimeout(RequestCallback callback) { 186 | if (xmlHttpRequest == null) { 187 | // the request has been received at this point 188 | return; 189 | } 190 | 191 | cancel(); 192 | 193 | callback.onError(this, new RequestTimeoutException(this, timeoutMillis)); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/RequestCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** The primary interface a caller must implement to receive a response to a {@link Request}. */ 19 | public interface RequestCallback { 20 | 21 | /** 22 | * Called when a pending {@link Request} completes normally. Note this method is called even when 23 | * the status code of the HTTP response is not "OK", 200. 24 | * 25 | * @param request the object that generated this event 26 | * @param response an instance of the {@link Response} class 27 | */ 28 | void onResponseReceived(Request request, Response response); 29 | 30 | /** 31 | * Called when a {@link Request} does not complete normally. A {@link RequestTimeoutException 32 | * RequestTimeoutException} is one example of the type of error that a request may encounter. 33 | * 34 | * @param request the request object which has experienced the error condition, may be null if the 35 | * request was never generated 36 | * @param exception the error that was encountered 37 | */ 38 | void onError(Request request, Throwable exception); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/RequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** RequestException is the superclass for the HTTP request related exceptions. */ 19 | @SuppressWarnings("serial") 20 | public class RequestException extends Exception { 21 | 22 | public RequestException() { 23 | super(); 24 | } 25 | 26 | public RequestException(String message) { 27 | super(message); 28 | } 29 | 30 | public RequestException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public RequestException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/RequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** Thrown to indicate that an HTTP request has timed out. */ 19 | @SuppressWarnings("serial") 20 | public class RequestTimeoutException extends RequestException { 21 | private static String formatMessage(int timeoutMillis) { 22 | return "A request timeout has expired after " + timeoutMillis + " ms"; 23 | } 24 | 25 | /** Time, in milliseconds, of the timeout. */ 26 | private final int timeoutMillis; 27 | 28 | /** Request object which experienced the timed out. */ 29 | private final Request request; 30 | 31 | /** 32 | * Constructs a timeout exception for the given {@link Request}. 33 | * 34 | * @param request the request which timed out 35 | * @param timeoutMillis the number of milliseconds which expired 36 | */ 37 | public RequestTimeoutException(Request request, int timeoutMillis) { 38 | super(formatMessage(timeoutMillis)); 39 | this.request = request; 40 | this.timeoutMillis = timeoutMillis; 41 | } 42 | 43 | /** 44 | * Returns the {@link Request} instance which timed out. 45 | * 46 | * @return the {@link Request} instance which timed out 47 | */ 48 | public Request getRequest() { 49 | return request; 50 | } 51 | 52 | /** 53 | * Returns the request timeout value in milliseconds. 54 | * 55 | * @return the request timeout value in milliseconds 56 | */ 57 | public int getTimeoutMillis() { 58 | return timeoutMillis; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** Wrapper which provides access to the components of an HTTP response. */ 19 | public abstract class Response { 20 | 21 | public static final int SC_ACCEPTED = 202; 22 | public static final int SC_BAD_GATEWAY = 502; 23 | public static final int SC_BAD_REQUEST = 400; 24 | public static final int SC_CONFLICT = 409; 25 | public static final int SC_CONTINUE = 100; 26 | public static final int SC_CREATED = 201; 27 | public static final int SC_EXPECTATION_FAILED = 417; 28 | public static final int SC_FORBIDDEN = 403; 29 | public static final int SC_GATEWAY_TIMEOUT = 504; 30 | public static final int SC_GONE = 410; 31 | public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505; 32 | public static final int SC_INTERNAL_SERVER_ERROR = 500; 33 | public static final int SC_LENGTH_REQUIRED = 411; 34 | public static final int SC_METHOD_NOT_ALLOWED = 405; 35 | public static final int SC_MOVED_PERMANENTLY = 301; 36 | public static final int SC_MOVED_TEMPORARILY = 302; 37 | public static final int SC_MULTIPLE_CHOICES = 300; 38 | public static final int SC_NO_CONTENT = 204; 39 | public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203; 40 | public static final int SC_NOT_ACCEPTABLE = 406; 41 | public static final int SC_NOT_FOUND = 404; 42 | public static final int SC_NOT_IMPLEMENTED = 501; 43 | public static final int SC_NOT_MODIFIED = 304; 44 | public static final int SC_OK = 200; 45 | public static final int SC_PARTIAL_CONTENT = 206; 46 | public static final int SC_PAYMENT_REQUIRED = 402; 47 | public static final int SC_PRECONDITION_FAILED = 412; 48 | public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; 49 | public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413; 50 | public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416; 51 | public static final int SC_RESET_CONTENT = 205; 52 | public static final int SC_SEE_OTHER = 303; 53 | public static final int SC_SERVICE_UNAVAILABLE = 503; 54 | public static final int SC_SWITCHING_PROTOCOLS = 101; 55 | public static final int SC_TEMPORARY_REDIRECT = 307; 56 | public static final int SC_UNAUTHORIZED = 401; 57 | public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415; 58 | public static final int SC_USE_PROXY = 305; 59 | 60 | /** 61 | * Returns the value of the requested header or null if the header was not specified. 62 | * 63 | * @param header the header to query for 64 | * @return the value of response header 65 | * @throws IllegalArgumentException if the header name is empty 66 | * @throws NullPointerException if the header name is null 67 | */ 68 | public abstract String getHeader(String header); 69 | 70 | /** 71 | * Returns an array of HTTP headers associated with this response. 72 | * 73 | * @return array of HTTP headers; returns zero length array if there are no headers 74 | */ 75 | public abstract Header[] getHeaders(); 76 | 77 | /** 78 | * Returns all headers as a single string. The individual headers are delimited by a CR (U+000D) 79 | * LF (U+000A) pair. An individual header is formatted according to RFC 2616. 81 | * 82 | * @return all headers as a single string delimited by CRLF pairs 83 | */ 84 | public abstract String getHeadersAsString(); 85 | 86 | /** 87 | * Returns the HTTP status code that is part of this response. 88 | * 89 | *

The value will be 0 if the request failed (e.g. network error, or the server disallowed the request) or has been aborted (this will 91 | * generally be the case when leaving the page). 92 | * 93 | * @return the HTTP status code or 0 94 | */ 95 | public abstract int getStatusCode(); 96 | 97 | /** 98 | * Returns the HTTP status message text. 99 | * 100 | * @return the HTTP status message text 101 | */ 102 | public abstract String getStatusText(); 103 | 104 | /** 105 | * Returns the text associated with the response. 106 | * 107 | * @return the response text 108 | */ 109 | public abstract String getText(); 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/ResponseImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import elemental2.dom.XMLHttpRequest; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** A {@link Response} implementation based on a {@link XMLHttpRequest}. */ 23 | class ResponseImpl extends Response { 24 | 25 | private final XMLHttpRequest xmlHttpRequest; 26 | 27 | public ResponseImpl(XMLHttpRequest xmlHttpRequest) { 28 | this.xmlHttpRequest = xmlHttpRequest; 29 | 30 | assert isResponseReady(); 31 | } 32 | 33 | @Override 34 | public String getHeader(String header) { 35 | StringValidator.throwIfEmptyOrNull("header", header); 36 | 37 | return xmlHttpRequest.getResponseHeader(header); 38 | } 39 | 40 | @Override 41 | public Header[] getHeaders() { 42 | String allHeaders = getHeadersAsString(); 43 | String[] unparsedHeaders = allHeaders.split("\n"); 44 | List

parsedHeaders = new ArrayList<>(); 45 | 46 | for (String unparsedHeader : unparsedHeaders) { 47 | 48 | if (unparsedHeader == null || unparsedHeader.trim().isEmpty()) { 49 | continue; 50 | } 51 | 52 | int endOfNameIdx = unparsedHeader.indexOf(':'); 53 | if (endOfNameIdx < 0) { 54 | continue; 55 | } 56 | 57 | final String name = unparsedHeader.substring(0, endOfNameIdx).trim(); 58 | final String value = unparsedHeader.substring(endOfNameIdx + 1).trim(); 59 | Header header = 60 | new Header() { 61 | @Override 62 | public String getName() { 63 | return name; 64 | } 65 | 66 | @Override 67 | public String getValue() { 68 | return value; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return name + " : " + value; 74 | } 75 | }; 76 | 77 | parsedHeaders.add(header); 78 | } 79 | 80 | return parsedHeaders.toArray(new Header[parsedHeaders.size()]); 81 | } 82 | 83 | @Override 84 | public String getHeadersAsString() { 85 | String headers = xmlHttpRequest.getAllResponseHeaders(); 86 | return headers != null ? headers : ""; 87 | } 88 | 89 | @Override 90 | public int getStatusCode() { 91 | return xmlHttpRequest.status; 92 | } 93 | 94 | @Override 95 | public String getStatusText() { 96 | return xmlHttpRequest.statusText; 97 | } 98 | 99 | @Override 100 | public String getText() { 101 | return xmlHttpRequest.responseText; 102 | } 103 | 104 | protected boolean isResponseReady() { 105 | return xmlHttpRequest.readyState == XMLHttpRequest.DONE; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/StringValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | /** 19 | * Utility class for validating strings. 20 | * 21 | *

TODO(mmendez): Is there a better place for this? 22 | */ 23 | final class StringValidator { 24 | /** 25 | * Returns true if the string is empty or null. 26 | * 27 | * @param string to test if null or empty 28 | * @return true if the string is empty or null 29 | */ 30 | public static boolean isEmptyOrNullString(String string) { 31 | return (string == null) || (0 == string.trim().length()); 32 | } 33 | 34 | /** 35 | * Throws if value is null or empty. This method ignores leading and 36 | * trailing whitespace. 37 | * 38 | * @param name the name of the value, used in error messages 39 | * @param value the string value that needs to be validated 40 | * @throws IllegalArgumentException if the string is empty, or all whitespace 41 | * @throws NullPointerException if the string is null 42 | */ 43 | public static void throwIfEmptyOrNull(String name, String value) { 44 | assert (name != null); 45 | assert (name.trim().length() != 0); 46 | 47 | throwIfNull(name, value); 48 | 49 | if (0 == value.trim().length()) { 50 | throw new IllegalArgumentException(name + " cannot be empty"); 51 | } 52 | } 53 | 54 | /** 55 | * Throws a {@link NullPointerException} if the value is null. 56 | * 57 | * @param name the name of the value, used in error messages 58 | * @param value the value that needs to be validated 59 | * @throws NullPointerException if the value is null 60 | */ 61 | public static void throwIfNull(String name, Object value) { 62 | if (null == value) { 63 | throw new NullPointerException(name + " cannot be null"); 64 | } 65 | } 66 | 67 | private StringValidator() {} 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/URL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2006 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static elemental2.core.Global.*; 19 | 20 | import elemental2.core.JsRegExp; 21 | import elemental2.core.JsString; 22 | import jsinterop.base.Js; 23 | 24 | /** 25 | * Utility class for the encoding and decoding URLs in their entirety or by their individual 26 | * components. 27 | */ 28 | public final class URL { 29 | 30 | /** 31 | * Returns a string where all URL escape sequences have been converted back to their original 32 | * character representations. 33 | * 34 | * @param encodedURL string containing encoded URL encoded sequences 35 | * @return string with no encoded URL encoded sequences 36 | * @throws NullPointerException if encodedURL is null 37 | */ 38 | public static String decode(String encodedURL) { 39 | StringValidator.throwIfNull("encodedURL", encodedURL); 40 | return decodeImpl(encodedURL); 41 | } 42 | 43 | /** 44 | * Returns a string where all URL component escape sequences have been converted back to their 45 | * original character representations. 46 | * 47 | * @param encodedURLComponent string containing encoded URL component sequences 48 | * @return string with no encoded URL component encoded sequences 49 | * @throws NullPointerException if encodedURLComponent is null 50 | */ 51 | public static String decodePathSegment(String encodedURLComponent) { 52 | StringValidator.throwIfNull("encodedURLComponent", encodedURLComponent); 53 | return decodePathSegmentImpl(encodedURLComponent); 54 | } 55 | 56 | /** 57 | * Returns a string where all URL component escape sequences have been converted back to their 58 | * original character representations. 59 | * 60 | *

Note: this method will convert the space character escape short form, '+', into a space. It 61 | * should therefore only be used for query-string parts. 62 | * 63 | * @param encodedURLComponent string containing encoded URL component sequences 64 | * @return string with no encoded URL component encoded sequences 65 | * @throws NullPointerException if encodedURLComponent is null 66 | */ 67 | public static String decodeQueryString(String encodedURLComponent) { 68 | StringValidator.throwIfNull("encodedURLComponent", encodedURLComponent); 69 | return decodeQueryStringImpl(encodedURLComponent); 70 | } 71 | 72 | /** 73 | * Returns a string where all characters that are not valid for a complete URL have been escaped. 74 | * The escaping of a character is done by converting it into its UTF-8 encoding and then encoding 75 | * each of the resulting bytes as a %xx hexadecimal escape sequence. 76 | * 77 | *

The following character sets are not escaped by this method: 78 | * 79 | *

    80 | *
  • ASCII digits or letters 81 | *
  • ASCII punctuation characters: 82 | *
     83 |    * - _ . ! ~ * ' ( )
     84 |    * 
    85 | *
  • URL component delimiter characters: 86 | *
     87 |    * ; / ? : & = + $ , #
     88 |    * 
    89 | *
90 | * 91 | * @param decodedURL a string containing URL characters that may require encoding 92 | * @return a string with all invalid URL characters escaped 93 | * @throws NullPointerException if decodedURL is null 94 | */ 95 | public static String encode(String decodedURL) { 96 | StringValidator.throwIfNull("decodedURL", decodedURL); 97 | return encodeImpl(decodedURL); 98 | } 99 | 100 | /** 101 | * Returns a string where all characters that are not valid for a URL component have been escaped. 102 | * The escaping of a character is done by converting it into its UTF-8 encoding and then encoding 103 | * each of the resulting bytes as a %xx hexadecimal escape sequence. 104 | * 105 | *

The following character sets are not escaped by this method: 106 | * 107 | *

    108 | *
  • ASCII digits or letters 109 | *
  • ASCII punctuation characters: 110 | *
    - _ . ! ~ * ' ( )
    111 | *
112 | * 113 | *

Notice that this method does encode the URL component delimiter characters: 114 | * 115 | *

116 |    * ; / ? : & = + $ , #
117 |    * 
118 | * 119 | * @param decodedURLComponent a string containing invalid URL characters 120 | * @return a string with all invalid URL characters escaped 121 | * @throws NullPointerException if decodedURLComponent is null 122 | */ 123 | public static String encodePathSegment(String decodedURLComponent) { 124 | StringValidator.throwIfNull("decodedURLComponent", decodedURLComponent); 125 | return encodePathSegmentImpl(decodedURLComponent); 126 | } 127 | 128 | /** 129 | * Returns a string where all characters that are not valid for a URL component have been escaped. 130 | * The escaping of a character is done by converting it into its UTF-8 encoding and then encoding 131 | * each of the resulting bytes as a %xx hexadecimal escape sequence. 132 | * 133 | *

Note: this method will convert any the space character into its escape short form, '+' 134 | * rather than %20. It should therefore only be used for query-string parts. 135 | * 136 | *

The following character sets are not escaped by this method: 137 | * 138 | *

    139 | *
  • ASCII digits or letters 140 | *
  • ASCII punctuation characters: 141 | *
    - _ . ! ~ * ' ( )
    142 | *
143 | * 144 | *

Notice that this method does encode the URL component delimiter characters: 145 | * 146 | *

147 |    * ; / ? : & = + $ , #
148 |    * 
149 | * 150 | * @param decodedURLComponent a string containing invalid URL characters 151 | * @return a string with all invalid URL characters escaped 152 | * @throws NullPointerException if decodedURLComponent is null 153 | */ 154 | public static String encodeQueryString(String decodedURLComponent) { 155 | StringValidator.throwIfNull("decodedURLComponent", decodedURLComponent); 156 | return encodeQueryStringImpl(decodedURLComponent); 157 | } 158 | 159 | private static String decodeImpl(String encodedURL) { 160 | return decodeURI(encodedURL); 161 | } 162 | 163 | private static String decodePathSegmentImpl(String encodedURLComponent) { 164 | return decodeURIComponent(encodedURLComponent); 165 | } 166 | 167 | private static String decodeQueryStringImpl(String encodedURLComponent) { 168 | JsRegExp regexp = new JsRegExp("\\+", "g"); 169 | return decodeURIComponent( 170 | Js.uncheckedCast(encodedURLComponent).replace(regexp, "%20")); 171 | } 172 | 173 | private static String encodeImpl(String decodedURL) { 174 | return encodeURI(decodedURL); 175 | } 176 | 177 | private static String encodePathSegmentImpl(String decodedURLComponent) { 178 | return encodeURIComponent(decodedURLComponent); 179 | } 180 | 181 | private static String encodeQueryStringImpl(String decodedURLComponent) { 182 | JsRegExp regexp = new JsRegExp("%20", "g"); 183 | return Js.uncheckedCast(encodeURIComponent(decodedURLComponent)).replace(regexp, "+"); 184 | } 185 | 186 | private URL() {} 187 | } 188 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/UrlBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import java.util.LinkedHashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * Utility class to build a URL from components. 23 | * 24 | *

TODO(jlabanca): Add a constructor that parses an existing URL 25 | */ 26 | public class UrlBuilder { 27 | 28 | /** The port to use when no port should be specified. */ 29 | public static final int PORT_UNSPECIFIED = Integer.MIN_VALUE; 30 | 31 | /** A mapping of query parameters to their values. */ 32 | private Map listParamMap = new LinkedHashMap<>(); 33 | 34 | private String protocol = "http"; 35 | private String host = null; 36 | private int port = PORT_UNSPECIFIED; 37 | private String path = null; 38 | private String hash = null; 39 | 40 | /** 41 | * Build the URL and return it as an encoded string. 42 | * 43 | * @return the encoded URL string 44 | */ 45 | public String buildString() { 46 | StringBuilder url = new StringBuilder(); 47 | 48 | // http:// 49 | url.append(URL.encode(protocol)).append("://"); 50 | 51 | // http://www.google.com 52 | if (host != null) { 53 | url.append(URL.encode(host)); 54 | } 55 | 56 | // http://www.google.com:80 57 | if (port != PORT_UNSPECIFIED) { 58 | url.append(":").append(port); 59 | } 60 | 61 | // http://www.google.com:80/path/to/file.html 62 | if (path != null && !"".equals(path)) { 63 | url.append("/").append(URL.encode(path).replace("?", "%3F").replace("#", "%23")); 64 | } 65 | 66 | // Generate the query string. 67 | // http://www.google.com:80/path/to/file.html?k0=v0&k1=v1 68 | char prefix = '?'; 69 | for (Map.Entry entry : listParamMap.entrySet()) { 70 | for (String val : entry.getValue()) { 71 | url.append(prefix).append(URL.encodeQueryString(entry.getKey())).append('='); 72 | if (val != null) { 73 | // Also encodes +,& etc. 74 | url.append(URL.encodeQueryString(val)); 75 | } 76 | prefix = '&'; 77 | } 78 | } 79 | 80 | // http://www.google.com:80/path/to/file.html?k0=v0&k1=v1#token 81 | if (hash != null) { 82 | // Hash characters in the hash fragment must be encoded separately 83 | // because URL.encode does not do that (issue #8396) 84 | url.append("#").append(URL.encode(hash).replace("#", "%23")); 85 | } 86 | 87 | return url.toString(); 88 | } 89 | 90 | /** 91 | * Remove a query parameter from the map. 92 | * 93 | * @param name the parameter name 94 | */ 95 | public UrlBuilder removeParameter(String name) { 96 | listParamMap.remove(name); 97 | return this; 98 | } 99 | 100 | /** 101 | * Set the hash portion of the location (ex. myAnchor or #myAnchor). 102 | * 103 | * @param hash the hash 104 | */ 105 | public UrlBuilder setHash(String hash) { 106 | if (hash != null && hash.startsWith("#")) { 107 | hash = hash.substring(1); 108 | } 109 | this.hash = hash; 110 | return this; 111 | } 112 | 113 | /** 114 | * Set the host portion of the location (ex. google.com). You can also specify the port in this 115 | * method (ex. localhost:8888). 116 | * 117 | * @param host the host 118 | */ 119 | public UrlBuilder setHost(String host) { 120 | // Extract the port from the host. 121 | if (host != null && host.contains(":")) { 122 | String[] parts = host.split(":"); 123 | if (parts.length > 2) { 124 | throw new IllegalArgumentException("Host contains more than one colon: " + host); 125 | } 126 | try { 127 | setPort(Integer.parseInt(parts[1])); 128 | } catch (NumberFormatException e) { 129 | throw new IllegalArgumentException("Could not parse port out of host: " + host); 130 | } 131 | host = parts[0]; 132 | } 133 | this.host = host; 134 | return this; 135 | } 136 | 137 | /** 138 | * Set a query parameter to a list of values. Each value in the list will be added as its own 139 | * key/value pair. 140 | * 141 | *

Example output: {@code ?mykey=value0&mykey=value1&mykey=value2 } 142 | * 143 | * @param key the key 144 | * @param values the list of values 145 | */ 146 | public UrlBuilder setParameter(String key, String... values) { 147 | assertNotNullOrEmpty(key, "Key cannot be null or empty", false); 148 | assertNotNull(values, "Values cannot null. Try using removeParameter instead."); 149 | if (values.length == 0) { 150 | throw new IllegalArgumentException( 151 | "Values cannot be empty. Try using removeParameter instead."); 152 | } 153 | listParamMap.put(key, values); 154 | return this; 155 | } 156 | 157 | /** 158 | * Set the path portion of the location (ex. path/to/file.html). 159 | * 160 | * @param path the path 161 | */ 162 | public UrlBuilder setPath(String path) { 163 | if (path != null && path.startsWith("/")) { 164 | path = path.substring(1); 165 | } 166 | this.path = path; 167 | return this; 168 | } 169 | 170 | /** 171 | * Set the port to connect to. 172 | * 173 | * @param port the port, or {@link #PORT_UNSPECIFIED} 174 | */ 175 | public UrlBuilder setPort(int port) { 176 | this.port = port; 177 | return this; 178 | } 179 | 180 | /** 181 | * Set the protocol portion of the location (ex. http). 182 | * 183 | * @param protocol the protocol 184 | */ 185 | public UrlBuilder setProtocol(String protocol) { 186 | assertNotNull(protocol, "Protocol cannot be null"); 187 | if (protocol.endsWith("://")) { 188 | protocol = protocol.substring(0, protocol.length() - 3); 189 | } else if (protocol.endsWith(":/")) { 190 | protocol = protocol.substring(0, protocol.length() - 2); 191 | } else if (protocol.endsWith(":")) { 192 | protocol = protocol.substring(0, protocol.length() - 1); 193 | } 194 | if (protocol.contains(":")) { 195 | throw new IllegalArgumentException("Invalid protocol: " + protocol); 196 | } 197 | assertNotNullOrEmpty(protocol, "Protocol cannot be empty", false); 198 | this.protocol = protocol; 199 | return this; 200 | } 201 | 202 | /** 203 | * Assert that the value is not null. 204 | * 205 | * @param value the value 206 | * @param message the message to include with any exceptions 207 | * @throws IllegalArgumentException if value is null 208 | */ 209 | private void assertNotNull(Object value, String message) throws IllegalArgumentException { 210 | if (value == null) { 211 | throw new IllegalArgumentException(message); 212 | } 213 | } 214 | 215 | /** 216 | * Assert that the value is not null or empty. 217 | * 218 | * @param value the value 219 | * @param message the message to include with any exceptions 220 | * @param isState if true, throw a state exception instead 221 | * @throws IllegalArgumentException if value is null 222 | * @throws IllegalStateException if value is null and isState is true 223 | */ 224 | private void assertNotNullOrEmpty(String value, String message, boolean isState) 225 | throws IllegalArgumentException { 226 | if (value == null || value.length() == 0) { 227 | if (isState) { 228 | throw new IllegalStateException(message); 229 | } else { 230 | throw new IllegalArgumentException(message); 231 | } 232 | } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/main/java/org/gwtproject/http/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | /** 18 | * Provides the client-side classes and interfaces for making HTTP requests and processing the 19 | * associated responses. 20 | * 21 | *

Most applications will be interested in the {@link Request}, {@link RequestBuilder}, {@link 22 | * RequestCallback} and {@link Response} classes. 23 | */ 24 | package org.gwtproject.http.client; 25 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gwt/mainModule: -------------------------------------------------------------------------------- 1 | org.gwtproject.http.HTTP 2 | -------------------------------------------------------------------------------- /src/main/resources/org/gwtproject/http/HTTP.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/HTTPSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http; 17 | 18 | import org.gwtproject.http.client.RequestBuilderTest; 19 | import org.gwtproject.http.client.RequestTest; 20 | import org.gwtproject.http.client.ResponseTest; 21 | import org.gwtproject.http.client.URLTest; 22 | import org.gwtproject.http.client.UrlBuilderTest; 23 | import org.junit.runner.RunWith; 24 | import org.junit.runners.Suite; 25 | 26 | /** Test for suite for the org.gwtproject.http module */ 27 | @RunWith(Suite.class) 28 | @Suite.SuiteClasses({ 29 | URLTest.class, 30 | RequestBuilderTest.class, 31 | RequestTest.class, 32 | ResponseTest.class, 33 | UrlBuilderTest.class 34 | }) 35 | public class HTTPSuite {} 36 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/RequestBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_DELETE_RESPONSE; 19 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_GET_RESPONSE; 20 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_HEAD_RESPONSE; 21 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_POST_RESPONSE; 22 | import static org.gwtproject.http.shared.RequestBuilderTestConstants.SERVLET_PUT_RESPONSE; 23 | 24 | import com.google.gwt.core.client.GWT; 25 | import com.google.gwt.junit.DoNotRunWith; 26 | import com.google.gwt.junit.Platform; 27 | 28 | /** Test cases for the {@link RequestBuilder} class. */ 29 | public class RequestBuilderTest extends RequestTestBase { 30 | 31 | private static String getTestBaseURL() { 32 | return GWT.getModuleBaseURL() + "testRequestBuilder/"; 33 | } 34 | 35 | @Override 36 | public String getModuleName() { 37 | return "org.gwtproject.http.RequestBuilderTest"; 38 | } 39 | 40 | /** 41 | * Test method for {@link RequestBuilder#RequestBuilder(String, String)}. 42 | * 43 | *

Test Cases: 44 | * 45 | *

    46 | *
  • httpMethod == null 47 | *
  • httpMethod == "" 48 | *
  • url == null 49 | *
  • url == "" 50 | *
51 | */ 52 | public void testRequestBuilderStringString() throws RequestException { 53 | try { 54 | new RequestBuilder((RequestBuilder.Method) null, null); 55 | fail("NullPointerException should have been thrown for construction with null method."); 56 | } catch (NullPointerException ex) { 57 | // purposely ignored 58 | } 59 | 60 | try { 61 | new RequestBuilder(RequestBuilder.GET, null); 62 | fail("NullPointerException should have been thrown for construction with null URL."); 63 | } catch (NullPointerException ex) { 64 | // purposely ignored 65 | } 66 | 67 | try { 68 | new RequestBuilder(RequestBuilder.GET, ""); 69 | fail("IllegalArgumentException should have been throw for construction with empty URL."); 70 | } catch (IllegalArgumentException ex) { 71 | // purposely ignored 72 | } 73 | } 74 | 75 | /** Test method for {@link RequestBuilder#RequestBuilder(String, String)}. */ 76 | public void testRequestBuilderStringString_HTTPMethodRestrictionOverride() { 77 | new RequestBuilder(RequestBuilder.GET, "FOO"); 78 | 79 | class MyRequestBuilder extends RequestBuilder { 80 | MyRequestBuilder(String httpMethod, String url) { 81 | super(httpMethod, url); 82 | } 83 | } 84 | 85 | new MyRequestBuilder("HEAD", "FOO"); 86 | // should reach here without any exceptions being thrown 87 | } 88 | 89 | public void testSend_DELETE() throws RequestException { 90 | RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, getTestBaseURL()); 91 | testSend(builder, SERVLET_DELETE_RESPONSE); 92 | } 93 | 94 | public void testSend_GET() throws RequestException { 95 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "send_GET"); 96 | testSend(builder, SERVLET_GET_RESPONSE); 97 | } 98 | 99 | public void testSend_HEAD() throws RequestException { 100 | RequestBuilder builder = new RequestBuilder(RequestBuilder.HEAD, getTestBaseURL()); 101 | testSend(builder, SERVLET_HEAD_RESPONSE); 102 | } 103 | 104 | public void testSend_POST() throws RequestException { 105 | RequestBuilder builder = 106 | new RequestBuilder(RequestBuilder.POST, getTestBaseURL() + "sendRequest_POST"); 107 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 108 | testSend(builder, SERVLET_POST_RESPONSE); 109 | } 110 | 111 | public void testSend_PUT() throws RequestException { 112 | RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, getTestBaseURL()); 113 | builder.setHeader("Content-Type", "text/html"); 114 | builder.setRequestData("Put Me"); 115 | testSend(builder, SERVLET_PUT_RESPONSE); 116 | } 117 | 118 | public void testSendRequest_DELETE() throws RequestException { 119 | RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, getTestBaseURL()); 120 | testSendRequest(builder, null, SERVLET_DELETE_RESPONSE); 121 | } 122 | 123 | public void testSendRequest_GET() throws RequestException { 124 | RequestBuilder builder = 125 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "sendRequest_GET"); 126 | testSendRequest(builder, null, SERVLET_GET_RESPONSE); 127 | } 128 | 129 | public void testSendRequest_HEAD() throws RequestException { 130 | RequestBuilder builder = new RequestBuilder(RequestBuilder.HEAD, getTestBaseURL()); 131 | testSendRequest(builder, null, SERVLET_HEAD_RESPONSE); 132 | } 133 | 134 | public void testSendRequest_POST() throws RequestException { 135 | RequestBuilder builder = 136 | new RequestBuilder(RequestBuilder.POST, getTestBaseURL() + "sendRequest_POST"); 137 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 138 | testSendRequest(builder, null, SERVLET_POST_RESPONSE); 139 | } 140 | 141 | public void testSendRequest_PUT() throws RequestException { 142 | RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, getTestBaseURL()); 143 | builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); 144 | testSendRequest(builder, "Put Me", SERVLET_PUT_RESPONSE); 145 | } 146 | 147 | public void testSetCallback() { 148 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 149 | try { 150 | builder.setCallback(null); 151 | fail("Expected NullPointerException"); 152 | } catch (NullPointerException expected) { 153 | } 154 | } 155 | 156 | public void testSetPassword() { 157 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 158 | try { 159 | builder.setPassword(null); 160 | fail("Expected NullPointerException"); 161 | } catch (NullPointerException expected) { 162 | } 163 | 164 | try { 165 | builder.setPassword(""); 166 | fail("Expected IllegalArgumentException"); 167 | } catch (IllegalArgumentException expected) { 168 | } 169 | } 170 | 171 | public void testSetRequestData() { 172 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 173 | // Legal. 174 | builder.setRequestData(null); 175 | builder.setRequestData(""); 176 | } 177 | 178 | /** 179 | * Test method for {@link RequestBuilder#setHeader(String, String)}. 180 | * 181 | *

Test Cases: 182 | * 183 | *

    184 | *
  • name == null 185 | *
  • name == "" 186 | *
  • value == null 187 | *
  • value == "" 188 | *
189 | */ 190 | public void testSetRequestHeader() throws RequestException { 191 | RequestBuilder builder = 192 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setRequestHeader"); 193 | 194 | try { 195 | builder.setHeader(null, "bar"); 196 | fail("setRequestHeader(null, \"bar\")"); 197 | } catch (NullPointerException expected) { 198 | } 199 | 200 | try { 201 | builder.setHeader("", "bar"); 202 | fail("setRequestHeader(\"\", \"bar\")"); 203 | } catch (IllegalArgumentException expected) { 204 | } 205 | 206 | try { 207 | builder.setHeader("foo", null); 208 | fail("setRequestHeader(\"foo\", null)"); 209 | } catch (NullPointerException expected) { 210 | } 211 | 212 | try { 213 | builder.setHeader("foo", ""); 214 | fail("setRequestHeader(\"foo\", \"\")"); 215 | } catch (IllegalArgumentException expected) { 216 | } 217 | 218 | delayTestFinishForRequest(); 219 | 220 | builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setRequestHeader"); 221 | builder.setHeader("Foo", "Bar"); 222 | builder.setHeader("Foo", "Bar1"); 223 | 224 | builder.sendRequest( 225 | null, 226 | new RequestCallback() { 227 | @Override 228 | public void onError(Request request, Throwable exception) { 229 | fail(exception.getMessage()); 230 | } 231 | 232 | @Override 233 | public void onResponseReceived(Request request, Response response) { 234 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 235 | assertEquals(200, response.getStatusCode()); 236 | finishTest(); 237 | } 238 | }); 239 | } 240 | 241 | /** 242 | * Test method for {@link RequestBuilder#setTimeoutMillis(int)}. 243 | * 244 | *

Test Cases: 245 | * 246 | *

    247 | *
  • Timeout greater than the server's response time 248 | *
  • Timeout is less than the server's response time 249 | *
250 | */ 251 | public void testSetTimeout_noTimeout() throws RequestException { 252 | delayTestFinishForRequest(); 253 | 254 | RequestBuilder builder = 255 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setTimeout/noTimeout"); 256 | builder.setTimeoutMillis(10000); 257 | builder.sendRequest( 258 | null, 259 | new RequestCallback() { 260 | @Override 261 | public void onError(Request request, Throwable exception) { 262 | fail(exception.getMessage()); 263 | } 264 | 265 | @Override 266 | public void onResponseReceived(Request request, Response response) { 267 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 268 | assertEquals(200, response.getStatusCode()); 269 | finishTest(); 270 | } 271 | }); 272 | } 273 | 274 | /** 275 | * Test method for {@link RequestBuilder#setTimeoutMillis(int)}. 276 | * 277 | *

Test Cases: 278 | * 279 | *

    280 | *
  • Timeout greater than the server's response time 281 | *
  • Timeout is less than the server's response time 282 | *
283 | * 284 | *

XHR handling is synchronous in HtmlUnit at present (svn r5607). 285 | */ 286 | @DoNotRunWith(Platform.HtmlUnitBug) 287 | public void testSetTimeout_timeout() throws RequestException { 288 | delayTestFinishForRequest(); 289 | 290 | RequestBuilder builder = 291 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "setTimeout/timeout"); 292 | builder.setTimeoutMillis(2000); 293 | builder.sendRequest( 294 | null, 295 | new RequestCallback() { 296 | @Override 297 | public void onError(Request request, Throwable exception) { 298 | finishTest(); 299 | } 300 | 301 | @Override 302 | public void onResponseReceived(Request request, Response response) { 303 | assertEquals(SERVLET_GET_RESPONSE, response.getText()); 304 | assertEquals(200, response.getStatusCode()); 305 | fail("Test did not timeout"); 306 | } 307 | }); 308 | } 309 | 310 | public void testSetUser() { 311 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL()); 312 | try { 313 | builder.setUser(null); 314 | fail("Expected NullPointerException"); 315 | } catch (NullPointerException expected) { 316 | } 317 | 318 | try { 319 | builder.setUser(""); 320 | fail("Expected IllegalArgumentException"); 321 | } catch (IllegalArgumentException expected) { 322 | } 323 | } 324 | 325 | /** 326 | * Helper method to test {@link RequestBuilder#send()}. 327 | * 328 | * @param builder the {@link RequestBuilder} 329 | * @param expectedResponse the expected response 330 | */ 331 | private void testSend(RequestBuilder builder, final String expectedResponse) 332 | throws RequestException { 333 | delayTestFinishForRequest(); 334 | builder.setCallback( 335 | new RequestCallback() { 336 | @Override 337 | public void onError(Request request, Throwable exception) { 338 | fail(exception.getMessage()); 339 | } 340 | 341 | @Override 342 | public void onResponseReceived(Request request, Response response) { 343 | assertEquals(expectedResponse, response.getText()); 344 | assertEquals(200, response.getStatusCode()); 345 | finishTest(); 346 | } 347 | }); 348 | builder.send(); 349 | } 350 | 351 | /** 352 | * Helper method to test {@link RequestBuilder#sendRequest(String, RequestCallback)}. 353 | * 354 | * @param builder the {@link RequestBuilder} 355 | * @param requestData the data to request 356 | * @param expectedResponse the expected response 357 | */ 358 | private void testSendRequest( 359 | RequestBuilder builder, String requestData, final String expectedResponse) 360 | throws RequestException { 361 | delayTestFinishForRequest(); 362 | builder.sendRequest( 363 | requestData, 364 | new RequestCallback() { 365 | @Override 366 | public void onError(Request request, Throwable exception) { 367 | fail(exception.getMessage()); 368 | } 369 | 370 | @Override 371 | public void onResponseReceived(Request request, Response response) { 372 | assertEquals(expectedResponse, response.getText()); 373 | assertEquals(200, response.getStatusCode()); 374 | finishTest(); 375 | } 376 | }); 377 | } 378 | } 379 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/RequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import com.google.gwt.core.client.GWT; 19 | import elemental2.dom.XMLHttpRequest; 20 | 21 | /** TODO: document me. */ 22 | public class RequestTest extends RequestTestBase { 23 | 24 | private static String getTestBaseURL() { 25 | return GWT.getModuleBaseURL() + "testRequest/"; 26 | } 27 | 28 | @Override 29 | public String getModuleName() { 30 | return "org.gwtproject.http.RequestTest"; 31 | } 32 | 33 | /** Test method for {@link Request#cancel()}. */ 34 | public void testCancel() { 35 | delayTestFinishForRequest(); 36 | 37 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "/cancel"); 38 | try { 39 | Request request = 40 | builder.sendRequest( 41 | null, 42 | new RequestCallback() { 43 | @Override 44 | public void onResponseReceived(Request request, Response response) { 45 | fail("Request was canceled - no response should be received"); 46 | } 47 | 48 | @Override 49 | public void onError(Request request, Throwable exception) { 50 | fail("Request was canceled - no timeout should occur"); 51 | } 52 | }); 53 | 54 | assertTrue(request.isPending()); 55 | request.cancel(); 56 | assertFalse(request.isPending()); 57 | 58 | finishTest(); 59 | } catch (RequestException e) { 60 | fail(e.getMessage()); 61 | } 62 | } 63 | 64 | /** Test method for {@link Request#Request(XMLHttpRequest, int, RequestCallback)}. */ 65 | public void testRequest() { 66 | RequestCallback callback = 67 | new RequestCallback() { 68 | @Override 69 | public void onResponseReceived(Request request, Response response) {} 70 | 71 | @Override 72 | public void onError(Request request, Throwable exception) {} 73 | }; 74 | 75 | try { 76 | new Request(null, 0, callback); 77 | fail(); 78 | } catch (NullPointerException ex) { 79 | // Success (The Request ctor explicitly throws an NPE). 80 | } 81 | 82 | try { 83 | new Request(new XMLHttpRequest(), -1, callback); 84 | fail(); 85 | } catch (IllegalArgumentException ex) { 86 | // Success. 87 | } 88 | 89 | try { 90 | new Request(new XMLHttpRequest(), -1, null); 91 | fail(); 92 | } catch (NullPointerException ex) { 93 | // Success (The Request ctor explicitly throws an NPE). 94 | } 95 | 96 | try { 97 | new Request(new XMLHttpRequest(), 0, callback); 98 | } catch (Throwable ex) { 99 | fail(ex.getMessage()); 100 | } 101 | } 102 | 103 | /** Test method for {@link Request#isPending()}. */ 104 | public void testIsPending() { 105 | // delayTestFinishForRequest(); 106 | 107 | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "isPending"); 108 | try { 109 | Request request = 110 | builder.sendRequest( 111 | null, 112 | new RequestCallback() { 113 | @Override 114 | public void onResponseReceived(Request request, Response response) { 115 | finishTest(); 116 | } 117 | 118 | @Override 119 | public void onError(Request request, Throwable exception) { 120 | finishTest(); 121 | } 122 | }); 123 | 124 | assertTrue(request.isPending()); 125 | // finishTest(); 126 | } catch (RequestException e) { 127 | fail(e.getMessage()); 128 | } 129 | } 130 | 131 | /* 132 | * Checks that the status code is correct when receiving a 204-No-Content. This needs special 133 | * handling in IE6-9. See http://code.google.com/p/google-web-toolkit/issues/detail?id=5031 134 | */ 135 | public void test204NoContent() { 136 | delayTestFinishForRequest(); 137 | 138 | RequestBuilder builder = 139 | new RequestBuilder(RequestBuilder.GET, getTestBaseURL() + "204NoContent"); 140 | try { 141 | builder.sendRequest( 142 | null, 143 | new RequestCallback() { 144 | 145 | @Override 146 | public void onResponseReceived(Request request, Response response) { 147 | assertEquals(204, response.getStatusCode()); 148 | finishTest(); 149 | } 150 | 151 | @Override 152 | public void onError(Request request, Throwable exception) { 153 | fail(exception.getMessage()); 154 | } 155 | }); 156 | } catch (RequestException e) { 157 | fail(e.getMessage()); 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/RequestTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import com.google.gwt.junit.client.GWTTestCase; 19 | 20 | /** Base class for tests that send an http request. */ 21 | public abstract class RequestTestBase extends GWTTestCase { 22 | /** The timeout for request tests. */ 23 | protected static final int REQUEST_TIMEOUT = 15000; 24 | 25 | /** 26 | * Delay finishing a test while we wait for a response. This method should be used instead of 27 | * {@link #delayTestFinish(int)} so we can adjust timeouts for all Rpc tests at once. 28 | * 29 | * @see #delayTestFinish(int) 30 | */ 31 | protected final void delayTestFinishForRequest() { 32 | delayTestFinish(REQUEST_TIMEOUT); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/ResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import com.google.gwt.core.client.GWT; 19 | import elemental2.dom.XMLHttpRequest; 20 | 21 | /** */ 22 | public class ResponseTest extends RequestTestBase { 23 | 24 | private static RequestBuilder getHTTPRequestBuilder() { 25 | return getHTTPRequestBuilder(getTestBaseURL()); 26 | } 27 | 28 | private static RequestBuilder getHTTPRequestBuilder(String testURL) { 29 | return new RequestBuilder(RequestBuilder.GET, testURL); 30 | } 31 | 32 | private static String getTestBaseURL() { 33 | return GWT.getModuleBaseURL() + "testResponse/"; 34 | } 35 | 36 | private static void raiseUnexpectedException(Throwable exception) { 37 | fail("Unexpected exception: " + exception.toString()); 38 | } 39 | 40 | @Override 41 | public String getModuleName() { 42 | return "org.gwtproject.http.ResponseTest"; 43 | } 44 | 45 | /** Test method for {@link Response#getStatusCode()}. */ 46 | public void testGetStatusCode() { 47 | executeTest( 48 | new RequestCallback() { 49 | @Override 50 | public void onError(Request request, Throwable exception) { 51 | fail(); 52 | } 53 | 54 | @Override 55 | public void onResponseReceived(Request request, Response response) { 56 | assertEquals(200, response.getStatusCode()); 57 | finishTest(); 58 | } 59 | }); 60 | } 61 | 62 | /** Test method for {@link Response#getStatusText()}. */ 63 | public void testGetStatusText() { 64 | executeTest( 65 | new RequestCallback() { 66 | @Override 67 | public void onError(Request request, Throwable exception) { 68 | if (exception instanceof RuntimeException) { 69 | 70 | } else { 71 | raiseUnexpectedException(exception); 72 | } 73 | } 74 | 75 | @Override 76 | public void onResponseReceived(Request request, Response response) { 77 | assertEquals("OK", response.getStatusText()); 78 | finishTest(); 79 | } 80 | }); 81 | } 82 | 83 | public void testGetHeadersOffline() { 84 | ResponseImpl resp = 85 | new ResponseImpl(new XMLHttpRequest()) { 86 | @Override 87 | protected boolean isResponseReady() { 88 | return true; 89 | } 90 | }; 91 | Header[] headers = resp.getHeaders(); 92 | assertNotNull(headers); 93 | assertEquals(0, headers.length); 94 | } 95 | 96 | private void executeTest(RequestBuilder builder, RequestCallback callback) { 97 | delayTestFinishForRequest(); 98 | 99 | try { 100 | builder.sendRequest(null, callback); 101 | } catch (RequestException e) { 102 | fail(e.getMessage()); 103 | } 104 | } 105 | 106 | private void executeTest(RequestCallback callback) { 107 | executeTest(getHTTPRequestBuilder(), callback); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/URLTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import com.google.gwt.core.client.JavaScriptException; 19 | import com.google.gwt.junit.client.GWTTestCase; 20 | 21 | /** Tests for the URL utility class. */ 22 | public class URLTest extends GWTTestCase { 23 | 24 | private final String DECODED_URL = "http://www.foo \u00E9+bar.com/1_!~*'();/?@&=+$,#"; 25 | private final String DECODED_URL_COMPONENT = "-_.!~*'():/#?@ \u00E9+"; 26 | private final String ENCODED_URL = "http://www.foo%20%C3%A9+bar.com/1_!~*'();/?@&=+$,#"; 27 | private final String ENCODED_URL_COMPONENT = "-_.!~*'()%3A%2F%23%3F%40%20%C3%A9%2B"; 28 | private final String ENCODED_URL_COMPONENT_QS = "-_.!~*'()%3A%2F%23%3F%40+%C3%A9%2B"; 29 | 30 | @Override 31 | public String getModuleName() { 32 | return "org.gwtproject.http.HTTP"; 33 | } 34 | 35 | /** Test method for {@link URL#decode(String)}. */ 36 | public void testDecode() { 37 | try { 38 | URL.decode(null); 39 | fail("Expected NullPointerException"); 40 | } catch (NullPointerException ex) { 41 | // expected exception was thrown 42 | } 43 | 44 | assertEquals("", URL.decode("")); 45 | assertEquals(" ", URL.decode(" ")); 46 | 47 | String actualURL = URL.decode(ENCODED_URL); 48 | assertEquals(DECODED_URL, actualURL); 49 | } 50 | 51 | /** Test method for {@link URL#decodePathSegment(String)}. */ 52 | public void testDecodePathSegment() { 53 | try { 54 | URL.decodePathSegment(null); 55 | fail("Expected NullPointerException"); 56 | } catch (NullPointerException ex) { 57 | // expected exception was thrown 58 | } 59 | 60 | assertEquals("", URL.decodePathSegment("")); 61 | assertEquals(" ", URL.decodePathSegment(" ")); 62 | assertEquals("+", URL.decodePathSegment("+")); 63 | assertEquals(" ", URL.decodePathSegment("%20")); 64 | 65 | String actualURLComponent = URL.decodePathSegment(ENCODED_URL_COMPONENT); 66 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 67 | } 68 | 69 | /** Test method for {@link URL#decodeQueryString(String)}. */ 70 | public void testDecodeQueryString() { 71 | try { 72 | URL.decodeQueryString(null); 73 | fail("Expected NullPointerException"); 74 | } catch (NullPointerException ex) { 75 | // expected exception was thrown 76 | } 77 | 78 | try { 79 | // Malformed URI sequence 80 | URL.decodeQueryString("%E4"); 81 | fail("Expected JavaScriptException"); 82 | } catch (JavaScriptException ignored) { 83 | // expected exception was thrown 84 | } 85 | 86 | assertEquals("", URL.decodeQueryString("")); 87 | assertEquals(" ", URL.decodeQueryString(" ")); 88 | assertEquals(" ", URL.decodeQueryString("+")); 89 | assertEquals(" ", URL.decodeQueryString("%20")); 90 | 91 | String actualURLComponent = URL.decodeQueryString(ENCODED_URL_COMPONENT); 92 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 93 | 94 | actualURLComponent = URL.decodeQueryString(ENCODED_URL_COMPONENT_QS); 95 | assertEquals(DECODED_URL_COMPONENT, actualURLComponent); 96 | } 97 | 98 | /** Test method for {@link URL#encode(String)}. */ 99 | public void testEncode() { 100 | try { 101 | URL.encode(null); 102 | fail("Expected NullPointerException"); 103 | } catch (NullPointerException ex) { 104 | // expected exception was thrown 105 | } 106 | 107 | assertEquals("", URL.encode("")); 108 | assertEquals("%20", URL.encode(" ")); 109 | 110 | String actualURL = URL.encode(DECODED_URL); 111 | assertEquals(ENCODED_URL, actualURL); 112 | } 113 | 114 | /** Test method for {@link URL#encodePathSegment(String)}. */ 115 | public void testEncodePathSegment() { 116 | try { 117 | URL.encodePathSegment(null); 118 | fail("Expected NullPointerException"); 119 | } catch (NullPointerException ex) { 120 | // expected exception was thrown 121 | } 122 | 123 | assertEquals("", URL.encodePathSegment("")); 124 | assertEquals("%20", URL.encodePathSegment(" ")); 125 | 126 | String actualURLComponent = URL.encodePathSegment(DECODED_URL_COMPONENT); 127 | assertEquals(ENCODED_URL_COMPONENT, actualURLComponent); 128 | } 129 | 130 | /** Test method for {@link URL#encodeQueryString(String)}. */ 131 | public void testEncodeQueryString() { 132 | try { 133 | URL.encodeQueryString(null); 134 | fail("Expected NullPointerException"); 135 | } catch (NullPointerException ex) { 136 | // expected exception was thrown 137 | } 138 | 139 | assertEquals("", URL.encodeQueryString("")); 140 | assertEquals("+", URL.encodeQueryString(" ")); 141 | 142 | String actualURLComponent = URL.encodeQueryString(DECODED_URL_COMPONENT); 143 | assertEquals(ENCODED_URL_COMPONENT_QS, actualURLComponent); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/client/UrlBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.client; 17 | 18 | import com.google.gwt.junit.client.GWTTestCase; 19 | 20 | /** Test Case for {@link UrlBuilder}. */ 21 | public class UrlBuilderTest extends GWTTestCase { 22 | 23 | @Override 24 | public String getModuleName() { 25 | return "org.gwtproject.http.HTTP"; 26 | } 27 | 28 | /** Test that the URL is encoded correctly. */ 29 | public void testBuildStringEncode() { 30 | UrlBuilder builder = new UrlBuilder(); 31 | builder.setHost("google.com"); 32 | builder.setPath("path to file"); 33 | builder.setParameter("the key", "the value"); 34 | assertEquals("http://google.com/path%20to%20file?the+key=the+value", builder.buildString()); 35 | 36 | builder = new UrlBuilder(); 37 | builder.setHost("google.com"); 38 | builder.setPath("?not-query#not-hash"); 39 | builder.setParameter("not=value¬-next", "¬-next=pair"); 40 | builder.setParameter("#not-hash", "#not-hash"); 41 | builder.setHash("hash#in-hash"); 42 | assertEquals( 43 | "http://google.com/%3Fnot-query%23not-hash?not%3Dvalue%26not-next=%26not-next%3Dpair&%23not-hash=%23not-hash#hash%23in-hash", 44 | builder.buildString()); 45 | 46 | builder = new UrlBuilder(); 47 | builder.setHost("google.com"); 48 | builder.setPath("path"); 49 | builder.setHash("hash"); 50 | 51 | builder.setParameter("a_b", "a+b"); 52 | assertEquals("http://google.com/path?a_b=a%2Bb#hash", builder.buildString()); 53 | 54 | builder.setParameter("a_b", "a&b"); 55 | assertEquals("http://google.com/path?a_b=a%26b#hash", builder.buildString()); 56 | 57 | builder.setParameter("a_b", "a%b"); 58 | assertEquals("http://google.com/path?a_b=a%25b#hash", builder.buildString()); 59 | 60 | // Hash characters in the fragment should be encoded (issue #8396) 61 | builder.setHash("ha#sh#"); 62 | assertEquals("http://google.com/path?a_b=a%25b#ha%23sh%23", builder.buildString()); 63 | } 64 | 65 | public void testBuildStringEntireUrl() { 66 | UrlBuilder builder = new UrlBuilder(); 67 | builder.setHost("google.com"); 68 | 69 | // Host only. 70 | assertEquals("http://google.com", builder.buildString()); 71 | 72 | // Host:Port 73 | builder.setPort(100); 74 | assertEquals("http://google.com:100", builder.buildString()); 75 | 76 | // Host:Port/Path 77 | builder.setPath("path/to/file"); 78 | assertEquals("http://google.com:100/path/to/file", builder.buildString()); 79 | 80 | // Host:Port/Path?Param 81 | builder.setParameter("key", "value"); 82 | assertEquals("http://google.com:100/path/to/file?key=value", builder.buildString()); 83 | 84 | // Host:Port/Path?Param#Hash 85 | builder.setHash("token"); 86 | assertEquals("http://google.com:100/path/to/file?key=value#token", builder.buildString()); 87 | } 88 | 89 | public void testBuildStringEntireUrlWithReturns() { 90 | UrlBuilder builder = new UrlBuilder(); 91 | builder 92 | .setHost("google.com") 93 | .setPort(100) 94 | .setPath("path/to/file") 95 | .setParameter("key", "value") 96 | .setHash("token"); 97 | assertEquals("http://google.com:100/path/to/file?key=value#token", builder.buildString()); 98 | } 99 | 100 | public void testBuildStringParts() { 101 | UrlBuilder builder = new UrlBuilder(); 102 | builder.setHost("google.com"); 103 | 104 | // Host only. 105 | assertEquals("http://google.com", builder.buildString()); 106 | 107 | // Host:Port 108 | builder.setPort(100); 109 | assertEquals("http://google.com:100", builder.buildString()); 110 | builder.setPort(UrlBuilder.PORT_UNSPECIFIED); 111 | 112 | // Host/Path 113 | builder.setPath("path/to/file"); 114 | assertEquals("http://google.com/path/to/file", builder.buildString()); 115 | builder.setPath(null); 116 | 117 | // Host?Param 118 | builder.setParameter("key", "value"); 119 | assertEquals("http://google.com?key=value", builder.buildString()); 120 | builder.removeParameter("key"); 121 | 122 | // Host#Hash 123 | builder.setHash("token"); 124 | assertEquals("http://google.com#token", builder.buildString()); 125 | builder.setHash(null); 126 | } 127 | 128 | public void testSetHash() { 129 | UrlBuilder builder = new UrlBuilder(); 130 | builder.setHost("google.com"); 131 | 132 | // Hash not specified 133 | assertEquals("http://google.com", builder.buildString()); 134 | 135 | // # added if not present 136 | builder.setHash("myHash"); 137 | assertEquals("http://google.com#myHash", builder.buildString()); 138 | 139 | // Null hash 140 | builder.setHash(null); 141 | assertEquals("http://google.com", builder.buildString()); 142 | 143 | // # not added if present 144 | builder.setHash("#myHash2"); 145 | assertEquals("http://google.com#myHash2", builder.buildString()); 146 | } 147 | 148 | public void testSetHost() { 149 | UrlBuilder builder = new UrlBuilder(); 150 | 151 | // Host not specified. 152 | assertEquals("http://", builder.buildString()); 153 | 154 | // Null host. 155 | builder.setHost(null); 156 | assertEquals("http://", builder.buildString()); 157 | 158 | // Empty host. 159 | builder.setHost(""); 160 | assertEquals("http://", builder.buildString()); 161 | 162 | // google.com 163 | builder.setHost("google.com"); 164 | assertEquals("http://google.com", builder.buildString()); 165 | 166 | // google.com:80 167 | builder.setHost("google.com:80"); 168 | assertEquals("http://google.com:80", builder.buildString()); 169 | 170 | // google.com:80 with overridden port. 171 | builder.setHost("google.com:80"); 172 | builder.setPort(1000); 173 | assertEquals("http://google.com:1000", builder.buildString()); 174 | 175 | // google.com:80 with overridden port in host. 176 | builder.setPort(1000); 177 | builder.setHost("google.com:80"); 178 | assertEquals("http://google.com:80", builder.buildString()); 179 | 180 | // Specify to many ports. 181 | // google.com:80:90 182 | try { 183 | builder.setHost("google.com:80:90"); 184 | fail("Expected IllegalArgumentException"); 185 | } catch (IllegalArgumentException e) { 186 | // Expected. 187 | } 188 | 189 | // Specify invalid port. 190 | // google.com:test 191 | try { 192 | builder.setHost("google.com:test"); 193 | fail("Expected IllegalArgumentException"); 194 | } catch (IllegalArgumentException e) { 195 | // Expected. 196 | } 197 | } 198 | 199 | public void testSetParameter() { 200 | UrlBuilder builder = new UrlBuilder(); 201 | builder.setHost("google.com"); 202 | 203 | // Parameters not specified. 204 | assertEquals("http://google.com", builder.buildString()); 205 | 206 | // Simple parameter. 207 | builder.setParameter("key", "value"); 208 | assertEquals("http://google.com?key=value", builder.buildString()); 209 | 210 | // Remove simple parameter. 211 | builder.removeParameter("key"); 212 | assertEquals("http://google.com", builder.buildString()); 213 | 214 | // List parameter. 215 | builder.setParameter("key", "value0", "value1", "value2"); 216 | assertEquals("http://google.com?key=value0&key=value1&key=value2", builder.buildString()); 217 | 218 | // Remove list parameter. 219 | builder.removeParameter("key"); 220 | assertEquals("http://google.com", builder.buildString()); 221 | 222 | // Multiple parameters. 223 | builder.setParameter("key0", "value0", "value1", "value2"); 224 | builder.setParameter("key1", "simpleValue"); 225 | 226 | // The order of query params is not defined, so either URL is acceptable. 227 | String url = builder.buildString(); 228 | assertTrue( 229 | url.equals("http://google.com?key0=value0&key0=value1&key0=value2&key1=simpleValue") 230 | || url.equals( 231 | "http://google.com?key1=simpleValue&key0=value0&key0=value1&key0=value2")); 232 | 233 | // Empty list of multiple parameters. 234 | builder.setParameter("key0", "value0", "value1", "value2"); 235 | builder.setParameter("key1", "simpleValue"); 236 | assertTrue( 237 | url.equals("http://google.com?key0=value0&key0=value1&key0=value2&key1=simpleValue") 238 | || url.equals( 239 | "http://google.com?key1=simpleValue&key0=value0&key0=value1&key0=value2")); 240 | } 241 | 242 | public void testSetParameterToNull() { 243 | UrlBuilder builder = new UrlBuilder(); 244 | builder.setHost("google.com"); 245 | 246 | try { 247 | builder.setParameter(null, "value"); 248 | fail("Expected IllegalArgumentException"); 249 | } catch (IllegalArgumentException e) { 250 | // Expected. 251 | } 252 | 253 | try { 254 | builder.setParameter(null); 255 | fail("Expected IllegalArgumentException"); 256 | } catch (IllegalArgumentException e) { 257 | // Expected. 258 | } 259 | 260 | try { 261 | builder.setParameter("key", new String[0]); 262 | fail("Expected IllegalArgumentException"); 263 | } catch (IllegalArgumentException e) { 264 | // Expected. 265 | } 266 | 267 | try { 268 | builder.setParameter("key", (String[]) null); 269 | fail("Expected IllegalArgumentException"); 270 | } catch (IllegalArgumentException e) { 271 | // Expected. 272 | } 273 | 274 | // Null values are okay. 275 | builder.setParameter("key", (String) null); 276 | assertEquals("http://google.com?key=", builder.buildString()); 277 | } 278 | 279 | public void testSetPath() { 280 | UrlBuilder builder = new UrlBuilder(); 281 | builder.setHost("google.com"); 282 | 283 | // Path not specified. 284 | assertEquals("http://google.com", builder.buildString()); 285 | 286 | // Null path. 287 | builder.setPath(null); 288 | assertEquals("http://google.com", builder.buildString()); 289 | 290 | // Empty path. 291 | builder.setPath(""); 292 | assertEquals("http://google.com", builder.buildString()); 293 | 294 | // path/to/file.html 295 | builder.setPath("path/to/file.html"); 296 | assertEquals("http://google.com/path/to/file.html", builder.buildString()); 297 | 298 | // /path/to/file.html 299 | builder.setPath("/path/to/file.html"); 300 | assertEquals("http://google.com/path/to/file.html", builder.buildString()); 301 | } 302 | 303 | public void testSetPort() { 304 | UrlBuilder builder = new UrlBuilder(); 305 | builder.setHost("google.com"); 306 | 307 | // Port not specified. 308 | assertEquals("http://google.com", builder.buildString()); 309 | 310 | // Port 1000. 311 | builder.setPort(1000); 312 | assertEquals("http://google.com:1000", builder.buildString()); 313 | 314 | // PORT_UNSPECIFIED. 315 | builder.setPort(UrlBuilder.PORT_UNSPECIFIED); 316 | assertEquals("http://google.com", builder.buildString()); 317 | } 318 | 319 | public void testSetProtocol() { 320 | UrlBuilder builder = new UrlBuilder(); 321 | builder.setHost("google.com"); 322 | 323 | // Protocol not specified. 324 | assertEquals("http://google.com", builder.buildString()); 325 | 326 | // Null host. 327 | try { 328 | builder.setProtocol(null); 329 | fail("Expected IllegalArgumentException"); 330 | } catch (IllegalArgumentException e) { 331 | // Expected. 332 | } 333 | 334 | // Empty host. 335 | try { 336 | builder.setProtocol(""); 337 | fail("Expected IllegalArgumentException"); 338 | } catch (IllegalArgumentException e) { 339 | // Expected. 340 | } 341 | 342 | // ftp 343 | builder.setProtocol("ftp"); 344 | assertEquals("ftp://google.com", builder.buildString()); 345 | 346 | // tcp: 347 | builder.setProtocol("tcp:"); 348 | assertEquals("tcp://google.com", builder.buildString()); 349 | 350 | // http:/ 351 | builder.setProtocol("http:/"); 352 | assertEquals("http://google.com", builder.buildString()); 353 | 354 | // http:// 355 | builder.setProtocol("http://"); 356 | assertEquals("http://google.com", builder.buildString()); 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/server/RequestBuilderTestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.server; 17 | 18 | import java.io.BufferedReader; 19 | import java.io.IOException; 20 | import javax.servlet.annotation.WebServlet; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | import org.gwtproject.http.client.RequestBuilderTest; 25 | import org.gwtproject.http.shared.RequestBuilderTestConstants; 26 | 27 | /** Servlet component of the {@link RequestBuilderTest}. */ 28 | @SuppressWarnings("serial") 29 | @WebServlet("/testRequestBuilder/*") 30 | public class RequestBuilderTestServlet extends HttpServlet { 31 | 32 | @Override 33 | protected void doDelete(HttpServletRequest request, HttpServletResponse response) { 34 | try { 35 | response.setStatus(HttpServletResponse.SC_OK); 36 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_DELETE_RESPONSE); 37 | } catch (IOException e) { 38 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 39 | } 40 | } 41 | 42 | @Override 43 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 44 | throws IOException { 45 | String pathInfo = request.getPathInfo(); 46 | switch (pathInfo) { 47 | case "/setRequestHeader": 48 | String value = request.getHeader("Foo"); 49 | if (value.equals("Bar1")) { 50 | response.setStatus(HttpServletResponse.SC_OK); 51 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 52 | } else { 53 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 54 | } 55 | break; 56 | case "/send_GET": 57 | response.setStatus(HttpServletResponse.SC_OK); 58 | response.getWriter().write(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 59 | break; 60 | case "/sendRequest_GET": 61 | response.setStatus(HttpServletResponse.SC_OK); 62 | response.getWriter().write(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 63 | break; 64 | case "/setTimeout/timeout": 65 | // cause a timeout on the client 66 | try { 67 | Thread.sleep(5000); 68 | } catch (InterruptedException e) { 69 | throw new AssertionError(e); 70 | } 71 | response.setStatus(HttpServletResponse.SC_OK); 72 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 73 | break; 74 | case "/setTimeout/noTimeout": 75 | // wait but not long enough to timeout 76 | try { 77 | Thread.sleep(1000); 78 | } catch (InterruptedException e) { 79 | throw new AssertionError(e); 80 | } 81 | response.setStatus(HttpServletResponse.SC_OK); 82 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 83 | break; 84 | case "/user/pass": 85 | String auth = request.getHeader("Authorization"); 86 | if (auth == null) { 87 | response.setHeader("WWW-Authenticate", "BASIC"); 88 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 89 | } else { 90 | response.setStatus(HttpServletResponse.SC_OK); 91 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_GET_RESPONSE); 92 | } 93 | break; 94 | default: 95 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 96 | break; 97 | } 98 | } 99 | 100 | @Override 101 | protected void doHead(HttpServletRequest request, HttpServletResponse response) { 102 | response.setStatus(HttpServletResponse.SC_OK); 103 | } 104 | 105 | @Override 106 | protected void doPost(HttpServletRequest request, HttpServletResponse response) { 107 | try { 108 | if (request.getPathInfo().equals("/sendRequest_POST")) { 109 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_POST_RESPONSE); 110 | response.setStatus(HttpServletResponse.SC_OK); 111 | } else { 112 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 113 | } 114 | } catch (IOException e) { 115 | response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 116 | } 117 | } 118 | 119 | @Override 120 | protected void doPut(HttpServletRequest request, HttpServletResponse response) 121 | throws IOException { 122 | BufferedReader reader = request.getReader(); 123 | String content = reader.readLine(); 124 | if (content != null && content.equals("Put Me")) { 125 | response.getWriter().print(RequestBuilderTestConstants.SERVLET_PUT_RESPONSE); 126 | response.setStatus(HttpServletResponse.SC_OK); 127 | } else { 128 | response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/server/RequestTestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.server; 17 | 18 | import java.io.IOException; 19 | import javax.servlet.ServletException; 20 | import javax.servlet.annotation.WebServlet; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | /** TODO: document me. */ 26 | @SuppressWarnings("serial") 27 | @WebServlet("/testRequest/*") 28 | public class RequestTestServlet extends HttpServlet { 29 | 30 | @Override 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 32 | throws ServletException, IOException { 33 | if (request.getRequestURI().endsWith("/204NoContent")) { 34 | response.setStatus(HttpServletResponse.SC_NO_CONTENT); 35 | } else { 36 | try { 37 | Thread.sleep(5000); 38 | } catch (InterruptedException e) { 39 | throw new RuntimeException(e); 40 | } 41 | response.setStatus(HttpServletResponse.SC_OK); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/gwtproject/http/server/ResponseTestServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.server; 17 | 18 | import java.io.IOException; 19 | import javax.servlet.ServletException; 20 | import javax.servlet.annotation.WebServlet; 21 | import javax.servlet.http.HttpServlet; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | /** TODO: document me. */ 26 | @SuppressWarnings("serial") 27 | @WebServlet("/testResponse/*") 28 | public class ResponseTestServlet extends HttpServlet { 29 | 30 | @Override 31 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 32 | throws ServletException, IOException { 33 | response.addHeader("header1", "value1"); 34 | response.addHeader("header2", "value2"); 35 | response.addHeader("header3", "value3"); 36 | response.setStatus(HttpServletResponse.SC_OK); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/org/gwtproject/http/RequestBuilderTest.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/resources/org/gwtproject/http/RequestTest.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/resources/org/gwtproject/http/ResponseTest.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | -------------------------------------------------------------------------------- /src/testFixtures/java/org/gwtproject/http/shared/RequestBuilderTestConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 The GWT Project Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * 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 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.gwtproject.http.shared; 17 | 18 | public interface RequestBuilderTestConstants { 19 | String SERVLET_DELETE_RESPONSE = "delete"; 20 | String SERVLET_GET_RESPONSE = "get"; 21 | String SERVLET_POST_RESPONSE = "post"; 22 | // W3C's XMLHttpRequest requires it be the empty string 23 | String SERVLET_HEAD_RESPONSE = ""; 24 | String SERVLET_PUT_RESPONSE = "put"; 25 | } 26 | --------------------------------------------------------------------------------