FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support protected resources with RDF body handlers by acoburn · Pull Request #1248 · inrupt/solid-client-java · GitHub

Repository navigation

Support protected resources with RDF body handlers - #1248

Closed
acoburn wants to merge 3 commits into
mainfrom
rework-rdf-handlers
Closed

acoburn wants to merge 3 commits into
mainfrom
rework-rdf-handlers

Conversation

acoburn commented May 6, 2024

Copy link
Copy Markdown
Contributor

With the current code, it is not possible to use the ofJenaModel (and similar) method on protected resources, because the code will throw an exception at the first 401, interfering with the reactive style of the JCL

acoburn requested a review from a team as a code owner May 6, 2024 21:18
acoburn marked this pull request as draft May 7, 2024 01:30
acoburn marked this pull request as ready for review May 7, 2024 13:15
acoburn enabled auto-merge (squash) May 7, 2024 14:20
return builder.build();
}

@SuppressWarnings("unchecked")

Copy link
Copy Markdown
Contributor

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 Quality

Could you reduce suppression from method scope to assignment scope.

Comment on lines +141 to +143
if (ex.getStatusCode() == UNAUTHORIZED) {
return new NoBodyResponse<T>(ex.getUri(), ex.getStatusCode(), ex.getHeaders());
}

Copy link
Copy Markdown
Contributor

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 Quality

Duplicate of above. Might be worth extracting for readability.


@SuppressWarnings("unchecked")
static <T, R extends Throwable> Response<T> recover(final Response<T> res, final Throwable err) throws R {
if (err != null) {

Copy link
Copy Markdown
Contributor

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 Quality

Inverting this conditional would reduce indentation of whole method.

.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))

Copy link
Copy Markdown
Contributor

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 Quality

Could recover be a method reference or are they not available in 8?

Copy link
Copy Markdown
Contributor

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 Quality

I also think an inline comment here would help, just like the explanatory notes above.

if (ex.getStatusCode() == UNAUTHORIZED) {
return new NoBodyResponse<T>(ex.getUri(), ex.getStatusCode(), ex.getHeaders());
}
} else if (err.getCause() instanceof ClientHttpException) {

Copy link
Copy Markdown
Contributor

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 Quality

The error and its cause are inpected, but the hierarchy is not traversed further.
I'm sure this is accurate vis a vis our architecture, but it feels off.
I think an explanation with inline comments would be good.

Comment on lines +132 to +148
static <T, R extends Throwable> Response<T> recover(final Response<T> res, final Throwable err) throws R {
if (err != null) {
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) {
final ClientHttpException ex = (ClientHttpException) err.getCause();
if (ex.getStatusCode() == UNAUTHORIZED) {
return new NoBodyResponse<T>(ex.getUri(), ex.getStatusCode(), ex.getHeaders());
}
}
throw (R) err;
}
return res;
}

Copy link
Copy Markdown
Contributor

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 Quality

This new functionality is quite complex and branching.
Would it not make sense to add tests that highlight its behavior specifically?

acoburn commented May 8, 2024

Copy link
Copy Markdown
Contributor Author

An alternative approach is implemented in #1253

acoburn changed the title Proper handling of protected resources with RDF body handlers Support protected resources with RDF body handlers May 8, 2024
acoburn disabled auto-merge May 8, 2024 22:08
acoburn marked this pull request as draft May 8, 2024 22:08

Copy link
Copy Markdown
Contributor

This is not directly related to this PR in particular, but should we update the integration tests so that this would have been caught before getting merged?

acoburn commented May 15, 2024

Copy link
Copy Markdown
Contributor Author

This is not directly related to this PR in particular, but should we update the integration tests so that this would have been caught before getting merged?

The issue is that there were new methods introduced. Those new methods were not part of the integration tests, and it was only when I changed the old methods in those integration tests to the new methods that I discovered the implementation problem.

acoburn closed this May 15, 2024
acoburn deleted the rework-rdf-handlers branch May 15, 2024 15:16

acoburn commented May 15, 2024

Copy link
Copy Markdown
Contributor Author

Closed in favor of #1253

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL