| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b4f2cf8 commit fac5e70
20 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,6 @@ | |||
| 1 | + [SNAPSHOT] | ||
| 2 | + * fix Muplipart request model and implement it for a jdk HTTP client (thanks to https://github.com/NTPape) | ||
| 3 | + | ||
| 1 | 4 | [6.2.0] | |
| 2 | 5 | * add new API Microsoft Azure Active Directory (Azure AD) 2.0 (thanks to https://github.com/rzukow and https://github.com/dgrudenic) | |
| 3 | 6 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,7 +68,7 @@ | |||
| 68 | 68 | <dependency> | |
| 69 | 69 | <groupId>com.squareup.okhttp3</groupId> | |
| 70 | 70 | <artifactId>mockwebserver</artifactId> | |
| 71 | - <version>3.12.0</version> | ||
| 71 | + <version>3.12.1</version> | ||
| 72 | 72 | <scope>test</scope> | |
| 73 | 73 | </dependency> | |
| 74 | 74 | </dependencies> | |
@@ -92,7 +92,7 @@ | |||
| 92 | 92 | <plugin> | |
| 93 | 93 | <groupId>org.apache.maven.plugins</groupId> | |
| 94 | 94 | <artifactId>maven-jar-plugin</artifactId> | |
| 95 | - <version>3.1.0</version> | ||
| 95 | + <version>3.1.1</version> | ||
| 96 | 96 | <configuration> | |
| 97 | 97 | <archive> | |
| 98 | 98 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
@@ -107,7 +107,7 @@ | |||
| 107 | 107 | <dependency> | |
| 108 | 108 | <groupId>com.puppycrawl.tools</groupId> | |
| 109 | 109 | <artifactId>checkstyle</artifactId> | |
| 110 | - <version>8.15</version> | ||
| 110 | + <version>8.16</version> | ||
| 111 | 111 | </dependency> | |
| 112 | 112 | </dependencies> | |
| 113 | 113 | </plugin> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,14 +18,27 @@ public Response execute(String userAgent, Map<String, String> headers, Verb http | |||
| 18 | 18 | (OAuthRequest.ResponseConverter<Response>) null).get(); | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | + /** | ||
| 22 | + * @deprecated {@inheritDoc} | ||
| 23 | + */ | ||
| 21 | 24 | @Override | |
| 25 | + @Deprecated | ||
| 22 | 26 | public Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 23 | 27 | MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException { | |
| 24 | 28 | ||
| 25 | 29 | return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, | |
| 26 | 30 | (OAuthRequest.ResponseConverter<Response>) null).get(); | |
| 27 | 31 | } | |
| 28 | 32 | ||
| 33 | + @Override | ||
| 34 | + public Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | ||
| 35 | + com.github.scribejava.core.httpclient.multipart.MultipartPayload bodyContents) | ||
| 36 | + throws InterruptedException, ExecutionException, IOException { | ||
| 37 | + | ||
| 38 | + return executeAsync(userAgent, headers, httpVerb, completeUrl, bodyContents, null, | ||
| 39 | + (OAuthRequest.ResponseConverter<Response>) null).get(); | ||
| 40 | + } | ||
| 41 | + | ||
| 29 | 42 | @Override | |
| 30 | 43 | public Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 31 | 44 | String bodyContents) throws InterruptedException, ExecutionException, IOException { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,27 +1,69 @@ | |||
| 1 | 1 | package com.github.scribejava.core.httpclient; | |
| 2 | 2 | ||
| 3 | + import java.util.Collections; | ||
| 4 | + import java.util.HashMap; | ||
| 5 | + import java.util.Map; | ||
| 6 | + | ||
| 7 | + /** | ||
| 8 | + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.ByteArrayBodyPartPayload} | ||
| 9 | + */ | ||
| 10 | + @Deprecated | ||
| 3 | 11 | public class BodyPartPayload { | |
| 4 | 12 | ||
| 5 | - private final String contentDisposition; | ||
| 6 | - private final String contentType; | ||
| 13 | + private final Map<String, String> headers; | ||
| 7 | 14 | private final byte[] payload; | |
| 8 | 15 | ||
| 9 | - public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { | ||
| 10 | - this.contentDisposition = contentDisposition; | ||
| 11 | - this.contentType = contentType; | ||
| 16 | + public BodyPartPayload(Map<String, String> headers, byte[] payload) { | ||
| 17 | + this.headers = headers; | ||
| 12 | 18 | this.payload = payload; | |
| 13 | 19 | } | |
| 14 | 20 | ||
| 21 | + public BodyPartPayload(String contentDisposition, String contentType, byte[] payload) { | ||
| 22 | + this(createHeadersMap(contentDisposition, contentType), payload); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public BodyPartPayload(String contentDisposition, byte[] payload) { | ||
| 26 | + this(contentDisposition, null, payload); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public Map<String, String> getHeaders() { | ||
| 30 | + return headers; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @return return | ||
| 35 | + * @deprecated use {@link #getHeaders() } and then get("Content-Disposition") | ||
| 36 | + */ | ||
| 37 | + @Deprecated | ||
| 15 | 38 | public String getContentDisposition() { | |
| 16 | - return contentDisposition; | ||
| 39 | + return headers.get("Content-Disposition"); | ||
| 17 | 40 | } | |
| 18 | 41 | ||
| 42 | + /** | ||
| 43 | + * @return return | ||
| 44 | + * @deprecated use {@link #getHeaders() } and then get("Content-Type") | ||
| 45 | + */ | ||
| 46 | + @Deprecated | ||
| 19 | 47 | public String getContentType() { | |
| 20 | - return contentType; | ||
| 48 | + return headers.get(HttpClient.CONTENT_TYPE); | ||
| 21 | 49 | } | |
| 22 | 50 | ||
| 23 | 51 | public byte[] getPayload() { | |
| 24 | 52 | return payload; | |
| 25 | 53 | } | |
| 26 | 54 | ||
| 55 | + private static Map<String, String> createHeadersMap(String contentDisposition, String contentType) { | ||
| 56 | + if (contentDisposition == null && contentType == null) { | ||
| 57 | + return Collections.emptyMap(); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + final Map<String, String> headers = new HashMap<>(); | ||
| 61 | + if (contentDisposition != null) { | ||
| 62 | + headers.put("Content-Disposition", contentDisposition); | ||
| 63 | + } | ||
| 64 | + if (contentType != null) { | ||
| 65 | + headers.put(HttpClient.CONTENT_TYPE, contentType); | ||
| 66 | + } | ||
| 67 | + return headers; | ||
| 68 | + } | ||
| 27 | 69 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | package com.github.scribejava.core.httpclient; | |
| 2 | 2 | ||
| 3 | + import com.github.scribejava.core.httpclient.multipart.MultipartPayload; | ||
| 3 | 4 | import com.github.scribejava.core.model.OAuthAsyncRequestCallback; | |
| 4 | 5 | import com.github.scribejava.core.model.OAuthRequest; | |
| 5 | 6 | import com.github.scribejava.core.model.Response; | |
@@ -20,6 +21,27 @@ public interface HttpClient extends Closeable { | |||
| 20 | 21 | <T> Future<T> executeAsync(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 21 | 22 | byte[] bodyContents, OAuthAsyncRequestCallback<T> callback, OAuthRequest.ResponseConverter<T> converter); | |
| 22 | 23 | ||
| 24 | + /** | ||
| 25 | + * @param <T> T | ||
| 26 | + * @param userAgent userAgent | ||
| 27 | + * @param headers headers | ||
| 28 | + * @param httpVerb httpVerb | ||
| 29 | + * @param completeUrl completeUrl | ||
| 30 | + * @param bodyContents bodyContents | ||
| 31 | + * @param callback callback | ||
| 32 | + * @param converter converter | ||
| 33 | + * @return return | ||
| 34 | + * | ||
| 35 | + * @deprecated use {@link #executeAsync(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, | ||
| 36 | + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload, | ||
| 37 | + * com.github.scribejava.core.model.OAuthAsyncRequestCallback, | ||
| 38 | + * com.github.scribejava.core.model.OAuthRequest.ResponseConverter)} | ||
| 39 | + */ | ||
| 40 | + @Deprecated | ||
| 41 | + <T> Future<T> executeAsync(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | ||
| 42 | + com.github.scribejava.core.httpclient.MultipartPayload bodyContents, OAuthAsyncRequestCallback<T> callback, | ||
| 43 | + OAuthRequest.ResponseConverter<T> converter); | ||
| 44 | + | ||
| 23 | 45 | <T> Future<T> executeAsync(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 24 | 46 | MultipartPayload bodyContents, OAuthAsyncRequestCallback<T> callback, | |
| 25 | 47 | OAuthRequest.ResponseConverter<T> converter); | |
@@ -33,6 +55,24 @@ <T> Future<T> executeAsync(String userAgent, Map<String, String> headers, Verb h | |||
| 33 | 55 | Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 34 | 56 | byte[] bodyContents) throws InterruptedException, ExecutionException, IOException; | |
| 35 | 57 | ||
| 58 | + /** | ||
| 59 | + * @param userAgent userAgent | ||
| 60 | + * @param headers headers | ||
| 61 | + * @param httpVerb httpVerb | ||
| 62 | + * @param completeUrl completeUrl | ||
| 63 | + * @param bodyContents bodyContents | ||
| 64 | + * @return return | ||
| 65 | + * @throws InterruptedException InterruptedException | ||
| 66 | + * @throws ExecutionException ExecutionException | ||
| 67 | + * @throws IOException IOException | ||
| 68 | + * @deprecated use {@link #execute(java.lang.String, java.util.Map, com.github.scribejava.core.model.Verb, | ||
| 69 | + * java.lang.String, com.github.scribejava.core.httpclient.multipart.MultipartPayload)} | ||
| 70 | + */ | ||
| 71 | + @Deprecated | ||
| 72 | + Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | ||
| 73 | + com.github.scribejava.core.httpclient.MultipartPayload bodyContents) | ||
| 74 | + throws InterruptedException, ExecutionException, IOException; | ||
| 75 | + | ||
| 36 | 76 | Response execute(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, | |
| 37 | 77 | MultipartPayload bodyContents) throws InterruptedException, ExecutionException, IOException; | |
| 38 | 78 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,47 +1,80 @@ | |||
| 1 | 1 | package com.github.scribejava.core.httpclient; | |
| 2 | 2 | ||
| 3 | 3 | import java.util.ArrayList; | |
| 4 | + import java.util.Collections; | ||
| 4 | 5 | import java.util.List; | |
| 6 | + import java.util.Map; | ||
| 5 | 7 | ||
| 6 | 8 | /** | |
| 7 | 9 | * The class containing more than one payload of multipart/form-data request | |
| 10 | + * | ||
| 11 | + * @deprecated use {@link com.github.scribejava.core.httpclient.multipart.MultipartPayload} | ||
| 8 | 12 | */ | |
| 13 | + @Deprecated | ||
| 9 | 14 | public class MultipartPayload { | |
| 10 | 15 | ||
| 16 | + private static final String DEFAULT_SUBTYPE = "form-data"; | ||
| 17 | + | ||
| 11 | 18 | private final String boundary; | |
| 19 | + private final Map<String, String> headers; | ||
| 12 | 20 | private final List<BodyPartPayload> bodyParts = new ArrayList<>(); | |
| 13 | 21 | ||
| 14 | 22 | public MultipartPayload(String boundary) { | |
| 15 | 23 | this.boundary = boundary; | |
| 24 | + headers = Collections.singletonMap(HttpClient.CONTENT_TYPE, | ||
| 25 | + "multipart/" + DEFAULT_SUBTYPE + "; boundary=\"" + boundary + '"'); | ||
| 16 | 26 | } | |
| 17 | 27 | ||
| 28 | + /** | ||
| 29 | + * @param bodyPart bodyPart | ||
| 30 | + * @return return | ||
| 31 | + * @deprecated no replace for that. implement yourself. See code here | ||
| 32 | + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient | ||
| 33 | + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} | ||
| 34 | + */ | ||
| 35 | + @Deprecated | ||
| 18 | 36 | public byte[] getStartBoundary(BodyPartPayload bodyPart) { | |
| 19 | - return ("--" + boundary + "\r\n" | ||
| 20 | - + "Content-Disposition: " + bodyPart.getContentDisposition() + "\r\n" | ||
| 21 | - + (bodyPart.getContentType() == null | ||
| 22 | - ? "" : HttpClient.CONTENT_TYPE + ": " + bodyPart.getContentType() + "\r\n") | ||
| 23 | - + "\r\n").getBytes(); | ||
| 37 | + final StringBuilder startBoundary = new StringBuilder(); | ||
| 38 | + startBoundary.append("\r\n--") | ||
| 39 | + .append(boundary) | ||
| 40 | + .append("\r\n"); | ||
| 41 | + | ||
| 42 | + for (Map.Entry<String, String> header : bodyPart.getHeaders().entrySet()) { | ||
| 43 | + startBoundary.append(header.getKey()) | ||
| 44 | + .append(": ") | ||
| 45 | + .append(header.getValue()) | ||
| 46 | + .append("\r\n"); | ||
| 47 | + } | ||
| 48 | + return startBoundary.append("\r\n").toString().getBytes(); | ||
| 24 | 49 | } | |
| 25 | 50 | ||
| 51 | + /** | ||
| 52 | + * @return return | ||
| 53 | + * @deprecated no replace for that. implement yourself. See code here | ||
| 54 | + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient | ||
| 55 | + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} | ||
| 56 | + */ | ||
| 57 | + @Deprecated | ||
| 26 | 58 | public byte[] getEndBoundary() { | |
| 27 | 59 | return ("\r\n--" + boundary + "--\r\n").getBytes(); | |
| 28 | 60 | } | |
| 29 | 61 | ||
| 62 | + /** | ||
| 63 | + * @return return | ||
| 64 | + * @deprecated no replace for that. implement yourself. See code here | ||
| 65 | + * {@link com.github.scribejava.core.httpclient.jdk.JDKHttpClient | ||
| 66 | + * #getPayload(com.github.scribejava.core.httpclient.MultipartPayload)} | ||
| 67 | + */ | ||
| 68 | + @Deprecated | ||
| 30 | 69 | public int getContentLength() { | |
| 31 | 70 | int contentLength = 0; | |
| 71 | + | ||
| 32 | 72 | for (BodyPartPayload bodyPart : bodyParts) { | |
| 33 | - contentLength += bodyPart.getPayload().length | ||
| 34 | - + bodyPart.getContentDisposition().length(); | ||
| 35 | - if (bodyPart.getContentType() != null) { | ||
| 36 | - contentLength += 16 //length of constant portions of contentType header | ||
| 37 | - + bodyPart.getContentType().length(); | ||
| 38 | - } | ||
| 73 | + contentLength += getStartBoundary(bodyPart).length + bodyPart.getPayload().length; | ||
| 74 | + } | ||
| 75 | + if (!bodyParts.isEmpty()) { | ||
| 76 | + contentLength += getEndBoundary().length; | ||
| 39 | 77 | } | |
| 40 | - | ||
| 41 | - contentLength += (37 //length of constant portions of contentDisposition header, | ||
| 42 | - //see getStartBoundary and getEndBoundary methods | ||
| 43 | - + boundary.length() * 2 //twice. start and end parts | ||
| 44 | - ) * bodyParts.size(); //for every part | ||
| 45 | 78 | return contentLength; | |
| 46 | 79 | } | |
| 47 | 80 | ||
@@ -52,4 +85,21 @@ public List<BodyPartPayload> getBodyParts() { | |||
| 52 | 85 | public void addMultipartPayload(String contentDisposition, String contentType, byte[] payload) { | |
| 53 | 86 | bodyParts.add(new BodyPartPayload(contentDisposition, contentType, payload)); | |
| 54 | 87 | } | |
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * @return return | ||
| 91 | + * @deprecated use {@link #getHeaders() } and then get("Content-Type") | ||
| 92 | + */ | ||
| 93 | + @Deprecated | ||
| 94 | + public String getContentType() { | ||
| 95 | + return headers.get(HttpClient.CONTENT_TYPE); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public Map<String, String> getHeaders() { | ||
| 99 | + return headers; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public String getBoundary() { | ||
| 103 | + return boundary; | ||
| 104 | + } | ||
| 55 | 105 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments