12
12
13
13
import javax .servlet .AsyncContext ;
14
14
import javax .servlet .Servlet ;
15
+ import javax .servlet .ServletConfig ;
15
16
import javax .servlet .ServletException ;
16
17
import javax .servlet .http .HttpServlet ;
17
18
import javax .servlet .http .HttpServletRequest ;
@@ -50,26 +51,52 @@ public abstract class AbstractGraphQLHttpServlet extends HttpServlet implements
50
51
private static final GraphQLRequest INTROSPECTION_REQUEST = new GraphQLRequest (IntrospectionQuery .INTROSPECTION_QUERY , new HashMap <>(), null );
51
52
private static final String [] MULTIPART_KEYS = new String []{"operations" , "graphql" , "query" };
52
53
54
+ /**
55
+ * @deprecated use {@link #getConfiguration()} instead
56
+ */
57
+ @ Deprecated
53
58
protected abstract GraphQLQueryInvoker getQueryInvoker ();
54
59
60
+ /**
61
+ * @deprecated use {@link #getConfiguration()} instead
62
+ */
63
+ @ Deprecated
55
64
protected abstract GraphQLInvocationInputFactory getInvocationInputFactory ();
56
65
66
+ /**
67
+ * @deprecated use {@link #getConfiguration()} instead
68
+ */
69
+ @ Deprecated
57
70
protected abstract GraphQLObjectMapper getGraphQLObjectMapper ();
58
71
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 ();
60
79
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 ;
63
85
64
- private final boolean asyncServletMode ;
86
+ private HttpRequestHandler getHandler ;
87
+ private HttpRequestHandler postHandler ;
65
88
66
89
public AbstractGraphQLHttpServlet () {
67
- this (null , false );
90
+ this (null );
68
91
}
69
92
70
- public AbstractGraphQLHttpServlet (List <GraphQLServletListener > listeners , boolean asyncServletMode ) {
93
+ public AbstractGraphQLHttpServlet (List <GraphQLServletListener > listeners ) {
71
94
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 ();
73
100
74
101
this .getHandler = (request , response ) -> {
75
102
GraphQLInvocationInputFactory invocationInputFactory = getInvocationInputFactory ();
@@ -116,8 +143,8 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
116
143
query (queryInvoker , graphQLObjectMapper , invocationInputFactory .create (new GraphQLRequest (query , null , null )), response );
117
144
} else if (request .getContentType () != null && request .getContentType ().startsWith ("multipart/form-data" ) && !request .getParts ().isEmpty ()) {
118
145
final Map <String , List <Part >> fileItems = request .getParts ()
119
- .stream ()
120
- .collect (Collectors .groupingBy (Part ::getName ));
146
+ .stream ()
147
+ .collect (Collectors .groupingBy (Part ::getName ));
121
148
122
149
for (String key : MULTIPART_KEYS ) {
123
150
// Check to see if there is a part under the key we seek
@@ -134,14 +161,14 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
134
161
InputStream inputStream = asMarkableInputStream (queryItem .get ().getInputStream ());
135
162
136
163
final Optional <Map <String , List <String >>> variablesMap =
137
- getFileItem (fileItems , "map" ).map (graphQLObjectMapper ::deserializeMultipartMap );
164
+ getFileItem (fileItems , "map" ).map (graphQLObjectMapper ::deserializeMultipartMap );
138
165
139
166
if (isBatchedQuery (inputStream )) {
140
167
List <GraphQLRequest > graphQLRequests =
141
- graphQLObjectMapper .readBatchedGraphQLRequest (inputStream );
168
+ graphQLObjectMapper .readBatchedGraphQLRequest (inputStream );
142
169
variablesMap .ifPresent (map -> graphQLRequests .forEach (r -> mapMultipartVariables (r , map , fileItems )));
143
170
GraphQLBatchedInvocationInput invocationInput =
144
- invocationInputFactory .create (graphQLRequests , request , response );
171
+ invocationInputFactory .create (graphQLRequests , request , response );
145
172
invocationInput .getContext ().setParts (fileItems );
146
173
queryBatched (queryInvoker , graphQLObjectMapper , invocationInput , response );
147
174
return ;
@@ -155,7 +182,7 @@ public AbstractGraphQLHttpServlet(List<GraphQLServletListener> listeners, boolea
155
182
156
183
variablesMap .ifPresent (m -> mapMultipartVariables (graphQLRequest , m , fileItems ));
157
184
GraphQLSingleInvocationInput invocationInput =
158
- invocationInputFactory .create (graphQLRequest , request , response );
185
+ invocationInputFactory .create (graphQLRequest , request , response );
159
186
invocationInput .getContext ().setParts (fileItems );
160
187
query (queryInvoker , graphQLObjectMapper , invocationInput , response );
161
188
return ;
@@ -255,7 +282,7 @@ public String executeQuery(String query) {
255
282
}
256
283
257
284
private void doRequestAsync (HttpServletRequest request , HttpServletResponse response , HttpRequestHandler handler ) {
258
- if (asyncServletMode ) {
285
+ if (isAsyncServletMode () ) {
259
286
AsyncContext asyncContext = request .startAsync ();
260
287
HttpServletRequest asyncRequest = (HttpServletRequest ) asyncContext .getRequest ();
261
288
HttpServletResponse asyncResponse = (HttpServletResponse ) asyncContext .getResponse ();
0 commit comments