Skip to content

Commit 2710ebf

Browse files
author
richard-jones
committed
add support for 404
Previously this library did not expressly support 404 responses (although it was possible with a workaround). This patch: * allows implementers to throw a sworderror with just a the status code as an argument * allows errors which have only status code arguments to be returned to the client with an empty body (rather than the server's 404 page or a sword error document) git-svn-id: http://sword-app.svn.sourceforge.net/svnroot/sword-app/JavaServer2.0/trunk@504 2bf6ea0f-123d-0410-b71a-f1a21eb24612
1 parent 8e23d5f commit 2710ebf

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/main/java/org/swordapp/server/ErrorDocument.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class ErrorDocument
1818
{
19-
private String errorUri;
19+
private String errorUri = null;
2020
private Map<String, Integer> errorCodes = new HashMap<String, Integer>();
2121
private String summary = null;
2222
private String verboseDescription = null;
@@ -66,7 +66,7 @@ public int getStatus()
6666
return this.status;
6767
}
6868

69-
if (this.errorCodes.containsKey(errorUri))
69+
if (errorUri != null && this.errorCodes.containsKey(errorUri))
7070
{
7171
return this.errorCodes.get(errorUri);
7272
}

src/main/java/org/swordapp/server/SwordAPIEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ protected void swordError(HttpServletRequest req, HttpServletResponse resp, Swor
347347
{
348348
try
349349
{
350-
if (!this.config.returnErrorBody())
350+
if (!this.config.returnErrorBody() || !e.hasBody())
351351
{
352352
ErrorDocument doc = new ErrorDocument(e.getErrorUri(), e.getStatus());
353-
resp.sendError(doc.getStatus());
353+
resp.setStatus(doc.getStatus());
354354
return;
355355
}
356356

src/main/java/org/swordapp/server/SwordError.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ public class SwordError extends Exception
77
{
88
private String errorUri;
99
private int status = -1;
10+
private boolean hasBody = true;
1011

1112
public SwordError()
1213
{
1314
super();
1415
}
1516

17+
public SwordError(int status)
18+
{
19+
super();
20+
this.status = status;
21+
this.hasBody = false;
22+
}
23+
1624
public SwordError(String errorUri)
1725
{
1826
super(errorUri);
@@ -74,4 +82,9 @@ public int getStatus()
7482
{
7583
return status;
7684
}
85+
86+
public boolean hasBody()
87+
{
88+
return hasBody;
89+
}
7790
}

0 commit comments

Comments
 (0)