1212
1313import javax .servlet .AsyncContext ;
1414import javax .servlet .Servlet ;
15+ import javax .servlet .ServletConfig ;
1516import javax .servlet .ServletException ;
1617import javax .servlet .http .HttpServlet ;
1718import javax .servlet .http .HttpServletRequest ;
@@ -50,26 +51,52 @@ public abstract class AbstractGraphQLHttpServlet extends HttpServlet implements
5051 private static final GraphQLRequest INTROSPECTION_REQUEST = new GraphQLRequest (IntrospectionQuery .INTROSPECTION_QUERY , new HashMap <>(), null );
5152 private static final String [] MULTIPART_KEYS = new String []{"operations" , "graphql" , "query" };
5253
54+ /**
55+ * @deprecated use {@link #getConfiguration()} instead
56+ */
57+ @ Deprecated
5358 protected abstract GraphQLQueryInvoker getQueryInvoker ();
5459
60+ /**
61+ * @deprecated use {@link #getConfiguration()} instead
62+ */
63+ @ Deprecated
5564 protected abstract GraphQLInvocationInputFactory getInvocationInputFactory ();
5665
66+ /**
67+ * @deprecated use {@link #getConfiguration()} instead
68+ */
69+ @ Deprecated
5770 protected abstract GraphQLObjectMapper getGraphQLObjectMapper ();
5871
59- private final List <GraphQLServletListener > listeners ;
72+ /**
73+ * @deprecated use {@link #getConfiguration()} instead
74+ */
75+ @ Deprecated
76+ protected abstract boolean isAsyncServletMode ();
77+
78+ protected abstract GraphQLConfiguration getConfiguration ();
6079
61- private final HttpRequestHandler getHandler ;
62- private final HttpRequestHandler postHandler ;
80+ /**
81+ * @deprecated use {@link #getConfiguration()} instead
82+ */
83+ @ Deprecated
84+ private final List <GraphQLServletListener > listeners ;
6385
64- private final boolean asyncServletMode ;
86+ private HttpRequestHandler getHandler ;
87+ private HttpRequestHandler postHandler ;
6588
6689 public AbstractGraphQLHttpServlet () {
67- this (null , false );
90+ this (null );
6891 }
6992
70- public AbstractGraphQLHttpServlet (List <GraphQLServletListener > listeners , boolean asyncServletMode ) {
93+ public AbstractGraphQLHttpServlet (List <GraphQLServletListener > listeners ) {
7194 this .listeners = listeners != null ? new ArrayList <>(listeners ) : new ArrayList <>();
72- this .asyncServletMode = asyncServletMode ;
95+ }
96+
97+ @ Override
98+ public void init (ServletConfig config ) {
99+ GraphQLConfiguration configuration = getConfiguration ();
73100
74101 this .getHandler = (request , response ) -> {
75102 GraphQLInvocationInputFactory invocationInputFactory = getInvocationInputFactory ();
@@ -116,8 +143,8 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
116143 query (queryInvoker , graphQLObjectMapper , invocationInputFactory .create (new GraphQLRequest (query , null , null )), response );
117144 } else if (request .getContentType () != null && request .getContentType ().startsWith ("multipart/form-data" ) && !request .getParts ().isEmpty ()) {
118145 final Map <String , List <Part >> fileItems = request .getParts ()
119- .stream ()
120- .collect (Collectors .groupingBy (Part ::getName ));
146+ .stream ()
147+ .collect (Collectors .groupingBy (Part ::getName ));
121148
122149 for (String key : MULTIPART_KEYS ) {
123150 // Check to see if there is a part under the key we seek
@@ -134,14 +161,14 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
134161 InputStream inputStream = asMarkableInputStream (queryItem .get ().getInputStream ());
135162
136163 final Optional <Map <String , List <String >>> variablesMap =
137- getFileItem (fileItems , "map" ).map (graphQLObjectMapper ::deserializeMultipartMap );
164+ getFileItem (fileItems , "map" ).map (graphQLObjectMapper ::deserializeMultipartMap );
138165
139166 if (isBatchedQuery (inputStream )) {
140167 List <GraphQLRequest > graphQLRequests =
141- graphQLObjectMapper .readBatchedGraphQLRequest (inputStream );
168+ graphQLObjectMapper .readBatchedGraphQLRequest (inputStream );
142169 variablesMap .ifPresent (map -> graphQLRequests .forEach (r -> mapMultipartVariables (r , map , fileItems )));
143170 GraphQLBatchedInvocationInput invocationInput =
144- invocationInputFactory .create (graphQLRequests , request , response );
171+ invocationInputFactory .create (graphQLRequests , request , response );
145172 invocationInput .getContext ().setParts (fileItems );
146173 queryBatched (queryInvoker , graphQLObjectMapper , invocationInput , response );
147174 return ;
@@ -155,7 +182,7 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
155182
156183 variablesMap .ifPresent (m -> mapMultipartVariables (graphQLRequest , m , fileItems ));
157184 GraphQLSingleInvocationInput invocationInput =
158- invocationInputFactory .create (graphQLRequest , request , response );
185+ invocationInputFactory .create (graphQLRequest , request , response );
159186 invocationInput .getContext ().setParts (fileItems );
160187 query (queryInvoker , graphQLObjectMapper , invocationInput , response );
161188 return ;
@@ -255,7 +282,7 @@ public String executeQuery(String query) {
255282 }
256283
257284 private void doRequestAsync (HttpServletRequest request , HttpServletResponse response , HttpRequestHandler handler ) {
258- if (asyncServletMode ) {
285+ if (isAsyncServletMode () ) {
259286 AsyncContext asyncContext = request .startAsync ();
260287 HttpServletRequest asyncRequest = (HttpServletRequest ) asyncContext .getRequest ();
261288 HttpServletResponse asyncResponse = (HttpServletResponse ) asyncContext .getResponse ();
0 commit comments