-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement handleException on the server interceptor framework, as well
as some site and documentation enhancements
- Loading branch information
1 parent
8f70403
commit d22a357
Showing
26 changed files
with
528 additions
and
179 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
examples/src/main/java/example/RequestCounterInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package example; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; | ||
|
||
//START SNIPPET: interceptor | ||
public class RequestCounterInterceptor extends InterceptorAdapter | ||
{ | ||
|
||
private int myRequestCount; | ||
|
||
public int getRequestCount() { | ||
return myRequestCount; | ||
} | ||
|
||
/** | ||
* Override the incomingRequestPreProcessed method, which is called | ||
* for each incoming request before any processing is done | ||
*/ | ||
@Override | ||
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) { | ||
myRequestCount++; | ||
return true; | ||
} | ||
|
||
} | ||
//END SNIPPET: interceptor |
42 changes: 42 additions & 0 deletions
42
examples/src/main/java/example/RequestExceptionInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package example; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import ca.uhn.fhir.rest.method.RequestDetails; | ||
import ca.uhn.fhir.rest.server.Constants; | ||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; | ||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; | ||
|
||
//START SNIPPET: interceptor | ||
public class RequestExceptionInterceptor extends InterceptorAdapter | ||
{ | ||
|
||
@Override | ||
public boolean handleException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest, | ||
HttpServletResponse theServletResponse) throws ServletException, IOException { | ||
|
||
// If the exception is a built-in type, it defines the correct status | ||
// code to return. Otherwise default to 500. | ||
if (theException instanceof BaseServerResponseException) { | ||
theServletResponse.setStatus(((BaseServerResponseException) theException).getStatusCode()); | ||
} else { | ||
theServletResponse.setStatus(Constants.STATUS_HTTP_500_INTERNAL_ERROR); | ||
} | ||
|
||
// Provide a response ourself | ||
theServletResponse.setContentType("text/plain"); | ||
theServletResponse.getWriter().append("Failed to process!"); | ||
theServletResponse.getWriter().close(); | ||
|
||
// Since we handled this response in the interceptor, we must return false | ||
// to stop processing immediately | ||
return false; | ||
} | ||
|
||
|
||
} | ||
//END SNIPPET: interceptor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/ISecurityManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.