├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── library.gradle ├── bintray.gradle └── library-publish.gradle ├── http-requests-documentation ├── src │ ├── docs │ │ ├── images │ │ │ ├── logo.png │ │ │ ├── filters.png │ │ │ └── filter-lifecycle.png │ │ ├── components │ │ │ ├── httpentity.adoc │ │ │ ├── entityconvertermanager.adoc │ │ │ ├── httpclientfactory.adoc │ │ │ └── httpresponse.adoc │ │ ├── components.adoc │ │ ├── index.adoc │ │ ├── spring.adoc │ │ ├── introduction.adoc │ │ └── converters.adoc │ └── images │ │ ├── filters.graffle │ │ └── logo.svg └── build.gradle ├── http-requests-functional-test ├── src │ └── main │ │ ├── resources │ │ ├── keystore.jks │ │ ├── log4j.properties │ │ └── logback.xml │ │ └── groovy │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ ├── AbstractHttpsIntegrationSpec.groovy │ │ ├── HttpsIntegrationTestSuiteSpec.groovy │ │ └── AbstractIntegrationSpec.groovy └── build.gradle ├── http-requests-spring ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ └── spring │ │ ├── HttpRequestsAutoConfiguration.java │ │ ├── GroovyExtensionConfiguration.java │ │ ├── EntityConverterConfiguration.java │ │ └── JacksonEntityConverterConfiguration.java ├── gradle.properties └── build.gradle ├── README.md ├── .gitignore ├── http-requests-mock ├── gradle.properties ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── budjb │ └── httprequests │ └── test │ ├── UnmatchedRequestMockException.java │ └── MockHttpClient.java ├── http-requests-bom ├── gradle.properties └── build.gradle ├── http-requests-jackson ├── gradle.properties ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── budjb │ └── httprequests │ └── filter │ └── jackson │ ├── JacksonMapReader.java │ ├── JacksonListReader.java │ ├── JacksonMapWriter.java │ └── JacksonListWriter.java ├── http-requests-core ├── gradle.properties ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── budjb │ │ │ └── httprequests │ │ │ ├── converter │ │ │ ├── EntityConverter.java │ │ │ ├── EntityReader.java │ │ │ ├── EntityWriter.java │ │ │ └── bundled │ │ │ │ ├── ByteArrayEntityReader.java │ │ │ │ ├── ByteArrayEntityWriter.java │ │ │ │ ├── StringEntityReader.java │ │ │ │ └── StringEntityWriter.java │ │ │ ├── filter │ │ │ ├── HttpClientFilter.java │ │ │ ├── bundled │ │ │ │ ├── ConsoleLoggingFilter.java │ │ │ │ ├── HttpStatusExceptionFilter.java │ │ │ │ ├── DeflateFilter.java │ │ │ │ ├── GZIPFilter.java │ │ │ │ └── BasicAuthFilter.java │ │ │ ├── RequestFilter.java │ │ │ ├── OutputStreamFilter.java │ │ │ ├── ResponseFilter.java │ │ │ ├── RetryFilter.java │ │ │ └── LifecycleFilter.java │ │ │ ├── exception │ │ │ ├── EmptyEntityException.java │ │ │ ├── EntityException.java │ │ │ ├── NullEntityException.java │ │ │ ├── HttpFoundException.java │ │ │ ├── HttpGoneException.java │ │ │ ├── HttpConflictException.java │ │ │ ├── HttpNotFoundException.java │ │ │ ├── HttpSeeOtherException.java │ │ │ ├── HttpUseProxyException.java │ │ │ ├── HttpBadGatewayException.java │ │ │ ├── HttpBadRequestException.java │ │ │ ├── HttpForbiddenException.java │ │ │ ├── HttpNotModifiedException.java │ │ │ ├── HttpNotAcceptableException.java │ │ │ ├── HttpUnauthorizedException.java │ │ │ ├── HttpGatewayTimeoutException.java │ │ │ ├── HttpLengthRequiredException.java │ │ │ ├── HttpMultipleChoicesException.java │ │ │ ├── HttpNotImplementedException.java │ │ │ ├── HttpPaymentRequiredException.java │ │ │ ├── HttpRequestTimeoutException.java │ │ │ ├── UnsupportedConversionException.java │ │ │ ├── HttpMethodNotAllowedException.java │ │ │ ├── HttpMovedPermanentlyException.java │ │ │ ├── HttpTemporaryRedirectException.java │ │ │ ├── HttpExpectationFailedException.java │ │ │ ├── HttpPreconditionFailedException.java │ │ │ ├── HttpRequestUriTooLongException.java │ │ │ ├── HttpServiceUnavailableException.java │ │ │ ├── HttpInternalServerErrorException.java │ │ │ ├── HttpUnprocessableEntityException.java │ │ │ ├── HttpUnsupportedMediaTypeException.java │ │ │ ├── HttpRequestEntityTooLargeException.java │ │ │ ├── HttpHttpVersionNotSupportedException.java │ │ │ ├── HttpProxyAuthenticationRequiredException.java │ │ │ ├── HttpRequestedRangeNotSatisfiableException.java │ │ │ ├── HttpMethodUnsupportedException.java │ │ │ ├── EntityConverterException.java │ │ │ └── HttpClientException.java │ │ │ ├── HttpRequestsUtil.java │ │ │ ├── Ordered.java │ │ │ ├── mock │ │ │ ├── MockHttpClientFactory.java │ │ │ └── MockHttpResponse.java │ │ │ ├── HttpClientFactory.java │ │ │ ├── reference │ │ │ └── ReferenceHttpClientFactory.java │ │ │ ├── AbstractHttpClientFactory.java │ │ │ ├── FormData.java │ │ │ └── HttpMethod.java │ └── test │ │ └── groovy │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ ├── reference │ │ ├── HttpsIntegrationSpec.groovy │ │ └── HttpIntegrationSpec.groovy │ │ ├── converter │ │ └── bundled │ │ │ ├── StringEntityReaderSpec.groovy │ │ │ ├── ByteArrayEntityReaderSpec.groovy │ │ │ ├── StringEntityWriterSpec.groovy │ │ │ ├── ByteArrayEntityWriterSpec.groovy │ │ │ └── FormDataEntityWriterSpec.groovy │ │ ├── filter │ │ └── bundled │ │ │ ├── BasicAuthFilterSpec.groovy │ │ │ ├── DeflateFilterspec.groovy │ │ │ ├── HttpStatusExceptionFilterSpec.groovy │ │ │ └── GZIPFilterSpec.groovy │ │ └── MultiValuedMapSpec.groovy └── build.gradle ├── http-requests-jersey1 ├── gradle.properties ├── build.gradle └── src │ ├── test │ └── groovy │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ └── jersey1 │ │ ├── HttpTestSuiteSpec.groovy │ │ └── HttpsTestSuiteSpec.groovy │ └── main │ └── java │ └── com │ └── budjb │ └── httprequests │ └── jersey1 │ └── JerseyHttpClientFactory.java ├── http-requests-jersey2 ├── gradle.properties ├── build.gradle └── src │ ├── test │ └── groovy │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ └── jersey2 │ │ ├── HttpTestSuiteSpec.groovy │ │ └── HttpsTestSuiteSpec.groovy │ └── main │ └── java │ └── com │ └── budjb │ └── httprequests │ └── jersey2 │ └── JerseyHttpClientFactory.java ├── http-requests-httpcomponents-client ├── gradle.properties ├── build.gradle └── src │ ├── test │ └── groovy │ │ └── com │ │ └── budjb │ │ └── httprequests │ │ └── httpcomponents │ │ └── client │ │ ├── HttpsTestSuiteSpec.groovy │ │ └── HttpTestSuiteSpec.groovy │ └── main │ └── java │ └── com │ └── budjb │ └── httprequests │ └── httpcomponents │ └── client │ └── HttpComponentsClientFactory.java ├── http-requests-groovy ├── gradle.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── org.codehaus.groovy.runtime.ExtensionModule │ │ └── java │ │ │ └── com │ │ │ └── budjb │ │ │ └── httprequests │ │ │ └── groovy │ │ │ ├── XmlSlurperEntityReader.java │ │ │ ├── JsonEntityReader.java │ │ │ ├── HttpClientStaticGroovyExtensions.java │ │ │ ├── GStringEntityWriter.java │ │ │ └── JsonEntityWriter.java │ └── test │ │ └── groovy │ │ └── HttpClientStaticGroovyExtensionsSpec.groovy └── build.gradle ├── gradle.properties ├── settings.gradle └── gradlew.bat /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/http-requests-documentation/src/docs/images/logo.png -------------------------------------------------------------------------------- /http-requests-documentation/src/images/filters.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/http-requests-documentation/src/images/filters.graffle -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/images/filters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/http-requests-documentation/src/docs/images/filters.png -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/http-requests-functional-test/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/images/filter-lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/budjb/http-requests/HEAD/http-requests-documentation/src/docs/images/filter-lifecycle.png -------------------------------------------------------------------------------- /http-requests-spring/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.budjb.httprequests.spring.HttpRequestsAutoConfiguration 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 08 15:18:30 CDT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip 7 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/components/httpentity.adoc: -------------------------------------------------------------------------------- 1 | === HttpEntity 2 | 3 | An `HttpEntity` is the container object for an entity to be used for a request or returned with a response. The 4 | `HttpEntity` class itself contains an `InputStream`, which contains the actual content of the entity, and optionally 5 | a content type and character set. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](http://img.shields.io/travis/budjb/http-requests.svg?branch=master)](https://travis-ci.org/budjb/http-requests) 2 | [![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) 3 | 4 | # HTTP Requests Library 5 | 6 | See the documentation at https://budjb.github.io/http-requests/latest. 7 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/components.adoc: -------------------------------------------------------------------------------- 1 | == Components 2 | 3 | include::components/entityconvertermanager.adoc[] 4 | 5 | include::components/httpclientfactory.adoc[] 6 | 7 | include::components/httprequest.adoc[] 8 | 9 | include::components/httpentity.adoc[] 10 | 11 | include::components/httpclient.adoc[] 12 | 13 | include::components/httpresponse.adoc[] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | out/ 20 | 21 | ### NetBeans ### 22 | nbproject/private/ 23 | build/ 24 | nbbuild/ 25 | dist/ 26 | nbdist/ 27 | .nb-gradle/ 28 | 29 | ### OSX ### 30 | .DS_Store 31 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/index.adoc: -------------------------------------------------------------------------------- 1 | = HTTP Requests Library Documentation 2 | Bud Byrd 3 | :imagesdir: images 4 | :title-logo-image: logo.png 5 | 6 | include::introduction.adoc[] 7 | 8 | include::installing.adoc[] 9 | 10 | include::components.adoc[] 11 | 12 | include::filters.adoc[] 13 | 14 | include::converters.adoc[] 15 | 16 | include::spring.adoc[] 17 | 18 | include::examples.adoc[] 19 | 20 | include::testing.adoc[] 21 | 22 | include::changelog.adoc[] 23 | -------------------------------------------------------------------------------- /http-requests-mock/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Mock requests with HTTP Requests. 17 | -------------------------------------------------------------------------------- /http-requests-bom/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=An easy to use facade used to make HTTP requests. 17 | -------------------------------------------------------------------------------- /http-requests-spring/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Integrates the HTTP requests library with Spring Boot. 17 | -------------------------------------------------------------------------------- /http-requests-jackson/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Adds Jackson entity converters to the HTTP requests library. 17 | jacksonVersion=2.9.6 18 | -------------------------------------------------------------------------------- /http-requests-core/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Contains the interfaces and foundation of the HTTP requests library, as well as\ 17 | a basic implementation of the client. 18 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/components/entityconvertermanager.adoc: -------------------------------------------------------------------------------- 1 | === EntityConverterManager 2 | 3 | The `EntityConverterManager` serves as both a place to aggregate entity converters and as an entry point to object 4 | marshalling. 5 | 6 | .Example Usage 7 | [source,java] 8 | ---- 9 | EntityConverterManager converterManager = new EntityConverterManager(); 10 | 11 | converterManager.add(new ExampleWriter()); 12 | converterManager.add(new ExampleReader()); 13 | ---- 14 | 15 | The converter manager may be used directly to marshal objects to and from `InputStream` instances, but it is intended 16 | to be a support component of `HttpClient`. Therefore, the converter manager is a requirement to build an 17 | `HttpClientFactory`. 18 | 19 | NOTE: More information can be found in the section that covers <>. -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/EntityConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter; 17 | 18 | public interface EntityConverter {} 19 | -------------------------------------------------------------------------------- /http-requests-jersey1/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Provides a concrete implementation of the http-requests library using the \ 17 | Jersey Client 1.x library. 18 | jersey1Version=1.19.4 19 | -------------------------------------------------------------------------------- /http-requests-jersey2/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Provides a concrete implementation of the http-requests library using the \ 17 | Jersey Client 2.x library. 18 | jersey2Version=2.28 19 | -------------------------------------------------------------------------------- /gradle/library.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'java-library' 19 | apply plugin: 'groovy' 20 | apply plugin: 'idea' 21 | 22 | sourceCompatibility = 1.8 23 | targetCompatibility = 1.8 24 | -------------------------------------------------------------------------------- /http-requests-httpcomponents-client/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Provides a concrete implementation of the http-requests library using the\ 17 | Apache HttpComponents Client library. 18 | httpComponentsClientVersion=4.5.8 19 | -------------------------------------------------------------------------------- /http-requests-core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api "org.slf4j:slf4j-api:1.7.26" 21 | testImplementation project(":http-requests-functional-test") 22 | } 23 | -------------------------------------------------------------------------------- /http-requests-jackson/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api project(":http-requests-core") 21 | api "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" 22 | } -------------------------------------------------------------------------------- /http-requests-groovy/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | projectDescription=Adds Groovy extensions to the HTTP requests library. This library enhances the\ 17 | HttpClient and its descendents with Groovy-style DSL method variants, and adds Groovy-specific\ 18 | entity converters. 19 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/HttpClientFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | /** 19 | * A base interface that gives a common class type to all HTTP filter implementations. 20 | */ 21 | public interface HttpClientFilter { 22 | 23 | } -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/EmptyEntityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | public class EmptyEntityException extends EntityException { 20 | public EmptyEntityException() { 21 | super(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/EntityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | public abstract class EntityException extends HttpClientException { 20 | protected EntityException() { 21 | super(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/NullEntityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | public class NullEntityException extends EntityException { 20 | public NullEntityException() { 21 | super(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-jersey1/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api project(":http-requests-core") 21 | api "com.sun.jersey:jersey-client:${jersey1Version}" 22 | testImplementation project(":http-requests-functional-test") 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=ERROR, STDOUT 18 | log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender 19 | log4j.appender.STDOUT.layout=layout=org.apache.log4j.PatternLayout 20 | log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n 21 | log4j.logger.com.budjb=ALL -------------------------------------------------------------------------------- /http-requests-httpcomponents-client/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api project(":http-requests-core") 21 | api "org.apache.httpcomponents:httpclient:${httpComponentsClientVersion}" 22 | testImplementation project(":http-requests-functional-test") 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/spring.adoc: -------------------------------------------------------------------------------- 1 | == Spring Boot Integration 2 | 3 | The `http-requests-spring` is available to automatically configure the various library components to the application 4 | context as Spring beans. It supports automatic entity converter registry for all entity converters that are registered 5 | as beans, and it automatically configures the `HttpClientFactory` instance as a bean depending on which provider is 6 | present on the classpath. 7 | 8 | NOTE: Auto configuration must be enabled for the HTTP requests components to be automatically registered. 9 | This can be enabled with the `EnableAutoConfiguration` annotation on the main application class or a `Configuration` 10 | class. Alternatively, the `HttpRequestsAutoConfiguration` configuration class may be configured as a bean to accomplish 11 | automatic configuration of the library. 12 | 13 | With the Spring support added, other beans may inject the `HttpClientFactory` (with the name `httpClientFactory`) bean 14 | as a dependency. 15 | -------------------------------------------------------------------------------- /http-requests-groovy/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | moduleName=Groovy extensions for the http-requests library. 18 | moduleVersion=2.0.0 19 | extensionClasses=com.budjb.httprequests.groovy.HttpClientGroovyExtensions 20 | staticExtensionClasses=com.budjb.httprequests.groovy.HttpClientStaticGroovyExtensions 21 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpFoundException extends HttpStatusException { 21 | public HttpFoundException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpGoneException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpGoneException extends HttpStatusException { 21 | public HttpGoneException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpConflictException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpConflictException extends HttpStatusException { 21 | public HttpConflictException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpNotFoundException extends HttpStatusException { 21 | public HttpNotFoundException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpSeeOtherException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpSeeOtherException extends HttpStatusException { 21 | public HttpSeeOtherException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpUseProxyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpUseProxyException extends HttpStatusException { 21 | public HttpUseProxyException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpBadGatewayException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpBadGatewayException extends HttpStatusException { 21 | public HttpBadGatewayException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpBadRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpBadRequestException extends HttpStatusException { 21 | public HttpBadRequestException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpForbiddenException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpForbiddenException extends HttpStatusException { 21 | public HttpForbiddenException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpNotModifiedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpNotModifiedException extends HttpStatusException { 21 | public HttpNotModifiedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpNotAcceptableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpNotAcceptableException extends HttpStatusException { 21 | public HttpNotAcceptableException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpUnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpUnauthorizedException extends HttpStatusException { 21 | public HttpUnauthorizedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpGatewayTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpGatewayTimeoutException extends HttpStatusException { 21 | public HttpGatewayTimeoutException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpLengthRequiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpLengthRequiredException extends HttpStatusException { 21 | public HttpLengthRequiredException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpMultipleChoicesException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpMultipleChoicesException extends HttpStatusException { 21 | public HttpMultipleChoicesException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpNotImplementedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpNotImplementedException extends HttpStatusException { 21 | public HttpNotImplementedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpPaymentRequiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpPaymentRequiredException extends HttpStatusException { 21 | public HttpPaymentRequiredException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpRequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpRequestTimeoutException extends HttpStatusException { 21 | public HttpRequestTimeoutException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/UnsupportedConversionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | public class UnsupportedConversionException extends Exception { 19 | public UnsupportedConversionException(Class type) { 20 | super("no converter is available to convert the class type " + type.getName()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpMethodNotAllowedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpMethodNotAllowedException extends HttpStatusException { 21 | public HttpMethodNotAllowedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpMovedPermanentlyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpMovedPermanentlyException extends HttpStatusException { 21 | public HttpMovedPermanentlyException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpTemporaryRedirectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpTemporaryRedirectException extends HttpStatusException { 21 | public HttpTemporaryRedirectException(HttpResponse request) { 22 | super(request); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpExpectationFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpExpectationFailedException extends HttpStatusException { 21 | public HttpExpectationFailedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpPreconditionFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpPreconditionFailedException extends HttpStatusException { 21 | public HttpPreconditionFailedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpRequestUriTooLongException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpRequestUriTooLongException extends HttpStatusException { 21 | public HttpRequestUriTooLongException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpServiceUnavailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpServiceUnavailableException extends HttpStatusException { 21 | public HttpServiceUnavailableException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpInternalServerErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpInternalServerErrorException extends HttpStatusException { 21 | public HttpInternalServerErrorException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpUnprocessableEntityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpUnprocessableEntityException extends HttpStatusException { 21 | public HttpUnprocessableEntityException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpUnsupportedMediaTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpUnsupportedMediaTypeException extends HttpStatusException { 21 | public HttpUnsupportedMediaTypeException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpRequestEntityTooLargeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpRequestEntityTooLargeException extends HttpStatusException { 21 | public HttpRequestEntityTooLargeException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpHttpVersionNotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpHttpVersionNotSupportedException extends HttpStatusException { 21 | public HttpHttpVersionNotSupportedException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-mock/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | apply plugin: "groovy" 20 | 21 | dependencies { 22 | api project(':http-requests-core') 23 | 24 | testImplementation "org.codehaus.groovy:groovy:${groovyVersion}" 25 | testImplementation "org.spockframework:spock-core:${spockVersion}" 26 | testImplementation project(':http-requests-groovy') 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-groovy/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api project(":http-requests-core") 21 | api "org.codehaus.groovy:groovy:${groovyVersion}" 22 | api "org.codehaus.groovy:groovy-json:${groovyVersion}" 23 | api "org.codehaus.groovy:groovy-xml:${groovyVersion}" 24 | testImplementation project(":http-requests-functional-test") 25 | } 26 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpProxyAuthenticationRequiredException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpProxyAuthenticationRequiredException extends HttpStatusException { 21 | public HttpProxyAuthenticationRequiredException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpRequestedRangeNotSatisfiableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.exception; 17 | 18 | import com.budjb.httprequests.HttpResponse; 19 | 20 | public class HttpRequestedRangeNotSatisfiableException extends HttpStatusException { 21 | public HttpRequestedRangeNotSatisfiableException(HttpResponse response) { 22 | super(response); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /http-requests-spring/src/main/java/com/budjb/httprequests/spring/HttpRequestsAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.spring; 18 | 19 | import org.springframework.context.annotation.Import; 20 | 21 | @Import({HttpClientFactoryConfiguration.class, EntityConverterConfiguration.class, JacksonEntityConverterConfiguration.class, GroovyExtensionConfiguration.class}) 22 | public class HttpRequestsAutoConfiguration { 23 | } 24 | -------------------------------------------------------------------------------- /http-requests-jersey2/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api project(":http-requests-core") 21 | api "org.glassfish.jersey.core:jersey-client:${jersey2Version}" 22 | api "org.glassfish.jersey.core:jersey-common:${jersey2Version}" 23 | api "org.glassfish.jersey.inject:jersey-hk2:${jersey2Version}" 24 | testImplementation project(":http-requests-functional-test") 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016-2018 the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | version=2.0.7 17 | group=com.budjb 18 | githubHttpsUrl=https://github.com/budjb/http-requests 19 | githubGitUrl=git@github.com:budjb/http-requests.git 20 | bintrayUsernameEnvVar=BINTRAY_USER 21 | bintrayKeyEnvVar=BINTRAY_KEY 22 | sonatypeUsernameEnvVar=SONATYPE_USERNAME 23 | sonatypePasswordEnvVar=SONATYPE_PASSWORD 24 | springDependencyManagementVersion=1.0.7.RELEASE 25 | springBootVersion=2.1.4.RELEASE 26 | groovyVersion=2.5.6 27 | spockVersion=1.3-groovy-2.5 28 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/bundled/ConsoleLoggingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled; 17 | 18 | /** 19 | * A {@link LoggingFilter} implementation the logs the HTTP conversation to the console. 20 | */ 21 | public class ConsoleLoggingFilter extends LoggingFilter { 22 | /** 23 | * {@inheritDoc} 24 | */ 25 | @Override 26 | protected void write(String content) { 27 | System.out.println(content); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/introduction.adoc: -------------------------------------------------------------------------------- 1 | == Introduction 2 | The HTTP Requests library provides a clean and simplified interface to make HTTP requests. 3 | 4 | The spirit of this library is to make it trivial to do easy things with HTTP requests. It can accomplish the most 5 | common use cases for an HTTP client, but does not aim to be a complete HTTP client implementation. 6 | 7 | At its core, the library defines a framework for making requests. A built-in implementation of this framework based on 8 | Java's built-in HTTP classes is included to make the library extremely lightweight, with its only external dependency 9 | being SLF4J. There are also several providers available that use popular HTTP client libraries, such as Jersey and 10 | Apache HTTP Components Client. When one of these providers is used, the library serves as a facade, making the use of 11 | these popular libraries much easier and your code more concise. 12 | 13 | Indeed, the driving philosophy behind this project is to serve as a facade for HTTP requests, so that library authors 14 | may perform HTTP operations without dictating what HTTP library is required, much like SLF4J does for logging. 15 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = 'http-requests' 18 | 19 | include 'http-requests-bom' 20 | 21 | include 'http-requests-core' 22 | include 'http-requests-httpcomponents-client' 23 | include 'http-requests-jersey1' 24 | include 'http-requests-jersey2' 25 | include 'http-requests-groovy' 26 | 27 | include 'http-requests-functional-test' 28 | include 'http-requests-jackson' 29 | 30 | include 'http-requests-spring' 31 | include 'http-requests-documentation' 32 | 33 | include 'http-requests-mock' 34 | -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpMethodUnsupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | import com.budjb.httprequests.HttpClient; 20 | import com.budjb.httprequests.HttpMethod; 21 | 22 | public class HttpMethodUnsupportedException extends HttpClientException { 23 | public HttpMethodUnsupportedException(HttpClient client, HttpMethod method) { 24 | super("HttpClient implementation " + client.getClass().getName() + " does not support the HTTP method " + method.name()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/HttpRequestsUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | public abstract class HttpRequestsUtil { 23 | public static boolean isNullOrEmpty(String str) { 24 | if (str == null) { 25 | return true; 26 | } 27 | 28 | return str.trim().isEmpty(); 29 | } 30 | 31 | public static List tokenize(String input, String regex) { 32 | return Arrays.asList(input.split(regex)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/reference/HttpsIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.reference 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpsIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpsIntegrationSpec extends HttpsIntegrationTestSuiteSpec { 23 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 24 | return new ReferenceHttpClientFactory(converterManager) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /http-requests-jersey1/src/test/groovy/com/budjb/httprequests/jersey1/HttpTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey1 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpTestSuiteSpec extends HttpIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new JerseyHttpClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-jersey2/src/test/groovy/com/budjb/httprequests/jersey2/HttpTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey2 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpTestSuiteSpec extends HttpIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new JerseyHttpClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/reference/HttpIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.reference 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpIntegrationSpec extends HttpIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new ReferenceHttpClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-jersey1/src/test/groovy/com/budjb/httprequests/jersey1/HttpsTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey1 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpsIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpsTestSuiteSpec extends HttpsIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new JerseyHttpClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-jersey2/src/test/groovy/com/budjb/httprequests/jersey2/HttpsTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey2 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpsIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpsTestSuiteSpec extends HttpsIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new JerseyHttpClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-spring/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library-publish.gradle" 18 | 19 | dependencies { 20 | api platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") 21 | api project(":http-requests-core") 22 | api "org.springframework.boot:spring-boot-starter" 23 | 24 | compileOnly project(":http-requests-httpcomponents-client") 25 | compileOnly project(":http-requests-jersey1") 26 | compileOnly project(":http-requests-jersey2") 27 | compileOnly project(":http-requests-jackson") 28 | compileOnly project(":http-requests-groovy") 29 | } 30 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/RequestFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | import com.budjb.httprequests.HttpRequest; 19 | 20 | /** 21 | * An {@link HttpClientFilter} that allows modification of the {@link HttpRequest} instance before 22 | * the request is transmitted. 23 | */ 24 | public interface RequestFilter extends HttpClientFilter { 25 | /** 26 | * Provides an opportunity to modify the {@link HttpRequest} before it is transmitted. 27 | * 28 | * @param request HTTP request. 29 | */ 30 | void filter(HttpRequest request); 31 | } 32 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/EntityConverterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | public class EntityConverterException extends HttpClientException { 20 | public EntityConverterException() { 21 | super(); 22 | } 23 | 24 | public EntityConverterException(String msg) { 25 | super(msg); 26 | } 27 | 28 | public EntityConverterException(String msg, Throwable throwable) { 29 | super(msg, throwable); 30 | } 31 | 32 | public EntityConverterException(Throwable throwable) { 33 | super(throwable); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /http-requests-httpcomponents-client/src/test/groovy/com/budjb/httprequests/httpcomponents/client/HttpsTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.httpcomponents.client 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpsIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpsTestSuiteSpec extends HttpsIntegrationTestSuiteSpec { 23 | @Override 24 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 25 | return new HttpComponentsClientFactory(converterManager) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /http-requests-documentation/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'org.asciidoctor.jvm.convert' 18 | 19 | asciidoctor { 20 | baseDir file("src/docs") 21 | sourceDir file("src/docs") 22 | 23 | sources { 24 | include 'index.adoc' 25 | } 26 | 27 | outputOptions { 28 | backends 'html5' 29 | } 30 | 31 | attributes 'copyright': 'Apache License, Version 2.0', 32 | 'toc': 'left', 33 | 'toclevels': 2, 34 | 'numbered': 'true', 35 | 'icons': 'font', 36 | 'version': project.version, 37 | 'revnumber': project.version, 38 | 'source-highlighter': 'prettify' 39 | } -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/OutputStreamFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | import java.io.OutputStream; 19 | 20 | /** 21 | * An HTTP client filter that allows modification of the request entity before it is 22 | * transmitted with the request. 23 | */ 24 | public interface OutputStreamFilter extends HttpClientFilter { 25 | /** 26 | * Filters a request entity's {@link OutputStream} 27 | * 28 | * @param outputStream The {@link OutputStream} of the request. 29 | * @return Filtered request {@link OutputStream}. 30 | */ 31 | OutputStream filter(OutputStream outputStream); 32 | } 33 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/exception/HttpClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.exception; 18 | 19 | /** 20 | * A base exception type used in the HTTP request library. 21 | */ 22 | public class HttpClientException extends RuntimeException { 23 | public HttpClientException() { 24 | super(); 25 | } 26 | 27 | public HttpClientException(String msg) { 28 | super(msg); 29 | } 30 | 31 | public HttpClientException(String msg, Throwable throwable) { 32 | super(msg, throwable); 33 | } 34 | 35 | public HttpClientException(Throwable throwable) { 36 | super(throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/ResponseFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | import com.budjb.httprequests.HttpClient; 19 | import com.budjb.httprequests.HttpResponse; 20 | 21 | /** 22 | * An {@link HttpClientFilter} that allows modification of the {@link HttpResponse} instance before 23 | * it is returned from the {@link HttpClient}. 24 | */ 25 | public interface ResponseFilter extends HttpClientFilter { 26 | /** 27 | * Provides an opportunity to modify the {@link HttpResponse} before it is returned. 28 | * 29 | * @param response HTTP response. 30 | */ 31 | void filter(HttpResponse response); 32 | } 33 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/Ordered.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests; 18 | 19 | public interface Ordered { 20 | /** 21 | * Default priority. 22 | */ 23 | int DEFAULT_PRIORITY = 0; 24 | 25 | /** 26 | * Lowest priority. 27 | */ 28 | int LOWEST_PRIORITY = Integer.MIN_VALUE; 29 | 30 | /** 31 | * Highest priority. 32 | */ 33 | int HIGHEST_PRIORITY = Integer.MAX_VALUE; 34 | 35 | /** 36 | * Returns an order used for comparison and sorting. 37 | * 38 | * @return An order used for comparison and sorting. 39 | */ 40 | default int getOrder() { 41 | return DEFAULT_PRIORITY; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /http-requests-groovy/src/test/groovy/HttpClientStaticGroovyExtensionsSpec.groovy: -------------------------------------------------------------------------------- 1 | import com.budjb.httprequests.HttpRequest 2 | import spock.lang.Specification 3 | 4 | /* 5 | * Copyright 2016-2018 the original author or authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | class HttpClientStaticGroovyExtensionsSpec extends Specification { 21 | def 'The groovy HttpRequest DSL parses properties correctly'() { 22 | when: 23 | HttpRequest request = HttpRequest.build { 24 | uri 'https://foo.bar.com' 25 | header 'foo', 'bar' 26 | queryParameter 'foo', 'bar' 27 | } 28 | 29 | then: 30 | request.uri == 'https://foo.bar.com' 31 | request.headers == ['foo': ['bar']] 32 | request.queryParameters == ['foo': ['bar']] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /http-requests-httpcomponents-client/src/test/groovy/com/budjb/httprequests/httpcomponents/client/HttpTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.httpcomponents.client 17 | 18 | import com.budjb.httprequests.HttpClientFactory 19 | import com.budjb.httprequests.HttpIntegrationTestSuiteSpec 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | 22 | class HttpTestSuiteSpec extends HttpIntegrationTestSuiteSpec { 23 | /** 24 | * Create an HTTP client factory to use with tests. 25 | * 26 | * @return 27 | */ 28 | @Override 29 | HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) { 30 | return new HttpComponentsClientFactory(converterManager) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /http-requests-functional-test/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library.gradle" 18 | 19 | apply plugin: "groovy" 20 | apply plugin: "java" 21 | apply plugin: "java-library" 22 | 23 | dependencies { 24 | api platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") 25 | 26 | api project(":http-requests-core") 27 | api project(":http-requests-jackson") 28 | api project(":http-requests-spring") 29 | 30 | api "org.codehaus.groovy:groovy:${groovyVersion}" 31 | 32 | api "org.springframework.boot:spring-boot-starter-web" 33 | api "org.springframework.boot:spring-boot-starter-test" 34 | api "org.spockframework:spock-spring:${spockVersion}" 35 | api "org.spockframework:spock-core:${spockVersion}" 36 | } 37 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/bundled/HttpStatusExceptionFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled; 17 | 18 | import com.budjb.httprequests.HttpContext; 19 | import com.budjb.httprequests.exception.HttpStatusException; 20 | import com.budjb.httprequests.filter.LifecycleFilter; 21 | 22 | /** 23 | * A filter that throws an exception specific to an HTTP status if that status is not in the 200-299 range. 24 | */ 25 | public class HttpStatusExceptionFilter implements LifecycleFilter { 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public void onComplete(HttpContext context) { 31 | if (context.getResponse().getStatus() >= 300) { 32 | throw HttpStatusException.build(context.getResponse()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /http-requests-groovy/src/main/java/com/budjb/httprequests/groovy/XmlSlurperEntityReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.groovy; 18 | 19 | import com.budjb.httprequests.converter.EntityReader; 20 | import groovy.util.XmlSlurper; 21 | import groovy.util.slurpersupport.GPathResult; 22 | 23 | import java.io.InputStream; 24 | 25 | public class XmlSlurperEntityReader implements EntityReader { 26 | /** 27 | * {@inheritDoc} 28 | */ 29 | @Override 30 | public boolean supports(Class type) { 31 | return GPathResult.class.isAssignableFrom(type); 32 | } 33 | 34 | /** 35 | * {@inheritDoc} 36 | */ 37 | @Override 38 | public Object read(InputStream entity, String contentType, String charset) throws Exception { 39 | return new XmlSlurper(false, false).parse(entity); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /http-requests-httpcomponents-client/src/main/java/com/budjb/httprequests/httpcomponents/client/HttpComponentsClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.httpcomponents.client; 17 | 18 | import com.budjb.httprequests.AbstractHttpClientFactory; 19 | import com.budjb.httprequests.HttpClient; 20 | import com.budjb.httprequests.converter.EntityConverterManager; 21 | 22 | public class HttpComponentsClientFactory extends AbstractHttpClientFactory { 23 | /** 24 | * Constructor. 25 | * 26 | * @param converterManager Entity converter manager. 27 | */ 28 | public HttpComponentsClientFactory(EntityConverterManager converterManager) { 29 | super(converterManager); 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | @Override 36 | public HttpClient createHttpClient() { 37 | return new HttpComponentsHttpClient(getConverterManager()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/mock/MockHttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.mock; 18 | 19 | import com.budjb.httprequests.AbstractHttpClientFactory; 20 | import com.budjb.httprequests.HttpClient; 21 | import com.budjb.httprequests.converter.EntityConverterManager; 22 | 23 | /** 24 | * A factory for {@link MockHttpClient}. 25 | */ 26 | public class MockHttpClientFactory extends AbstractHttpClientFactory { 27 | /** 28 | * Constructor. 29 | * 30 | * @param entityConverterManager Entity converter manager. 31 | */ 32 | public MockHttpClientFactory(EntityConverterManager entityConverterManager) { 33 | super(entityConverterManager); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public HttpClient createHttpClient() { 41 | return new MockHttpClient(getConverterManager()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/converter/bundled/StringEntityReaderSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.converter.bundled 18 | 19 | import spock.lang.Specification 20 | 21 | class StringEntityReaderSpec extends Specification { 22 | def 'StringEntityReader only supports Strings'() { 23 | setup: 24 | StringEntityReader reader = new StringEntityReader() 25 | 26 | expect: 27 | reader.supports(String) 28 | !reader.supports(String[]) 29 | !reader.supports(Object) 30 | } 31 | 32 | def 'StringEntityReader returns a String'() { 33 | setup: 34 | StringEntityReader reader = new StringEntityReader() 35 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream([102, 111, 111, 98, 97, 114] as byte[]) 36 | 37 | expect: 38 | reader.read(byteArrayInputStream, null, null) == 'foobar' 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/HttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests; 17 | 18 | import com.budjb.httprequests.converter.EntityConverterManager; 19 | 20 | /** 21 | * Describes a factory class that creates an {@link HttpClient} instance. Individual HTTP client libraries 22 | * should implement this factory for the creation of HTTP clients. 23 | *

24 | * These factories are suitable for instantiation as Spring beans so that the factory can be injected where needed. 25 | */ 26 | public interface HttpClientFactory { 27 | /** 28 | * Create a new HTTP client. 29 | * 30 | * @return An {@link HttpClient} implementation instance. 31 | */ 32 | HttpClient createHttpClient(); 33 | 34 | /** 35 | * Returns the entity converter manager. 36 | * 37 | * @return The entity converter manager. 38 | */ 39 | EntityConverterManager getConverterManager(); 40 | } 41 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/bundled/DeflateFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled; 17 | 18 | import com.budjb.httprequests.HttpRequest; 19 | import com.budjb.httprequests.filter.OutputStreamFilter; 20 | import com.budjb.httprequests.filter.RequestFilter; 21 | 22 | import java.io.OutputStream; 23 | import java.util.zip.DeflaterOutputStream; 24 | 25 | /** 26 | * A filter that compresses the entity with the deflate algorithm. 27 | */ 28 | public class DeflateFilter implements OutputStreamFilter, RequestFilter { 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public OutputStream filter(OutputStream outputStream) { 34 | return new DeflaterOutputStream(outputStream); 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public void filter(HttpRequest request) { 42 | request.setHeader("Content-Encoding", "deflate"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/converter/bundled/ByteArrayEntityReaderSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.converter.bundled 18 | 19 | import spock.lang.Specification 20 | 21 | class ByteArrayEntityReaderSpec extends Specification { 22 | def 'ByteArrayEntityReader only supports byte arrays'() { 23 | setup: 24 | ByteArrayEntityReader reader = new ByteArrayEntityReader() 25 | 26 | expect: 27 | reader.supports(byte[]) 28 | !reader.supports(String[]) 29 | !reader.supports(Object) 30 | !reader.supports(String) 31 | } 32 | 33 | def 'ByteArrayEntityReader returns a byte array'() { 34 | setup: 35 | ByteArrayEntityReader reader = new ByteArrayEntityReader() 36 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream([1, 2, 3] as byte[]) 37 | 38 | expect: 39 | reader.read(byteArrayInputStream, null, null) == [1, 2, 3] as byte[] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /http-requests-groovy/src/main/java/com/budjb/httprequests/groovy/JsonEntityReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.groovy; 18 | 19 | import com.budjb.httprequests.converter.EntityReader; 20 | import groovy.json.JsonSlurper; 21 | 22 | import java.io.InputStream; 23 | import java.nio.charset.Charset; 24 | import java.util.List; 25 | import java.util.Map; 26 | 27 | public class JsonEntityReader implements EntityReader { 28 | /** 29 | * {@inheritDoc} 30 | */ 31 | @Override 32 | public boolean supports(Class type) { 33 | return List.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public Object read(InputStream entity, String contentType, String charset) { 41 | if (charset == null) { 42 | charset = Charset.defaultCharset().toString(); 43 | } 44 | return new JsonSlurper().parse(entity, charset); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/reference/ReferenceHttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.reference; 18 | 19 | import com.budjb.httprequests.AbstractHttpClientFactory; 20 | import com.budjb.httprequests.HttpClient; 21 | import com.budjb.httprequests.converter.EntityConverterManager; 22 | 23 | /** 24 | * A factory for {@link ReferenceHttpClient}. 25 | */ 26 | public class ReferenceHttpClientFactory extends AbstractHttpClientFactory { 27 | /** 28 | * Constructor using the provided converter and filter managers. 29 | * 30 | * @param entityConverterManager Entity converter manager. 31 | */ 32 | public ReferenceHttpClientFactory(EntityConverterManager entityConverterManager) { 33 | super(entityConverterManager); 34 | } 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public HttpClient createHttpClient() { 41 | return new ReferenceHttpClient(getConverterManager()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/groovy/com/budjb/httprequests/AbstractHttpsIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests 17 | 18 | import org.junit.runner.RunWith 19 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest 20 | import org.springframework.boot.test.context.SpringBootTest 21 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment 22 | import org.springframework.test.context.junit4.SpringRunner 23 | import spock.lang.Ignore 24 | 25 | @Ignore 26 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = [ 27 | 'server.ssl.key-store = classpath:keystore.jks', 28 | 'server.ssl.key-password = password' 29 | ]) 30 | abstract class AbstractHttpsIntegrationSpec extends AbstractIntegrationSpec { 31 | /** 32 | * Return the base URL of the running server. 33 | * 34 | * @return 35 | */ 36 | @Override 37 | String getBaseUrl() { 38 | return "https://localhost:${webPort}" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /http-requests-jersey2/src/main/java/com/budjb/httprequests/jersey2/JerseyHttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey2; 17 | 18 | import com.budjb.httprequests.AbstractHttpClientFactory; 19 | import com.budjb.httprequests.HttpClient; 20 | import com.budjb.httprequests.converter.EntityConverterManager; 21 | 22 | public class JerseyHttpClientFactory extends AbstractHttpClientFactory { 23 | /** 24 | * Constructor that can optionally register the default set of entity converters. 25 | * 26 | * @param converterManager Entity converter manager. 27 | */ 28 | public JerseyHttpClientFactory(EntityConverterManager converterManager) { 29 | super(converterManager); 30 | } 31 | 32 | /** 33 | * Create a new HTTP client. 34 | * 35 | * @return An {@link HttpClient} implementation instance. 36 | */ 37 | @Override 38 | public HttpClient createHttpClient() { 39 | return new JerseyHttpClient(getConverterManager()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/filter/bundled/BasicAuthFilterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.bundled 18 | 19 | import com.budjb.httprequests.HttpClient 20 | import com.budjb.httprequests.HttpRequest 21 | import com.budjb.httprequests.mock.MockHttpClientFactory 22 | import spock.lang.Specification 23 | 24 | class BasicAuthFilterSpec extends Specification { 25 | def 'When the basic auth filter is used, the correct header is set'() { 26 | setup: 27 | HttpClient client = new MockHttpClientFactory().createHttpClient() 28 | String username = 'foo' 29 | String password = 'bar' 30 | 31 | HttpRequest request = new HttpRequest('http://foo.bar.com').addFilter(new BasicAuthFilter(username, password)) 32 | 33 | when: 34 | def response = client.get request 35 | 36 | then: 37 | response.request.getHeaders().get('Authorization') == ["Basic " + "$username:$password".getBytes().encodeBase64()] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /http-requests-groovy/src/main/java/com/budjb/httprequests/groovy/HttpClientStaticGroovyExtensions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.groovy; 18 | 19 | import com.budjb.httprequests.HttpRequest; 20 | import groovy.lang.Closure; 21 | import groovy.lang.DelegatesTo; 22 | 23 | public class HttpClientStaticGroovyExtensions { 24 | /** 25 | * Uses the given closure DSL to build an {@link HttpRequest}. 26 | * 27 | * @param closure A closure that configures the HTTP request. 28 | * @return The resulting HTTP request object. 29 | */ 30 | public static HttpRequest build(HttpRequest self, @DelegatesTo(HttpRequestDelegate.class) Closure closure) { 31 | HttpRequest request = new HttpRequest(); 32 | HttpRequestDelegate delegate = new HttpRequestDelegate(request); 33 | 34 | closure = (Closure) closure.clone(); 35 | closure.setResolveStrategy(Closure.DELEGATE_FIRST); 36 | closure.setDelegate(delegate); 37 | closure.call(); 38 | 39 | return request; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /http-requests-spring/src/main/java/com/budjb/httprequests/spring/GroovyExtensionConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.spring; 18 | 19 | import com.budjb.httprequests.groovy.*; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.context.annotation.Configuration; 23 | 24 | @Configuration 25 | @ConditionalOnClass(HttpClientGroovyExtensions.class) 26 | public class GroovyExtensionConfiguration { 27 | @Bean 28 | public GStringEntityWriter gStringEntityWriter() { 29 | return new GStringEntityWriter(); 30 | } 31 | 32 | @Bean 33 | public JsonEntityWriter jsonEntityWriter() { 34 | return new JsonEntityWriter(); 35 | } 36 | 37 | @Bean 38 | public JsonEntityReader jsonEntityReader() { 39 | return new JsonEntityReader(); 40 | } 41 | 42 | @Bean 43 | public XmlSlurperEntityReader xmlSlurperEntityReader() { 44 | return new XmlSlurperEntityReader(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/AbstractHttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests; 17 | 18 | import com.budjb.httprequests.converter.EntityConverterManager; 19 | 20 | public abstract class AbstractHttpClientFactory implements HttpClientFactory { 21 | /** 22 | * Instance of {@link EntityConverterManager} which will be used by the {@link HttpClient} and {@link HttpResponse}.. 23 | */ 24 | private final EntityConverterManager converterManager; 25 | 26 | /** 27 | * Constructor. 28 | * 29 | * @param entityConverterManager Entity converter manager. 30 | */ 31 | protected AbstractHttpClientFactory(EntityConverterManager entityConverterManager) { 32 | this.converterManager = entityConverterManager; 33 | } 34 | 35 | /** 36 | * Returns the entity converter manager. 37 | * 38 | * @return The entity converter manager. 39 | */ 40 | @Override 41 | public EntityConverterManager getConverterManager() { 42 | return converterManager; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/EntityReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter; 17 | 18 | import java.io.InputStream; 19 | 20 | public interface EntityReader extends EntityConverter { 21 | /** 22 | * Determines if the reader supports converting an entity to the given class type. 23 | * 24 | * @param type Type to convert to. 25 | * @return Whether the type is supported. 26 | */ 27 | boolean supports(Class type); 28 | 29 | /** 30 | * Convert the given entity. 31 | *

32 | * If an error occurs, null may be returned so that another converter can attempt a conversion. 33 | * 34 | * @param entity Entity as an {@link InputStream}. 35 | * @param contentType Content-Type of the entity. 36 | * @param charset Character set of the entity. 37 | * @return The converted entity. 38 | * @throws Exception when an unexpected error occurs during conversion. 39 | */ 40 | Object read(InputStream entity, String contentType, String charset) throws Exception; 41 | } 42 | -------------------------------------------------------------------------------- /http-requests-documentation/src/images/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | </> 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/RetryFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | import com.budjb.httprequests.HttpContext; 19 | import com.budjb.httprequests.HttpRequest; 20 | import com.budjb.httprequests.HttpResponse; 21 | 22 | /** 23 | * An {@link HttpClientFilter} that supports retrying HTTP requests. 24 | */ 25 | public interface RetryFilter extends HttpClientFilter { 26 | /** 27 | * Called once the request has been completed. This method should return {@code true} if the request 28 | * should be retried. Changes to the {@link HttpRequest} and {@link HttpResponse} objects will be lost, since 29 | * every request attempt receives a fresh copy of the request and the previous response is lost. If the retry 30 | * filter needs to modify the subsequent request before it is sent out, classes that implement this filter should 31 | * also implement the {@link RequestFilter} interface. 32 | * 33 | * @param context HTTP context. 34 | * @return Whether the request should be retried. 35 | */ 36 | boolean isRetryRequired(HttpContext context); 37 | } -------------------------------------------------------------------------------- /http-requests-groovy/src/main/java/com/budjb/httprequests/groovy/GStringEntityWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.groovy; 18 | 19 | import com.budjb.httprequests.converter.EntityWriter; 20 | import groovy.lang.GString; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.InputStream; 24 | import java.nio.charset.Charset; 25 | 26 | public class GStringEntityWriter implements EntityWriter { 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | @Override 31 | public String getContentType() { 32 | return "text/plain"; 33 | } 34 | 35 | /** 36 | * {@inheritDoc} 37 | */ 38 | @Override 39 | public boolean supports(Class type) { 40 | return GString.class.isAssignableFrom(type); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public InputStream write(Object entity, String characterSet) throws Exception { 48 | if (characterSet == null) { 49 | characterSet = Charset.defaultCharset().toString(); 50 | } 51 | return new ByteArrayInputStream(entity.toString().getBytes(characterSet)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gradle/bintray.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.jfrog.bintray' 18 | 19 | bintray { 20 | user = System.getenv(bintrayUsernameEnvVar) 21 | key = System.getenv(bintrayKeyEnvVar) 22 | publish = true 23 | 24 | pkg { 25 | websiteUrl = githubHttpsUrl 26 | issueTrackerUrl = "${githubHttpsUrl}/issues" 27 | vcsUrl = githubGitUrl 28 | githubRepo = 'budjb/http-requests' 29 | 30 | desc = projectDescription 31 | labels = ['REST', 'HTTP', 'java'] 32 | repo = 'maven' 33 | name = project.name 34 | licenses = ['Apache-2.0'] 35 | publications = ['library'] 36 | 37 | version { 38 | name = project.version 39 | released = new Date() 40 | vcsTag = project.version 41 | gpg { 42 | sign = true 43 | passphrase = System.getenv('GPG_PASSWORD') 44 | } 45 | mavenCentralSync { 46 | sync = true 47 | user = System.getenv(sonatypeUsernameEnvVar) 48 | password = System.getenv(sonatypePasswordEnvVar) 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/converter/bundled/StringEntityWriterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.converter.bundled 18 | 19 | import com.budjb.httprequests.StreamUtils 20 | import spock.lang.Specification 21 | 22 | class StringEntityWriterSpec extends Specification { 23 | def 'StringEntityWriter only supports byte arrays'() { 24 | setup: 25 | StringEntityWriter writer = new StringEntityWriter() 26 | 27 | expect: 28 | writer.supports(String) 29 | !writer.supports(String[]) 30 | !writer.supports(Object) 31 | } 32 | 33 | def 'StringEntityWriter creates an input stream from a String'() { 34 | setup: 35 | StringEntityWriter writer = new StringEntityWriter() 36 | 37 | when: 38 | InputStream inputStream = writer.write("foobar", null) 39 | 40 | then: 41 | StreamUtils.readBytes(inputStream) == [102, 111, 111, 98, 97, 114] as byte[] 42 | } 43 | 44 | def 'StringEntityWriter has a default content type of text/plain'() { 45 | expect: 46 | new StringEntityWriter().contentType == 'text/plain' 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /http-requests-jersey1/src/main/java/com/budjb/httprequests/jersey1/JerseyHttpClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.jersey1; 17 | 18 | import com.budjb.httprequests.AbstractHttpClientFactory; 19 | import com.budjb.httprequests.HttpClient; 20 | import com.budjb.httprequests.HttpClientFactory; 21 | import com.budjb.httprequests.converter.EntityConverterManager; 22 | 23 | /** 24 | * An {@link HttpClientFactory} implementation that creates Jersey 1.x HTTP clients. 25 | */ 26 | public class JerseyHttpClientFactory extends AbstractHttpClientFactory { 27 | /** 28 | * Constructor that can optionally register the default set of entity converters. 29 | * 30 | * @param converterManager Entity converter manager. 31 | */ 32 | public JerseyHttpClientFactory(EntityConverterManager converterManager) { 33 | super(converterManager); 34 | } 35 | 36 | /** 37 | * Create a new Jersey HTTP client. 38 | * 39 | * @return A new Jersey 1.x {@link HttpClient} implementation. 40 | */ 41 | @Override 42 | public HttpClient createHttpClient() { 43 | return new JerseyHttpClient(getConverterManager()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /http-requests-mock/src/main/java/com/budjb/httprequests/test/UnmatchedRequestMockException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.test; 18 | 19 | import com.budjb.httprequests.HttpMethod; 20 | import com.budjb.httprequests.HttpRequest; 21 | import com.budjb.httprequests.exception.HttpClientException; 22 | 23 | public class UnmatchedRequestMockException extends HttpClientException { 24 | /** 25 | * The unmatched HTTP request. 26 | */ 27 | private final HttpRequest request; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param request The HTTP request that did not have a matching mock. 33 | * @param method The HTTP method of the request. 34 | */ 35 | public UnmatchedRequestMockException(HttpRequest request, HttpMethod method) { 36 | super("No HTTP request mock found matching URI " + method.toString() + " " + request.getUri()); 37 | this.request = request; 38 | } 39 | 40 | /** 41 | * Returns the HTTP request that did not have a matching mock. 42 | * 43 | * @return The unmatched HTTP request. 44 | */ 45 | public HttpRequest getRequest() { 46 | return request; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/bundled/GZIPFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled; 17 | 18 | import com.budjb.httprequests.HttpRequest; 19 | import com.budjb.httprequests.exception.EntityConverterException; 20 | import com.budjb.httprequests.filter.OutputStreamFilter; 21 | import com.budjb.httprequests.filter.RequestFilter; 22 | 23 | import java.io.IOException; 24 | import java.io.OutputStream; 25 | import java.util.zip.GZIPOutputStream; 26 | 27 | /** 28 | * A filter that compresses the entity with the GZIP algorithm. 29 | */ 30 | public class GZIPFilter implements OutputStreamFilter, RequestFilter { 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public OutputStream filter(OutputStream outputStream) { 36 | try { 37 | return new GZIPOutputStream(outputStream); 38 | } 39 | catch (IOException e) { 40 | throw new EntityConverterException(e); 41 | } 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void filter(HttpRequest request) { 49 | request.setHeader("Content-Encoding", "gzip"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/filter/bundled/DeflateFilterspec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled 17 | 18 | import com.budjb.httprequests.HttpRequest 19 | import com.budjb.httprequests.converter.EntityConverterManager 20 | import com.budjb.httprequests.converter.bundled.StringEntityWriter 21 | import com.budjb.httprequests.mock.MockHttpClient 22 | import com.budjb.httprequests.mock.MockHttpClientFactory 23 | import spock.lang.Specification 24 | 25 | class DeflateFilterspec extends Specification { 26 | def 'When the deflate filter is used, the input is compressed and the proper header is set'() { 27 | setup: 28 | EntityConverterManager converterManager = new EntityConverterManager([new StringEntityWriter()]) 29 | MockHttpClient client = (MockHttpClient) new MockHttpClientFactory(converterManager).createHttpClient() 30 | 31 | HttpRequest request = new HttpRequest('http://foo.bar.com').addFilter(new DeflateFilter()) 32 | 33 | when: 34 | def response = client.post request, 'hi there' 35 | 36 | then: 37 | response.request.getHeaders().get('Content-Encoding') == ['deflate'] 38 | client.requestBuffer == [120, -100] as byte[] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /http-requests-groovy/src/main/java/com/budjb/httprequests/groovy/JsonEntityWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.groovy; 18 | 19 | import com.budjb.httprequests.converter.EntityWriter; 20 | import groovy.json.JsonBuilder; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.InputStream; 24 | import java.nio.charset.Charset; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | public class JsonEntityWriter implements EntityWriter { 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public String getContentType() { 34 | return "application/json"; 35 | } 36 | 37 | /** 38 | * {@inheritDoc} 39 | */ 40 | @Override 41 | public boolean supports(Class type) { 42 | return List.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | @Override 49 | public InputStream write(Object entity, String characterSet) throws Exception { 50 | if (characterSet == null) { 51 | characterSet = Charset.defaultCharset().toString(); 52 | } 53 | return new ByteArrayInputStream(new JsonBuilder(entity).toString().getBytes(characterSet)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /http-requests-jackson/src/main/java/com/budjb/httprequests/filter/jackson/JacksonMapReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.jackson; 18 | 19 | import com.budjb.httprequests.converter.EntityReader; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | import java.io.InputStream; 23 | import java.util.Map; 24 | 25 | /** 26 | * A map JSON writer that utilizes Jackson. 27 | */ 28 | public class JacksonMapReader implements EntityReader { 29 | /** 30 | * Jackson object mapper. 31 | */ 32 | private final ObjectMapper objectMapper; 33 | 34 | /** 35 | * Constructor. 36 | * 37 | * @param objectMapper Jackson object mapper. 38 | */ 39 | public JacksonMapReader(ObjectMapper objectMapper) { 40 | this.objectMapper = objectMapper; 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public boolean supports(Class type) { 48 | return Map.class.isAssignableFrom(type); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public Object read(InputStream entity, String contentType, String charset) throws Exception { 56 | return objectMapper.readValue(entity, Map.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/converter/bundled/ByteArrayEntityWriterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.converter.bundled 18 | 19 | import com.budjb.httprequests.StreamUtils 20 | import spock.lang.Specification 21 | 22 | class ByteArrayEntityWriterSpec extends Specification { 23 | def 'ByteArrayEntityWriter only supports byte arrays'() { 24 | setup: 25 | ByteArrayEntityWriter writer = new ByteArrayEntityWriter() 26 | 27 | expect: 28 | writer.supports(byte[]) 29 | !writer.supports(String[]) 30 | !writer.supports(Object) 31 | !writer.supports(String) 32 | } 33 | 34 | def 'ByteArrayEntityWriter creates an input stream from a byte array'() { 35 | setup: 36 | ByteArrayEntityWriter writer = new ByteArrayEntityWriter() 37 | 38 | when: 39 | InputStream inputStream = writer.write([1, 2, 3] as byte[], null) 40 | 41 | then: 42 | StreamUtils.readBytes(inputStream) == [1, 2, 3] as byte[] 43 | } 44 | 45 | def 'ByteArrayEntityWriter has a default content type of application/octet-stream'() { 46 | expect: 47 | new ByteArrayEntityWriter().contentType == 'application/octet-stream' 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /http-requests-jackson/src/main/java/com/budjb/httprequests/filter/jackson/JacksonListReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.jackson; 18 | 19 | import com.budjb.httprequests.converter.EntityReader; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | import java.io.InputStream; 23 | import java.util.List; 24 | 25 | /** 26 | * A map JSON writer that utilizes Jackson. 27 | */ 28 | public class JacksonListReader implements EntityReader { 29 | /** 30 | * Jackson object mapper. 31 | */ 32 | private final ObjectMapper objectMapper; 33 | 34 | /** 35 | * Constructor. 36 | * 37 | * @param objectMapper Jackson object mapper. 38 | */ 39 | public JacksonListReader(ObjectMapper objectMapper) { 40 | this.objectMapper = objectMapper; 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public boolean supports(Class type) { 48 | return List.class.isAssignableFrom(type); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public Object read(InputStream entity, String contentType, String charset) throws Exception { 56 | return objectMapper.readValue(entity, List.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/bundled/BasicAuthFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter.bundled; 17 | 18 | import com.budjb.httprequests.HttpRequest; 19 | import com.budjb.httprequests.filter.HttpClientFilter; 20 | import com.budjb.httprequests.filter.RequestFilter; 21 | 22 | import java.util.Base64; 23 | 24 | /** 25 | * An {@link HttpClientFilter} that provides Basic Authentication support. 26 | */ 27 | public class BasicAuthFilter implements RequestFilter { 28 | /** 29 | * Name of the header for basic authentication. 30 | */ 31 | private static final String HEADER = "Authorization"; 32 | 33 | /** 34 | * Contains the encoded credentials 35 | */ 36 | private String credentials; 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param username User name to authentication with. 42 | * @param password Password to authenticate with. 43 | */ 44 | public BasicAuthFilter(String username, String password) { 45 | credentials = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public void filter(HttpRequest request) { 53 | request.setHeader(HEADER, credentials); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/components/httpclientfactory.adoc: -------------------------------------------------------------------------------- 1 | === HttpClientFactory 2 | 3 | An `HttpClient` is used to make requests, but should not be created directly. HTTP client providers contain 4 | implementations of `HttpClient` specific to the HTTP client being wrapped. In order to ensure that authors do not need 5 | to worry about what type of `HttpClient` needs to be created, an `HttpClientFactory` should be used to create the client 6 | instances using the `createHttpClient()` method. 7 | 8 | The `HttpClientFactory` interface is implemented by provider libraries and can be created directly. As an example, 9 | the Jersey 1.x module's factory can be used to create a Jersey-specific `HttpClient` instance. 10 | 11 | [source,java] 12 | ---- 13 | // Note that EntityConverterManager is required by HttpClientFactory implementations 14 | HttpClientFactory factory = new JerseyHttpClientFactory(entityConverterManager); 15 | HttpClient client = factory.createHttpClient(); 16 | ---- 17 | 18 | TIP: The `HttpClientFactory` can be registered as a Spring bean when applications utilize Spring Framework so that it 19 | may be injected as necessary. If Spring is not in use, the `HttpClientFactoryHolder` may be used as a singleton holder 20 | for the `HttpClientFactory` instance. 21 | 22 | Each provider library declares its own `HttpClientFactory` implementation, which can be looked up in the following 23 | table. 24 | 25 | .HttpClientFactory Classes By Provider 26 | [grid="rows"] 27 | |=== 28 | | Provider | HttpClientFactory Class | 29 | 30 | | http-requests-core | `com.budjb.httprequests.reference.ReferenceHttpClientFactory` | 31 | | http-requests-jersey1 | `com.budjb.httprequests.jersey1.JerseyHttpClientFactory` | 32 | | http-requests-jersey2 | `com.budjb.httprequests.jersey2.JerseyHttpClientFactory` | 33 | | http-requests-httpcomponents-client | `com.budjb.httprequests.httpcomponents.client.HttpComponentsClientFactory` | 34 | |=== 35 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/EntityWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | 21 | public interface EntityWriter extends EntityConverter { 22 | /** 23 | * Returns a Content-Type of the converted object that will be set in the HTTP request. 24 | *

25 | * If no Content-Type is known, null is returned. 26 | * 27 | * @return Content-Type of the converted object, or null if unknown. 28 | */ 29 | String getContentType(); 30 | 31 | /** 32 | * Determines whether the given class type is supported by the writer. 33 | * 34 | * @param type Type to convert. 35 | * @return Whether the type is supported. 36 | */ 37 | boolean supports(Class type); 38 | 39 | /** 40 | * Convert the given entity. 41 | *

42 | * If an error occurs, null may be returned so that another converter may attempt conversion. 43 | * 44 | * @param entity Entity object to convert into a byte array. 45 | * @param characterSet The character set of the request. 46 | * @return An {@link InputStream} containing the converted entity. 47 | * @throws Exception when an unexpected error occurs. 48 | */ 49 | InputStream write(Object entity, String characterSet) throws Exception; 50 | } 51 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/converter/bundled/FormDataEntityWriterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.converter.bundled 18 | 19 | import com.budjb.httprequests.FormData 20 | import com.budjb.httprequests.StreamUtils 21 | import spock.lang.Specification 22 | 23 | class FormDataEntityWriterSpec extends Specification { 24 | def 'FormDataEntityWriter only supports FormData'() { 25 | setup: 26 | FormDataEntityWriter writer = new FormDataEntityWriter() 27 | 28 | expect: 29 | writer.supports(FormData) 30 | !writer.supports(String[]) 31 | !writer.supports(Object) 32 | !writer.supports(String) 33 | } 34 | 35 | def 'FormDataEntityWriter creates an input stream from a FormData object'() { 36 | setup: 37 | FormDataEntityWriter writer = new FormDataEntityWriter() 38 | FormData formData = new FormData().addField('foo', 'bar').addField('foo', 'baz') 39 | 40 | when: 41 | InputStream inputStream = writer.write(formData, null) 42 | 43 | then: 44 | new String(StreamUtils.readBytes(inputStream)) == 'foo=bar&foo=baz' 45 | } 46 | 47 | def 'FormDataEntityWriter has a default content type of application/x-www-form-urlencoded'() { 48 | expect: 49 | new FormDataEntityWriter().contentType == 'application/x-www-form-urlencoded' 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/bundled/ByteArrayEntityReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter.bundled; 17 | 18 | import com.budjb.httprequests.StreamUtils; 19 | import com.budjb.httprequests.converter.EntityReader; 20 | 21 | import java.io.InputStream; 22 | 23 | public class ByteArrayEntityReader implements EntityReader { 24 | /** 25 | * Determines if the reader supports converting an entity to the given class type. 26 | * 27 | * @param type Type to convert to. 28 | * @return Whether the type is supported. 29 | */ 30 | @Override 31 | public boolean supports(Class type) { 32 | return type.isArray() && byte.class.isAssignableFrom(type.getComponentType()); 33 | } 34 | 35 | /** 36 | * Convert the given entity. 37 | *

38 | * If an error occurs, null may be returned so that another converter can attempt a conversion. 39 | * 40 | * @param entity Entity as an {@link InputStream}. 41 | * @param contentType Content-Type of the entity. 42 | * @param charset Character set of the entity. 43 | * @return The converted entity. 44 | * @throws Exception when an unexpected error occurs during conversion. 45 | */ 46 | @Override 47 | public Object read(InputStream entity, String contentType, String charset) throws Exception { 48 | return StreamUtils.readBytes(entity); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/mock/MockHttpResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.mock; 17 | 18 | import com.budjb.httprequests.HttpEntity; 19 | import com.budjb.httprequests.HttpRequest; 20 | import com.budjb.httprequests.HttpResponse; 21 | import com.budjb.httprequests.MultiValuedMap; 22 | import com.budjb.httprequests.converter.EntityConverterManager; 23 | 24 | import java.io.IOException; 25 | 26 | /** 27 | * A standalone {@link HttpResponse} implementation where its properties are injected rather 28 | * than read from an HTTP client's response. This is useful for testing scenarios where calls 29 | * to an HTTP client should not necessarily be transmit across the wire. 30 | */ 31 | public class MockHttpResponse extends HttpResponse { 32 | /** 33 | * Constructor. 34 | * 35 | * @param converterManager Converter manager. 36 | * @param request Request properties used to make the request. 37 | * @param status HTTP status of the response. 38 | * @param headers Response headers. 39 | * @param entity Entity of the response. 40 | * @throws IOException When an IO exception occurs. 41 | */ 42 | public MockHttpResponse(EntityConverterManager converterManager, HttpRequest request, int status, MultiValuedMap headers, HttpEntity entity) throws IOException { 43 | super(converterManager, request, status, headers, entity); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/filter/bundled/HttpStatusExceptionFilterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.bundled 18 | 19 | import com.budjb.httprequests.HttpContext 20 | import com.budjb.httprequests.HttpResponse 21 | import com.budjb.httprequests.exception.HttpStatusException 22 | import spock.lang.Specification 23 | 24 | class HttpStatusExceptionFilterSpec extends Specification { 25 | def 'A non-2xx HTTP status code will throw an HttpStatusException'() { 26 | setup: 27 | HttpStatusExceptionFilter filter = new HttpStatusExceptionFilter() 28 | 29 | HttpResponse response = Mock(HttpResponse) 30 | response.getStatus() >> 300 31 | 32 | HttpContext context = new HttpContext() 33 | context.response = response 34 | 35 | when: 36 | filter.onComplete(context) 37 | 38 | then: 39 | thrown HttpStatusException 40 | } 41 | 42 | def 'A 2xx HTTP status code will not throw an HttpStatusException'() { 43 | setup: 44 | HttpStatusExceptionFilter filter = new HttpStatusExceptionFilter() 45 | 46 | HttpResponse response = Mock(HttpResponse) 47 | response.getStatus() >> 201 48 | 49 | HttpContext context = new HttpContext() 50 | context.response = response 51 | 52 | when: 53 | filter.onComplete(context) 54 | 55 | then: 56 | notThrown HttpStatusException 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /http-requests-jackson/src/main/java/com/budjb/httprequests/filter/jackson/JacksonMapWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.jackson; 18 | 19 | import com.budjb.httprequests.converter.EntityWriter; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.InputStream; 24 | import java.util.Map; 25 | 26 | /** 27 | * A map JSON writer that utilizes Jackson. 28 | */ 29 | public class JacksonMapWriter implements EntityWriter { 30 | /** 31 | * Jackson object mapper. 32 | */ 33 | private final ObjectMapper objectMapper; 34 | 35 | /** 36 | * Constructor. 37 | * 38 | * @param objectMapper Jackson object mapper. 39 | */ 40 | public JacksonMapWriter(ObjectMapper objectMapper) { 41 | this.objectMapper = objectMapper; 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public String getContentType() { 49 | return "application/json"; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public boolean supports(Class type) { 57 | return Map.class.isAssignableFrom(type); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public InputStream write(Object entity, String characterSet) throws Exception { 65 | return new ByteArrayInputStream(objectMapper.writeValueAsBytes(entity)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /http-requests-jackson/src/main/java/com/budjb/httprequests/filter/jackson/JacksonListWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.jackson; 18 | 19 | import com.budjb.httprequests.converter.EntityWriter; 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | 22 | import java.io.ByteArrayInputStream; 23 | import java.io.InputStream; 24 | import java.util.List; 25 | 26 | /** 27 | * A list JSON writer that utilizes Jackson. 28 | */ 29 | public class JacksonListWriter implements EntityWriter { 30 | /** 31 | * Jackson object mapper. 32 | */ 33 | private final ObjectMapper objectMapper; 34 | 35 | /** 36 | * Constructor. 37 | * 38 | * @param objectMapper Jackson object mapper. 39 | */ 40 | public JacksonListWriter(ObjectMapper objectMapper) { 41 | this.objectMapper = objectMapper; 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public String getContentType() { 49 | return "application/json"; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public boolean supports(Class type) { 57 | return List.class.isAssignableFrom(type); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public InputStream write(Object entity, String characterSet) throws Exception { 65 | return new ByteArrayInputStream(objectMapper.writeValueAsBytes(entity)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /http-requests-spring/src/main/java/com/budjb/httprequests/spring/EntityConverterConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.spring; 18 | 19 | import com.budjb.httprequests.converter.EntityConverter; 20 | import com.budjb.httprequests.converter.EntityConverterManager; 21 | import com.budjb.httprequests.converter.bundled.*; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | 26 | import java.util.List; 27 | 28 | @Configuration 29 | public class EntityConverterConfiguration { 30 | @Bean 31 | @ConditionalOnMissingBean 32 | public EntityConverterManager entityConverterManager(List entityConverters) { 33 | return new EntityConverterManager(entityConverters); 34 | } 35 | 36 | @Bean 37 | public StringEntityWriter stringEntityWriter() { 38 | return new StringEntityWriter(); 39 | } 40 | 41 | @Bean 42 | public StringEntityReader stringEntityReader() { 43 | return new StringEntityReader(); 44 | } 45 | 46 | @Bean 47 | public ByteArrayEntityWriter byteArrayEntityWriter() { 48 | return new ByteArrayEntityWriter(); 49 | } 50 | 51 | @Bean 52 | public ByteArrayEntityReader byteArrayEntityReader() { 53 | return new ByteArrayEntityReader(); 54 | } 55 | 56 | @Bean 57 | public FormDataEntityWriter formDataEntityWriter() { 58 | return new FormDataEntityWriter(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/groovy/com/budjb/httprequests/HttpsIntegrationTestSuiteSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests 17 | 18 | import com.budjb.httprequests.application.TestApp 19 | import org.springframework.boot.test.context.SpringBootTest 20 | import spock.lang.Ignore 21 | 22 | import javax.net.ssl.SSLException 23 | 24 | @Ignore 25 | @SpringBootTest(classes = TestApp, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = [ 26 | 'server.ssl.key-store=classpath:keystore.jks', 27 | 'server.ssl.key-password=password', 28 | 'spring.mvc.dispatch-trace-request=true' 29 | ]) 30 | abstract class HttpsIntegrationTestSuiteSpec extends AbstractHttpsIntegrationSpec { 31 | def 'Given that the keystore does not contain a localhost cert, when a request is made over SSL with cert validation enabled, an SSL exception is thrown'() { 32 | setup: 33 | HttpClient client = httpClientFactory.createHttpClient() 34 | 35 | when: 36 | client.get(new HttpRequest().setUri("${baseUrl}/test")) 37 | 38 | then: 39 | thrown SSLException 40 | } 41 | 42 | def 'Given that the keystore does not contain a localhost cert, when a request is made over SSL with cert validation disabled, no SSL exception is thrown'() { 43 | setup: 44 | HttpClient client = httpClientFactory.createHttpClient() 45 | 46 | when: 47 | client.get(new HttpRequest().setUri("${baseUrl}/testBasicGet").setSslValidated(false)) 48 | 49 | then: 50 | notThrown SSLException 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /http-requests-mock/src/main/java/com/budjb/httprequests/test/MockHttpClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.test; 17 | 18 | import com.budjb.httprequests.*; 19 | import com.budjb.httprequests.converter.EntityConverterManager; 20 | import com.budjb.httprequests.filter.HttpClientFilterProcessor; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * An implementation of {@link HttpClient} that uses the Jersey Client 1.x library. 26 | */ 27 | public class MockHttpClient extends AbstractHttpClient { 28 | /** 29 | * Mock HTTP client factory. 30 | */ 31 | private final MockHttpClientFactory httpClientFactory; 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param converterManager Entity converter manager. 37 | */ 38 | MockHttpClient(MockHttpClientFactory httpClientFactory, EntityConverterManager converterManager) { 39 | super(converterManager); 40 | this.httpClientFactory = httpClientFactory; 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | protected HttpResponse execute(HttpContext context, HttpEntity entity, HttpClientFilterProcessor filterProcessor) throws IOException { 48 | HttpRequest request = context.getRequest(); 49 | HttpMethod method = context.getMethod(); 50 | 51 | RequestMock mock = httpClientFactory.findMatchingMock(context.getRequest(), context.getMethod()); 52 | 53 | if (mock == null) { 54 | throw new UnmatchedRequestMockException(request, method); 55 | } 56 | 57 | mock.incrementCalled(); 58 | 59 | return new MockHttpResponse(request, getConverterManager(), mock); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/MultiValuedMapSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests 18 | 19 | import spock.lang.Specification 20 | 21 | class MultiValuedMapSpec extends Specification { 22 | def 'Setting a null value to a key that does not exist in the map results in an entry with no value'() { 23 | setup: 24 | MultiValuedMap map = new MultiValuedMap(); 25 | 26 | when: 27 | map.set('foo', null) 28 | 29 | then: 30 | (Map) map == [ 31 | foo: [] 32 | ] 33 | } 34 | 35 | def 'Adding null values to a key that does not exist in the map results in an entry with no value'() { 36 | setup: 37 | MultiValuedMap map = new MultiValuedMap(); 38 | 39 | when: 40 | map.add('foo', null) 41 | 42 | then: 43 | (Map) map == [ 44 | foo: [] 45 | ] 46 | } 47 | 48 | def 'Adding null values to a key with an existing value in the map has no effect'() { 49 | setup: 50 | MultiValuedMap map = new MultiValuedMap(); 51 | map.add('foo', 'bar') 52 | 53 | when: 54 | map.add('foo', null) 55 | 56 | then: 57 | (Map) map == [ 58 | foo: [ 59 | 'bar' 60 | ] 61 | ] 62 | } 63 | 64 | def 'Setting a null value to a key with an existing value in the map results in an entry with no value'() { 65 | setup: 66 | MultiValuedMap map = new MultiValuedMap(); 67 | map.add('foo', 'bar') 68 | 69 | when: 70 | map.set('foo', null) 71 | 72 | then: 73 | (Map) map == [ 74 | foo: [] 75 | ] 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /http-requests-spring/src/main/java/com/budjb/httprequests/spring/JacksonEntityConverterConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.spring; 18 | 19 | import com.budjb.httprequests.filter.jackson.JacksonListReader; 20 | import com.budjb.httprequests.filter.jackson.JacksonListWriter; 21 | import com.budjb.httprequests.filter.jackson.JacksonMapReader; 22 | import com.budjb.httprequests.filter.jackson.JacksonMapWriter; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | @Configuration 30 | @ConditionalOnClass({ObjectMapper.class, JacksonMapWriter.class, JacksonListReader.class, JacksonMapReader.class}) 31 | public class JacksonEntityConverterConfiguration { 32 | @Bean 33 | @ConditionalOnMissingBean 34 | public ObjectMapper objectMapper() { 35 | return new ObjectMapper(); 36 | } 37 | 38 | @Bean 39 | public JacksonMapWriter jacksonMapWriter(ObjectMapper objectMapper) { 40 | return new JacksonMapWriter(objectMapper); 41 | } 42 | 43 | @Bean 44 | public JacksonListWriter jacksonListWriter(ObjectMapper objectMapper) { 45 | return new JacksonListWriter(objectMapper); 46 | } 47 | 48 | @Bean 49 | public JacksonMapReader jacksonMapReader(ObjectMapper objectMapper) { 50 | return new JacksonMapReader(objectMapper); 51 | } 52 | 53 | @Bean 54 | public JacksonListReader jacksonListReader(ObjectMapper objectMapper) { 55 | return new JacksonListReader(objectMapper); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/bundled/ByteArrayEntityWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter.bundled; 17 | 18 | import com.budjb.httprequests.converter.EntityWriter; 19 | 20 | import java.io.ByteArrayInputStream; 21 | import java.io.InputStream; 22 | 23 | public class ByteArrayEntityWriter implements EntityWriter { 24 | /** 25 | * Returns a Content-Type of the converted object that will be set in the HTTP request. 26 | *

27 | * If no Content-Type is known, null is returned. 28 | * 29 | * @return Content-Type of the converted object, or null if unknown. 30 | */ 31 | @Override 32 | public String getContentType() { 33 | return "application/octet-stream"; 34 | } 35 | 36 | /** 37 | * Determines whether the given class type is supported by the writer. 38 | * 39 | * @param type Type to convert. 40 | * @return Whether the type is supported. 41 | */ 42 | @Override 43 | public boolean supports(Class type) { 44 | return type.isArray() && byte.class.isAssignableFrom(type.getComponentType()); 45 | } 46 | 47 | /** 48 | * Convert the given entity. 49 | *

50 | * If an error occurs, null may be returned so that another converter may attempt conversion. 51 | * 52 | * @param entity Entity object to convert into a byte array. 53 | * @param characterSet The character set of the request. 54 | * @return An {@link InputStream} containing the converted entity. 55 | * @throws Exception when an unexpected error occurs. 56 | */ 57 | @Override 58 | public InputStream write(Object entity, String characterSet) throws Exception { 59 | return new ByteArrayInputStream((byte[]) entity); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/bundled/StringEntityReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter.bundled; 17 | 18 | import com.budjb.httprequests.Ordered; 19 | import com.budjb.httprequests.StreamUtils; 20 | import com.budjb.httprequests.converter.EntityReader; 21 | 22 | import java.io.InputStream; 23 | import java.nio.charset.Charset; 24 | 25 | /** 26 | * An entity reader that converts an entity into a String. The character set of the entity is respected. 27 | */ 28 | public class StringEntityReader implements EntityReader, Ordered { 29 | /** 30 | * Determines if the reader supports converting an entity to the given class type. 31 | * 32 | * @param type Type to convert to. 33 | * @return Whether the type is supported. 34 | */ 35 | @Override 36 | public boolean supports(Class type) { 37 | return String.class.isAssignableFrom(type); 38 | } 39 | 40 | /** 41 | * Convert the given entity. 42 | *

43 | * If an error occurs, null may be returned so that another converter can attempt a conversion. 44 | * 45 | * @param entity Entity as an {@link InputStream}. 46 | * @param contentType Content-Type of the entity. 47 | * @param charset Character set of the entity. 48 | * @return The converted entity. 49 | * @throws Exception when an unexpected error occurs during conversion. 50 | */ 51 | @Override 52 | public Object read(InputStream entity, String contentType, String charset) throws Exception { 53 | if (charset == null) { 54 | charset = Charset.defaultCharset().name(); 55 | } 56 | 57 | return StreamUtils.readString(entity, charset); 58 | } 59 | 60 | /** 61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public int getOrder() { 65 | return Ordered.LOWEST_PRIORITY + 10; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /http-requests-core/src/test/groovy/com/budjb/httprequests/filter/bundled/GZIPFilterSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.budjb.httprequests.filter.bundled 18 | 19 | import com.budjb.httprequests.HttpRequest 20 | import com.budjb.httprequests.converter.EntityConverterManager 21 | import com.budjb.httprequests.converter.bundled.StringEntityWriter 22 | import com.budjb.httprequests.exception.EntityConverterException 23 | import com.budjb.httprequests.mock.MockHttpClient 24 | import com.budjb.httprequests.mock.MockHttpClientFactory 25 | import spock.lang.Specification 26 | 27 | class GZIPFilterSpec extends Specification { 28 | def 'When the GZIP filter is used, the input is compressed and the proper header is set'() { 29 | setup: 30 | EntityConverterManager converterManager = new EntityConverterManager([new StringEntityWriter()]) 31 | MockHttpClient client = (MockHttpClient) new MockHttpClientFactory(converterManager).createHttpClient() 32 | HttpRequest request = new HttpRequest('http://foo.bar.com').addFilter(new GZIPFilter()) 33 | 34 | when: 35 | def response = client.post request, 'hi there' 36 | 37 | then: 38 | response.request.getHeaders().get('Content-Encoding') == ['gzip'] 39 | client.requestBuffer == [31, -117, 8, 0, 0, 0, 0, 0, 0, 0] as byte[] 40 | } 41 | 42 | def 'When an IOException occurs, it is wrapped in an EntityConverterException'() { 43 | setup: 44 | GZIPFilter filter = new GZIPFilter() 45 | 46 | OutputStream outputStream = new OutputStream() { 47 | @Override 48 | void write(int b) throws IOException { 49 | throw new IOException("foo") 50 | } 51 | } 52 | 53 | when: 54 | filter.filter(outputStream) 55 | 56 | then: 57 | EntityConverterException exception = thrown EntityConverterException 58 | exception.cause.message == 'foo' 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/filter/LifecycleFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.filter; 17 | 18 | import com.budjb.httprequests.HttpContext; 19 | 20 | /** 21 | * A filter that allows fairly low-level manipulation of the HTTP context throughout 22 | * the various stages of the request lifecycle. Concrete implementations of this 23 | * interface should take care to not adversely interfere with the state of the request. 24 | */ 25 | public interface LifecycleFilter extends HttpClientFilter { 26 | /** 27 | * Called before any processing of the request has started. This is the first callback 28 | * opportunity available during the lifecycle of request processing. 29 | * 30 | * @param context HTTP context. 31 | */ 32 | default void onStart(HttpContext context) { 33 | 34 | } 35 | 36 | /** 37 | * Called immediately before the request is actually executed, and after all filters 38 | * have been applied. 39 | * 40 | * @param context HTTP context. 41 | */ 42 | default void onRequest(HttpContext context) { 43 | 44 | } 45 | 46 | /** 47 | * Called before the response is returned after the request is executed, and after 48 | * all filters have been applied. Note that the request may still be retried if an 49 | * implementation returns true for {@link RetryFilter#isRetryRequired}}. 50 | * 51 | * @param context HTTP context. 52 | */ 53 | default void onResponse(HttpContext context) { 54 | 55 | } 56 | 57 | /** 58 | * Called immediately before the response is returned after the request is executed. 59 | * This method will only be called once no more retries are attempted, and is the 60 | * final callback opportunity before the response is returned to the caller. 61 | * 62 | * @param context HTTP context. 63 | */ 64 | default void onComplete(HttpContext context) { 65 | 66 | } 67 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /http-requests-bom/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/bintray.gradle" 18 | 19 | apply plugin: "java-platform" 20 | apply plugin: 'maven-publish' 21 | 22 | dependencies { 23 | constraints { 24 | api project(':http-requests-core') 25 | api project(':http-requests-groovy') 26 | api project(':http-requests-httpcomponents-client') 27 | api project(':http-requests-mock') 28 | api project(':http-requests-jackson') 29 | api project(':http-requests-jersey1') 30 | api project(':http-requests-jersey2') 31 | api project(':http-requests-spring') 32 | } 33 | } 34 | 35 | publishing { 36 | publications { 37 | library(MavenPublication) { 38 | from components.javaPlatform 39 | 40 | groupId project.group 41 | artifactId project.name 42 | version project.version 43 | 44 | pom { 45 | name = project.name 46 | description = projectDescription 47 | url = githubHttpsUrl 48 | 49 | licenses { 50 | license { 51 | name = 'The Apache License, Version 2.0' 52 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 53 | } 54 | } 55 | developers { 56 | developer { 57 | id = 'budjb' 58 | name = 'Bud Byrd' 59 | email = 'bud.byrd@gmail.com' 60 | } 61 | } 62 | scm { 63 | url = githubHttpsUrl 64 | connection = "scm:git:" + githubHttpsUrl + ".git" 65 | developerConnection = "scm:git:" + githubHttpsUrl + ".git" 66 | } 67 | issueManagement { 68 | system = 'GitHub Issues' 69 | url = githubHttpsUrl + "/issues" 70 | } 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/FormData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * The {@code FormData} class contains a multi-valued map useful for submitting form elements with an HTTP request. 22 | */ 23 | public class FormData { 24 | /** 25 | * Map containing the values of the form. 26 | */ 27 | private MultiValuedMap fields = new MultiValuedMap(); 28 | 29 | /** 30 | * Adds a form field. 31 | * 32 | * @param name Name of the form field. 33 | * @param value Value of the form field. 34 | * @return The same object the method was called on. 35 | */ 36 | public FormData addField(String name, String value) { 37 | fields.add(name, value); 38 | return this; 39 | } 40 | 41 | /** 42 | * Adds a form field with multiple values. 43 | * 44 | * @param name Name of the field to add. 45 | * @param values List of values to add to the field. 46 | * @return The same object the method was called on. 47 | */ 48 | public FormData addField(String name, List values) { 49 | fields.add(name, values); 50 | return this; 51 | } 52 | 53 | /** 54 | * Adds many elements to the form. 55 | * 56 | * @param data A map of fields to add, where the key is the name of the field and the value 57 | * is either a String or a List of Strings. 58 | * @return The same object the method was called on. 59 | */ 60 | public FormData addFields(MultiValuedMap data) { 61 | this.fields.add(data); 62 | return this; 63 | } 64 | 65 | /** 66 | * Return the form elements as a map, where the key is the name of the form field and the value is a list of values 67 | * for the form field, even if there is only one value. 68 | * 69 | * @return All fields in the object. 70 | */ 71 | public MultiValuedMap getFields() { 72 | return fields; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/converters.adoc: -------------------------------------------------------------------------------- 1 | == Entity Converters 2 | 3 | Entity converters are responsible for marshalling request and response entities to and from a byte stream. This 4 | prevents applications from having to make separate calls to helper methods or classes to do the conversion. 5 | 6 | Entity converters are registered with an `EntityConverterManager`, which is a requirement to create an 7 | `HttpClientFactory`. This allows the `HttpClient` to marshal objects to use as request entities. The manager is 8 | subsequently passed to `HttpResponse` objects so that it too may marshal response objects. 9 | 10 | === Entity Readers 11 | 12 | Entity readers are responsible for marshalling the byte stream of a response entity into some other type of object. 13 | Applications can create a new entity reader for a custom object type that contains the logic to read relevant 14 | information from the byte stream and create the custom object from it, bound with the data from the response. 15 | 16 | Entity readers should implement the `EntityReader` interface. 17 | 18 | === Entity Writers 19 | 20 | Entity writers are responsible for marshalling an object into a byte stream for use in a request. Much like entity 21 | readers, entity writers provide applications a method to convert custom objects for use in a request without having to 22 | handle that logic separately from the request call. 23 | 24 | Entity writers should implement the `EntityWriter` interface. 25 | 26 | NOTE: Entity writers have the option to provide a default content type if it was able to marshal the entity. The 27 | default content type is only used if one was not otherwise provided with the entity. 28 | 29 | === Built-In Converters 30 | 31 | The library contains several out of the box entity converters that may be used without including any other dependencies. 32 | 33 | * `ByteArrayEntityReader` 34 | * `ByteArrayEntityWriter` 35 | * `FormDataEntityWriter` 36 | * `StringEntityReader` 37 | * `StringEntityWriter` 38 | 39 | === Jackson Converters 40 | 41 | The `http-requests-jackson` library adds entity converters for `List` and `Map` objects using the 42 | Jackson[https://github.com/FasterXML/jackson] library. The following entity converters are available: 43 | 44 | * `JacksonListReader` 45 | * `JacksonMapReader` 46 | * `JacksonMapListWriter` 47 | 48 | === Groovy Converters 49 | 50 | The `http-requests-groovy` library adds entity converters specific to Groovy class types. The following 51 | entity converters are available: 52 | 53 | * `GStringEntityWriter` 54 | * `JsonEntityWriter` 55 | * `JsonEntityReader` 56 | * `XmlSlurperEntityReader` 57 | 58 | NOTE: If the Groovy JSON converters are in use, the Jackson library is redundant. The groovy variants utilize 59 | `JsonSlurper` and `JsonBuilder`. 60 | -------------------------------------------------------------------------------- /http-requests-documentation/src/docs/components/httpresponse.adoc: -------------------------------------------------------------------------------- 1 | === Handling Responses 2 | 3 | `HttpClient` request methods return an `HttpResponse` object that contains information about the response. 4 | 5 | ==== HttpResponse Properties 6 | 7 | [grid="rows", cols=[1,1,3] 8 | |=== 9 | | Property | Type | Description 10 | 11 | | `status` | `Integer` | HTTP status code of the response. 12 | | `headers` | `MultiValueMap` | Response headers. 13 | | `entity` | `HttpEntity` | Response entity (may be `null`). 14 | |=== 15 | 16 | IMPORTANT: To ensure that all resources used during the request are released, it is critical that the response is 17 | closed via the `HttpResponse.close()` method once the response is no longer needed. 18 | 19 | ==== Response Entities 20 | 21 | The response entity can be retrieved by using the `getEntity()` method of the `HttpResponse`, which return an 22 | `HttpEntity` containing the entity. By default, the response entity, if available, is buffered and the response is 23 | closed. Subsequent calls to retrieve the response entity will reproduce the entity an unlimited amount of times. If the 24 | request properties disabled this functionality, the response's entity can be read only once, but it does not require the memory space to buffer the entity in the `HttpResponse` object. Additionally, it 25 | is important to close the response when this functionality is disabled. 26 | 27 | IMPORTANT: When `bufferResponseEntity` is `false`, it is very important that the `HttpResponse` is closed 28 | when it is no longer needed. If it is not closed, underlying system resources may not be freed up. The `close()` method 29 | can be called on the `HttpResponse` to properly clean up the request. 30 | 31 | The `HttpResponse` supports <> using the `getEntity(Class type)` method. If an 32 | entity reader is registered that supports the requested type, it will be converted and returned. 33 | 34 | .Retrieving the Response Entity as an InputStream 35 | [source,java] 36 | ---- 37 | HttpResponse response = client.get("https://example.com/api/foo_resource"); 38 | 39 | try { 40 | InputStream inputStream = response.getEntity(); 41 | // do some work with the input stream 42 | } 43 | finally { 44 | response.close() 45 | } 46 | ---- 47 | 48 | .Retrieving the Response Entity as a String 49 | [source,java] 50 | ---- 51 | HttpResponse response = client.get("https://example.com/api/foo_resource"); 52 | 53 | try { 54 | String inputStream = response.getEntity(String.class); 55 | } 56 | finally { 57 | response.close(); 58 | } 59 | ---- 60 | 61 | NOTE: The above example assumes that an entity converter that can read the entity into a `String` is registered with 62 | the `EntityConverterManager` that the `HttpClientFactory` was built with. 63 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/converter/bundled/StringEntityWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests.converter.bundled; 17 | 18 | import com.budjb.httprequests.Ordered; 19 | import com.budjb.httprequests.converter.EntityWriter; 20 | 21 | import java.io.ByteArrayInputStream; 22 | import java.io.InputStream; 23 | import java.nio.charset.Charset; 24 | 25 | /** 26 | * An entity writer that converts a String. 27 | */ 28 | public class StringEntityWriter implements EntityWriter, Ordered { 29 | /** 30 | * Returns a Content-Type of the converted object that will be set in the HTTP request. 31 | *

32 | * If no Content-Type is known, null is returned. 33 | * 34 | * @return Content-Type of the converted object, or null if unknown. 35 | */ 36 | @Override 37 | public String getContentType() { 38 | return "text/plain"; 39 | } 40 | 41 | /** 42 | * Determines whether the given class type is supported by the writer. 43 | * 44 | * @param type Type to convert. 45 | * @return Whether the type is supported. 46 | */ 47 | @Override 48 | public boolean supports(Class type) { 49 | return String.class.isAssignableFrom(type); 50 | } 51 | 52 | /** 53 | * Convert the given entity. 54 | *

55 | * If an error occurs, null may be returned so that another converter may attempt conversion. 56 | * 57 | * @param entity Entity object to convert into a byte array. 58 | * @param characterSet The character set of the request. 59 | * @return An {@link InputStream} containing the converted entity. 60 | * @throws Exception when an unexpected error occurs. 61 | */ 62 | @Override 63 | public InputStream write(Object entity, String characterSet) throws Exception { 64 | if (characterSet == null) { 65 | characterSet = Charset.defaultCharset().name(); 66 | } 67 | 68 | return new ByteArrayInputStream(((String) entity).getBytes(characterSet)); 69 | } 70 | 71 | /** 72 | * {@inheritDoc} 73 | */ 74 | @Override 75 | public int getOrder() { 76 | return Ordered.LOWEST_PRIORITY + 10; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /gradle/library-publish.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply from: "${rootDir}/gradle/library.gradle" 18 | apply from: "${rootDir}/gradle/bintray.gradle" 19 | 20 | apply plugin: 'maven-publish' 21 | 22 | task sourcesJar(type: Jar, dependsOn: classes) { 23 | classifier = 'sources' 24 | from sourceSets.main.allSource 25 | } 26 | 27 | task javadocJar(type: Jar, dependsOn: javadoc) { 28 | classifier = 'javadoc' 29 | from javadoc.destinationDir 30 | } 31 | 32 | artifacts { 33 | archives sourcesJar 34 | archives javadocJar 35 | } 36 | 37 | publishing { 38 | publications { 39 | library(MavenPublication) { 40 | from components.java 41 | 42 | artifact sourcesJar 43 | artifact javadocJar 44 | 45 | groupId project.group 46 | artifactId project.name 47 | version project.version 48 | 49 | pom { 50 | name = project.name 51 | description = projectDescription 52 | url = githubHttpsUrl 53 | 54 | licenses { 55 | license { 56 | name = 'The Apache License, Version 2.0' 57 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 58 | } 59 | } 60 | developers { 61 | developer { 62 | id = 'budjb' 63 | name = 'Bud Byrd' 64 | email = 'bud.byrd@gmail.com' 65 | } 66 | } 67 | scm { 68 | url = githubHttpsUrl 69 | connection = "scm:git:" + githubHttpsUrl + ".git" 70 | developerConnection = "scm:git:" + githubHttpsUrl + ".git" 71 | } 72 | issueManagement { 73 | system = 'GitHub Issues' 74 | url = githubHttpsUrl + "/issues" 75 | } 76 | // if (excludeSpringDependencyManagement) { 77 | // withXml { 78 | // asNode().dependencyManagement*.replaceNode {} 79 | // } 80 | // } 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /http-requests-core/src/main/java/com/budjb/httprequests/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests; 17 | 18 | /** 19 | * An enumeration of supported HTTP methods. 20 | */ 21 | public enum HttpMethod { 22 | /** 23 | * HTTP GET. 24 | */ 25 | GET(false, true), 26 | 27 | /** 28 | * HTTP POST. 29 | */ 30 | POST(true, true), 31 | 32 | /** 33 | * HTTP PUT. 34 | */ 35 | PUT(true, true), 36 | 37 | /** 38 | * HTTP DELETE. 39 | */ 40 | DELETE(true, true), 41 | 42 | /** 43 | * HTTP HEAD. 44 | */ 45 | HEAD(true, false), 46 | 47 | /** 48 | * HTTP TRACE. 49 | */ 50 | TRACE(false, true), 51 | 52 | /** 53 | * HTTP OPTIONS. 54 | */ 55 | OPTIONS(true, true), 56 | 57 | /** 58 | * HTTP PATCH. 59 | */ 60 | PATCH(true, true); 61 | 62 | /** 63 | * Whether the method supports a request entity. 64 | */ 65 | private final boolean supportsRequestEntity; 66 | 67 | /** 68 | * Whether the method supports a response entity. 69 | */ 70 | private final boolean supportsResponseEntity; 71 | 72 | /** 73 | * Constructor. 74 | * 75 | * @param supportsRequestEntity Whether the method supports a request entity. 76 | * @param supportsResponseEntity Whether the method supports a response entity. 77 | */ 78 | HttpMethod(boolean supportsRequestEntity, boolean supportsResponseEntity) { 79 | this.supportsRequestEntity = supportsRequestEntity; 80 | this.supportsResponseEntity = supportsResponseEntity; 81 | } 82 | 83 | /** 84 | * Returns whether the method supports a request entity. 85 | * 86 | * @return Whether the method supports a request entity. 87 | */ 88 | public boolean isSupportsRequestEntity() { 89 | return supportsRequestEntity; 90 | } 91 | 92 | /** 93 | * Returns whether the method supports a response entity. 94 | * 95 | * @return Whether the method supports a response entity. 96 | */ 97 | public boolean isSupportsResponseEntity() { 98 | return supportsResponseEntity; 99 | } 100 | } -------------------------------------------------------------------------------- /http-requests-functional-test/src/main/groovy/com/budjb/httprequests/AbstractIntegrationSpec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.budjb.httprequests 17 | 18 | import com.budjb.httprequests.converter.EntityConverterManager 19 | import com.budjb.httprequests.converter.bundled.* 20 | import com.budjb.httprequests.filter.jackson.JacksonListReader 21 | import com.budjb.httprequests.filter.jackson.JacksonListWriter 22 | import com.budjb.httprequests.filter.jackson.JacksonMapReader 23 | import com.budjb.httprequests.filter.jackson.JacksonMapWriter 24 | import com.fasterxml.jackson.databind.ObjectMapper 25 | import org.springframework.beans.factory.annotation.Value 26 | import spock.lang.Ignore 27 | import spock.lang.Specification 28 | 29 | @Ignore 30 | abstract class AbstractIntegrationSpec extends Specification { 31 | /** 32 | * HTTP client factory to use with tests. 33 | */ 34 | HttpClientFactory httpClientFactory 35 | 36 | /** 37 | * The port the spring boot application is running on. 38 | */ 39 | @Value('${local.server.port}') 40 | int webPort 41 | 42 | /** 43 | * Create an HTTP client factory to use with tests. 44 | * 45 | * @return 46 | */ 47 | abstract HttpClientFactory createHttpClientFactory(EntityConverterManager converterManager) 48 | 49 | /** 50 | * Return the base URL of the running server. 51 | * 52 | * @return 53 | */ 54 | String getBaseUrl() { 55 | return "http://localhost:${webPort}" 56 | } 57 | 58 | /** 59 | * Set up the environment for each test. 60 | * 61 | * @return 62 | */ 63 | def setup() { 64 | ObjectMapper objectMapper = new ObjectMapper() 65 | 66 | EntityConverterManager converterManager = new EntityConverterManager([ 67 | new StringEntityReader(), 68 | new StringEntityWriter(), 69 | new ByteArrayEntityWriter(), 70 | new ByteArrayEntityReader(), 71 | new JacksonMapReader(objectMapper), 72 | new JacksonListReader(objectMapper), 73 | new JacksonMapWriter(objectMapper), 74 | new JacksonListWriter(objectMapper), 75 | new FormDataEntityWriter() 76 | ]) 77 | 78 | httpClientFactory = createHttpClientFactory(converterManager) 79 | } 80 | } 81 | --------------------------------------------------------------------------------