From f8858a2cefdbbbd7785e0bfc5a3f7de3a703500a Mon Sep 17 00:00:00 2001 From: Jimmy Sun Date: Mon, 16 Nov 2020 14:22:10 -0800 Subject: [PATCH] Allow Request Handler construct and calling for frameworks like Jersey not needing servlet construct --- .../servlet/AbstractGraphQLHttpServlet.java | 2 +- .../kickstart/servlet/HttpRequestHandler.java | 2 +- .../servlet/HttpRequestHandlerFactory.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandlerFactory.java diff --git a/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/AbstractGraphQLHttpServlet.java b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/AbstractGraphQLHttpServlet.java index 1a955f9e..60b735f6 100644 --- a/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/AbstractGraphQLHttpServlet.java +++ b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/AbstractGraphQLHttpServlet.java @@ -83,7 +83,7 @@ protected GraphQLConfiguration getConfiguration() { public void init() { if (configuration == null) { this.configuration = getConfiguration(); - this.requestHandler = new HttpRequestHandlerImpl(configuration); + this.requestHandler = HttpRequestHandlerFactory.create(configuration); } } diff --git a/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandler.java b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandler.java index 758d2f8e..5c7a2dca 100644 --- a/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandler.java +++ b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandler.java @@ -3,7 +3,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -interface HttpRequestHandler { +public interface HttpRequestHandler { String APPLICATION_JSON_UTF8 = "application/json;charset=UTF-8"; String APPLICATION_EVENT_STREAM_UTF8 = "text/event-stream;charset=UTF-8"; diff --git a/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandlerFactory.java b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandlerFactory.java new file mode 100644 index 00000000..92a600af --- /dev/null +++ b/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestHandlerFactory.java @@ -0,0 +1,14 @@ +package graphql.kickstart.servlet; + +public interface HttpRequestHandlerFactory { + + /** + * Create a Request Handler instance for current servlet constructs + * and frameworks not needing explicit servlet construct (Jersey). + * @param configuration GraphQLConfiguration object + * @return HttpRequestHandler interface instance + */ + static HttpRequestHandler create(GraphQLConfiguration configuration) { + return new HttpRequestHandlerImpl(configuration); + } +}