Skip to content

Commit 2795de9

Browse files
authored
JCL-309: Specialized HTTP client exceptions (#480)
1 parent cae253c commit 2795de9

19 files changed

+752
-31
lines changed

integration/base/src/main/java/com/inrupt/client/integration/base/AccessGrantScenarios.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
import com.inrupt.client.auth.Session;
3737
import com.inrupt.client.openid.OpenIdException;
3838
import com.inrupt.client.openid.OpenIdSession;
39-
import com.inrupt.client.solid.SolidClientException;
40-
import com.inrupt.client.solid.SolidNonRDFSource;
41-
import com.inrupt.client.solid.SolidRDFSource;
42-
import com.inrupt.client.solid.SolidSyncClient;
39+
import com.inrupt.client.solid.*;
4340
import com.inrupt.client.spi.RDFFactory;
4441
import com.inrupt.client.util.URIBuilder;
4542
import com.inrupt.client.vocabulary.ACL;
@@ -240,7 +237,7 @@ void accessGrantIssuanceLifecycleTest(final Session session) {
240237

241238
//unauthorized request test
242239
final SolidSyncClient client = SolidSyncClient.getClientBuilder().build();
243-
final SolidClientException err = assertThrows(SolidClientException.class,
240+
final var err = assertThrows(UnauthorizedException.class,
244241
() -> client.read(sharedTextFileURI, SolidNonRDFSource.class));
245242
assertEquals(Utils.UNAUTHORIZED, err.getStatusCode());
246243
final Request reqRead =

integration/base/src/main/java/com/inrupt/client/integration/base/AuthenticationScenarios.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.inrupt.client.solid.SolidClientException;
3434
import com.inrupt.client.solid.SolidRDFSource;
3535
import com.inrupt.client.solid.SolidSyncClient;
36+
import com.inrupt.client.solid.UnauthorizedException;
3637
import com.inrupt.client.util.URIBuilder;
3738
import com.inrupt.client.webid.WebIdProfile;
3839

@@ -190,7 +191,7 @@ void fetchPrivateResourceUnauthenticatedTest(final Session session) {
190191
assertDoesNotThrow(() -> authClient.create(testResource));
191192

192193
final SolidSyncClient client = SolidSyncClient.getClient();
193-
final SolidClientException err = assertThrows(SolidClientException.class,
194+
final var err = assertThrows(UnauthorizedException.class,
194195
() -> client.read(privateResourceURL, SolidRDFSource.class));
195196
assertEquals(Utils.UNAUTHORIZED, err.getStatusCode());
196197

@@ -242,7 +243,7 @@ void fetchPrivateResourceUnauthAuthTest(final Session session) {
242243
assertDoesNotThrow(() -> authClient.create(testResource));
243244

244245
final SolidSyncClient client = SolidSyncClient.getClient();
245-
final SolidClientException err = assertThrows(SolidClientException.class,
246+
final var err = assertThrows(UnauthorizedException.class,
246247
() -> client.read(privateResourceURL, SolidRDFSource.class));
247248
assertEquals(Utils.UNAUTHORIZED, err.getStatusCode());
248249

@@ -278,7 +279,7 @@ void multiSessionTest(final Session session) {
278279
assertDoesNotThrow(() -> authClient2.read(privateResourceURL, SolidRDFSource.class));
279280

280281
final SolidSyncClient client = SolidSyncClient.getClient();
281-
final SolidClientException err = assertThrows(SolidClientException.class,
282+
final var err = assertThrows(UnauthorizedException.class,
282283
() -> client.read(privateResourceURL, SolidRDFSource.class));
283284
assertEquals(Utils.UNAUTHORIZED, err.getStatusCode());
284285

integration/base/src/main/java/com/inrupt/client/integration/base/DomainModulesResource.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
import com.inrupt.client.Request;
2727
import com.inrupt.client.Response;
2828
import com.inrupt.client.auth.Session;
29-
import com.inrupt.client.solid.SolidClientException;
30-
import com.inrupt.client.solid.SolidContainer;
31-
import com.inrupt.client.solid.SolidRDFSource;
32-
import com.inrupt.client.solid.SolidResourceHandlers;
33-
import com.inrupt.client.solid.SolidSyncClient;
29+
import com.inrupt.client.solid.*;
3430
import com.inrupt.client.spi.RDFFactory;
3531
import com.inrupt.client.util.URIBuilder;
3632
import com.inrupt.client.vocabulary.PIM;
@@ -261,7 +257,7 @@ void findStorageTest() {
261257
}
262258

263259
final var missingWebId = URIBuilder.newBuilder(URI.create(webidUrl)).path(UUID.randomUUID().toString()).build();
264-
final var err = assertThrows(SolidClientException.class, () -> client.read(missingWebId, WebIdProfile.class));
260+
final var err = assertThrows(NotFoundException.class, () -> client.read(missingWebId, WebIdProfile.class));
265261
assertEquals(404, err.getStatusCode());
266262
assertEquals(missingWebId, err.getUri());
267263
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP bad request (400) response.
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.400">RFC 9110 (15.5.1.) 400 Bad Request</a>
31+
*/
32+
public class BadRequestException extends SolidClientException {
33+
private static final long serialVersionUID = -3379457428921025570L;
34+
35+
public static final int STATUS_CODE = 400;
36+
37+
/**
38+
* Create a BadRequestException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public BadRequestException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP conflict (409) response..
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.409">RFC 9110 (15.5.10.) 409 Conflict</a>
31+
*/
32+
public class ConflictException extends SolidClientException {
33+
private static final long serialVersionUID = -203198307847520748L;
34+
35+
public static final int STATUS_CODE = 409;
36+
37+
/**
38+
* Create a ConflictException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public ConflictException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP forbidden (403) response.
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.403">RFC 9110 (15.5.4.) 403 Forbidden</a>
31+
*/
32+
public class ForbiddenException extends SolidClientException {
33+
private static final long serialVersionUID = 3299286274724874244L;
34+
35+
public static final int STATUS_CODE = 403;
36+
37+
/**
38+
* Create a ForbiddenException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public ForbiddenException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP gone (410) response.
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.410">RFC 9110 (15.5.11.) 410 Gone</a>
31+
*/
32+
public class GoneException extends SolidClientException {
33+
private static final long serialVersionUID = -6892345582498100242L;
34+
35+
public static final int STATUS_CODE = 410;
36+
37+
/**
38+
* Create a GoneException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public GoneException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP internal server error (500) response.
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.500">RFC 9110 (15.6.1.) 500 Internal Server Error</a>
31+
*/
32+
public class InternalServerErrorException extends SolidClientException {
33+
private static final long serialVersionUID = -6672490715281719330L;
34+
35+
public static final int STATUS_CODE = 500;
36+
37+
/**
38+
* Create an InternalServerErrorException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public InternalServerErrorException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Inrupt Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to use,
7+
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8+
* Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package com.inrupt.client.solid;
22+
23+
import com.inrupt.client.Headers;
24+
25+
import java.net.URI;
26+
27+
/**
28+
* A runtime exception that represents an HTTP method not allowed (405) response.
29+
*
30+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9110#status.405">RFC 9110 (15.5.6.) 405 Method Not Allowed</a>
31+
*/
32+
public class MethodNotAllowedException extends SolidClientException {
33+
private static final long serialVersionUID = -9125437562813923030L;
34+
35+
public static final int STATUS_CODE = 405;
36+
37+
/**
38+
* Create a MethodNotAllowedException exception.
39+
*
40+
* @param message the message
41+
* @param uri the uri
42+
* @param headers the response headers
43+
* @param body the body
44+
*/
45+
public MethodNotAllowedException(
46+
final String message,
47+
final URI uri,
48+
final Headers headers,
49+
final String body) {
50+
super(message, uri, STATUS_CODE, headers, body);
51+
}
52+
}

0 commit comments

Comments
 (0)