| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -21,6 +21,7 @@ | |
| package com.inrupt.client.core; | ||
|
|
||
| import com.inrupt.client.Client; | ||
| import com.inrupt.client.ClientHttpException; | ||
| import com.inrupt.client.Headers.WwwAuthenticate; | ||
| import com.inrupt.client.Request; | ||
| import com.inrupt.client.Response; | ||
| Expand Down Expand Up | @@ -84,6 +85,7 @@ public <T> CompletionStage<Response<T>> send(final Request request, | |
| .map(token -> httpClient.send(upgradeRequest(request, token), responseBodyHandler)) | ||
| // Otherwise perform the regular HTTP authorization dance | ||
| .orElseGet(() -> httpClient.send(request, responseBodyHandler) | ||
| .handle((res, err) -> recover(res, err)) | ||
| .thenCompose(res -> { | ||
| if (res.statusCode() == UNAUTHORIZED) { | ||
| final List<Challenge> challenges = WwwAuthenticate | ||
| Expand Down Expand Up | @@ -126,6 +128,25 @@ Request upgradeRequest(final Request request, final Credential token) { | |
| return builder.build(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCould you reduce suppression from method scope to assignment scope.
Sorry, something went wrong.
All reactions
|
||
| static <T, R extends Throwable> Response<T> recover(final Response<T> res, final Throwable err) throws R { | ||
| if (err != null) { | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityInverting this conditional would reduce indentation of whole method.
Sorry, something went wrong.
All reactions
|
||
| if (err instanceof ClientHttpException) { | ||
| final ClientHttpException ex = (ClientHttpException) err; | ||
| if (ex.getStatusCode() == UNAUTHORIZED) { | ||
| return new NoBodyResponse<T>(ex.getUri(), ex.getStatusCode(), ex.getHeaders()); | ||
| } | ||
| } else if (err.getCause() instanceof ClientHttpException) { | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe error and its cause are inpected, but the hierarchy is not traversed further.
Sorry, something went wrong.
All reactions
|
||
| final ClientHttpException ex = (ClientHttpException) err.getCause(); | ||
| if (ex.getStatusCode() == UNAUTHORIZED) { | ||
| return new NoBodyResponse<T>(ex.getUri(), ex.getStatusCode(), ex.getHeaders()); | ||
| } | ||
|
Comment thread
Comment on lines
+141
to
+143
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDuplicate of above. Might be worth extracting for readability.
Sorry, something went wrong.
All reactions
|
||
| } | ||
| throw (R) err; | ||
| } | ||
| return res; | ||
| } | ||
|
Comment thread
Comment on lines
+132
to
+148
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis new functionality is quite complex and branching.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| public static Client.Builder newBuilder() { | ||
| return new Builder(); | ||
| } | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright Inrupt Inc. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal in | ||
| * the Software without restriction, including without limitation the rights to use, | ||
| * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
| * Software, and to permit persons to whom the Software is furnished to do so, | ||
| * subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
| * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
| package com.inrupt.client.core; | ||
|
|
||
| import com.inrupt.client.Headers; | ||
| import com.inrupt.client.Response; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| class NoBodyResponse<T> implements Response<T> { | ||
|
|
||
| private final Headers responseHeaders; | ||
| private final int responseStatusCode; | ||
| private final URI responseUri; | ||
|
|
||
| public NoBodyResponse(final URI uri, final int statusCode, final Headers headers) { | ||
| this.responseHeaders = headers; | ||
| this.responseStatusCode = statusCode; | ||
| this.responseUri = uri; | ||
| } | ||
|
|
||
| @Override | ||
| public Headers headers() { | ||
| return responseHeaders; | ||
| } | ||
|
|
||
| @Override | ||
| public URI uri() { | ||
| return responseUri; | ||
| } | ||
|
|
||
| @Override | ||
| public int statusCode() { | ||
| return responseStatusCode; | ||
| } | ||
|
|
||
| @Override | ||
| public T body() { | ||
| return (T) null; | ||
| } | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityCould recover be a method reference or are they not available in 8?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI also think an inline comment here would help, just like the explanatory notes above.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.