From 16a614381b8ab3c3428823e649c05a890fe114dc Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Thu, 4 Apr 2024 11:26:34 +0200 Subject: [PATCH 01/14] Data classes for HTTP Problem Details support Initial ClientHttpException class Create HTTP status enum Add some tests Add javadoc Refactor HttpStatus Add specialized builder to ProblemDetails Add missing header Make problem details parsing more resilient Add tests for problem details parsing The tests are in the solid-client module, because it will need the additional json service anyways in the test dependencies for testing the rest of this feature, and putting these tests in the api module creates a circular dependency. License header --- .../inrupt/client/ClientHttpException.java | 54 ++++++ .../java/com/inrupt/client/HttpStatus.java | 80 +++++++++ .../com/inrupt/client/ProblemDetails.java | 132 ++++++++++++++ .../com/inrupt/client/HttpStatusTest.java | 63 +++++++ solid/pom.xml | 6 + .../client/solid/ProblemDetailsTest.java | 164 ++++++++++++++++++ 6 files changed, 499 insertions(+) create mode 100644 api/src/main/java/com/inrupt/client/ClientHttpException.java create mode 100644 api/src/main/java/com/inrupt/client/HttpStatus.java create mode 100644 api/src/main/java/com/inrupt/client/ProblemDetails.java create mode 100644 api/src/test/java/com/inrupt/client/HttpStatusTest.java create mode 100644 solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java diff --git a/api/src/main/java/com/inrupt/client/ClientHttpException.java b/api/src/main/java/com/inrupt/client/ClientHttpException.java new file mode 100644 index 00000000000..d2401e3cbc2 --- /dev/null +++ b/api/src/main/java/com/inrupt/client/ClientHttpException.java @@ -0,0 +1,54 @@ +/* + * 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; + +/** + * A runtime exception representing an HTTP error response carrying a structured representation of the problem. The + * problem description is embedded in a {@link ProblemDetails} instance. + */ +public class ClientHttpException extends InruptClientException { + private final ProblemDetails problemDetails; + + /** + * Create a ClientHttpException. + * @param problemDetails the {@link ProblemDetails} instance + * @param message the exception message + */ + public ClientHttpException(final ProblemDetails problemDetails, final String message) { + super(message); + this.problemDetails = problemDetails; + } + + /** + * Create a ClientHttpException. + * @param problemDetails the {@link ProblemDetails} instance + * @param message the exception message + * @param cause a wrapped exception cause + */ + public ClientHttpException(final ProblemDetails problemDetails, final String message, final Exception cause) { + super(message, cause); + this.problemDetails = problemDetails; + } + + public ProblemDetails getProblemDetails() { + return this.problemDetails; + } +} diff --git a/api/src/main/java/com/inrupt/client/HttpStatus.java b/api/src/main/java/com/inrupt/client/HttpStatus.java new file mode 100644 index 00000000000..193c14edcf2 --- /dev/null +++ b/api/src/main/java/com/inrupt/client/HttpStatus.java @@ -0,0 +1,80 @@ +/* + * 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; + +import java.util.Arrays; + +public final class HttpStatus { + + public static final int BAD_REQUEST = 400; + public static final int UNAUTHORIZED = 401; + public static final int FORBIDDEN = 403; + public static final int NOT_FOUND = 404; + public static final int METHOD_NOT_ALLOWED = 405; + public static final int NOT_ACCEPTABLE = 406; + public static final int CONFLICT = 409; + public static final int GONE = 410; + public static final int PRECONDITION_FAILED = 412; + public static final int UNSUPPORTED_MEDIA_TYPE = 415; + public static final int TOO_MANY_REQUESTS = 429; + public static final int INTERNAL_SERVER_ERROR = 500; + + enum StatusMessages { + BAD_REQUEST(HttpStatus.BAD_REQUEST, "Bad Request"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "Unauthorized"), + FORBIDDEN(HttpStatus.FORBIDDEN, "Forbidden"), + NOT_FOUND(HttpStatus.NOT_FOUND, "Not Found"), + METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, "Method Not Allowed"), + NOT_ACCEPTABLE(HttpStatus.NOT_ACCEPTABLE, "Not Acceptable"), + CONFLICT(HttpStatus.CONFLICT, "Conflict"), + GONE(HttpStatus.GONE, "Gone"), + PRECONDITION_FAILED(HttpStatus.PRECONDITION_FAILED, "Precondition Failed"), + UNSUPPORTED_MEDIA_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"), + TOO_MANY_REQUESTS(HttpStatus.TOO_MANY_REQUESTS, "Too Many Requests"), + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error"); + + private final int code; + final String message; + + StatusMessages(final int code, final String message) { + this.code = code; + this.message = message; + } + + static String getStatusMessage(final int statusCode) { + return Arrays.stream(StatusMessages.values()) + .filter(status -> status.code == statusCode) + .findFirst() + .map(knownStatus -> knownStatus.message) + .orElseGet(() -> { + // If the status is unknown, default to 400 for client errors and 500 for server errors + if (statusCode >= 400 && statusCode <= 499) { + return BAD_REQUEST.message; + } + return INTERNAL_SERVER_ERROR.message; + }); + } + } + + private HttpStatus() { + // noop + } +} diff --git a/api/src/main/java/com/inrupt/client/ProblemDetails.java b/api/src/main/java/com/inrupt/client/ProblemDetails.java new file mode 100644 index 00000000000..becf9edc2da --- /dev/null +++ b/api/src/main/java/com/inrupt/client/ProblemDetails.java @@ -0,0 +1,132 @@ +/* + * 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; + +import com.inrupt.client.spi.JsonService; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * A data class representing a structured problem description sent by the server on error response. + * + * @see RFC 9457 Problem Details for HTTP APIs + */ +public class ProblemDetails { + public static final String MIME_TYPE = "application/problem+json"; + public static final String DEFAULT_TYPE = "about:blank"; + private final URI type; + private final String title; + private final String details; + private final int status; + private final URI instance; + + public ProblemDetails( + final URI type, + final String title, + final String details, + final int status, + final URI instance + ) { + // The `type` is not mandatory in RFC9457, so we want to set + // a default value here even when deserializing from JSON. + if (type != null) { + this.type = type; + } else { + this.type = URI.create(DEFAULT_TYPE); + } + this.title = title; + this.details = details; + this.status = status; + this.instance = instance; + } + + public URI getType() { + return this.type; + }; + + public String getTitle() { + return this.title; + }; + + public String getDetails() { + return this.details; + }; + + public int getStatus() { + return this.status; + }; + + public URI getInstance() { + return this.instance; + }; + + public static ProblemDetails fromErrorResponse( + final int statusCode, + final Headers headers, + final byte[] body, + final JsonService jsonService + ) { + if (jsonService == null + || (headers != null && !headers.allValues("Content-Type").contains(ProblemDetails.MIME_TYPE))) { + return new ProblemDetails( + null, + HttpStatus.StatusMessages.getStatusMessage(statusCode), + null, + statusCode, + null + ); + } + try { + // ProblemDetails doesn't have a default constructor, and we can't use JSON mapping annotations because + // the JSON service is an abstraction over JSON-B and Jackson, so we deserialize the JSON object in a Map + // and build the ProblemDetails from the Map values. + final Map pdData = jsonService.fromJson( + new ByteArrayInputStream(body), + new HashMap(){}.getClass().getGenericSuperclass() + ); + final String title = Optional.ofNullable((String) pdData.get("title")) + .orElse(HttpStatus.StatusMessages.getStatusMessage(statusCode)); + final String details = (String) pdData.get("details"); + final URI type = Optional.ofNullable((String) pdData.get("type")) + .map(URI::create) + .orElse(null); + final URI instance = Optional.ofNullable((String) pdData.get("instance")) + .map(URI::create) + .orElse(null); + // Note that the status code is disregarded from the body, and reused from the HTTP response directly, + // as they must be the same as per https://www.rfc-editor.org/rfc/rfc9457.html#name-status. + return new ProblemDetails(type, title, details, statusCode, instance); + } catch (IOException e) { + return new ProblemDetails( + null, + HttpStatus.StatusMessages.getStatusMessage(statusCode), + null, + statusCode, + null + ); + } + } +} diff --git a/api/src/test/java/com/inrupt/client/HttpStatusTest.java b/api/src/test/java/com/inrupt/client/HttpStatusTest.java new file mode 100644 index 00000000000..35126cb23c0 --- /dev/null +++ b/api/src/test/java/com/inrupt/client/HttpStatusTest.java @@ -0,0 +1,63 @@ +/* + * 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; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class HttpStatusTest { + @Test + void checkHttpStatusSearchKnownStatus() { + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(HttpStatus.NOT_FOUND), + HttpStatus.StatusMessages.NOT_FOUND.message + ); + } + + @Test + void checkHttpStatusSearchUnknownClientError () { + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(418), + HttpStatus.StatusMessages.BAD_REQUEST.message + ); + } + + @Test + void checkHttpStatusSearchUnknownServerError () { + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(555), + HttpStatus.StatusMessages.INTERNAL_SERVER_ERROR.message + ); + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(999), + HttpStatus.StatusMessages.INTERNAL_SERVER_ERROR.message + ); + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(-1), + HttpStatus.StatusMessages.INTERNAL_SERVER_ERROR.message + ); + assertEquals( + HttpStatus.StatusMessages.getStatusMessage(15), + HttpStatus.StatusMessages.INTERNAL_SERVER_ERROR.message + ); + } +} diff --git a/solid/pom.xml b/solid/pom.xml index 15163ab2e65..3be4e20184b 100644 --- a/solid/pom.xml +++ b/solid/pom.xml @@ -79,6 +79,12 @@ ${project.version} test + + com.inrupt.client + inrupt-client-jackson + ${project.version} + test + org.slf4j slf4j-api diff --git a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java new file mode 100644 index 00000000000..b013b2999fa --- /dev/null +++ b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java @@ -0,0 +1,164 @@ +/* + * 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.solid; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import com.inrupt.client.Headers; +import com.inrupt.client.ProblemDetails; +import com.inrupt.client.spi.JsonService; +import com.inrupt.client.spi.ServiceProvider; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +// Ideally, this class should be in the api module, but it creates +// a circular dependency with the JSON module implementation. +public class ProblemDetailsTest { + Headers mockProblemDetailsHeader() { + final List headerValues = new ArrayList<>(); + headerValues.add("application/problem+json"); + final Map> headerMap = new HashMap<>(); + headerMap.put("Content-Type", headerValues); + return Headers.of(headerMap); + } + + final JsonService jsonService = ServiceProvider.getJsonService(); + @Test + void testEmptyProblemDetails() { + final int statusCode = 400; + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + statusCode, + mockProblemDetailsHeader(), + "{}".getBytes(), + jsonService + ); + assertEquals(ProblemDetails.DEFAULT_TYPE, pd.getType().toString()); + assertEquals(statusCode, pd.getStatus()); + Assertions.assertEquals("Bad Request", pd.getTitle()); + assertNull(pd.getDetails()); + assertNull(pd.getInstance()); + } + @Test + void testCompleteProblemDetails() { + final int statusCode = 400; + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + statusCode, + mockProblemDetailsHeader(), + ("{" + + "\"title\":\"Some title\"," + + "\"status\":400," + + "\"details\":\"Some details\"," + + "\"instance\":\"https://example.org/instance\"," + + "\"type\":\"https://example.org/type\"" + + "}").getBytes(), + jsonService + ); + assertEquals("https://example.org/type", pd.getType().toString()); + assertEquals(statusCode, pd.getStatus()); + Assertions.assertEquals("Some title", pd.getTitle()); + assertEquals("Some details", pd.getDetails()); + assertEquals("https://example.org/instance", pd.getInstance().toString()); + } + + @Test + void testIgnoreUnknownProblemDetails() { + final int statusCode = 400; + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + statusCode, + mockProblemDetailsHeader(), + ("{" + + "\"title\":\"Some title\"," + + "\"status\":400," + + "\"details\":\"Some details\"," + + "\"instance\":\"https://example.org/instance\"," + + "\"type\":\"https://example.org/type\"," + + "\"unknown\":\"Some unknown property\"" + + "}").getBytes(), + jsonService + ); + assertEquals("https://example.org/type", pd.getType().toString()); + assertEquals(statusCode, pd.getStatus()); + Assertions.assertEquals("Some title", pd.getTitle()); + assertEquals("Some details", pd.getDetails()); + assertEquals("https://example.org/instance", pd.getInstance().toString()); + } + + @Test + void testInvalidStatusProblemDetails() { + final int statusCode = 400; + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + statusCode, + mockProblemDetailsHeader(), + ("{" + + "\"status\":\"Some invalid status\"," + + "}").getBytes(), + jsonService + ); + assertEquals(statusCode, pd.getStatus()); + } + + @Test + void testMismatchingStatusProblemDetails() { + final int statusCode = 400; + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + statusCode, + mockProblemDetailsHeader(), + ("{" + + "\"status\":500," + + "}").getBytes(), + jsonService + ); + assertEquals(statusCode, pd.getStatus()); + } + + @Test + void testInvalidTypeProblemDetails() { + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + 400, + mockProblemDetailsHeader(), + ("{" + + "\"type\":\"Some invalid type\"," + + "}").getBytes(), + jsonService + ); + assertEquals(ProblemDetails.DEFAULT_TYPE, pd.getType().toString()); + } + + @Test + void testInvalidInstanceProblemDetails() { + final ProblemDetails pd = ProblemDetails.fromErrorResponse( + 400, + mockProblemDetailsHeader(), + ("{" + + "\"instance\":\"Some invalid instance\"," + + "}").getBytes(), + jsonService + ); + assertNull(pd.getInstance()); + } +} From 7a59d45e5e05d59ad48246a5c77f02d26183325f Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 22:45:41 +0200 Subject: [PATCH 02/14] Use typed JSON deserialization --- .../com/inrupt/client/ProblemDetails.java | 43 ++++++--------- .../com/inrupt/client/ProblemDetailsData.java | 55 +++++++++++++++++++ 2 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 api/src/main/java/com/inrupt/client/ProblemDetailsData.java diff --git a/api/src/main/java/com/inrupt/client/ProblemDetails.java b/api/src/main/java/com/inrupt/client/ProblemDetails.java index becf9edc2da..65d512db343 100644 --- a/api/src/main/java/com/inrupt/client/ProblemDetails.java +++ b/api/src/main/java/com/inrupt/client/ProblemDetails.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.util.HashMap; import java.util.Map; @@ -50,13 +51,7 @@ public ProblemDetails( final int status, final URI instance ) { - // The `type` is not mandatory in RFC9457, so we want to set - // a default value here even when deserializing from JSON. - if (type != null) { - this.type = type; - } else { - this.type = URI.create(DEFAULT_TYPE); - } + this.type = type; this.title = title; this.details = details; this.status = status; @@ -92,7 +87,7 @@ public static ProblemDetails fromErrorResponse( if (jsonService == null || (headers != null && !headers.allValues("Content-Type").contains(ProblemDetails.MIME_TYPE))) { return new ProblemDetails( - null, + URI.create(ProblemDetails.DEFAULT_TYPE), HttpStatus.StatusMessages.getStatusMessage(statusCode), null, statusCode, @@ -100,28 +95,26 @@ public static ProblemDetails fromErrorResponse( ); } try { - // ProblemDetails doesn't have a default constructor, and we can't use JSON mapping annotations because - // the JSON service is an abstraction over JSON-B and Jackson, so we deserialize the JSON object in a Map - // and build the ProblemDetails from the Map values. - final Map pdData = jsonService.fromJson( + final ProblemDetailsData pdData = jsonService.fromJson( new ByteArrayInputStream(body), - new HashMap(){}.getClass().getGenericSuperclass() + ProblemDetailsData.class ); - final String title = Optional.ofNullable((String) pdData.get("title")) + final URI type = Optional.ofNullable(pdData.getType()) + .orElse(URI.create(ProblemDetails.DEFAULT_TYPE)); + final String title = Optional.ofNullable(pdData.getTitle()) .orElse(HttpStatus.StatusMessages.getStatusMessage(statusCode)); - final String details = (String) pdData.get("details"); - final URI type = Optional.ofNullable((String) pdData.get("type")) - .map(URI::create) - .orElse(null); - final URI instance = Optional.ofNullable((String) pdData.get("instance")) - .map(URI::create) - .orElse(null); - // Note that the status code is disregarded from the body, and reused from the HTTP response directly, - // as they must be the same as per https://www.rfc-editor.org/rfc/rfc9457.html#name-status. - return new ProblemDetails(type, title, details, statusCode, instance); + // JSON mappers map invalid integers to 0, which is an invalid value in our case anyway. + final int status = Optional.of(pdData.getStatus()).filter(s -> s != 0).orElse(statusCode); + return new ProblemDetails( + type, + title, + pdData.getDetails(), + status, + pdData.getInstance() + ); } catch (IOException e) { return new ProblemDetails( - null, + URI.create(ProblemDetails.DEFAULT_TYPE), HttpStatus.StatusMessages.getStatusMessage(statusCode), null, statusCode, diff --git a/api/src/main/java/com/inrupt/client/ProblemDetailsData.java b/api/src/main/java/com/inrupt/client/ProblemDetailsData.java new file mode 100644 index 00000000000..fde3f633764 --- /dev/null +++ b/api/src/main/java/com/inrupt/client/ProblemDetailsData.java @@ -0,0 +1,55 @@ +package com.inrupt.client; + +import java.net.URI; + +/** + * This package-private mutable class is used for JSON deserialization. + * Once instantiated, it is used to build an immutable {@link ProblemDetails}. + */ +class ProblemDetailsData { + private URI type; + private String title; + private String details; + private int status; + private URI instance; + + public URI getType() { + return this.type; + }; + + public String getTitle() { + return this.title; + }; + + public String getDetails() { + return this.details; + }; + + public int getStatus() { + return this.status; + }; + + public URI getInstance() { + return this.instance; + }; + + public void setType(URI type) { + this.type = type; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setDetails(String details) { + this.details = details; + } + + public void setStatus(int status) { + this.status = status; + } + + public void setInstance(URI instance) { + this.instance = instance; + } +} From 2ed0a03ba49d8c5fac59e0f01ae37ee3e545798c Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 22:57:08 +0200 Subject: [PATCH 03/14] =?UTF-8?q?Move=20JSON=20service=20discovery=20in=20?= =?UTF-8?q?ProblemDetails=C2=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/inrupt/client/ProblemDetails.java | 14 +++++++++---- .../client/solid/ProblemDetailsTest.java | 21 +++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/com/inrupt/client/ProblemDetails.java b/api/src/main/java/com/inrupt/client/ProblemDetails.java index 65d512db343..0af2f4cf338 100644 --- a/api/src/main/java/com/inrupt/client/ProblemDetails.java +++ b/api/src/main/java/com/inrupt/client/ProblemDetails.java @@ -21,6 +21,7 @@ package com.inrupt.client; import com.inrupt.client.spi.JsonService; +import com.inrupt.client.spi.ServiceProvider; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -43,6 +44,7 @@ public class ProblemDetails { private final String details; private final int status; private final URI instance; + private static JsonService jsonService; public ProblemDetails( final URI type, @@ -81,10 +83,14 @@ public URI getInstance() { public static ProblemDetails fromErrorResponse( final int statusCode, final Headers headers, - final byte[] body, - final JsonService jsonService + final byte[] body ) { - if (jsonService == null + try { + ProblemDetails.jsonService = ServiceProvider.getJsonService(); + } catch (IllegalStateException e) { + ProblemDetails.jsonService = null; + } + if (ProblemDetails.jsonService == null || (headers != null && !headers.allValues("Content-Type").contains(ProblemDetails.MIME_TYPE))) { return new ProblemDetails( URI.create(ProblemDetails.DEFAULT_TYPE), @@ -95,7 +101,7 @@ public static ProblemDetails fromErrorResponse( ); } try { - final ProblemDetailsData pdData = jsonService.fromJson( + final ProblemDetailsData pdData = ProblemDetails.jsonService.fromJson( new ByteArrayInputStream(body), ProblemDetailsData.class ); diff --git a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java index b013b2999fa..63bfeac46f2 100644 --- a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java @@ -54,8 +54,7 @@ void testEmptyProblemDetails() { final ProblemDetails pd = ProblemDetails.fromErrorResponse( statusCode, mockProblemDetailsHeader(), - "{}".getBytes(), - jsonService + "{}".getBytes() ); assertEquals(ProblemDetails.DEFAULT_TYPE, pd.getType().toString()); assertEquals(statusCode, pd.getStatus()); @@ -75,8 +74,7 @@ void testCompleteProblemDetails() { "\"details\":\"Some details\"," + "\"instance\":\"https://example.org/instance\"," + "\"type\":\"https://example.org/type\"" + - "}").getBytes(), - jsonService + "}").getBytes() ); assertEquals("https://example.org/type", pd.getType().toString()); assertEquals(statusCode, pd.getStatus()); @@ -98,8 +96,7 @@ void testIgnoreUnknownProblemDetails() { "\"instance\":\"https://example.org/instance\"," + "\"type\":\"https://example.org/type\"," + "\"unknown\":\"Some unknown property\"" + - "}").getBytes(), - jsonService + "}").getBytes() ); assertEquals("https://example.org/type", pd.getType().toString()); assertEquals(statusCode, pd.getStatus()); @@ -116,8 +113,7 @@ void testInvalidStatusProblemDetails() { mockProblemDetailsHeader(), ("{" + "\"status\":\"Some invalid status\"," + - "}").getBytes(), - jsonService + "}").getBytes() ); assertEquals(statusCode, pd.getStatus()); } @@ -130,8 +126,7 @@ void testMismatchingStatusProblemDetails() { mockProblemDetailsHeader(), ("{" + "\"status\":500," + - "}").getBytes(), - jsonService + "}").getBytes() ); assertEquals(statusCode, pd.getStatus()); } @@ -143,8 +138,7 @@ void testInvalidTypeProblemDetails() { mockProblemDetailsHeader(), ("{" + "\"type\":\"Some invalid type\"," + - "}").getBytes(), - jsonService + "}").getBytes() ); assertEquals(ProblemDetails.DEFAULT_TYPE, pd.getType().toString()); } @@ -156,8 +150,7 @@ void testInvalidInstanceProblemDetails() { mockProblemDetailsHeader(), ("{" + "\"instance\":\"Some invalid instance\"," + - "}").getBytes(), - jsonService + "}").getBytes() ); assertNull(pd.getInstance()); } From f1e5d17e598db60b008dddd6c2bd86373bbb241b Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 23:01:57 +0200 Subject: [PATCH 04/14] Make JSON service singleton --- .../com/inrupt/client/ProblemDetails.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/com/inrupt/client/ProblemDetails.java b/api/src/main/java/com/inrupt/client/ProblemDetails.java index 0af2f4cf338..e88d7ba870e 100644 --- a/api/src/main/java/com/inrupt/client/ProblemDetails.java +++ b/api/src/main/java/com/inrupt/client/ProblemDetails.java @@ -45,6 +45,7 @@ public class ProblemDetails { private final int status; private final URI instance; private static JsonService jsonService; + private static boolean isJsonServiceInitialized; public ProblemDetails( final URI type, @@ -80,17 +81,28 @@ public URI getInstance() { return this.instance; }; - public static ProblemDetails fromErrorResponse( - final int statusCode, - final Headers headers, - final byte[] body - ) { + private static JsonService getJsonService() { + if (ProblemDetails.isJsonServiceInitialized) { + return ProblemDetails.jsonService; + } + // It is acceptable for a JenaBodyHandlers instance to be in a classpath without any implementation for + // JsonService, in which case the ProblemDetails exceptions will fallback to default and not be parsed. try { ProblemDetails.jsonService = ServiceProvider.getJsonService(); } catch (IllegalStateException e) { ProblemDetails.jsonService = null; } - if (ProblemDetails.jsonService == null + ProblemDetails.isJsonServiceInitialized = true; + return ProblemDetails.jsonService; + } + + public static ProblemDetails fromErrorResponse( + 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 ProblemDetails( URI.create(ProblemDetails.DEFAULT_TYPE), @@ -101,7 +113,7 @@ public static ProblemDetails fromErrorResponse( ); } try { - final ProblemDetailsData pdData = ProblemDetails.jsonService.fromJson( + final ProblemDetailsData pdData = jsonService.fromJson( new ByteArrayInputStream(body), ProblemDetailsData.class ); From 2b4a707c1ce8bf8b05a4f65c9e50995b30043a6c Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 23:11:47 +0200 Subject: [PATCH 05/14] =?UTF-8?q?fixup!=20Move=20JSON=20service=20discover?= =?UTF-8?q?y=20in=20ProblemDetails=C2=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/inrupt/client/solid/ProblemDetailsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java index 63bfeac46f2..3e98b098905 100644 --- a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java @@ -47,7 +47,6 @@ Headers mockProblemDetailsHeader() { return Headers.of(headerMap); } - final JsonService jsonService = ServiceProvider.getJsonService(); @Test void testEmptyProblemDetails() { final int statusCode = 400; From 249ff57966f4ec31d0d962cd0840132606777f02 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 23:15:48 +0200 Subject: [PATCH 06/14] Change default ProblemDetails titles --- api/src/main/java/com/inrupt/client/HttpStatus.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/inrupt/client/HttpStatus.java b/api/src/main/java/com/inrupt/client/HttpStatus.java index 193c14edcf2..85a71151313 100644 --- a/api/src/main/java/com/inrupt/client/HttpStatus.java +++ b/api/src/main/java/com/inrupt/client/HttpStatus.java @@ -67,9 +67,9 @@ static String getStatusMessage(final int statusCode) { .orElseGet(() -> { // If the status is unknown, default to 400 for client errors and 500 for server errors if (statusCode >= 400 && statusCode <= 499) { - return BAD_REQUEST.message; + return "Unknown Client Error"; } - return INTERNAL_SERVER_ERROR.message; + return "unknown Server Error"; }); } } From 93cfccff3ba3472886d600ace8fcb1b186dead04 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Mon, 15 Apr 2024 23:19:49 +0200 Subject: [PATCH 07/14] Fix ProblemDetails parsing tests the JSON was invalid, causing the intended code path not to be used. --- .../com/inrupt/client/solid/ProblemDetailsTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java index 3e98b098905..5ee2cafad83 100644 --- a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java @@ -111,7 +111,7 @@ void testInvalidStatusProblemDetails() { statusCode, mockProblemDetailsHeader(), ("{" + - "\"status\":\"Some invalid status\"," + + "\"status\":\"Some invalid status\"" + "}").getBytes() ); assertEquals(statusCode, pd.getStatus()); @@ -124,10 +124,10 @@ void testMismatchingStatusProblemDetails() { statusCode, mockProblemDetailsHeader(), ("{" + - "\"status\":500," + + "\"status\":500" + "}").getBytes() ); - assertEquals(statusCode, pd.getStatus()); + assertEquals(500, pd.getStatus()); } @Test @@ -136,7 +136,7 @@ void testInvalidTypeProblemDetails() { 400, mockProblemDetailsHeader(), ("{" + - "\"type\":\"Some invalid type\"," + + "\"type\":\"Some invalid type\"" + "}").getBytes() ); assertEquals(ProblemDetails.DEFAULT_TYPE, pd.getType().toString()); @@ -148,7 +148,7 @@ void testInvalidInstanceProblemDetails() { 400, mockProblemDetailsHeader(), ("{" + - "\"instance\":\"Some invalid instance\"," + + "\"instance\":\"Some invalid instance\"" + "}").getBytes() ); assertNull(pd.getInstance()); From b27cd0ad6ac83bd10f37bef351e4796300c8a1db Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 09:23:28 +0200 Subject: [PATCH 08/14] Lift SolidClientExceptions members to parent --- .../inrupt/client/ClientHttpException.java | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/inrupt/client/ClientHttpException.java b/api/src/main/java/com/inrupt/client/ClientHttpException.java index d2401e3cbc2..214f672ba11 100644 --- a/api/src/main/java/com/inrupt/client/ClientHttpException.java +++ b/api/src/main/java/com/inrupt/client/ClientHttpException.java @@ -20,35 +20,78 @@ */ package com.inrupt.client; +import java.net.URI; + /** * A runtime exception representing an HTTP error response carrying a structured representation of the problem. The * problem description is embedded in a {@link ProblemDetails} instance. */ public class ClientHttpException extends InruptClientException { private final ProblemDetails problemDetails; + private final URI uri; + private final int statusCode; + private final String body; + private final transient Headers headers; /** * Create a ClientHttpException. - * @param problemDetails the {@link ProblemDetails} instance * @param message the exception message + * @param uri the error response URI + * @param statusCode the error response status code + * @param headers the error response headers */ - public ClientHttpException(final ProblemDetails problemDetails, final String message) { + public ClientHttpException(final String message, final URI uri, final int statusCode, + final Headers headers, final String body) { super(message); - this.problemDetails = problemDetails; + this.uri = uri; + this.statusCode = statusCode; + this.headers = headers; + this.body = body; + this.problemDetails = ProblemDetails.fromErrorResponse(statusCode, headers, body.getBytes()); } /** - * Create a ClientHttpException. - * @param problemDetails the {@link ProblemDetails} instance - * @param message the exception message - * @param cause a wrapped exception cause + * Retrieve the URI associated with this exception. + * + * @return the uri + */ + public URI getUri() { + return uri; + } + + /** + * Retrieve the status code associated with this exception. + * + * @return the status code + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Retrieve the headers associated with this exception. + * + * @return the headers */ - public ClientHttpException(final ProblemDetails problemDetails, final String message, final Exception cause) { - super(message, cause); - this.problemDetails = problemDetails; + public Headers getHeaders() { + return headers; } + /** + * Retrieve the body associated with this exception. + * + * @return the body + */ + public String getBody() { + return body; + } + + /** + * Retrieve the {@link ProblemDetails} instance describing the HTTP error response. + * @return the problem details object + */ public ProblemDetails getProblemDetails() { return this.problemDetails; } + } From 6b9a5deceff8d008cd2bf0e21cf3ad89eeb0b89e Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 09:30:26 +0200 Subject: [PATCH 09/14] Fix typo in default HTTP status --- api/src/main/java/com/inrupt/client/HttpStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/inrupt/client/HttpStatus.java b/api/src/main/java/com/inrupt/client/HttpStatus.java index 85a71151313..6d7654eeaca 100644 --- a/api/src/main/java/com/inrupt/client/HttpStatus.java +++ b/api/src/main/java/com/inrupt/client/HttpStatus.java @@ -69,7 +69,7 @@ static String getStatusMessage(final int statusCode) { if (statusCode >= 400 && statusCode <= 499) { return "Unknown Client Error"; } - return "unknown Server Error"; + return "Unknown Server Error"; }); } } From 5672101d2d368fd6a4f721f52150c0a7553920f8 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 10:03:47 +0200 Subject: [PATCH 10/14] Lint --- .../java/com/inrupt/client/ClientHttpException.java | 1 + .../main/java/com/inrupt/client/ProblemDetails.java | 3 --- .../java/com/inrupt/client/ProblemDetailsData.java | 10 +++++----- .../com/inrupt/client/solid/ProblemDetailsTest.java | 2 -- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/inrupt/client/ClientHttpException.java b/api/src/main/java/com/inrupt/client/ClientHttpException.java index 214f672ba11..38313f0d465 100644 --- a/api/src/main/java/com/inrupt/client/ClientHttpException.java +++ b/api/src/main/java/com/inrupt/client/ClientHttpException.java @@ -39,6 +39,7 @@ public class ClientHttpException extends InruptClientException { * @param uri the error response URI * @param statusCode the error response status code * @param headers the error response headers + * @param body the error response body */ public ClientHttpException(final String message, final URI uri, final int statusCode, final Headers headers, final String body) { diff --git a/api/src/main/java/com/inrupt/client/ProblemDetails.java b/api/src/main/java/com/inrupt/client/ProblemDetails.java index e88d7ba870e..43215292359 100644 --- a/api/src/main/java/com/inrupt/client/ProblemDetails.java +++ b/api/src/main/java/com/inrupt/client/ProblemDetails.java @@ -25,10 +25,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; import java.net.URI; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; /** diff --git a/api/src/main/java/com/inrupt/client/ProblemDetailsData.java b/api/src/main/java/com/inrupt/client/ProblemDetailsData.java index fde3f633764..876967eb1dc 100644 --- a/api/src/main/java/com/inrupt/client/ProblemDetailsData.java +++ b/api/src/main/java/com/inrupt/client/ProblemDetailsData.java @@ -33,23 +33,23 @@ public URI getInstance() { return this.instance; }; - public void setType(URI type) { + public void setType(final URI type) { this.type = type; } - public void setTitle(String title) { + public void setTitle(final String title) { this.title = title; } - public void setDetails(String details) { + public void setDetails(final String details) { this.details = details; } - public void setStatus(int status) { + public void setStatus(final int status) { this.status = status; } - public void setInstance(URI instance) { + public void setInstance(final URI instance) { this.instance = instance; } } diff --git a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java index 5ee2cafad83..227ea50d4ae 100644 --- a/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/ProblemDetailsTest.java @@ -25,8 +25,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.ProblemDetails; -import com.inrupt.client.spi.JsonService; -import com.inrupt.client.spi.ServiceProvider; import java.util.ArrayList; import java.util.HashMap; From b8b649042610205ba132d9eea1a11cad7624f3f3 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Wed, 10 Apr 2024 14:50:44 +0200 Subject: [PATCH 11/14] Refactor specialized exception constructors The exception are now built taking a ProblemDetails in. Use HttpStatus from API module as reference --- .../client/solid/BadRequestException.java | 23 +++++- .../client/solid/ConflictException.java | 23 +++++- .../client/solid/ForbiddenException.java | 23 +++++- .../inrupt/client/solid/GoneException.java | 23 +++++- .../solid/InternalServerErrorException.java | 23 +++++- .../solid/MethodNotAllowedException.java | 23 +++++- .../client/solid/NotAcceptableException.java | 23 +++++- .../client/solid/NotFoundException.java | 23 +++++- .../solid/PreconditionFailedException.java | 23 +++++- .../client/solid/SolidClientException.java | 78 ++++++++++++++++++- .../solid/TooManyRequestsException.java | 23 +++++- .../client/solid/UnauthorizedException.java | 23 +++++- .../solid/UnsupportedMediaTypeException.java | 23 +++++- .../client/solid/SolidExceptionTest.java | 21 +++++ 14 files changed, 360 insertions(+), 15 deletions(-) diff --git a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java index 3fc0ad547f1..3e86a0ec5b4 100644 --- a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java +++ b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class BadRequestException extends SolidClientException { private static final long serialVersionUID = -3379457428921025570L; - public static final int STATUS_CODE = 400; + public static final int STATUS_CODE = HttpStatus.BAD_REQUEST; /** * Create a BadRequestException exception. @@ -41,6 +43,7 @@ public class BadRequestException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public BadRequestException( final String message, @@ -49,4 +52,22 @@ public BadRequestException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a BadRequestException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public BadRequestException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java index d88386eb724..80b63b7decf 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class ConflictException extends SolidClientException { private static final long serialVersionUID = -203198307847520748L; - public static final int STATUS_CODE = 409; + public static final int STATUS_CODE = HttpStatus.CONFLICT; /** * Create a ConflictException exception. @@ -41,6 +43,7 @@ public class ConflictException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public ConflictException( final String message, @@ -49,4 +52,22 @@ public ConflictException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a ConflictException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public ConflictException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java index 7aeb3219bec..9fd94a4fb9e 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class ForbiddenException extends SolidClientException { private static final long serialVersionUID = 3299286274724874244L; - public static final int STATUS_CODE = 403; + public static final int STATUS_CODE = HttpStatus.FORBIDDEN; /** * Create a ForbiddenException exception. @@ -41,6 +43,7 @@ public class ForbiddenException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public ForbiddenException( final String message, @@ -49,4 +52,22 @@ public ForbiddenException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a ForbiddenException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public ForbiddenException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/GoneException.java b/solid/src/main/java/com/inrupt/client/solid/GoneException.java index 0882302e27b..511b5ca947a 100644 --- a/solid/src/main/java/com/inrupt/client/solid/GoneException.java +++ b/solid/src/main/java/com/inrupt/client/solid/GoneException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class GoneException extends SolidClientException { private static final long serialVersionUID = -6892345582498100242L; - public static final int STATUS_CODE = 410; + public static final int STATUS_CODE = HttpStatus.GONE; /** * Create a GoneException exception. @@ -41,6 +43,7 @@ public class GoneException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public GoneException( final String message, @@ -49,4 +52,22 @@ public GoneException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a GoneException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public GoneException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java index ea9acb1c56e..43a216fd307 100644 --- a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java +++ b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class InternalServerErrorException extends SolidClientException { private static final long serialVersionUID = -6672490715281719330L; - public static final int STATUS_CODE = 500; + public static final int STATUS_CODE = HttpStatus.INTERNAL_SERVER_ERROR; /** * Create an InternalServerErrorException exception. @@ -41,6 +43,7 @@ public class InternalServerErrorException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public InternalServerErrorException( final String message, @@ -49,4 +52,22 @@ public InternalServerErrorException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create an InternalServerErrorException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public InternalServerErrorException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java index d472b5fcbd3..378e166b2a0 100644 --- a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class MethodNotAllowedException extends SolidClientException { private static final long serialVersionUID = -9125437562813923030L; - public static final int STATUS_CODE = 405; + public static final int STATUS_CODE = HttpStatus.METHOD_NOT_ALLOWED; /** * Create a MethodNotAllowedException exception. @@ -41,6 +43,7 @@ public class MethodNotAllowedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public MethodNotAllowedException( final String message, @@ -49,4 +52,22 @@ public MethodNotAllowedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a MethodNotAllowedException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public MethodNotAllowedException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java index 53744c0b2e8..f1509073ef0 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class NotAcceptableException extends SolidClientException { private static final long serialVersionUID = 6594993822477388733L; - public static final int STATUS_CODE = 406; + public static final int STATUS_CODE = HttpStatus.NOT_ACCEPTABLE; /** * Create a NotAcceptableException exception. @@ -41,6 +43,7 @@ public class NotAcceptableException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public NotAcceptableException( final String message, @@ -49,4 +52,22 @@ public NotAcceptableException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a NotAcceptableException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public NotAcceptableException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java index 466bed74894..71e4dc16361 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class NotFoundException extends SolidClientException { private static final long serialVersionUID = -2256628528500739683L; - public static final int STATUS_CODE = 404; + public static final int STATUS_CODE = HttpStatus.NOT_FOUND; /** * Create a NotFoundException exception. @@ -41,6 +43,7 @@ public class NotFoundException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public NotFoundException( final String message, @@ -49,4 +52,22 @@ public NotFoundException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a NotFoundException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public NotFoundException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java index 461c937a0eb..4c1d30f0065 100644 --- a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class PreconditionFailedException extends SolidClientException { private static final long serialVersionUID = 4205761003697773528L; - public static final int STATUS_CODE = 412; + public static final int STATUS_CODE = HttpStatus.PRECONDITION_FAILED; /** * Create a PreconditionFailedException exception. @@ -41,6 +43,7 @@ public class PreconditionFailedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public PreconditionFailedException( final String message, @@ -49,4 +52,22 @@ public PreconditionFailedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a PreconditionFailedException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public PreconditionFailedException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java index 668df265d3d..f6c67683626 100644 --- a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java +++ b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java @@ -20,15 +20,16 @@ */ package com.inrupt.client.solid; +import com.inrupt.client.ClientHttpException; import com.inrupt.client.Headers; -import com.inrupt.client.InruptClientException; +import com.inrupt.client.ProblemDetails; import java.net.URI; /** * A runtime exception for use with SolidClient HTTP operations. */ -public class SolidClientException extends InruptClientException { +public class SolidClientException extends ClientHttpException { private static final long serialVersionUID = 2868432164225689934L; @@ -45,16 +46,31 @@ public class SolidClientException extends InruptClientException { * @param statusCode the HTTP status code * @param headers the response headers * @param body the body + * @deprecated */ public SolidClientException(final String message, final URI uri, final int statusCode, final Headers headers, final String body) { - super(message); + super(null, message); this.uri = uri; this.statusCode = statusCode; this.headers = headers; this.body = body; } + public SolidClientException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body + ) { + super(pd, message); + this.uri = uri; + this.statusCode = pd.getStatus(); + this.headers = headers; + this.body = body; + } + /** * Retrieve the URI associated with this exception. * @@ -91,6 +107,16 @@ public String getBody() { return body; } + /** + * + * @param message the resulting exception message + * @param uri the request URL + * @param statusCode the response status code + * @param headers the response {@link Headers} + * @param body the response body + * @return an appropriate exception based on the status code. + * @deprecated + */ public static SolidClientException handle( final String message, final URI uri, @@ -126,5 +152,51 @@ public static SolidClientException handle( return new SolidClientException(message, uri, statusCode, headers, body); } } + + /** + * + * @param message the resulting exception message + * @param pd the {@link ProblemDetails} instance + * @param uri the request URL + * @param headers the response {@link Headers} + * @param body the response body + * @return an appropriate exception based on the status code. + */ + public static SolidClientException handle( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body + ) { + switch (pd.getStatus()) { + case BadRequestException.STATUS_CODE: + return new BadRequestException(message, pd, uri, headers, body); + case UnauthorizedException.STATUS_CODE: + return new UnauthorizedException(message, pd, uri, headers, body); + case ForbiddenException.STATUS_CODE: + return new ForbiddenException(message, pd, uri, headers, body); + case NotFoundException.STATUS_CODE: + return new NotFoundException(message, pd, uri, headers, body); + case MethodNotAllowedException.STATUS_CODE: + return new MethodNotAllowedException(message, pd, uri, headers, body); + case NotAcceptableException.STATUS_CODE: + return new NotAcceptableException(message, pd, uri, headers, body); + case ConflictException.STATUS_CODE: + return new ConflictException(message, pd, uri, headers, body); + case GoneException.STATUS_CODE: + return new GoneException(message, pd, uri, headers, body); + case PreconditionFailedException.STATUS_CODE: + return new PreconditionFailedException(message, pd, uri, headers, body); + case UnsupportedMediaTypeException.STATUS_CODE: + return new UnsupportedMediaTypeException(message, pd, uri, headers, body); + case TooManyRequestsException.STATUS_CODE: + return new TooManyRequestsException(message, pd, uri, headers, body); + case InternalServerErrorException.STATUS_CODE: + return new InternalServerErrorException(message, pd, uri, headers, body); + default: + return new SolidClientException(message, pd, uri, headers, body); + } + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java index 4f299fc9492..d05b2f255fd 100644 --- a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java +++ b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class TooManyRequestsException extends SolidClientException { private static final long serialVersionUID = -1798491190232642824L; - public static final int STATUS_CODE = 429; + public static final int STATUS_CODE = HttpStatus.TOO_MANY_REQUESTS; /** * Create a TooManyRequestsException exception. @@ -41,6 +43,7 @@ public class TooManyRequestsException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public TooManyRequestsException( final String message, @@ -49,4 +52,22 @@ public TooManyRequestsException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a TooManyRequestsException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public TooManyRequestsException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java index db8615df958..e9d2d98571d 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class UnauthorizedException extends SolidClientException { private static final long serialVersionUID = -3219668517323678497L; - public static final int STATUS_CODE = 401; + public static final int STATUS_CODE = HttpStatus.UNAUTHORIZED; /** * Create an UnauthorizedException exception. @@ -41,6 +43,7 @@ public class UnauthorizedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public UnauthorizedException( final String message, @@ -49,4 +52,22 @@ public UnauthorizedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a UnauthorizedException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public UnauthorizedException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java index 27e9c96953d..4d90c434efc 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java @@ -21,6 +21,8 @@ package com.inrupt.client.solid; import com.inrupt.client.Headers; +import com.inrupt.client.HttpStatus; +import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -32,7 +34,7 @@ public class UnsupportedMediaTypeException extends SolidClientException { private static final long serialVersionUID = 1312856145838280673L; - public static final int STATUS_CODE = 415; + public static final int STATUS_CODE = HttpStatus.UNSUPPORTED_MEDIA_TYPE; /** * Create an UnsupportedMediaTypeException exception. @@ -41,6 +43,7 @@ public class UnsupportedMediaTypeException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body + * @deprecated */ public UnsupportedMediaTypeException( final String message, @@ -49,4 +52,22 @@ public UnsupportedMediaTypeException( final String body) { super(message, uri, STATUS_CODE, headers, body); } + + /** + * Create a UnsupportedMediaTypeException exception. + * + * @param message the message + * @param pd the ProblemDetails instance + * @param uri the uri + * @param headers the response headers + * @param body the body + */ + public UnsupportedMediaTypeException( + final String message, + final ProblemDetails pd, + final URI uri, + final Headers headers, + final String body) { + super(message, pd, uri, headers, body); + } } diff --git a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java index 15220345d68..cfddd012cd5 100644 --- a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java @@ -22,6 +22,10 @@ import static org.junit.jupiter.api.Assertions.*; +import com.inrupt.client.ProblemDetails; + +import java.net.URI; + import org.junit.jupiter.api.Test; class SolidExceptionTest { @@ -41,4 +45,21 @@ void checkSolidWrappedException() { assertEquals(upstream, err.getCause()); assertEquals(msg, err.getMessage()); } + + @Test + void checkSolidClientException() { + final String msg = "Error"; + final ProblemDetails pd = new ProblemDetails( + URI.create("https://example.org/problem"), + "Some title", + "Some details", + 123, + URI.create("https://example.org/instance") + ); + final SolidClientException err = new SolidClientException( + msg, pd, URI.create("https://example.org/request"), null, "some body" + ); + assertEquals(msg, err.getMessage()); + assertEquals(pd, err.getProblemDetails()); + } } From 6ba66c203962511abcf486fb53273211645fe2bf Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 09:35:39 +0200 Subject: [PATCH 12/14] fixup! JCL-403: SolidClient builds ProblemDetails --- .../client/solid/SolidClientException.java | 109 +----------------- 1 file changed, 1 insertion(+), 108 deletions(-) diff --git a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java index f6c67683626..cf472e6fc34 100644 --- a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java +++ b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java @@ -33,11 +33,6 @@ public class SolidClientException extends ClientHttpException { private static final long serialVersionUID = 2868432164225689934L; - private final URI uri; - private final int statusCode; - private final String body; - private final transient Headers headers; - /** * Create a SolidClient exception. * @@ -46,65 +41,10 @@ public class SolidClientException extends ClientHttpException { * @param statusCode the HTTP status code * @param headers the response headers * @param body the body - * @deprecated */ public SolidClientException(final String message, final URI uri, final int statusCode, final Headers headers, final String body) { - super(null, message); - this.uri = uri; - this.statusCode = statusCode; - this.headers = headers; - this.body = body; - } - - public SolidClientException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body - ) { - super(pd, message); - this.uri = uri; - this.statusCode = pd.getStatus(); - this.headers = headers; - this.body = body; - } - - /** - * Retrieve the URI associated with this exception. - * - * @return the uri - */ - public URI getUri() { - return uri; - } - - /** - * Retrieve the status code associated with this exception. - * - * @return the status code - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Retrieve the headers associated with this exception. - * - * @return the headers - */ - public Headers getHeaders() { - return headers; - } - - /** - * Retrieve the body associated with this exception. - * - * @return the body - */ - public String getBody() { - return body; + super(message, uri, statusCode, headers, body); } /** @@ -115,7 +55,6 @@ public String getBody() { * @param headers the response {@link Headers} * @param body the response body * @return an appropriate exception based on the status code. - * @deprecated */ public static SolidClientException handle( final String message, @@ -152,51 +91,5 @@ public static SolidClientException handle( return new SolidClientException(message, uri, statusCode, headers, body); } } - - /** - * - * @param message the resulting exception message - * @param pd the {@link ProblemDetails} instance - * @param uri the request URL - * @param headers the response {@link Headers} - * @param body the response body - * @return an appropriate exception based on the status code. - */ - public static SolidClientException handle( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body - ) { - switch (pd.getStatus()) { - case BadRequestException.STATUS_CODE: - return new BadRequestException(message, pd, uri, headers, body); - case UnauthorizedException.STATUS_CODE: - return new UnauthorizedException(message, pd, uri, headers, body); - case ForbiddenException.STATUS_CODE: - return new ForbiddenException(message, pd, uri, headers, body); - case NotFoundException.STATUS_CODE: - return new NotFoundException(message, pd, uri, headers, body); - case MethodNotAllowedException.STATUS_CODE: - return new MethodNotAllowedException(message, pd, uri, headers, body); - case NotAcceptableException.STATUS_CODE: - return new NotAcceptableException(message, pd, uri, headers, body); - case ConflictException.STATUS_CODE: - return new ConflictException(message, pd, uri, headers, body); - case GoneException.STATUS_CODE: - return new GoneException(message, pd, uri, headers, body); - case PreconditionFailedException.STATUS_CODE: - return new PreconditionFailedException(message, pd, uri, headers, body); - case UnsupportedMediaTypeException.STATUS_CODE: - return new UnsupportedMediaTypeException(message, pd, uri, headers, body); - case TooManyRequestsException.STATUS_CODE: - return new TooManyRequestsException(message, pd, uri, headers, body); - case InternalServerErrorException.STATUS_CODE: - return new InternalServerErrorException(message, pd, uri, headers, body); - default: - return new SolidClientException(message, pd, uri, headers, body); - } - } } From 8c3adf66ae0fb68f0c3bca293a3db480e7b60a9c Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 09:51:15 +0200 Subject: [PATCH 13/14] fixup! Refactor specialized exception constructors --- .../client/solid/BadRequestException.java | 20 +------------------ .../client/solid/ConflictException.java | 19 ------------------ .../client/solid/ForbiddenException.java | 19 ------------------ .../inrupt/client/solid/GoneException.java | 19 ------------------ .../solid/InternalServerErrorException.java | 19 ------------------ .../solid/MethodNotAllowedException.java | 19 ------------------ .../client/solid/NotAcceptableException.java | 19 ------------------ .../client/solid/NotFoundException.java | 19 ------------------ .../solid/PreconditionFailedException.java | 19 ------------------ .../solid/TooManyRequestsException.java | 19 ------------------ .../client/solid/UnauthorizedException.java | 19 ------------------ .../solid/UnsupportedMediaTypeException.java | 19 ------------------ .../client/solid/SolidExceptionTest.java | 11 ++-------- 13 files changed, 3 insertions(+), 237 deletions(-) diff --git a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java index 3e86a0ec5b4..5aba3d5a56b 100644 --- a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java +++ b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java @@ -36,23 +36,6 @@ public class BadRequestException extends SolidClientException { public static final int STATUS_CODE = HttpStatus.BAD_REQUEST; - /** - * Create a BadRequestException exception. - * - * @param message the message - * @param uri the uri - * @param headers the response headers - * @param body the body - * @deprecated - */ - public BadRequestException( - final String message, - final URI uri, - final Headers headers, - final String body) { - super(message, uri, STATUS_CODE, headers, body); - } - /** * Create a BadRequestException exception. * @@ -64,10 +47,9 @@ public BadRequestException( */ public BadRequestException( final String message, - final ProblemDetails pd, final URI uri, final Headers headers, final String body) { - super(message, pd, uri, headers, body); + super(message, uri, HttpStatus.BAD_REQUEST, headers, body); } } diff --git a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java index 80b63b7decf..66bc6e2aa57 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java @@ -43,7 +43,6 @@ public class ConflictException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public ConflictException( final String message, @@ -52,22 +51,4 @@ public ConflictException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a ConflictException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public ConflictException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java index 9fd94a4fb9e..30336ce1fda 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java @@ -43,7 +43,6 @@ public class ForbiddenException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public ForbiddenException( final String message, @@ -52,22 +51,4 @@ public ForbiddenException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a ForbiddenException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public ForbiddenException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/GoneException.java b/solid/src/main/java/com/inrupt/client/solid/GoneException.java index 511b5ca947a..61f4ab55fdf 100644 --- a/solid/src/main/java/com/inrupt/client/solid/GoneException.java +++ b/solid/src/main/java/com/inrupt/client/solid/GoneException.java @@ -43,7 +43,6 @@ public class GoneException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public GoneException( final String message, @@ -52,22 +51,4 @@ public GoneException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a GoneException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public GoneException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java index 43a216fd307..41f53b8e121 100644 --- a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java +++ b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java @@ -43,7 +43,6 @@ public class InternalServerErrorException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public InternalServerErrorException( final String message, @@ -52,22 +51,4 @@ public InternalServerErrorException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create an InternalServerErrorException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public InternalServerErrorException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java index 378e166b2a0..440de24d573 100644 --- a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java @@ -43,7 +43,6 @@ public class MethodNotAllowedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public MethodNotAllowedException( final String message, @@ -52,22 +51,4 @@ public MethodNotAllowedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a MethodNotAllowedException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public MethodNotAllowedException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java index f1509073ef0..fe15be1261a 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java @@ -43,7 +43,6 @@ public class NotAcceptableException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public NotAcceptableException( final String message, @@ -52,22 +51,4 @@ public NotAcceptableException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a NotAcceptableException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public NotAcceptableException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java index 71e4dc16361..46497b0ce9c 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java @@ -43,7 +43,6 @@ public class NotFoundException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public NotFoundException( final String message, @@ -52,22 +51,4 @@ public NotFoundException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a NotFoundException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public NotFoundException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java index 4c1d30f0065..ed5617efc5a 100644 --- a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java @@ -43,7 +43,6 @@ public class PreconditionFailedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public PreconditionFailedException( final String message, @@ -52,22 +51,4 @@ public PreconditionFailedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a PreconditionFailedException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public PreconditionFailedException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java index d05b2f255fd..80dc28ebd1b 100644 --- a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java +++ b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java @@ -43,7 +43,6 @@ public class TooManyRequestsException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public TooManyRequestsException( final String message, @@ -52,22 +51,4 @@ public TooManyRequestsException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a TooManyRequestsException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public TooManyRequestsException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java index e9d2d98571d..17af7272421 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java @@ -43,7 +43,6 @@ public class UnauthorizedException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public UnauthorizedException( final String message, @@ -52,22 +51,4 @@ public UnauthorizedException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a UnauthorizedException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public UnauthorizedException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java index 4d90c434efc..015796eb92c 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java @@ -43,7 +43,6 @@ public class UnsupportedMediaTypeException extends SolidClientException { * @param uri the uri * @param headers the response headers * @param body the body - * @deprecated */ public UnsupportedMediaTypeException( final String message, @@ -52,22 +51,4 @@ public UnsupportedMediaTypeException( final String body) { super(message, uri, STATUS_CODE, headers, body); } - - /** - * Create a UnsupportedMediaTypeException exception. - * - * @param message the message - * @param pd the ProblemDetails instance - * @param uri the uri - * @param headers the response headers - * @param body the body - */ - public UnsupportedMediaTypeException( - final String message, - final ProblemDetails pd, - final URI uri, - final Headers headers, - final String body) { - super(message, pd, uri, headers, body); - } } diff --git a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java index cfddd012cd5..22fe66894a7 100644 --- a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java @@ -49,17 +49,10 @@ void checkSolidWrappedException() { @Test void checkSolidClientException() { final String msg = "Error"; - final ProblemDetails pd = new ProblemDetails( - URI.create("https://example.org/problem"), - "Some title", - "Some details", - 123, - URI.create("https://example.org/instance") - ); final SolidClientException err = new SolidClientException( - msg, pd, URI.create("https://example.org/request"), null, "some body" + msg, URI.create("https://example.org/request"), 123, null, "some body" ); assertEquals(msg, err.getMessage()); - assertEquals(pd, err.getProblemDetails()); + assertEquals(123, err.getProblemDetails().getStatus()); } } From c41758edc61198f477763bfcffef9fc938bf1c3d Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Tue, 16 Apr 2024 10:07:48 +0200 Subject: [PATCH 14/14] Lint --- .../main/java/com/inrupt/client/solid/BadRequestException.java | 2 -- .../main/java/com/inrupt/client/solid/ConflictException.java | 1 - .../main/java/com/inrupt/client/solid/ForbiddenException.java | 1 - solid/src/main/java/com/inrupt/client/solid/GoneException.java | 1 - .../com/inrupt/client/solid/InternalServerErrorException.java | 1 - .../java/com/inrupt/client/solid/MethodNotAllowedException.java | 1 - .../java/com/inrupt/client/solid/NotAcceptableException.java | 1 - .../main/java/com/inrupt/client/solid/NotFoundException.java | 1 - .../com/inrupt/client/solid/PreconditionFailedException.java | 1 - .../main/java/com/inrupt/client/solid/SolidClientException.java | 1 - .../java/com/inrupt/client/solid/TooManyRequestsException.java | 1 - .../java/com/inrupt/client/solid/UnauthorizedException.java | 1 - .../com/inrupt/client/solid/UnsupportedMediaTypeException.java | 1 - .../test/java/com/inrupt/client/solid/SolidExceptionTest.java | 2 -- 14 files changed, 16 deletions(-) diff --git a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java index 5aba3d5a56b..0f380e5632c 100644 --- a/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java +++ b/solid/src/main/java/com/inrupt/client/solid/BadRequestException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; @@ -40,7 +39,6 @@ public class BadRequestException extends SolidClientException { * Create a BadRequestException exception. * * @param message the message - * @param pd the ProblemDetails instance * @param uri the uri * @param headers the response headers * @param body the body diff --git a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java index 66bc6e2aa57..fe2a15385f5 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ConflictException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ConflictException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java index 30336ce1fda..20bf1fd32dc 100644 --- a/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java +++ b/solid/src/main/java/com/inrupt/client/solid/ForbiddenException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/GoneException.java b/solid/src/main/java/com/inrupt/client/solid/GoneException.java index 61f4ab55fdf..2d247db4c87 100644 --- a/solid/src/main/java/com/inrupt/client/solid/GoneException.java +++ b/solid/src/main/java/com/inrupt/client/solid/GoneException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java index 41f53b8e121..d57ac187d86 100644 --- a/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java +++ b/solid/src/main/java/com/inrupt/client/solid/InternalServerErrorException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java index 440de24d573..dbba0b6003c 100644 --- a/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/MethodNotAllowedException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java index fe15be1261a..18b7bf929e5 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotAcceptableException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java index 46497b0ce9c..f0cf9ef7164 100644 --- a/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java +++ b/solid/src/main/java/com/inrupt/client/solid/NotFoundException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java index ed5617efc5a..4584bac47b9 100644 --- a/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/PreconditionFailedException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java index cf472e6fc34..bf6decd11ee 100644 --- a/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java +++ b/solid/src/main/java/com/inrupt/client/solid/SolidClientException.java @@ -22,7 +22,6 @@ import com.inrupt.client.ClientHttpException; import com.inrupt.client.Headers; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java index 80dc28ebd1b..018a95e1e8f 100644 --- a/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java +++ b/solid/src/main/java/com/inrupt/client/solid/TooManyRequestsException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java index 17af7272421..7ad2d425137 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnauthorizedException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java index 015796eb92c..866fe70cf7d 100644 --- a/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java +++ b/solid/src/main/java/com/inrupt/client/solid/UnsupportedMediaTypeException.java @@ -22,7 +22,6 @@ import com.inrupt.client.Headers; import com.inrupt.client.HttpStatus; -import com.inrupt.client.ProblemDetails; import java.net.URI; diff --git a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java index 22fe66894a7..147b48fb094 100644 --- a/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java +++ b/solid/src/test/java/com/inrupt/client/solid/SolidExceptionTest.java @@ -22,8 +22,6 @@ import static org.junit.jupiter.api.Assertions.*; -import com.inrupt.client.ProblemDetails; - import java.net.URI; import org.junit.jupiter.api.Test;