|
| 1 | +# 7.0.0 Interceptor Upgrade Guide |
| 2 | + |
| 3 | +As of HAPI-FHIR 7.0.0, dependency on the `javax.*` packages has now changed to instead use the `jakarta.*` packages. This is a breaking change for any users who have written their own interceptors, as the package names of the interfaces have changed. |
| 4 | + |
| 5 | +In order to upgrade your interceptors, you will need to change, at a minimum, the imports in your affected interceptor implementations. For example, if you have an interceptor that uses imports such as `javax.servlet.http.HttpServletRequest`, you will need to change these to `jakarta.servlet.http.HttpServletRequest`. The following is an example of a migration of an interceptor. |
| 6 | + |
| 7 | +## Example |
| 8 | + |
| 9 | +### Old Server Interceptor |
| 10 | + |
| 11 | +```java |
| 12 | +package com.example; |
| 13 | + |
| 14 | +import ca.uhn.fhir.interceptor.api.Hook; |
| 15 | +import ca.uhn.fhir.interceptor.api.Pointcut; |
| 16 | +import org.slf4j.Logger; |
| 17 | +import org.slf4j.LoggerFactory; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | + |
| 20 | +import javax.servlet.http.HttpServletRequest; |
| 21 | +import javax.servlet.http.HttpServletResponse; |
| 22 | +import java.util.Iterator; |
| 23 | +import java.util.function.Supplier; |
| 24 | + |
| 25 | +public class SampleInteceptor{ |
| 26 | + |
| 27 | + private static final Logger ourLog = LoggerFactory.getLogger(SampleInteceptor.class); |
| 28 | + |
| 29 | + @Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_PROCESSED) |
| 30 | + public boolean serverIncomingRequestPreProcessed(HttpServletRequest theHttpServletRequest, HttpServletResponse theHttpServletResponse) { |
| 31 | + ourLog.info("I'm an interceptor!"); |
| 32 | + return true; |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## New Server Interceptor |
| 38 | + |
| 39 | +```java |
| 40 | +package com.example; |
| 41 | + |
| 42 | +import ca.uhn.fhir.interceptor.api.Hook; |
| 43 | +import ca.uhn.fhir.interceptor.api.Pointcut; |
| 44 | +import org.slf4j.Logger; |
| 45 | +import org.slf4j.LoggerFactory; |
| 46 | +import org.springframework.beans.factory.annotation.Autowired; |
| 47 | + |
| 48 | +import jakarta.servlet.http.HttpServletRequest; |
| 49 | +import jakarta.servlet.http.HttpServletResponse; |
| 50 | +import java.util.Iterator; |
| 51 | +import java.util.function.Supplier; |
| 52 | + |
| 53 | +public class SampleInteceptor{ |
| 54 | + |
| 55 | + private static final Logger ourLog = LoggerFactory.getLogger(SampleInteceptor.class); |
| 56 | + |
| 57 | + @Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_PROCESSED) |
| 58 | + public boolean serverIncomingRequestPreProcessed(HttpServletRequest theHttpServletRequest, HttpServletResponse theHttpServletResponse) { |
| 59 | + ourLog.info("I'm an interceptor!"); |
| 60 | + return true; |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +You'll note that there is only one very subtle difference between these two versions, and that is the change from: |
| 66 | + |
| 67 | +```java |
| 68 | +import javax.servlet.http.HttpServletRequest; |
| 69 | +import javax.servlet.http.HttpServletResponse; |
| 70 | +``` |
| 71 | + |
| 72 | +to: |
| 73 | + |
| 74 | +```java |
| 75 | +import jakarta.servlet.http.HttpServletRequest; |
| 76 | +import jakarta.servlet.http.HttpServletResponse; |
| 77 | +``` |
| 78 | + |
0 commit comments