From 10c49d2bd381ce7de2724d8a943967d6b5f3925f Mon Sep 17 00:00:00 2001 From: petromykhailyshyn Date: Fri, 17 Oct 2014 12:52:09 +0300 Subject: [PATCH] Added Cookie interceptor. --- .../client/interceptor/CookieInterceptor.java | 33 +++++++++++++++++++ .../ca/uhn/fhir/rest/server/Constants.java | 1 + 2 files changed, 34 insertions(+) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/CookieInterceptor.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/CookieInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/CookieInterceptor.java new file mode 100644 index 00000000000..998741af954 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/CookieInterceptor.java @@ -0,0 +1,33 @@ +package ca.uhn.fhir.rest.client.interceptor; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpRequestBase; + +import ca.uhn.fhir.rest.client.IClientInterceptor; +import ca.uhn.fhir.rest.server.Constants; + +/** + * HTTP interceptor to be used for adding Cookie to requests. + *

+ * This interceptor adds a header resembling the following:
+ *    Cookie: [key]=[value]
+ *

+ */ + +public class CookieInterceptor implements IClientInterceptor { + private final String sessionCookie; + + public CookieInterceptor(String sessionCookie) { + this.sessionCookie = sessionCookie; + } + + @Override + public void interceptRequest(HttpRequestBase theRequest) { + theRequest.addHeader(Constants.HEADER_COOKIE, sessionCookie); //$NON-NLS-1$ + } + + @Override + public void interceptResponse(HttpResponse theResponse) { + // nothing + } +} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java index 057cc8b4ac2..fbf76fa06f7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java @@ -56,6 +56,7 @@ public class Constants { public static final String HEADER_CONTENT_LOCATION = "Content-Location"; public static final String HEADER_CONTENT_LOCATION_LC = HEADER_CONTENT_LOCATION.toLowerCase(); public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String HEADER_COOKIE = "Cookie"; public static final String HEADER_CORS_ALLOW_METHODS = "Access-Control-Allow-Methods"; public static final String HEADER_CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; public static final String HEADER_CORS_EXPOSE_HEADERS = "Access-Control-Expose-Headers";