Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions access-grant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand Down
3 changes: 1 addition & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/java/com/inrupt/client/ProblemDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface ProblemDetails {
/**
* The <a href="https://www.rfc-editor.org/rfc/rfc9457">RFC9457</a> default problem type.
*/
String DEFAULT_TYPE = "about:blank";
URI DEFAULT_TYPE = URI.create("about:blank");

/**
* The problem type.
Expand All @@ -52,10 +52,10 @@ public interface ProblemDetails {
String getTitle();

/**
* The problem details.
* @return the details
* The problem detail.
* @return the detail
*/
String getDetails();
String getDetail();

/**
* The problem status code.
Expand Down
3 changes: 1 addition & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencyManagement>
Expand Down
3 changes: 1 addition & 2 deletions examples/cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</description>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.release>17</maven.compiler.release>

<quarkus.version>3.12.0</quarkus.version>
</properties>
Expand Down
3 changes: 1 addition & 2 deletions examples/spring-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</description>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.release>17</maven.compiler.release>
<springboot.version>3.3.1</springboot.version>
</properties>

Expand Down
3 changes: 1 addition & 2 deletions examples/springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</description>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.release>17</maven.compiler.release>
<springboot.version>3.3.1</springboot.version>
</properties>

Expand Down
3 changes: 1 addition & 2 deletions examples/webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</description>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.release>17</maven.compiler.release>

<quarkus.version>3.12.0</quarkus.version>
</properties>
Expand Down
3 changes: 1 addition & 2 deletions okhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand Down
3 changes: 1 addition & 2 deletions openid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand Down
3 changes: 1 addition & 2 deletions parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand Down
5 changes: 0 additions & 5 deletions quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
Integration utilities for Quarkus support.
</description>

<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
3 changes: 1 addition & 2 deletions rdf-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>

<!-- version management -->
<commons.text.version>1.12.0</commons.text.version>
Expand Down
3 changes: 1 addition & 2 deletions rdf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
<rdf4j.version>5.0.0</rdf4j.version>
</properties>

Expand Down
14 changes: 6 additions & 8 deletions solid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</description>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>8</maven.compiler.release>
</properties>

<dependencies>
Expand All @@ -29,6 +28,11 @@
<artifactId>inrupt-client-vocabulary</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down Expand Up @@ -85,12 +89,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public String getBody() {
* @return the problem details object
*/
public ProblemDetails getProblemDetails() {
return SolidProblemDetails.fromErrorResponse(statusCode, headers, body.getBytes());
return SolidProblemDetails.fromErrorResponse(uri, statusCode, headers, body.getBytes());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SolidProblemDetails implements ProblemDetails {

private static final Logger LOGGER = LoggerFactory.getLogger(SolidProblemDetails.class);
private static final long serialVersionUID = -4597170432270957765L;

private final URI type;
private final String title;
private final String details;
private final String detail;
private final int status;
private final URI instance;
private static JsonService jsonService;
Expand All @@ -47,20 +52,20 @@ public class SolidProblemDetails implements ProblemDetails {
* <a href="https://www.rfc-editor.org/rfc/rfc9457">RFC9457</a>.
* @param type the problem type
* @param title the problem title
* @param details the problem details
* @param detail the problem details
* @param status the error response status code
* @param instance the problem instance
*/
public SolidProblemDetails(
final URI type,
final String title,
final String details,
final String detail,
final int status,
final URI instance
) {
this.type = type;
this.title = title;
this.details = details;
this.detail = detail;
this.status = status;
this.instance = instance;
}
Expand All @@ -76,8 +81,8 @@ public String getTitle() {
}

@Override
public String getDetails() {
return this.details;
public String getDetail() {
return this.detail;
}

@Override
Expand All @@ -103,9 +108,9 @@ static class Data {
*/
public String title;
/**
* The problem details.
* The problem detail.
*/
public String details;
public String detail;
/**
* The problem status code.
*/
Expand Down Expand Up @@ -133,51 +138,30 @@ private static JsonService getJsonService() {

/**
* Builds a {@link ProblemDetails} instance from an HTTP error response.
* @param uri the original URI
* @param statusCode the HTTP error response status code
* @param headers the HTTP error response headers
* @param body the HTTP error response body
* @return a {@link ProblemDetails} instance
*/
public static SolidProblemDetails fromErrorResponse(
final int statusCode,
final Headers headers,
final byte[] body
) {
static SolidProblemDetails fromErrorResponse(final URI uri, final int statusCode, final Headers headers,
final byte[] body) {
final JsonService jsonService = getJsonService();
if (jsonService == null
|| (headers != null && !headers.allValues("Content-Type").contains(ProblemDetails.MIME_TYPE))) {
return new SolidProblemDetails(
URI.create(ProblemDetails.DEFAULT_TYPE),
null,
null,
statusCode,
null
);
}
try {
final Data pdData = jsonService.fromJson(
new ByteArrayInputStream(body),
Data.class
);
final URI type = Optional.ofNullable(pdData.type)
.orElse(URI.create(ProblemDetails.DEFAULT_TYPE));
// JSON mappers map invalid integers to 0, which is an invalid value in our case anyway.
final int status = Optional.of(pdData.status).filter(s -> s != 0).orElse(statusCode);
return new SolidProblemDetails(
type,
pdData.title,
pdData.details,
status,
pdData.instance
);
} catch (IOException e) {
return new SolidProblemDetails(
URI.create(ProblemDetails.DEFAULT_TYPE),
null,
null,
statusCode,
null
);
if (jsonService != null
&& (headers != null && headers.allValues("Content-Type").contains(ProblemDetails.MIME_TYPE))) {
try (final InputStream input = new ByteArrayInputStream(body)) {
final Data pdData = jsonService.fromJson(input, Data.class);
final URI type = Optional.ofNullable(pdData.type)
.map(uri::resolve)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is required for the instance URI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 89c65a3

.orElse(ProblemDetails.DEFAULT_TYPE);
final URI instance = pdData.instance != null ? uri.resolve(pdData.instance) : null;
// JSON mappers map invalid integers to 0, which is an invalid value in our case anyway.
final int status = Optional.of(pdData.status).filter(s -> s != 0).orElse(statusCode);
return new SolidProblemDetails(type, pdData.title, pdData.detail, status, instance);
} catch (IOException e) {
LOGGER.debug("Unable to parse ProblemDetails response from server", e);
}
}
return new SolidProblemDetails(ProblemDetails.DEFAULT_TYPE, null, null, statusCode, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ public int statusCode() {
assertEquals(statusCode, exception.getStatusCode());
// The following assertions check that in absence of an RFC9457 compliant response, we properly initialize the
// default values for the attached Problem Details.
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType().toString());
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType());
assertEquals(statusCode, exception.getProblemDetails().getStatus());
assertNull(exception.getProblemDetails().getTitle());
assertNull(exception.getProblemDetails().getDetails());
assertNull(exception.getProblemDetails().getDetail());
assertNull(exception.getProblemDetails().getInstance());
}

Expand Down Expand Up @@ -487,7 +487,7 @@ public int statusCode() {
assertEquals(problemDetails.getType(), exception.getProblemDetails().getType());
assertEquals(problemDetails.getTitle(), exception.getProblemDetails().getTitle());
assertEquals(problemDetails.getStatus(), exception.getProblemDetails().getStatus());
assertEquals(problemDetails.getDetails(), exception.getProblemDetails().getDetails());
assertEquals(problemDetails.getDetail(), exception.getProblemDetails().getDetail());
assertEquals(problemDetails.getInstance(), exception.getProblemDetails().getInstance());
}

Expand Down Expand Up @@ -606,10 +606,10 @@ public int statusCode() {
);
assertEquals(statusCode, exception.getStatusCode());
// On malformed response, the ProblemDetails should fall back to defaults.
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType().toString());
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType());
assertNull(exception.getProblemDetails().getTitle());
assertEquals(statusCode, exception.getProblemDetails().getStatus());
assertNull(exception.getProblemDetails().getDetails());
assertNull(exception.getProblemDetails().getDetail());
assertNull(exception.getProblemDetails().getInstance());
}

Expand Down Expand Up @@ -653,10 +653,10 @@ public int statusCode() {
);
assertEquals(statusCode, exception.getStatusCode());
// On malformed response, the ProblemDetails should fall back to defaults.
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType().toString());
assertEquals(ProblemDetails.DEFAULT_TYPE, exception.getProblemDetails().getType());
assertNull(exception.getProblemDetails().getTitle());
assertEquals(statusCode, exception.getProblemDetails().getStatus());
assertNull(exception.getProblemDetails().getDetails());
assertNull(exception.getProblemDetails().getDetail());
assertNull(exception.getProblemDetails().getInstance());
}
}
Loading