├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── documentation.yml
│ ├── maven.yml
│ └── release.yml
├── .gitignore
├── .java-version
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── bad-maven-test
├── pom.xml
└── src
│ └── test
│ └── java
│ └── kong
│ └── BadMavenConfigTest.java
├── build
├── checkstyle.xml
├── fileHeader.txt
└── suppressions.xml
├── deploy.sh
├── mkdocs
├── docs
│ ├── caching.md
│ ├── configuration.md
│ ├── images
│ │ ├── favicon-180.png
│ │ └── kong.png
│ ├── index.md
│ ├── installation.md
│ ├── mocks.md
│ ├── requests.md
│ ├── responses.md
│ └── upgrade-guide.md
├── mkdocs.yml
└── requirements.txt
├── pom.xml
├── reports.sh
├── unirest-bdd-tests
├── pom.xml
└── src
│ └── test
│ ├── java
│ ├── BehaviorTests
│ │ ├── AsBytesTest.java
│ │ ├── AsEmptyTest.java
│ │ ├── AsFileTest.java
│ │ ├── AsGenericTypeTest.java
│ │ ├── AsJsonTest.java
│ │ ├── AsObjectTest.java
│ │ ├── AsPagedTest.java
│ │ ├── AsStringTest.java
│ │ ├── BaseUrlTest.java
│ │ ├── BddTest.java
│ │ ├── BodyLogSummaryTest.java
│ │ ├── CachingAlternativeTest.java
│ │ ├── CachingTest.java
│ │ ├── CallbackFutureTest.java
│ │ ├── CertificateTests.java
│ │ ├── ConsumerTest.java
│ │ ├── CookieTest.java
│ │ ├── CustomClientTest.java
│ │ ├── CustomObjectMapperTest.java
│ │ ├── DefectTest.java
│ │ ├── DownloadProgressTest.java
│ │ ├── ErrorParsingTest.java
│ │ ├── ErrorThing.java
│ │ ├── ExecutorTests.java
│ │ ├── Foo.java
│ │ ├── FormPostingTest.java
│ │ ├── GZipTest.java
│ │ ├── GenericMappingTest.java
│ │ ├── GetResponse.java
│ │ ├── HeaderAsserts.java
│ │ ├── HeaderAssertsTest.java
│ │ ├── HeaderTest.java
│ │ ├── HostsHeaderTest.java
│ │ ├── Http2Test.java
│ │ ├── InputStreamTest.java
│ │ ├── InterceptorTest.java
│ │ ├── JacksonObjectMapper.java
│ │ ├── JacksonObjectMapperTest.java
│ │ ├── JankyProxy.java
│ │ ├── JsonCoreTest.java
│ │ ├── JsonPatchTest.java
│ │ ├── MetricsTest.java
│ │ ├── MockCallback.java
│ │ ├── MockServer.java
│ │ ├── MultiPartFormPostingTest.java
│ │ ├── MyMetric.java
│ │ ├── NoopCallback.java
│ │ ├── ObjectFunctionalTest.java
│ │ ├── Pair.java
│ │ ├── PathParamTest.java
│ │ ├── PostRequestHandlersTest.java
│ │ ├── ProxyTest.java
│ │ ├── QueryStringTest.java
│ │ ├── RawUrlTest.java
│ │ ├── RedirectHandlingTest.java
│ │ ├── RequestCapture.java
│ │ ├── ResponseHeaderTest.java
│ │ ├── RetryAsyncTest.java
│ │ ├── RetryTest.java
│ │ ├── TestMonitor.java
│ │ ├── TestUtil.java
│ │ ├── TimeoutTest.java
│ │ ├── UniBodyPostingTest.java
│ │ ├── UploadProgressTest.java
│ │ ├── VerbTest.java
│ │ └── WebsocketTest.java
│ └── kong
│ │ └── unirest
│ │ └── core
│ │ ├── Clock.java
│ │ ├── CookieParsingTest.java
│ │ ├── JsonNodeTest.java
│ │ └── JsonPatchItemTest.java
│ └── resources
│ ├── certs
│ ├── badssl.com-client.p12
│ └── badssl.com-client.pem
│ ├── image.jpg
│ ├── public
│ └── data
│ │ └── cp1250.txt
│ ├── rawPost.txt
│ ├── spidey.jpg
│ ├── spidey.pdf
│ ├── test-json-patch.json
│ ├── test.txt
│ └── test2.txt
├── unirest-java-bom
└── pom.xml
├── unirest-modules-gson
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── checkstyle.xml
├── deploy.sh
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── kong
│ │ │ │ └── unirest
│ │ │ │ └── modules
│ │ │ │ └── gson
│ │ │ │ ├── GsonArray.java
│ │ │ │ ├── GsonElement.java
│ │ │ │ ├── GsonEngine.java
│ │ │ │ ├── GsonNull.java
│ │ │ │ ├── GsonObject.java
│ │ │ │ ├── GsonObjectMapper.java
│ │ │ │ └── GsonPrimitive.java
│ │ └── resources
│ │ │ └── META-INF
│ │ │ └── services
│ │ │ └── kong.unirest.core.json.JsonEngine
│ └── test
│ │ ├── java
│ │ └── kong
│ │ │ └── unirest
│ │ │ └── modules
│ │ │ └── gson
│ │ │ ├── GsonCoreFactoryTest.java
│ │ │ ├── GsonObjectMapperTest.java
│ │ │ ├── JSONArrayTest.java
│ │ │ ├── JSONObjectTest.java
│ │ │ ├── JSONPointerTest.java
│ │ │ └── JsonObjectMapperTest.java
│ │ └── resources
│ │ └── JSON_POINTER_REF.json
└── suppressions.xml
├── unirest-modules-jackson
├── .travis.yml
├── CHANGELOG.md
├── README.md
├── checkstyle.xml
├── deploy.sh
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── kong
│ │ │ │ └── unirest
│ │ │ │ └── modules
│ │ │ │ └── jackson
│ │ │ │ ├── JacksonArray.java
│ │ │ │ ├── JacksonElement.java
│ │ │ │ ├── JacksonEngine.java
│ │ │ │ ├── JacksonObject.java
│ │ │ │ ├── JacksonObjectMapper.java
│ │ │ │ └── JacksonPrimitive.java
│ │ └── resources
│ │ │ └── META-INF
│ │ │ └── services
│ │ │ └── kong.unirest.core.json.JsonEngine
│ └── test
│ │ ├── java
│ │ └── kong
│ │ │ └── unirest
│ │ │ └── modules
│ │ │ └── jackson
│ │ │ ├── JSONArrayTest.java
│ │ │ ├── JSONObjectTest.java
│ │ │ ├── JSONPointerTest.java
│ │ │ ├── JacksonCoreFactoryTest.java
│ │ │ ├── JacksonObjectMapperTest.java
│ │ │ └── JacksonTimeTests.java
│ │ └── resources
│ │ └── JSON_POINTER_REF.json
└── suppressions.xml
├── unirest-modules-mocks
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── kong
│ │ └── unirest
│ │ └── core
│ │ ├── Assert.java
│ │ ├── BodyMatcher.java
│ │ ├── EqualsBodyMatcher.java
│ │ ├── Expectation.java
│ │ ├── ExpectedResponse.java
│ │ ├── ExpectedResponseRecord.java
│ │ ├── FieldMatcher.java
│ │ ├── Invocation.java
│ │ ├── MatchStatus.java
│ │ ├── Matchers.java
│ │ ├── MockClient.java
│ │ ├── MockConfig.java
│ │ ├── MockListener.java
│ │ ├── MockRawResponse.java
│ │ ├── MockResponse.java
│ │ ├── MockWebSocket.java
│ │ ├── ResponseBuilder.java
│ │ ├── Routes.java
│ │ ├── SocketSet.java
│ │ ├── Times.java
│ │ └── UnirestAssertion.java
│ └── test
│ └── java
│ └── kong
│ ├── tests
│ ├── AssertTest.java
│ ├── AsyncTest.java
│ ├── Base.java
│ ├── BodyMatchingTest.java
│ ├── DefultResponseTest.java
│ ├── DocumentationExamplesTest.java
│ ├── ErrorTest.java
│ ├── ExpectedResponseTest.java
│ ├── MetricsTest.java
│ ├── MockClientInterceptorIssueTest.java
│ ├── MockWebSocketTest.java
│ ├── MultipleExpectsTest.java
│ ├── Pojo.java
│ ├── RawResponseTest.java
│ ├── RegistrationTest.java
│ ├── ResponseHandlerTest.java
│ └── VerifyTimesTest.java
│ └── unirest
│ └── core
│ ├── MockListenerTest.java
│ ├── MockResponseTest.java
│ ├── MockWebSocketResponseTest.java
│ └── TimesTest.java
└── unirest
├── pom.xml
└── src
├── main
└── java
│ └── kong
│ └── unirest
│ └── core
│ ├── BaseRequest.java
│ ├── BaseResponse.java
│ ├── BasicResponse.java
│ ├── Body.java
│ ├── BodyPart.java
│ ├── ByteArrayPart.java
│ ├── ByteResponse.java
│ ├── Cache.java
│ ├── CacheManager.java
│ ├── Callback.java
│ ├── CallbackFuture.java
│ ├── Client.java
│ ├── CompoundInterceptor.java
│ ├── Config.java
│ ├── ContentType.java
│ ├── Cookie.java
│ ├── CookieSpecs.java
│ ├── Cookies.java
│ ├── DefaultInterceptor.java
│ ├── Empty.java
│ ├── FailedResponse.java
│ ├── FilePart.java
│ ├── FileResponse.java
│ ├── GenericType.java
│ ├── GetRequest.java
│ ├── Header.java
│ ├── HeaderNames.java
│ ├── Headers.java
│ ├── HttpMethod.java
│ ├── HttpRequest.java
│ ├── HttpRequestBody.java
│ ├── HttpRequestJsonPatch.java
│ ├── HttpRequestMultiPart.java
│ ├── HttpRequestNoBody.java
│ ├── HttpRequestSummary.java
│ ├── HttpRequestUniBody.java
│ ├── HttpRequestWithBody.java
│ ├── HttpResponse.java
│ ├── HttpResponseSummary.java
│ ├── HttpStatus.java
│ ├── InputStreamBody.java
│ ├── InputStreamPart.java
│ ├── Interceptor.java
│ ├── JsonNode.java
│ ├── JsonPatch.java
│ ├── JsonPatchItem.java
│ ├── JsonPatchOperation.java
│ ├── JsonPatchRequest.java
│ ├── JsonResponse.java
│ ├── MetricContext.java
│ ├── MimeTypes.java
│ ├── MonitoringInputStream.java
│ ├── MultipartBody.java
│ ├── MultipartMode.java
│ ├── NoopMetric.java
│ ├── ObjectMapper.java
│ ├── ObjectResponse.java
│ ├── PagedList.java
│ ├── ParamPart.java
│ ├── Path.java
│ ├── ProgressMonitor.java
│ ├── Proxy.java
│ ├── QueryParams.java
│ ├── RawResponse.java
│ ├── RawResponseBase.java
│ ├── RequestBodyEntity.java
│ ├── RequestFactory.java
│ ├── RequestSummary.java
│ ├── ResponseSummary.java
│ ├── RetryStrategy.java
│ ├── StringResponse.java
│ ├── SummaryFormatter.java
│ ├── TestBody.java
│ ├── UniByteArrayBody.java
│ ├── UniMetric.java
│ ├── UnibodyString.java
│ ├── Unirest.java
│ ├── UnirestConfigException.java
│ ├── UnirestException.java
│ ├── UnirestInstance.java
│ ├── UnirestParsingException.java
│ ├── UnrecoverableException.java
│ ├── Util.java
│ ├── WebSocketRequest.java
│ ├── WebSocketRequestImpl.java
│ ├── WebSocketResponse.java
│ ├── java
│ ├── BodyBuilder.java
│ ├── BoundaryAppender.java
│ ├── JavaClient.java
│ ├── JavaClientBuilder.java
│ ├── JavaResponse.java
│ ├── MonitoringInputStream.java
│ ├── MultipartBodyPublisher.java
│ ├── MultipartSubscription.java
│ ├── NeverUseInProdTrustManager.java
│ ├── Part.java
│ ├── PartPublisher.java
│ ├── PartSubscriber.java
│ ├── Prefetcher.java
│ ├── SSLContextBuilder.java
│ ├── Upstream.java
│ └── WTF.md
│ └── json
│ ├── CoreFactory.java
│ ├── Foo.java
│ ├── JSONArray.java
│ ├── JSONElement.java
│ ├── JSONException.java
│ ├── JSONObject.java
│ ├── JSONPointer.java
│ ├── JSONPointerException.java
│ ├── JsonEngine.java
│ ├── NullObject.java
│ └── ToObjectMapper.java
└── test
├── java
└── kong
│ └── unirest
│ └── core
│ ├── BaseRequestTest.java
│ ├── BodyTest.java
│ ├── ByteArrayPartTest.java
│ ├── CacheManagerTest.java
│ ├── ClientFactoryTest.java
│ ├── CompoundInterceptorTest.java
│ ├── ConfigTest.java
│ ├── ContentTypeTest.java
│ ├── FilePartTest.java
│ ├── HeaderEntryTest.java
│ ├── HeadersTest.java
│ ├── HttpMethodTest.java
│ ├── InputStreamPartTest.java
│ ├── MockResponse.java
│ ├── NotImplemented.java
│ ├── PagedListTest.java
│ ├── ParamPartTest.java
│ ├── PathTest.java
│ ├── RequestFactoryTest.java
│ ├── ResponseUtilsTest.java
│ ├── RetryStrategyTest.java
│ ├── TestRawResponse.java
│ ├── UniByteArrayBodyTest.java
│ ├── UnibodyStringTest.java
│ ├── UnirestInstanceTest.java
│ ├── UriFormatterTest.java
│ ├── UtilTest.java
│ └── json
│ └── CoreFactoryTest.java
└── resources
├── JSON_POINTER_REF.json
└── test-json-patch.json
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Provide as much of a code sample as possible. Unirest is pretty small so it you should be able to mostly copy-paste into the issue
16 | 1. do **NOT** paste authentication or client keys into the issue
17 | 1. provide full stack traces if possible
18 |
19 | **Expected behavior**
20 | A clear and concise description of what you expected to happen.
21 |
22 | **Screenshots**
23 | If applicable, add screenshots to help explain your problem.
24 |
25 | **Environmental Data:**
26 | - Java Version
27 | - Version [e.g. 3.3.03]
28 |
29 | **Additional context**
30 | Add any other context about the problem here.
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/documentation.yml:
--------------------------------------------------------------------------------
1 | name: documentation
2 | on:
3 | push:
4 | branches:
5 | - master
6 | - main
7 | permissions:
8 | contents: write
9 | jobs:
10 | deploy:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v4
14 | - name: Configure Git Credentials
15 | run: |
16 | git config user.name github-actions[bot]
17 | git config user.email 41898282+github-actions[bot]@users.noreply.github.com
18 | - uses: actions/setup-python@v5
19 | with:
20 | python-version: 3.x
21 | - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
22 | - uses: actions/cache@v4
23 | with:
24 | key: mkdocs-material-${{ env.cache_id }}
25 | path: .cache
26 | restore-keys: |
27 | mkdocs-material-
28 | - run: pip install mkdocs-material
29 | - working-directory: ./mkdocs
30 | run: mkdocs gh-deploy --force
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | name: Verify
2 |
3 | on:
4 | push:
5 | # Sequence of patterns matched against refs/heads
6 | branches-ignore:
7 | - apache5
8 | pull_request:
9 |
10 | jobs:
11 | build:
12 | timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }}
13 |
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - uses: actions/checkout@v1
18 | - name: Set up JDK 1.11
19 | uses: actions/setup-java@v1
20 | with:
21 | java-version: 1.11
22 | - name: Cache
23 | uses: actions/cache@v4
24 | with:
25 | path: ~/.m2/repository
26 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
27 | restore-keys: |
28 | ${{ runner.os }}-maven-
29 | - name: Build with Maven
30 | run: mvn -B package --file pom.xml
31 |
32 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | # Sequence of patterns matched against refs/tags
4 | tags:
5 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
6 |
7 | name: Create Release
8 |
9 | jobs:
10 | build:
11 | timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT) }}
12 | name: Create Release
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: Checkout code
16 | uses: actions/checkout@v2
17 | - name: Create Release
18 | id: create_release
19 | uses: actions/create-release@v1
20 | env:
21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
22 | with:
23 | tag_name: ${{ github.ref }}
24 | release_name: Release ${{ github.ref }}
25 | body: |
26 | See CHANGELOG.md for details.
27 | Fresh releases may take up to 20 minutes to show up in Maven Central: https://mvnrepository.com/artifact/com.konghq/unirest-java
28 | draft: false
29 | prerelease: false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | pom.xml.releaseBackup
3 | .project
4 | target
5 | .DS_Store
6 | .settings
7 | release.properties
8 | .idea
9 | *.iml
10 | .gitconfig
11 | _site/
12 | Gemfile.lock
13 | .sass-cache/
14 | .jekyll-metadata
15 | 1.jpg
16 | dependency-reduced-pom.xml
17 | site
18 | ```
19 |
20 |
--------------------------------------------------------------------------------
/.java-version:
--------------------------------------------------------------------------------
1 | 11
2 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Unirest
2 |
3 | :+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
4 |
5 | ## Code of Conduct
6 |
7 | This project and everyone participating in it is governed by the [Open Unirest Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
8 |
9 | ## How Can I Contribute?
10 |
11 | ### Reporting Bugs
12 | **Explain how to produce the problem** in as many details as possible. When listing steps, **don't just say what you did, but explain how you did it**.
13 | * **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
14 | * **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
15 | * **Explain which behavior you expected to see instead and why.**
16 |
17 | Include details about your configuration and environment:
18 |
19 | * **What version of Unirest were you using?**
20 | * **What version of Java were you running it on?**
21 | * **Did you do any custom configuration to the client?**
22 |
23 |
24 | ### Contributing Code
25 |
26 | * Before you put in all the work to add a new feature. Try opening a issue and checking if it's something that will be accepted. Sometimes a feature you think might be useful might be contrary to the goals or direction of the project. We won't want folks to get frustrated, so take a minute and talk it through with us.
27 | * If we do all agree it's a good idea we would expect:
28 | * Backwards compatibility is important to this project and you should go out of your way to not make breaking changes.
29 | * All contributions should be issued as pull requests and get reviewed by the admins of this project.
30 | * All code should follow style guidelines enforced by the checkstyle and other static analysis.
31 | * All code should have tests.
32 | * Unit tests
33 | * Behavioral tests (see https://github.com/Kong/unirest-java/tree/master/unirest/src/test/java/BehaviorTests)
34 | * You should have run verify before submitting and the PR needs to have passed TravisCI before being merged.
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013-2019.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unirest for Java
2 |
3 | [](https://github.com/kong/unirest-java/actions)
4 | [](https://maven-badges.herokuapp.com/maven-central/com.kong/unirest-java)
5 | [](http://www.javadoc.io/doc/com.konghq/unirest-java)
6 |
7 |
8 | ## Unirest 4
9 | Unirest 4 is build on modern Java standards, and as such requires at least Java 11.
10 |
11 | Unirest 4's dependencies are fully modular, and have been moved to new Maven coordinates to avoid conflicts with the previous versions.
12 | You can use a maven bom to manage the modules:
13 |
14 | ## Documentation
15 | Our [Documentation](http://kong.github.io/unirest-java/)
16 |
17 | ## Upgrading from Previous Versions
18 | See the [Upgrade Guide](http://kong.github.io/unirest-java/upgrade-guilde)
19 |
20 | ## ChangeLog
21 | See the [Change Log](CHANGELOG.md) for recent changes.
22 |
23 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | | Version | Supported |
6 | | ------- | ------------------ |
7 | | 3.1.x | :white_check_mark: |
8 | | 3.0.x | :x: |
9 | | 2.4.x | :white_check_mark: |
10 | | < 2.4 | :x: |
11 | | 1.x.x | :x: |
12 |
13 | ## Reporting a Vulnerability
14 |
15 | Please report an issue and we will respond to security issues asap
16 |
--------------------------------------------------------------------------------
/bad-maven-test/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.kong
7 | bad-maven-test
8 | 2.3.00-SNAPSHOT
9 | Errors that happen when people are using crusty old version of apache Http client
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 11
17 | 11
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | com.konghq
26 | unirest-java
27 | 2.3.05
28 | standalone
29 |
30 |
31 |
--------------------------------------------------------------------------------
/bad-maven-test/src/test/java/kong/BadMavenConfigTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong;
27 |
28 |
29 | import kong.unirest.Unirest;
30 |
31 | public class BadMavenConfigTest {
32 |
33 |
34 | public static void main(String[] args) {
35 | Unirest.get("https://konghq.com").asString().ifSuccess(e -> System.out.println("e = " + e.getBody()));
36 | }
37 | }
--------------------------------------------------------------------------------
/build/fileHeader.txt:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/build/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # The MIT License
4 | #
5 | # Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # "Software"), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be
16 | # included in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 | #
26 |
27 |
28 | mvn clean verify -P ossrh
29 | mvn release:prepare -DskipTests -P ossrh
30 | mvn release:perform -DskipTests -P ossrh
31 |
--------------------------------------------------------------------------------
/mkdocs/docs/caching.md:
--------------------------------------------------------------------------------
1 |
2 | # Caching
3 | Unirest offers a simple im memory response caching mechanism with a few options for entry expiration.
4 | This can be either be enabled with defaults, with expiration options or consumers may supply a custom cache backed by the cache of their choice.
5 | It is reccomended that in high load systems consumers back the cache with a dedicated cache implementation like EHCache or Guava.
6 |
7 | #### Basic cache:
8 | ```java
9 | Unirest.config().cacheResponses(true);
10 |
11 | //These 1st response will be cached in this case:
12 | Unirest.get("https://somwhere").asString();
13 | Unirest.get("https://somwhere").asString();
14 | ```
15 | #### Advanced Options:
16 | You can use a builder to customize eviction rules:
17 |
18 | ```java
19 | Unirest.config().cacheResponses(builder()
20 | .depth(5) // Depth is the max number of entries cached
21 | .maxAge(5, TimeUnit.MINUTES)); // Max age is how long the entry will be kept.
22 | ```
23 |
24 | #### Custom Caches
25 | You can also supply a custom cache by implementing the Cache Interface
26 | ```java
27 | public static void main(String[] args){
28 | Unirest.config().cacheResponses(Cache.builder().backingCache(new GuavaCache()));
29 | }
30 |
31 | // Example backing cache using Guava
32 | public static class GuavaCache implements Cache {
33 | com.google.common.cache.Cache regular = CacheBuilder.newBuilder().build();
34 | com.google.common.cache.Cache async = CacheBuilder.newBuilder().build();
35 | @Override
36 | public HttpResponse get(Key key, Supplier> fetcher) {
37 | try {
38 | return regular.get(key, fetcher::get);
39 | } catch (ExecutionException e) {
40 | throw new RuntimeException(e);
41 | }
42 | }
43 |
44 | @Override
45 | public CompletableFuture getAsync(Key key, Supplier>> fetcher) {
46 | try {
47 | return async.get(key, fetcher::get);
48 | } catch (ExecutionException e) {
49 | throw new RuntimeException(e);
50 | }
51 | }
52 | }
53 |
54 | ```
--------------------------------------------------------------------------------
/mkdocs/docs/images/favicon-180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/mkdocs/docs/images/favicon-180.png
--------------------------------------------------------------------------------
/mkdocs/docs/images/kong.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/mkdocs/docs/images/kong.png
--------------------------------------------------------------------------------
/mkdocs/docs/index.md:
--------------------------------------------------------------------------------
1 | # Unirest-Java Documentation
2 |
3 | Welcome to Unirest-Java!
4 |
5 | ## About
6 | Unirest is intended to be a simple and obvious library for HTTP requests. It provides a fluent interface that makes discovery of commands easy in a modern IDE. Some of the features it supports are:
7 |
8 |
9 | * HTTP 1 and 2
10 | * WebSockets
11 | * JSON Patch (RFC-6902)
12 | * Default Object mappers for both Jackson and GSON
13 | * Easy request building including
14 | * Path parameters
15 | * Query param building
16 | * Headers including full suport for manipulating cookies
17 | * Multipart requests
18 | * Turning POJOs into string or binary bodies
19 | * Global request interceptors
20 | * Easy response handling including
21 | * Global response interceptors
22 | * Turning bodies into POJOs
23 | * Error handling
24 | * Mocking library for testing
25 |
26 |
27 | ## History
28 |
29 | Unirest-Java started off as just one of series of HTTP clients written in different languages which all conform to the same pattern.
30 |
31 | From the original Unirest-Java though Unirest-Java 3 the library was essentially a wrapper around the excellent Apache HTTP
32 |
--------------------------------------------------------------------------------
/mkdocs/docs/installation.md:
--------------------------------------------------------------------------------
1 | ## Unirest 4
2 | Unirest 4 is build on modern Java standards, and as such requires at least Java 11.
3 |
4 | Unirest 4's dependencies are fully modular, and have been moved to new Maven coordinates to avoid conflicts with the previous versions.
5 | You can use a maven bom to manage the modules:
6 |
7 | ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-java)[:](https://repo.maven.apache.org/maven2/com/konghq/unirest-java/)
8 | ```xml
9 |
10 |
11 |
12 |
13 | com.konghq
14 | unirest-java-bom
15 | 4.4.5
16 | pom
17 | import
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | com.konghq
26 | unirest-java-core
27 |
28 |
29 |
30 |
31 |
32 | com.konghq
33 | unirest-modules-gson
34 |
35 |
36 |
37 |
38 | com.konghq
39 | unirest-modules-jackson
40 |
41 |
42 | ```
43 |
44 | #### 🚨 Attention JSON users 🚨
45 | Under Unirest 4, core no longer comes with ANY transient dependencies, and because Java itself lacks a JSON parser you MUST declare a JSON implementation if you wish to do object mappings or use Json objects.
46 |
47 | ### Upgrading from Previous Versions
48 | See the [Upgrade Guide](https://github.com/Kong/unirest-java/blob/master/UPGRADE_GUIDE.md)
49 |
50 | ### ChangeLog
51 | See the [Change Log](https://github.com/Kong/unirest-java/blob/master/CHANGELOG.md) for recent changes.
52 |
53 |
54 | ## Unirest 3
55 | ### Maven
56 | ```xml
57 |
58 |
59 | com.konghq
60 | unirest-java
61 | 3.14.1
62 |
63 | ```
--------------------------------------------------------------------------------
/mkdocs/mkdocs.yml:
--------------------------------------------------------------------------------
1 | site_name: Unirest-Java Documentation
2 | site_url: https://kong.github.io/unirest-java/installation
3 | repo_url: https://github.com/Kong/unirest-java
4 | repo_name: Kong/unirest-java
5 | theme:
6 | name: material
7 | favicon: images/favicon-180.png
8 | logo: images/kong.png
9 | palette:
10 | # Palette toggle for automatic mode
11 | - media: "(prefers-color-scheme)"
12 | toggle:
13 | icon: material/brightness-auto
14 | name: Switch to light mode
15 |
16 | # Palette toggle for light mode
17 | - media: "(prefers-color-scheme: light)"
18 | scheme: default
19 | toggle:
20 | icon: material/brightness-7
21 | name: Switch to dark mode
22 |
23 | # Palette toggle for dark mode
24 | - media: "(prefers-color-scheme: dark)"
25 | scheme: slate
26 | toggle:
27 | icon: material/brightness-4
28 | name: Switch to system preference
29 | features:
30 | - content.code.copy
31 | - content.code.select
32 |
33 | nav:
34 | - About: index.md
35 | - Installation: installation.md
36 | - Upgrade Guide: upgrade-guide.md
37 | - Configuration: configuration.md
38 | - Making Requests: requests.md
39 | - Handling Responses: responses.md
40 | - Caching Responses: caching.md
41 | - Mocking: mocks.md
42 |
43 |
44 | markdown_extensions:
45 | - pymdownx.highlight:
46 | anchor_linenums: true
47 | line_spans: __span
48 | pygments_lang_class: true
49 | - pymdownx.inlinehilite
50 | - pymdownx.snippets
51 | - pymdownx.superfences:
52 | custom_fences:
53 | - name: mermaid
54 | class: mermaid
55 | format: !!python/name:pymdownx.superfences.fence_code_format
--------------------------------------------------------------------------------
/mkdocs/requirements.txt:
--------------------------------------------------------------------------------
1 | mkdocs-material
--------------------------------------------------------------------------------
/reports.sh:
--------------------------------------------------------------------------------
1 | #
2 | # The MIT License
3 | #
4 | # Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | #
6 | # Permission is hereby granted, free of charge, to any person obtaining
7 | # a copy of this software and associated documentation files (the
8 | # "Software"), to deal in the Software without restriction, including
9 | # without limitation the rights to use, copy, modify, merge, publish,
10 | # distribute, sublicense, and/or sell copies of the Software, and to
11 | # permit persons to whom the Software is furnished to do so, subject to
12 | # the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be
15 | # included in all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | #
25 |
26 | open ./unirest/target/site/jacoco/index.html
--------------------------------------------------------------------------------
/unirest-bdd-tests/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | unirest-java-parent
5 | com.konghq
6 | 4.4.8-SNAPSHOT
7 |
8 | 4.0.0
9 |
10 | unirest-bdd-tests
11 |
12 |
13 | 11
14 | 11
15 | ${project.parent.basedir}
16 |
17 |
18 |
19 |
20 | com.konghq
21 | unirest-java-core
22 | ${project.version}
23 | test
24 |
25 |
26 | com.konghq
27 | unirest-modules-gson
28 | ${project.version}
29 | test
30 |
31 |
32 | io.javalin
33 | javalin
34 | 6.6.0
35 | test
36 |
37 |
38 | com.fasterxml.jackson.datatype
39 | jackson-datatype-guava
40 | ${jackson.version}
41 | test
42 |
43 |
44 | com.fasterxml.jackson.core
45 | jackson-databind
46 | ${jackson.version}
47 | test
48 |
49 |
50 | org.slf4j
51 | slf4j-simple
52 | 2.0.17
53 | test
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/CustomClientTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import kong.unirest.core.Client;
29 | import kong.unirest.core.HttpRequest;
30 | import kong.unirest.core.HttpResponse;
31 | import kong.unirest.core.Unirest;
32 | import org.junit.jupiter.api.Test;
33 |
34 | import java.util.function.Function;
35 |
36 | import static org.junit.jupiter.api.Assertions.assertEquals;
37 | import static org.mockito.ArgumentMatchers.any;
38 | import static org.mockito.Mockito.mock;
39 | import static org.mockito.Mockito.when;
40 |
41 | class CustomClientTest extends BddTest {
42 |
43 | @Test
44 | void settingACustomClient() {
45 | var client = mock(Client.class);;
46 |
47 | var mock = mock(HttpResponse.class);
48 | when(client.request(any(HttpRequest.class),
49 | any(Function.class),
50 | any(Class.class))).thenReturn(mock);
51 | Unirest.config().httpClient(client);
52 |
53 | assertEquals(mock, Unirest.get("http://localhost/getme").asEmpty());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/ErrorThing.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import com.fasterxml.jackson.annotation.JsonCreator;
29 | import com.fasterxml.jackson.annotation.JsonProperty;
30 |
31 | import static org.junit.jupiter.api.Assertions.assertEquals;
32 |
33 | public class ErrorThing {
34 |
35 | private final String message;
36 |
37 | @JsonCreator
38 | public ErrorThing(@JsonProperty("message") String message){
39 | this.message = message;
40 | }
41 |
42 | public String getMessage() {
43 | return message;
44 | }
45 |
46 | public void assertError(String s) {
47 | assertEquals(s, message);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/ExecutorTests.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import kong.unirest.core.Unirest;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import java.util.concurrent.Executor;
32 | import java.util.concurrent.Executors;
33 |
34 | import static org.junit.jupiter.api.Assertions.assertTrue;
35 |
36 | public class ExecutorTests extends BddTest {
37 | @Test
38 | void canSetCustomExecutor() {
39 | var executor = new CustomExecutor();
40 | Unirest.config().executor(executor);
41 | Unirest.get(MockServer.GET).asEmpty();
42 | assertTrue(executor.wasUsed);
43 | }
44 |
45 | private class CustomExecutor implements Executor {
46 | Executor e = Executors.newSingleThreadExecutor();
47 | boolean wasUsed;
48 | @Override
49 | public void execute(Runnable command) {
50 | wasUsed = true;
51 | e.execute(command);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/Foo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import com.google.common.base.MoreObjects;
29 |
30 | import java.util.Objects;
31 |
32 | public class Foo {
33 | public String bar;
34 |
35 | public Foo(){ }
36 |
37 | public Foo(String bar) {
38 | this.bar = bar;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return MoreObjects.toStringHelper(this).add("bar",bar).toString();
44 | }
45 |
46 | @Override
47 | public boolean equals(Object o) {
48 | if (this == o) {return true;}
49 | if (o == null || getClass() != o.getClass()) {return false;}
50 | Foo foo = (Foo) o;
51 | return Objects.equals(bar, foo.bar);
52 | }
53 |
54 | @Override
55 | public int hashCode() {
56 | return Objects.hash(bar);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/GenericMappingTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import kong.unirest.core.HttpResponse;
29 | import kong.unirest.core.Unirest;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static org.junit.jupiter.api.Assertions.assertEquals;
33 |
34 | class GenericMappingTest extends BddTest {
35 |
36 | @Test
37 | void canMapBody() {
38 | MockServer.setStringResponse("123456");
39 |
40 | int body = Unirest.get(MockServer.GET).asString().mapBody(Integer::valueOf);
41 |
42 | assertEquals(123456, body);
43 | }
44 |
45 | @Test
46 | void canMapTheEntireResponseIntoAnotherResponse() {
47 | MockServer.setStringResponse("123456");
48 | MockServer.addResponseHeader("cheese","cheddar");
49 |
50 | var response = Unirest.get(MockServer.GET)
51 | .asString()
52 | .map(Integer::valueOf);
53 |
54 | assertEquals(123456, response.getBody().intValue());
55 | assertEquals(200, response.getStatus());
56 | assertEquals("cheddar", response.getHeaders().getFirst("cheese"));
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/GetResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29 | import com.fasterxml.jackson.annotation.JsonProperty;
30 |
31 | @JsonIgnoreProperties(ignoreUnknown = true)
32 | public class GetResponse {
33 |
34 | @JsonProperty("url")
35 | private String url;
36 |
37 | public String getUrl() {
38 | return url;
39 | }
40 |
41 | public void setUrl(String url) {
42 | this.url = url;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/HeaderAssertsTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import org.junit.jupiter.api.Test;
29 |
30 | import java.util.Map;
31 |
32 | class HeaderAssertsTest {
33 |
34 | @Test
35 | void canAssertHeaderWithParts() {
36 | new HeaderAsserts(Map.of("foo", "bar; baz=qux; zip=zap;;"))
37 | .assertHeader("foo", "bar")
38 | .assertHeaderWithParam("foo", "bar", "baz", "qux");
39 | }
40 | }
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/JsonCoreTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import kong.unirest.core.json.CoreFactory;
29 | import kong.unirest.modules.gson.GsonEngine;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static org.assertj.core.api.Assertions.assertThat;
33 |
34 | public class JsonCoreTest {
35 |
36 | @Test
37 | void getsFromServiceLocator() {
38 | assertThat(CoreFactory.findEngineWithServiceLocator()).isInstanceOf(GsonEngine.class);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/NoopCallback.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | import kong.unirest.core.Callback;
29 | import kong.unirest.core.HttpResponse;
30 | import kong.unirest.core.UnirestException;
31 |
32 | public class NoopCallback implements Callback {
33 | @Override
34 | public void completed(HttpResponse response) {
35 |
36 | }
37 |
38 | @Override
39 | public void failed(UnirestException e) {
40 |
41 | }
42 |
43 | @Override
44 | public void cancelled() {
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/BehaviorTests/Pair.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package BehaviorTests;
27 |
28 | public class Pair {
29 | public final K key;
30 | public final V value;
31 |
32 | public Pair(K key, V value){
33 |
34 | this.key = key;
35 | this.value = value;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/java/kong/unirest/core/Clock.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.Util;
29 |
30 | import java.time.Instant;
31 |
32 | public class Clock {
33 | public static void freeze(Instant now) {
34 | Util.freezeClock(now);
35 | }
36 |
37 | public static void reset() {
38 | Util.resetClock();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/certs/badssl.com-client.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/unirest-bdd-tests/src/test/resources/certs/badssl.com-client.p12
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/unirest-bdd-tests/src/test/resources/image.jpg
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/public/data/cp1250.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/unirest-bdd-tests/src/test/resources/public/data/cp1250.txt
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/rawPost.txt:
--------------------------------------------------------------------------------
1 | --IDENTIFIER
2 | Content-Disposition: form-data; name="file"; filename="test.txt"
3 | Content-Type: application/octet-stream
4 |
5 | This is a test file
6 | --IDENTIFIER
7 | Content-Disposition: form-data; name="funky"
8 | Content-Type: application/x-www-form-urlencoded; charset=UTF-8
9 |
10 | bunch
11 | --IDENTIFIER
12 | Content-Disposition: form-data; name="marky"
13 | Content-Type: application/x-www-form-urlencoded; charset=UTF-8
14 |
15 | mark
16 | --IDENTIFIER--
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/spidey.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/unirest-bdd-tests/src/test/resources/spidey.jpg
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/spidey.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kong/unirest-java/a7ac694dfb470eb821e0ab1708a5c1574f6252e8/unirest-bdd-tests/src/test/resources/spidey.pdf
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/test-json-patch.json:
--------------------------------------------------------------------------------
1 | [
2 | {"op":"add","path":"/fruits/-","value":"Apple"},
3 | {"op":"remove","path":"/bugs"},
4 | {"op":"replace","path":"/lastname","value":"Flintstone"},
5 | {"op":"test","path":"/firstname","value":"Fred"},
6 | {"op":"move","path":"/new/location","from":"/old/location"},
7 | {"op":"copy","path":"/new/location","from":"/original/location"}
8 | ]
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/test.txt:
--------------------------------------------------------------------------------
1 | This is a test file
--------------------------------------------------------------------------------
/unirest-bdd-tests/src/test/resources/test2.txt:
--------------------------------------------------------------------------------
1 | this is another test
--------------------------------------------------------------------------------
/unirest-java-bom/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | unirest-java-parent
5 | com.konghq
6 | 4.4.8-SNAPSHOT
7 |
8 | 4.0.0
9 | unirest-java-bom
10 | pom
11 |
12 |
13 | ${project.parent.basedir}
14 | 11
15 | 11
16 |
17 |
18 |
19 |
20 |
21 | com.konghq
22 | unirest-java-core
23 | ${project.version}
24 |
25 |
26 | com.konghq
27 | unirest-modules-jackson
28 | ${project.version}
29 |
30 |
31 | com.konghq
32 | unirest-modules-gson
33 | ${project.version}
34 |
35 |
36 | com.konghq
37 | unirest-modules-mocks
38 | ${project.version}
39 | test
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/unirest-modules-gson/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | os:
7 | - linux
8 |
9 | cache:
10 | directories:
11 | - .autoconf
12 | - $HOME/.m2
13 |
--------------------------------------------------------------------------------
/unirest-modules-gson/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 1.0.00
2 | * init release
--------------------------------------------------------------------------------
/unirest-modules-gson/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright for portions of unirest-java are held by Kong Inc (c) 2018.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/unirest-modules-gson/README.md:
--------------------------------------------------------------------------------
1 | # Gson Object Mapper for Unirest
2 |
3 | Welcome. This is a Object Mapper for Unirest based on the popular google Gson JSON parser.
4 | Use it like this:
5 |
6 | ```java
7 | Unirest.config().setObjectMapper(new GsonObjectMapper());
8 | ```
9 |
10 | You may also provide it with your own Gson instance.
11 |
12 | ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/unirest-object-mappers-gson)
13 | ```
14 |
15 | com.konghq
16 | unirest-object-mappers-gson
17 | 2.0.00
18 |
19 | ```
--------------------------------------------------------------------------------
/unirest-modules-gson/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # The MIT License
4 | #
5 | # Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # "Software"), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be
16 | # included in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 | #
26 |
27 |
28 | mvn clean verify
29 | mvn release:prepare -DskipTests
30 | mvn release:perform -DskipTests
31 |
--------------------------------------------------------------------------------
/unirest-modules-gson/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | com.konghq
7 | unirest-java-parent
8 | 4.4.8-SNAPSHOT
9 |
10 |
11 | unirest-modules-gson
12 | unirest-modules-gson
13 | Gson based object mapper for Unirest
14 | jar
15 |
16 |
17 | ${project.parent.basedir}
18 |
19 |
20 |
21 |
22 | com.konghq
23 | unirest-java-core
24 | ${project.version}
25 | provided
26 |
27 |
28 | com.google.code.gson
29 | gson
30 | 2.13.0
31 |
32 |
33 |
--------------------------------------------------------------------------------
/unirest-modules-gson/src/main/java/kong/unirest/modules/gson/GsonNull.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.modules.gson;
27 |
28 | import com.google.gson.JsonNull;
29 | import kong.unirest.core.json.JsonEngine;
30 |
31 | public class GsonNull extends GsonElement implements JsonEngine.Primitive {
32 | GsonNull() {
33 | super(JsonNull.INSTANCE);
34 | }
35 |
36 | @Override
37 | public boolean isBoolean() {
38 | return false;
39 | }
40 |
41 | @Override
42 | public boolean isNumber() {
43 | return false;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/unirest-modules-gson/src/main/java/kong/unirest/modules/gson/GsonPrimitive.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.modules.gson;
27 |
28 | import com.google.gson.JsonPrimitive;
29 | import kong.unirest.core.json.JsonEngine;
30 |
31 | class GsonPrimitive extends GsonElement implements JsonEngine.Primitive {
32 |
33 | GsonPrimitive(JsonPrimitive valueType) {
34 | super(valueType);
35 | }
36 |
37 | @Override
38 | public boolean isBoolean() {
39 | return element.isBoolean();
40 | }
41 |
42 | @Override
43 | public boolean isNumber() {
44 | return element.isNumber();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/unirest-modules-gson/src/main/resources/META-INF/services/kong.unirest.core.json.JsonEngine:
--------------------------------------------------------------------------------
1 | kong.unirest.modules.gson.GsonEngine
--------------------------------------------------------------------------------
/unirest-modules-gson/src/test/java/kong/unirest/modules/gson/GsonCoreFactoryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.modules.gson;
27 |
28 | import kong.unirest.core.json.CoreFactory;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 |
33 | public class GsonCoreFactoryTest {
34 | @Test
35 | void canLoadByServiceLocator() {
36 | assertThat(CoreFactory.findEngineWithServiceLocator())
37 | .isInstanceOf(GsonEngine.class);
38 | }
39 |
40 | @Test
41 | void canLoadByKnownClassNames() {
42 | assertThat(CoreFactory.findEngineWithClassLoader())
43 | .isInstanceOf(GsonEngine.class);
44 | }
45 |
46 | @Test
47 | void willLoadOneWaOrAnother() {
48 | assertThat(CoreFactory.findEngine())
49 | .isInstanceOf(GsonEngine.class);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unirest-modules-gson/src/test/resources/JSON_POINTER_REF.json:
--------------------------------------------------------------------------------
1 | {
2 | "foo": ["bar", "baz"],
3 | "": 0,
4 | "a/b": 1,
5 | "c%d": 2,
6 | "e^f": 3,
7 | "g|h": 4,
8 | "i\\j": 5,
9 | "k\"l": 6,
10 | " ": 7,
11 | "m~n": 8,
12 | "cucu": [
13 | {
14 | "banana": {
15 | "pants" : true
16 | }
17 | }
18 | ]
19 | }
--------------------------------------------------------------------------------
/unirest-modules-gson/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | os:
7 | - linux
8 |
9 | cache:
10 | directories:
11 | - .autoconf
12 | - $HOME/.m2
13 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 2.0.00
2 | * init release
--------------------------------------------------------------------------------
/unirest-modules-jackson/README.md:
--------------------------------------------------------------------------------
1 | # Jackson Object Mapper for Unirest
2 |
3 | Welcome. This is a Object Mapper for Unirest based on the popular Jackson JSON parser.
4 | Use it like this:
5 |
6 | ```java
7 | Unirest.config().setObjectMapper(new JacksonObjectMapper());
8 | ```
9 |
10 | You may also provide it with your own com.fasterxml.jackson.databind.ObjectMapper.
11 |
12 | ## Install With [Maven](https://mvnrepository.com/artifact/com.konghq/)
13 | ```
14 |
15 | com.konghq
16 | unirest-objectmapper-jackson
17 | 3.0.01
18 |
19 | ```
--------------------------------------------------------------------------------
/unirest-modules-jackson/deploy.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # The MIT License
4 | #
5 | # Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining
8 | # a copy of this software and associated documentation files (the
9 | # "Software"), to deal in the Software without restriction, including
10 | # without limitation the rights to use, copy, modify, merge, publish,
11 | # distribute, sublicense, and/or sell copies of the Software, and to
12 | # permit persons to whom the Software is furnished to do so, subject to
13 | # the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be
16 | # included in all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 | #
26 |
27 |
28 | mvn clean verify
29 | mvn release:prepare -DskipTests
30 | mvn release:perform -DskipTests
31 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | com.konghq
7 | unirest-java-parent
8 | 4.4.8-SNAPSHOT
9 |
10 |
11 | unirest-modules-jackson
12 | unirest-modules-jackson
13 | Jackson based object mapper for Unirest
14 |
15 |
16 | ${project.parent.basedir}
17 |
18 |
19 |
20 |
21 | com.konghq
22 | unirest-java-core
23 | ${project.version}
24 | provided
25 |
26 |
27 | com.fasterxml.jackson.core
28 | jackson-databind
29 | ${jackson.version}
30 |
31 |
32 | com.fasterxml.jackson.datatype
33 | jackson-datatype-jsr310
34 | ${jackson.version}
35 |
36 |
37 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/src/main/java/kong/unirest/modules/jackson/JacksonPrimitive.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.modules.jackson;
27 |
28 | import com.fasterxml.jackson.databind.node.ValueNode;
29 | import kong.unirest.core.json.JsonEngine;
30 |
31 | class JacksonPrimitive extends JacksonElement implements JsonEngine.Primitive {
32 | public JacksonPrimitive(ValueNode element) {
33 | super(element);
34 | }
35 |
36 | @Override
37 | public boolean isBoolean() {
38 | return element.isBoolean();
39 | }
40 |
41 | @Override
42 | public boolean isNumber() {
43 | return element.isNumber();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/src/main/resources/META-INF/services/kong.unirest.core.json.JsonEngine:
--------------------------------------------------------------------------------
1 | kong.unirest.modules.jackson.JacksonEngine
--------------------------------------------------------------------------------
/unirest-modules-jackson/src/test/java/kong/unirest/modules/jackson/JacksonCoreFactoryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.modules.jackson;
27 |
28 | import kong.unirest.core.json.CoreFactory;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 |
33 | public class JacksonCoreFactoryTest {
34 | @Test
35 | void canLoadByServiceLocator() {
36 | assertThat(CoreFactory.findEngineWithServiceLocator())
37 | .isInstanceOf(JacksonEngine.class);
38 | }
39 |
40 | @Test
41 | void canLoadByKnownClassNames() {
42 | assertThat(CoreFactory.findEngineWithClassLoader())
43 | .isInstanceOf(JacksonEngine.class);
44 | }
45 |
46 | @Test
47 | void willLoadOneWaOrAnother() {
48 | assertThat(CoreFactory.findEngine())
49 | .isInstanceOf(JacksonEngine.class);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unirest-modules-jackson/src/test/resources/JSON_POINTER_REF.json:
--------------------------------------------------------------------------------
1 | {
2 | "foo": ["bar", "baz"],
3 | "": 0,
4 | "a/b": 1,
5 | "c%d": 2,
6 | "e^f": 3,
7 | "g|h": 4,
8 | "i\\j": 5,
9 | "k\"l": 6,
10 | " ": 7,
11 | "m~n": 8,
12 | "cucu": [
13 | {
14 | "banana": {
15 | "pants" : true
16 | }
17 | }
18 | ]
19 | }
--------------------------------------------------------------------------------
/unirest-modules-jackson/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | com.konghq
5 | unirest-java-parent
6 | 4.4.8-SNAPSHOT
7 |
8 |
9 | 4.0.0
10 |
11 | unirest-modules-mocks
12 | unirest-modules-mocks
13 |
14 |
15 | ${project.parent.basedir}
16 |
17 |
18 |
19 |
20 | com.konghq
21 | unirest-java-core
22 | ${project.version}
23 | provided
24 |
25 |
26 | com.konghq
27 | unirest-modules-gson
28 | ${project.version}
29 | test
30 |
31 |
32 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/BodyMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.List;
29 |
30 | /**
31 | * Body Matchers can be used to evaluate a entity body.
32 | * This is represented by one or more (in the case of multi-part) sections
33 | * these sections are represented as strings in the same way as toString represents the part
34 | * For a single entity like a JSON payload this is simply going to be the JSON String
35 | * For field params it will be a key value pair like 'fruit=orange`
36 | * For binary types it will be some kind of indication like a file path.
37 | */
38 | public interface BodyMatcher {
39 | /**
40 | * indicates if the Matcher succeeded in matching the body
41 | * @param body the list of body parts
42 | * @return MatchStatus indicating if the Matcher succeeded in matching the body
43 | */
44 | MatchStatus matches(List body);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/EqualsBodyMatcher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.List;
29 | import java.util.Objects;
30 |
31 | public class EqualsBodyMatcher implements BodyMatcher {
32 | private final String expected;
33 |
34 | public EqualsBodyMatcher(String body) {
35 | this.expected = body;
36 | }
37 |
38 | @Override
39 | public MatchStatus matches(List body) throws AssertionError {
40 | return new MatchStatus(body.size() == 1 && Objects.equals(expected, body.get(0)), expected);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/MatchStatus.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * Indicates a successful match and a description of the failure (if any)
30 | */
31 | public class MatchStatus {
32 | private final boolean isSuccess;
33 | private final String description;
34 |
35 | /**
36 | * Contruct a Match status
37 | * @param isSuccess indicates success
38 | * @param description a failure description
39 | */
40 | public MatchStatus(boolean isSuccess, String description) {
41 | this.isSuccess = isSuccess;
42 | this.description = description;
43 | }
44 |
45 | /**
46 | * @return Was it successful or not?
47 | */
48 | public boolean isSuccess(){
49 | return isSuccess;
50 | }
51 |
52 | /**
53 | * @return a description of the failure (if any) or null
54 | */
55 | public String getDescription() {
56 | return description;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/Matchers.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * Static set of Matchers
30 | */
31 | public class Matchers {
32 |
33 | /**
34 | * Creates a FieldMatcher expecting a map of keys and values
35 | * use like: FieldMatcher.of("fruit", "orange", "quantity" "42")
36 | * @param keyValuePairs an array of key-value pairs to expect
37 | * @return a new FieldMatcher
38 | */
39 | public BodyMatcher bodyFields(String keyValuePairs){
40 | return FieldMatcher.of(keyValuePairs);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/MockConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * A Mock Config that will not actually start up any real clients.
30 | */
31 | public class MockConfig extends Config {
32 | private MockClient client = new MockClient(() -> this);
33 |
34 | @Override
35 | public Client getClient() {
36 | return client;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/ResponseBuilder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | interface ResponseBuilder {
29 | RawResponse toRawResponse(Config config, HttpRequest request);
30 | }
31 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/SocketSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.net.http.WebSocket;
29 |
30 | /**
31 | * A socket set represents a websocket and the listener for a target.
32 | * Each side of a websocket communication would be represented by a set
33 | */
34 | public class SocketSet {
35 |
36 | private final S socket;
37 | private final L listener;
38 | private final String name;
39 |
40 | public SocketSet(S socket, L listener, String name){
41 | this.socket = socket;
42 | this.listener = listener;
43 | this.name = name;
44 | }
45 |
46 | public S getSocket() {
47 | return socket;
48 | }
49 |
50 | public L getListener() {
51 | return listener;
52 | }
53 |
54 | public String getName() {
55 | return name;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return name;
61 | }
62 |
63 | public void open() {
64 | listener.onOpen(socket);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/main/java/kong/unirest/core/UnirestAssertion.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * Thrown to indicate that an assertion has failed.
30 | */
31 | public class UnirestAssertion extends AssertionError {
32 | public UnirestAssertion(String base, Object... args){
33 | super(String.format(base, args));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/AsyncTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | import kong.unirest.core.HttpMethod;
29 | import kong.unirest.core.Unirest;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static org.junit.jupiter.api.Assertions.assertEquals;
33 |
34 | class AsyncTest extends Base {
35 |
36 | @Test
37 | void canExpectAsync() throws Exception {
38 | client.expect(HttpMethod.GET, path).thenReturn("Hey Ma");
39 |
40 | String body = Unirest.get(path).asStringAsync().get().getBody();
41 |
42 | assertEquals("Hey Ma", body);
43 |
44 | client.verifyAll();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/DefultResponseTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | import kong.unirest.core.*;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
32 |
33 | public class DefultResponseTest {
34 |
35 | @Test
36 | void defaultResponseWorksWithHeaders(){
37 | var i = Unirest.spawnInstance();
38 | var mock = MockClient.register(i);
39 |
40 | mock.defaultResponse().withStatus(500);
41 |
42 | var response = i.get("http://fake-url")
43 | .header("header1", "value1")
44 | .asEmpty();
45 |
46 | assertThat(response.getStatus()).isEqualTo(500);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/ErrorTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | import kong.unirest.core.HttpMethod;
29 | import kong.unirest.core.Unirest;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static kong.unirest.core.HttpStatus.INTERNAL_SERVER_ERROR;
33 | import static org.junit.jupiter.api.Assertions.assertEquals;
34 |
35 | class ErrorTest extends Base {
36 |
37 | @Test
38 | void mapError() {
39 | client.expect(HttpMethod.GET, path)
40 | .thenReturn(new ErrorObj("Boo!"))
41 | .withStatus(INTERNAL_SERVER_ERROR);
42 |
43 | ErrorObj err = Unirest.get(path).asJson().mapError(ErrorObj.class);
44 |
45 | assertEquals("Boo!", err.say);
46 | }
47 |
48 | private static class ErrorObj {
49 | public String say;
50 |
51 | public ErrorObj(String say) {
52 | this.say = say;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/MetricsTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | import kong.unirest.core.HttpMethod;
29 | import kong.unirest.core.Unirest;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static org.junit.jupiter.api.Assertions.assertTrue;
33 |
34 | class MetricsTest extends Base {
35 |
36 | boolean wasCalled = false;
37 |
38 | @Test
39 | void willExecuteMetrics() {
40 | Unirest.config().instrumentWith(
41 | r -> (re, ex) -> {
42 | wasCalled = true;
43 | }
44 | );
45 |
46 | client.expect(HttpMethod.GET, "http://foo").thenReturn();
47 |
48 | Unirest.get("http://foo").asEmpty();
49 |
50 | assertTrue(wasCalled);
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/Pojo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | public class Pojo {
29 | public String fruit;
30 |
31 | public Pojo(){}
32 |
33 | public Pojo(String fruit) {
34 | this.fruit = fruit;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/unirest-modules-mocks/src/test/java/kong/tests/ResponseHandlerTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.tests;
27 |
28 | import kong.unirest.core.ExpectedResponse;
29 | import kong.unirest.core.HttpMethod;
30 | import kong.unirest.core.HttpResponse;
31 | import kong.unirest.core.Unirest;
32 | import org.junit.jupiter.api.Test;
33 |
34 | import static org.junit.jupiter.api.Assertions.assertEquals;
35 |
36 | public class ResponseHandlerTest extends Base {
37 |
38 | @Test
39 | void canSetAFullRequestHandler() {
40 | client.expect(HttpMethod.GET, "/fruit")
41 | .thenReturn(r -> ExpectedResponse.of(200)
42 | .thenReturn("Hello Jane")
43 | .withHeader("foo", "bar"));
44 |
45 | HttpResponse string = Unirest.get("/fruit").asString();
46 | assertEquals("Hello Jane", string.getBody());
47 | assertEquals("bar", string.getHeaders().getFirst("foo"));
48 | assertEquals(200, string.getStatus());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/unirest/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.konghq
6 | unirest-java-parent
7 | 4.4.8-SNAPSHOT
8 |
9 |
10 | Simplified, lightweight HTTP client library.
11 | unirest-java-core
12 | jar
13 |
14 |
15 | ${project.parent.basedir}
16 |
17 |
18 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/BasicResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class BasicResponse extends BaseResponse {
29 | private final T body;
30 |
31 | BasicResponse(BaseResponse response, T body) {
32 | super(response);
33 | this.body = body;
34 | }
35 |
36 | public BasicResponse(RawResponse httpResponse, T body) {
37 | super(httpResponse);
38 | this.body = body;
39 | }
40 |
41 | public BasicResponse(RawResponse httpResponse) {
42 | super(httpResponse);
43 | this.body = null;
44 | }
45 |
46 | public BasicResponse(RawResponse httpResponse, String ogBody, RuntimeException ex) {
47 | this(httpResponse, null);
48 | setParsingException(ogBody, ex);
49 | }
50 |
51 | @Override
52 | public T getBody() {
53 | return body;
54 | }
55 |
56 | @Override
57 | protected String getRawBody() {
58 | return null;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Body.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 |
29 | import java.nio.charset.Charset;
30 | import java.nio.charset.StandardCharsets;
31 | import java.util.Collection;
32 | import java.util.Collections;
33 |
34 | public interface Body {
35 | boolean isMultiPart();
36 |
37 | boolean isEntityBody();
38 |
39 | default Charset getCharset(){
40 | return StandardCharsets.UTF_8;
41 | }
42 |
43 | default Collection multiParts(){
44 | return Collections.emptyList();
45 | }
46 |
47 | default BodyPart uniPart(){
48 | return null;
49 | }
50 |
51 | default MultipartMode getMode(){
52 | return MultipartMode.BROWSER_COMPATIBLE;
53 | }
54 |
55 | default ProgressMonitor getMonitor(){
56 | return null;
57 | }
58 |
59 | default String getBoundary() {
60 | return null;
61 | }
62 |
63 | default BodyPart getField(String name){
64 | return multiParts()
65 | .stream()
66 | .filter(part -> part.getName().equals(name))
67 | .findFirst()
68 | .orElse(null);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/ByteArrayPart.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 |
29 | public class ByteArrayPart extends BodyPart {
30 | private final String fileName;
31 |
32 | ByteArrayPart(String name, byte[] bytes, ContentType contentType, String fileName) {
33 | super(bytes, name, contentType.toString());
34 | this.fileName = fileName;
35 | }
36 |
37 | @Override
38 | public String getFileName() {
39 | return fileName;
40 | }
41 |
42 | @Override
43 | public boolean isFile() {
44 | return true;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return String.format("%s=%s", getName(), fileName);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Callback.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public interface Callback {
29 | void completed(HttpResponse response);
30 |
31 | default void failed(UnirestException e){}
32 |
33 | default void cancelled(){}
34 | }
35 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/CallbackFuture.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.concurrent.CompletableFuture;
29 |
30 | class CallbackFuture {
31 |
32 | static CompletableFuture> wrap(Callback source){
33 | return new CompletableFuture>(){
34 | @Override
35 | public boolean complete(HttpResponse value) {
36 | source.completed(value);
37 | return super.complete(value);
38 | }
39 | @Override
40 | public boolean completeExceptionally(Throwable ex) {
41 | source.failed(new UnirestException(ex));
42 | return super.completeExceptionally(ex);
43 | }
44 | @Override
45 | public boolean cancel(boolean mayInterruptIfRunning) {
46 | source.cancelled();
47 | return super.cancel(mayInterruptIfRunning);
48 | }
49 | };
50 | }
51 | }
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/CookieSpecs.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 |
29 | /**
30 | * Standard cookie specifications supported by Unirest.
31 | */
32 | public final class CookieSpecs {
33 |
34 | /**
35 | * The default policy. This policy provides a higher degree of compatibility
36 | * with common cookie management of popular HTTP agents for non-standard
37 | * (Netscape style) cookies.
38 | */
39 | public static final String DEFAULT = "default";
40 |
41 | /**
42 | * The Netscape cookie draft compliant policy.
43 | */
44 | public static final String NETSCAPE = "netscape";
45 |
46 | /**
47 | * The RFC 6265 compliant policy (interoprability profile).
48 | */
49 | public static final String STANDARD = "standard";
50 |
51 | /**
52 | * The RFC 6265 compliant policy (strict profile)
53 | */
54 | public static final String STANDARD_STRICT = "standard-strict";
55 |
56 | /**
57 | * The policy that ignores cookies.
58 | */
59 | public static final String IGNORE_COOKIES = "ignoreCookies";
60 | }
61 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Cookies.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | /**
32 | * Represents a collection of cookies with some helper methods for parsing and getting cookie
33 | */
34 | public class Cookies extends ArrayList {
35 |
36 | public Cookies(){
37 |
38 | }
39 |
40 | Cookies(List strings) {
41 | strings.stream()
42 | .map(Cookie::new)
43 | .forEach(this::add);
44 | }
45 |
46 | /**
47 | * Get cookie by name
48 | * @param name the name of the cookie you want
49 | * @return the cookie with that name
50 | */
51 | public Cookie getNamed(String name) {
52 | return stream().
53 | filter(c -> c.getName().equalsIgnoreCase(name))
54 | .findFirst()
55 | .orElse(null);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/DefaultInterceptor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.function.Consumer;
29 |
30 | class DefaultInterceptor implements Interceptor {
31 |
32 | private Consumer> consumer;
33 |
34 | @Override
35 | public void onResponse(HttpResponse> response, HttpRequestSummary request, Config config) {
36 | if(consumer != null && !response.isSuccess()){
37 | consumer.accept(response);
38 | }
39 | }
40 |
41 | @Override
42 | public HttpResponse> onFail(Exception e, HttpRequestSummary request, Config config) {
43 | throw new UnirestException(e);
44 | }
45 |
46 | Consumer> getConsumer(){
47 | return consumer;
48 | }
49 |
50 | void setConsumer(Consumer> consumer) {
51 | this.consumer = consumer;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Empty.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class Empty {
29 | private Empty(){}
30 | }
31 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/FilePart.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.io.File;
29 |
30 | public class FilePart extends BodyPart {
31 | private String fileName;
32 |
33 | public FilePart(File file, String name) {
34 | this(file, name, null);
35 | }
36 |
37 | public FilePart(File file, String name, String contentType) {
38 | super(file, name, contentType);
39 | this.fileName = file.getName();
40 | }
41 |
42 | @Override
43 | public boolean isFile() {
44 | return true;
45 | }
46 |
47 | @Override
48 | public String getFileName(){
49 | return this.fileName;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return String.format("%s=%s", getName(), fileName);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/GetRequest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public interface GetRequest extends HttpRequest {
29 | }
30 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Header.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public interface Header {
29 | String getName();
30 | String getValue();
31 | }
32 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/HttpRequestNoBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Optional;
29 |
30 | class HttpRequestNoBody extends BaseRequest implements GetRequest {
31 | HttpRequestNoBody(Config config, HttpMethod method, String url) {
32 | super(config, method, url);
33 | }
34 |
35 | HttpRequestNoBody(HttpRequestNoBody baseRequest) {
36 | super(baseRequest);
37 | }
38 |
39 | @Override
40 | public Optional getBody() {
41 | return Optional.empty();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/HttpRequestSummary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Collection;
29 |
30 | /**
31 | * A summary of a request about to be performed
32 | */
33 | public interface HttpRequestSummary {
34 | /**
35 | * @return The HTTP method of the request
36 | */
37 | HttpMethod getHttpMethod();
38 |
39 | /**
40 | * @return The current full URL string for the request with query params (http://somewhere/else?colour=red)
41 | */
42 | String getUrl();
43 |
44 | /**
45 | * @return The raw un-parameterized path without query strings (http://somewhere/{param})
46 | */
47 | String getRawPath();
48 |
49 | /**
50 | * @return a string summary of the request suitable for logging
51 | */
52 | String asString();
53 |
54 |
55 | /**
56 | * @return an immutable collection of the headers for the request
57 | */
58 | Collection getHeaders();
59 | }
60 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/HttpResponseSummary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * A Summary of rhe response
30 | */
31 | public interface HttpResponseSummary {
32 | /**
33 | * @return the http response code
34 | */
35 | int getStatus();
36 |
37 | /**
38 | * @return the text of the http response code
39 | */
40 | String getStatusText();
41 | }
42 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/InputStreamBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.io.InputStream;
29 |
30 | class InputStreamBody extends BodyPart {
31 | public InputStreamBody(InputStream body) {
32 | super(body, null, null);
33 | }
34 |
35 | @Override
36 | public boolean isFile() {
37 | return false;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/InputStreamPart.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.io.InputStream;
29 |
30 | public class InputStreamPart extends BodyPart {
31 | private String fileName;
32 |
33 | InputStreamPart(String name, InputStream value, String contentType) {
34 | super(value, name, contentType);
35 | }
36 |
37 | InputStreamPart(String name, InputStream value, String contentType, String fileName) {
38 | super(value, name, contentType);
39 | this.fileName = fileName;
40 | }
41 |
42 | @Override
43 | public String getFileName() {
44 | return fileName;
45 | }
46 |
47 | @Override
48 | public boolean isFile() {
49 | return true;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return String.format("%s=%s", getName(), fileName);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/JsonPatchOperation.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public enum JsonPatchOperation {
29 | add("value"),
30 | remove("value"),
31 | replace("value"),
32 | test("value"),
33 | move("from"),
34 | copy("from");
35 |
36 | private final String operationtype;
37 |
38 | JsonPatchOperation(String operationtype) {
39 | this.operationtype = operationtype;
40 | }
41 |
42 | public String getOperationtype() {
43 | return operationtype;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/JsonPatchRequest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public interface JsonPatchRequest extends HttpRequest, Body {
29 | String CONTENT_TYPE = "application/json-patch+json";
30 |
31 | JsonPatchRequest add(String path, Object value);
32 |
33 | JsonPatchRequest remove(String path);
34 |
35 | JsonPatchRequest replace(String path, Object value);
36 |
37 | JsonPatchRequest test(String path, Object value);
38 |
39 | JsonPatchRequest move(String from, String path);
40 |
41 | JsonPatchRequest copy(String from, String path);
42 | }
43 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/JsonResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Objects;
29 |
30 | public class JsonResponse extends BaseResponse {
31 | private JsonNode node;
32 |
33 | protected JsonResponse(RawResponse response) {
34 | super(response);
35 | node = getNode(response);
36 | }
37 |
38 | private JsonNode getNode(RawResponse response) {
39 | if (Objects.isNull(response) || !response.hasContent()) {
40 | return new JsonNode(null);
41 | } else {
42 | String json = response.getContentAsString();
43 | return toJsonNode(json);
44 | }
45 | }
46 |
47 | private JsonNode toJsonNode(String json) {
48 | try {
49 | return new JsonNode(json);
50 | } catch (RuntimeException e) {
51 | super.setParsingException(json, e);
52 | return null;
53 | }
54 | }
55 |
56 | @Override
57 | public JsonNode getBody() {
58 | return node;
59 | }
60 |
61 | @Override
62 | protected String getRawBody() {
63 | return node.toString();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/MetricContext.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * A metric context for the current request
30 | */
31 | @FunctionalInterface
32 | public interface MetricContext {
33 | /**
34 | * Finishes a Http Request. Called just after the main request but before any mapping
35 | * function including before any streaming responses (like file downloads) are complete.
36 | * @param httpResponse a summary of the just executed response or null in the case of a system exception.
37 | * @param ex an exception if one happened or null .
38 | * Note that this is not just a 500 from the remote,
39 | * but more likely a socket or connection timeout.
40 | */
41 | void complete(HttpResponseSummary httpResponse, Exception ex);
42 | }
43 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/MultipartMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public enum MultipartMode {
29 | /** RFC 822, RFC 2045, RFC 2046 compliant */
30 | STRICT,
31 | /** browser-compatible mode, i.e. only write Content-Disposition; use content charset */
32 | BROWSER_COMPATIBLE,
33 | /** RFC 6532 compliant */
34 | RFC6532
35 | }
36 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/NoopMetric.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | class NoopMetric implements UniMetric {
29 | @Override
30 | public MetricContext begin(HttpRequestSummary request) {
31 | return (r,e) -> {};
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/ParamPart.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.io.UnsupportedEncodingException;
29 | import java.net.URLEncoder;
30 |
31 | public class ParamPart extends BodyPart {
32 | ParamPart(String name, String value) {
33 | this(name, value, null);
34 | }
35 |
36 | ParamPart(String name, String value, String contentType) {
37 | super(value, name, contentType);
38 | }
39 |
40 | @Override
41 | public boolean isFile() {
42 | return false;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | try {
48 | return String.format("%s=%s", getName(), URLEncoder.encode(getValue(), "UTF-8"));
49 | } catch (UnsupportedEncodingException e) {
50 | throw new UnirestException(e);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/Proxy.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class Proxy {
29 | private final String host;
30 | private final Integer port;
31 | private final String username;
32 | private final String password;
33 |
34 | public Proxy(String host, Integer port){
35 | this(host, port, null, null);
36 | }
37 |
38 | public Proxy(String host, Integer port, String username, String password) {
39 | this.host = host;
40 | this.port = port;
41 | this.username = username;
42 | this.password = password;
43 | }
44 |
45 | public String getHost() {
46 | return host;
47 | }
48 |
49 | public Integer getPort() {
50 | return port;
51 | }
52 |
53 | public String getUsername() {
54 | return username;
55 | }
56 |
57 | public String getPassword() {
58 | return password;
59 | }
60 |
61 | public boolean isAuthenticated() {
62 | return username != null && password != null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/RequestFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | class RequestFactory {
29 | public static R copy(HttpRequest baseRequest) {
30 | if(baseRequest instanceof HttpRequestNoBody){
31 | return (R) new HttpRequestNoBody((HttpRequestNoBody)baseRequest);
32 | }
33 | if(baseRequest instanceof HttpRequestBody){
34 | return (R) new HttpRequestBody((HttpRequestBody)baseRequest);
35 | }
36 | if(baseRequest instanceof HttpRequestUniBody){
37 | return (R) new HttpRequestUniBody((HttpRequestUniBody)baseRequest);
38 | }
39 | if(baseRequest instanceof HttpRequestMultiPart) {
40 | return (R) new HttpRequestMultiPart((HttpRequestMultiPart)baseRequest);
41 | }
42 | if(baseRequest instanceof HttpRequestJsonPatch) {
43 | return (R)new HttpRequestJsonPatch((HttpRequestJsonPatch)baseRequest);
44 | }
45 |
46 | throw new UnirestException("Cannot find matching type: " + baseRequest.getClass());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/RequestSummary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Collection;
29 | import java.util.List;
30 |
31 | class RequestSummary implements HttpRequestSummary {
32 | private static final SummaryFormatter FORMATTER = new SummaryFormatter();
33 | private final BaseRequest request;
34 |
35 |
36 | RequestSummary(BaseRequest request) {
37 | this.request = request;
38 | }
39 |
40 | @Override
41 | public HttpMethod getHttpMethod() {
42 | return request.getHttpMethod();
43 | }
44 |
45 | @Override
46 | public String getUrl() {
47 | return request.getUrl();
48 | }
49 |
50 | @Override
51 | public String getRawPath() {
52 | return request.getPath().rawPath();
53 | }
54 |
55 | @Override
56 | public String asString() {
57 | return FORMATTER.apply(request);
58 | }
59 |
60 | @Override
61 | public Collection getHeaders() {
62 | return List.copyOf(request.getHeaders().all());
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/ResponseSummary.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | class ResponseSummary implements HttpResponseSummary {
29 | private final int status;
30 | private final String statusText;
31 |
32 | ResponseSummary(RawResponse response) {
33 | this.status = response.getStatus();
34 | this.statusText = response.getStatusText();
35 | }
36 |
37 | @Override
38 | public int getStatus() {
39 | return status;
40 | }
41 |
42 | @Override
43 | public String getStatusText() {
44 | return statusText;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/StringResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class StringResponse extends BaseResponse {
29 | private String body;
30 |
31 | public StringResponse(RawResponse response, String encoding) {
32 | super(response);
33 | body = response.getContentAsString(encoding);
34 | }
35 |
36 | @Override
37 | public String getBody() {
38 | return body;
39 | }
40 |
41 | @Override
42 | protected String getRawBody() {
43 | return body;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/TestBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Arrays;
29 | import java.util.Collection;
30 | import java.util.List;
31 |
32 | public class TestBody implements Body {
33 |
34 | private final List parts;
35 |
36 | public TestBody(BodyPart... parts){
37 | this.parts = Arrays.asList(parts);
38 | }
39 |
40 | @Override
41 | public Collection multiParts() {
42 | return parts;
43 | }
44 |
45 | @Override
46 | public boolean isMultiPart() {
47 | return true;
48 | }
49 |
50 | @Override
51 | public boolean isEntityBody() {
52 | return false;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UniByteArrayBody.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | class UniByteArrayBody extends BodyPart {
29 | UniByteArrayBody(byte[] bodyBytes) {
30 | super(bodyBytes, null, null);
31 | }
32 |
33 | @Override
34 | public boolean isFile() {
35 | return false;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return String.format("[binary data length=%s]", getValue().length);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UniMetric.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * A UniMetric is a factory for producing a MetricContext this will be called just before
30 | * any Http Request
31 | */
32 | public interface UniMetric {
33 | /**
34 | * Factory method for a MetricContext
35 | * @param request A summary of the current Http Request about to be performed
36 | * @return a MetricContext for this request
37 | */
38 | MetricContext begin(HttpRequestSummary request);
39 | }
40 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UnibodyString.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | class UnibodyString extends BodyPart {
29 | UnibodyString(String bodyAsString) {
30 | super(bodyAsString, null, null);
31 | }
32 |
33 | @Override
34 | public boolean isFile() {
35 | return false;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return getValue();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UnirestConfigException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class UnirestConfigException extends UnirestException {
29 | public UnirestConfigException(Exception e){
30 | super(e);
31 | }
32 |
33 | public UnirestConfigException(String msg) {
34 | super(msg);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UnirestException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.util.Collection;
29 | import java.util.stream.Collectors;
30 |
31 | public class UnirestException extends RuntimeException {
32 |
33 | private static final long serialVersionUID = -3714840499934575734L;
34 |
35 | public UnirestException(Exception e) {
36 | super(e);
37 | }
38 |
39 | public UnirestException(String msg) {
40 | super(msg);
41 | }
42 |
43 | public UnirestException(Throwable ex) {
44 | super(ex);
45 | }
46 |
47 | public UnirestException(String message, Throwable e) {
48 | super(message, e);
49 | }
50 |
51 | public UnirestException(Collection ex) {
52 | super(ex.stream().map(e -> e.getClass().getName() + " " + e.getMessage()).collect(Collectors.joining("\n")));
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UnirestParsingException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class UnirestParsingException extends UnirestException {
29 | private final String originalBody;
30 |
31 | public UnirestParsingException(String originalBody, Exception e) {
32 | super(e);
33 | this.originalBody = originalBody;
34 | }
35 |
36 | public String getOriginalBody() {
37 | return originalBody;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/UnrecoverableException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | /**
29 | * An exception which prevents Unirest from attempting to recover the body from a failed response / parsing error
30 | */
31 | public class UnrecoverableException extends UnirestException {
32 | public UnrecoverableException(Exception e) {
33 | super(e);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/WebSocketResponse.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import java.net.http.WebSocket;
29 | import java.util.concurrent.CompletableFuture;
30 |
31 | /**
32 | * Just a silly little class that holds on to the socket and listener
33 | */
34 | public class WebSocketResponse {
35 | private final CompletableFuture webSocketFuture;
36 | private final WebSocket.Listener listener;
37 |
38 | /**
39 | * ctor
40 | * @param webSocketFuture the ws future
41 | * @param listener the listener
42 | */
43 | public WebSocketResponse(CompletableFuture webSocketFuture, WebSocket.Listener listener) {
44 | this.webSocketFuture = webSocketFuture;
45 | this.listener = listener;
46 | }
47 |
48 | /**
49 | * @return the ws future
50 | */
51 | public CompletableFuture socket(){
52 | return webSocketFuture;
53 | }
54 |
55 | /**
56 | * @return the listener
57 | */
58 | public WebSocket.Listener listener(){
59 | return listener;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/java/BoundaryAppender.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.java;
27 |
28 | /** Strategy for appending the boundary across parts. */
29 | enum BoundaryAppender {
30 | FIRST("--", "\r\n"),
31 | MIDDLE("\r\n--", "\r\n"),
32 | LAST("\r\n--", "--\r\n");
33 |
34 | private final String prefix;
35 | private final String suffix;
36 |
37 | BoundaryAppender(String prefix, String suffix) {
38 | this.prefix = prefix;
39 | this.suffix = suffix;
40 | }
41 |
42 | void append(StringBuilder target, String boundary) {
43 | target.append(prefix).append(boundary).append(suffix);
44 | }
45 |
46 | static BoundaryAppender get(int partIndex, int partsSize) {
47 | return partIndex <= 0 ? FIRST : (partIndex >= partsSize ? LAST : MIDDLE);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/java/PartPublisher.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.java;
27 |
28 | import static java.util.Objects.requireNonNull;
29 |
30 | import java.net.http.HttpRequest.BodyPublisher;
31 | import java.nio.ByteBuffer;
32 | import java.util.concurrent.Flow;
33 |
34 | class PartPublisher implements BodyPublisher {
35 |
36 | private final String mediaType;
37 | private final BodyPublisher upstream;
38 |
39 | public PartPublisher(BodyPublisher upstream, String mediaType) {
40 | this.upstream = upstream;
41 | this.mediaType = requireNonNull(mediaType);
42 | }
43 |
44 | public String mediaType() {
45 | return mediaType;
46 | }
47 |
48 | @Override
49 | public long contentLength() {
50 | return upstream.contentLength();
51 | }
52 |
53 | @Override
54 | public void subscribe(Flow.Subscriber super ByteBuffer> subscriber) {
55 | requireNonNull(subscriber);
56 | upstream.subscribe(subscriber);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/java/WTF.md:
--------------------------------------------------------------------------------
1 | ## Try and describe what is happening here:
2 |
3 |
4 | Class Structure:
5 | MultipartBoundaryPublisher.Builder -> gathers all the parts and builds a:
6 |
7 | MultipartBoundaryPublisher
8 | * Is the BodyPublisher (java) sent to the Http Client
9 | * A BodyPublisher creates a stream of bytebuffers that can be subscribed to by subscribe(Subscriber super T> subscriber);
10 |
11 |
12 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/json/Foo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.json;
27 |
28 |
29 |
30 | import java.util.Objects;
31 |
32 | public class Foo {
33 | public String bar;
34 |
35 | public Foo(){ }
36 |
37 | public Foo(String bar) {
38 | this.bar = bar;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "Foo{" +
44 | "bar='" + bar + '\'' +
45 | '}';
46 | }
47 |
48 | @Override
49 | public boolean equals(Object o) {
50 | if (this == o) {return true;}
51 | if (o == null || getClass() != o.getClass()) {return false;}
52 | Foo foo = (Foo) o;
53 | return Objects.equals(bar, foo.bar);
54 | }
55 |
56 | @Override
57 | public int hashCode() {
58 | return Objects.hash(bar);
59 | }
60 | }
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/json/JSONException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.json;
27 |
28 | public class JSONException extends RuntimeException {
29 | public JSONException(String message) {
30 | super(message);
31 | }
32 |
33 | public JSONException(String message, Object... tokens) {
34 | super(String.format(message, tokens));
35 | }
36 |
37 | public JSONException(Exception e) {
38 | super(e);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/json/JSONPointerException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.json;
27 |
28 | public class JSONPointerException extends JSONException {
29 | public JSONPointerException(String message, Object... tokens) {
30 | super(message, tokens);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/unirest/src/main/java/kong/unirest/core/json/NullObject.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core.json;
27 |
28 | class NullObject extends JSONObject {
29 | @Override
30 | public boolean equals(Object other) {
31 | return null == other;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return null;
37 | }
38 |
39 | @Override
40 | public String toString(int i) throws JSONException {
41 | return toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/BodyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.Body;
29 | import kong.unirest.core.BodyPart;
30 | import kong.unirest.core.ParamPart;
31 | import kong.unirest.core.TestBody;
32 | import org.junit.jupiter.api.Test;
33 |
34 | import static org.junit.jupiter.api.Assertions.*;
35 |
36 | class BodyTest {
37 |
38 | @Test
39 | void canGetPartsByName() {
40 | Body b = new TestBody(
41 | new ParamPart("band", "Talking Heads"),
42 | new ParamPart("computer", "ENIAC"),
43 | new ParamPart("Movie", "Tron")
44 | );
45 |
46 | BodyPart part = b.getField("Movie");
47 | assertEquals("Tron", part.getValue());
48 | }
49 |
50 | @Test
51 | void noMatchReturnsNull() {
52 | Body b = new TestBody(
53 | new ParamPart("band", "Talking Heads"),
54 | new ParamPart("computer", "ENIAC")
55 | );
56 |
57 | assertNull(b.getField("Movie"));
58 | }
59 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/ByteArrayPartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.ByteArrayPart;
29 | import kong.unirest.core.ContentType;
30 | import org.junit.jupiter.api.Test;
31 |
32 | import static org.junit.jupiter.api.Assertions.*;
33 |
34 | class ByteArrayPartTest {
35 | ByteArrayPart part = new ByteArrayPart(
36 | "uploadfile",
37 | "hey".getBytes(), ContentType.APPLICATION_ATOM_XML,
38 | "foo.xml");
39 |
40 | @Test
41 | void byteArraysAreFiles() {
42 | assertTrue(part.isFile());
43 | }
44 |
45 | @Test
46 | void byteArraysToString() {
47 | assertEquals("uploadfile=foo.xml", part.toString());
48 | }
49 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/ClientFactoryTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.Unirest;
29 | import org.junit.jupiter.api.AfterEach;
30 | import org.junit.jupiter.api.BeforeEach;
31 | import org.junit.jupiter.api.Test;
32 |
33 | import java.lang.management.ManagementFactory;
34 |
35 | import static org.junit.jupiter.api.Assertions.*;
36 |
37 | class ClientFactoryTest {
38 |
39 | @BeforeEach
40 | @AfterEach
41 | public void before(){
42 | Unirest.shutDown(true);
43 | }
44 |
45 | @Test
46 | void shouldReuseThreadPool() {
47 | int startingCount = ManagementFactory.getThreadMXBean().getThreadCount();
48 | //IntStream.range(0,100).forEach(i -> ClientFactory.refresh());
49 | assertTrue(ManagementFactory.getThreadMXBean().getThreadCount() < startingCount + 10);
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/ContentTypeTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import org.junit.jupiter.api.Test;
29 |
30 | import static org.junit.jupiter.api.Assertions.assertFalse;
31 | import static org.junit.jupiter.api.Assertions.assertTrue;
32 |
33 | class ContentTypeTest {
34 | @Test
35 | void checkForBinaryTypes() {
36 | assertTrue(ContentType.BINARY_OCTET_STREAM.isBinary());
37 | assertTrue(ContentType.APPLICATION_OCTET_STREAM.isBinary());
38 | assertFalse(ContentType.APPLICATION_JSON.isBinary());
39 | }
40 |
41 | @Test
42 | void checkForBinaryTypesByString() {
43 | assertTrue(ContentType.isBinary(ContentType.APPLICATION_OCTET_STREAM.getMimeType()));
44 | assertTrue(ContentType.isBinary(ContentType.APPLICATION_OCTET_STREAM.getMimeType().toUpperCase()));
45 | assertFalse(ContentType.isBinary(ContentType.APPLICATION_JSON.getMimeType()));
46 | assertFalse(ContentType.isBinary(null));
47 | }
48 |
49 | @Test
50 | void anyOldBinary() {
51 | assertTrue(ContentType.isBinary("binary/thing"));
52 | assertFalse(ContentType.isBinary("application/thing"));
53 | }
54 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/FilePartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.FilePart;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import java.io.File;
32 |
33 | import static org.junit.jupiter.api.Assertions.*;
34 |
35 | class FilePartTest {
36 |
37 | private final FilePart part = new FilePart(new File("./foo.xml"), "uploadFile", "application/xml");
38 |
39 | @Test
40 | void filePartsAreFiles() {
41 | assertTrue(part.isFile());
42 | }
43 |
44 | @Test
45 | void filePartToString() {
46 | assertEquals("uploadFile=foo.xml", part.toString());
47 | }
48 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/HttpMethodTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.HttpMethod;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.junit.jupiter.api.Assertions.*;
32 |
33 | class HttpMethodTest {
34 |
35 | @Test
36 | void equalsTest() {
37 | assertEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("GET"));
38 | assertEquals(HttpMethod.GET, HttpMethod.GET);
39 | assertNotEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("PUT"));
40 | assertNotEquals(HttpMethod.GET, HttpMethod.PUT);
41 | }
42 |
43 |
44 | @Test
45 | void notCaseSensitive() {
46 | assertEquals(HttpMethod.valueOf("GET"), HttpMethod.valueOf("get"));
47 | }
48 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/InputStreamPartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.InputStreamPart;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import java.io.ByteArrayInputStream;
32 |
33 | import static org.junit.jupiter.api.Assertions.assertEquals;
34 | import static org.junit.jupiter.api.Assertions.assertTrue;
35 |
36 | class InputStreamPartTest {
37 | private final InputStreamPart part = new InputStreamPart("uploadFile",
38 | new ByteArrayInputStream(new byte[]{}),
39 | "application/xml",
40 | "foo.xml");
41 |
42 | @Test
43 | void inputStreamsAreFiles() {
44 | assertTrue(part.isFile());
45 | }
46 |
47 | @Test
48 | void inputStreamPartToString() {
49 | assertEquals("uploadFile=foo.xml", part.toString());
50 | }
51 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/NotImplemented.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | public class NotImplemented extends RuntimeException {
29 | }
30 |
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/ParamPartTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.ParamPart;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.junit.jupiter.api.Assertions.*;
32 |
33 | class ParamPartTest {
34 | ParamPart part = new ParamPart("band", "Talking Heads");
35 |
36 | @Test
37 | void paramsAreNotFiles() {
38 | assertFalse(part.isFile());
39 | }
40 |
41 | @Test
42 | void paramPartToString() {
43 | assertEquals("band=Talking+Heads", part.toString());
44 | }
45 |
46 | @Test
47 | void valueIsTheValue() {
48 | assertEquals("Talking Heads", part.getValue());
49 | }
50 |
51 | @Test
52 | void contentTypeIsUrlParam() {
53 | assertEquals("application/x-www-form-urlencoded; charset=UTF-8", part.getContentType());
54 | }
55 |
56 | @Test
57 | void isAString() {
58 | assertEquals(String.class, part.getPartType());
59 | }
60 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/UniByteArrayBodyTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.UniByteArrayBody;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.junit.jupiter.api.Assertions.*;
32 |
33 | class UniByteArrayBodyTest {
34 | UniByteArrayBody bytes = new UniByteArrayBody(new byte[]{});
35 |
36 | @Test
37 | void isNotAFile() {
38 | assertFalse(bytes.isFile());
39 | }
40 |
41 | @Test
42 | void toStringJustSaysItsBinary() {
43 | assertEquals("[binary data length=0]", bytes.toString());
44 | }
45 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/UnibodyStringTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import kong.unirest.core.UnibodyString;
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.junit.jupiter.api.Assertions.assertEquals;
32 | import static org.junit.jupiter.api.Assertions.assertFalse;
33 |
34 | class UnibodyStringTest {
35 |
36 | UnibodyString body = new UnibodyString("Hi Mom");
37 |
38 | @Test
39 | void uniBodyIsNotAFile() {
40 | assertFalse(body.isFile());
41 | }
42 |
43 | @Test
44 | void uniBodyToString() {
45 | assertEquals("Hi Mom", body.toString());
46 | }
47 |
48 | @Test
49 | void valueIsClear() {
50 | assertEquals("Hi Mom", body.getValue());
51 | }
52 |
53 | @Test
54 | void isAString() {
55 | assertEquals(String.class, body.getPartType());
56 | }
57 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/UnirestInstanceTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 | import org.junit.jupiter.api.Test;
29 |
30 | import static org.mockito.Mockito.mock;
31 | import static org.mockito.Mockito.verify;
32 |
33 | class UnirestInstanceTest {
34 |
35 | @Test
36 | void canBeUsedWithTryWithResource() {
37 | var mock = mock(UnirestInstance.class);
38 |
39 | try(UnirestInstance instance = mock){ }
40 |
41 | verify(mock).close();
42 |
43 | Unirest.shutDown();
44 | }
45 | }
--------------------------------------------------------------------------------
/unirest/src/test/java/kong/unirest/core/UriFormatterTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The MIT License
3 | *
4 | * Copyright for portions of unirest-java are held by Kong Inc (c) 2013.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining
7 | * a copy of this software and associated documentation files (the
8 | * "Software"), to deal in the Software without restriction, including
9 | * without limitation the rights to use, copy, modify, merge, publish,
10 | * distribute, sublicense, and/or sell copies of the Software, and to
11 | * permit persons to whom the Software is furnished to do so, subject to
12 | * the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be
15 | * included in all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package kong.unirest.core;
27 |
28 |
29 | import kong.unirest.core.BaseRequest;
30 | import kong.unirest.core.Config;
31 | import kong.unirest.core.HttpMethod;
32 | import org.junit.jupiter.api.Test;
33 |
34 | import static org.junit.jupiter.api.Assertions.assertEquals;
35 |
36 | public class UriFormatterTest {
37 |
38 | @Test
39 | public void testMangler_encoding() {
40 | assertLinkSurvives("http://localhost/test%2Fthis");
41 | }
42 |
43 | @Test
44 | public void testMangler_fragment() {
45 | assertLinkSurvives("http://localhost/test?a=b#fragment");
46 | }
47 |
48 | @Test
49 | public void basicBoringUri() {
50 | assertLinkSurvives("http://localhost/test?a=b");
51 | }
52 |
53 | @Test
54 | public void semicolonsAsParam() {
55 | assertLinkSurvives("http://localhost/test?a=b;foo=bar");
56 | }
57 |
58 | @Test
59 | public void utf8Chars(){
60 | assertLinkSurvives("http://localhost/test?foo=こんにちは");
61 | }
62 |
63 | private void assertLinkSurvives(String s) {
64 | assertEquals(s, new BaseRequest(new Config(), HttpMethod.GET, s){}.url.toString());
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/unirest/src/test/resources/JSON_POINTER_REF.json:
--------------------------------------------------------------------------------
1 | {
2 | "foo": ["bar", "baz"],
3 | "": 0,
4 | "a/b": 1,
5 | "c%d": 2,
6 | "e^f": 3,
7 | "g|h": 4,
8 | "i\\j": 5,
9 | "k\"l": 6,
10 | " ": 7,
11 | "m~n": 8,
12 | "cucu": [
13 | {
14 | "banana": {
15 | "pants" : true
16 | }
17 | }
18 | ]
19 | }
--------------------------------------------------------------------------------
/unirest/src/test/resources/test-json-patch.json:
--------------------------------------------------------------------------------
1 | [
2 | {"op":"add","path":"/fruits/-","value":"Apple"},
3 | {"op":"remove","path":"/bugs"},
4 | {"op":"replace","path":"/lastname","value":"Flintstone"},
5 | {"op":"test","path":"/firstname","value":"Fred"},
6 | {"op":"move","path":"/new/location","from":"/old/location"},
7 | {"op":"copy","path":"/new/location","from":"/original/location"}
8 | ]
--------------------------------------------------------------------------------