|
30 | 30 | import graphql.schema.GraphQLFieldDefinition; |
31 | 31 | import graphql.schema.GraphQLSchema; |
32 | 32 | import graphql.validation.ValidationError; |
33 | | -import lombok.Getter; |
34 | | -import lombok.Setter; |
35 | | -import lombok.SneakyThrows; |
36 | | -import lombok.extern.slf4j.Slf4j; |
37 | 33 | import org.apache.commons.fileupload.FileItem; |
38 | 34 | import org.apache.commons.fileupload.FileItemFactory; |
39 | 35 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
40 | 36 | import org.apache.commons.fileupload.servlet.ServletFileUpload; |
| 37 | +import org.slf4j.Logger; |
| 38 | +import org.slf4j.LoggerFactory; |
41 | 39 |
|
42 | 40 | import javax.security.auth.Subject; |
43 | 41 | import javax.servlet.Servlet; |
|
62 | 60 | /** |
63 | 61 | * @author Andrew Potter |
64 | 62 | */ |
65 | | -@Slf4j |
66 | 63 | public abstract class GraphQLServlet extends HttpServlet implements Servlet, GraphQLMBean, GraphQLSchemaProvider { |
67 | 64 |
|
| 65 | + public static final Logger log = LoggerFactory.getLogger(GraphQLServlet.class); |
| 66 | + |
68 | 67 | public static final String APPLICATION_JSON_UTF8 = "application/json;charset=UTF-8"; |
69 | 68 | public static final int STATUS_OK = 200; |
70 | 69 | public static final int STATUS_BAD_REQUEST = 400; |
@@ -212,7 +211,7 @@ public String[] getMutations() { |
212 | 211 | return getSchema().getMutationType().getFieldDefinitions().stream().map(GraphQLFieldDefinition::getName).toArray(String[]::new); |
213 | 212 | } |
214 | 213 |
|
215 | | - @Override @SneakyThrows |
| 214 | + @Override |
216 | 215 | public String executeQuery(String query) { |
217 | 216 | try { |
218 | 217 | final ExecutionResult result = new GraphQL(getSchema()).execute(query, createContext(Optional.empty(), Optional.empty()), new HashMap<>()); |
@@ -258,12 +257,13 @@ private Optional<FileItem> getFileItem(Map<String, List<FileItem>> fileItems, St |
258 | 257 |
|
259 | 258 | private void query(String query, String operationName, Map<String, Object> variables, GraphQLSchema schema, HttpServletRequest req, HttpServletResponse resp, GraphQLContext context) throws IOException { |
260 | 259 | if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject().isPresent()) { |
261 | | - Subject.doAs(context.getSubject().get(), new PrivilegedAction<Void>() { |
262 | | - @Override @SneakyThrows |
263 | | - public Void run() { |
| 260 | + Subject.doAs(context.getSubject().get(), (PrivilegedAction<Void>) () -> { |
| 261 | + try { |
264 | 262 | query(query, operationName, variables, schema, req, resp, context); |
265 | | - return null; |
| 263 | + } catch (IOException e) { |
| 264 | + throw new RuntimeException(e); |
266 | 265 | } |
| 266 | + return null; |
267 | 267 | }); |
268 | 268 | } else { |
269 | 269 | runListeners(operationListeners, l -> runListener(l, it -> it.beforeGraphQLOperation(context, operationName, query, variables))); |
@@ -345,13 +345,34 @@ public Map<String, Object> deserialize(JsonParser p, DeserializationContext ctxt |
345 | 345 | } |
346 | 346 |
|
347 | 347 | protected static class GraphQLRequest { |
348 | | - @Getter |
349 | | - @Setter |
350 | 348 | private String query; |
351 | | - @Getter @Setter @JsonDeserialize(using = GraphQLServlet.VariablesDeserializer.class) |
| 349 | + @JsonDeserialize(using = GraphQLServlet.VariablesDeserializer.class) |
352 | 350 | private Map<String, Object> variables = new HashMap<>(); |
353 | | - @Getter @Setter |
354 | 351 | private String operationName; |
| 352 | + |
| 353 | + public String getQuery() { |
| 354 | + return query; |
| 355 | + } |
| 356 | + |
| 357 | + public void setQuery(String query) { |
| 358 | + this.query = query; |
| 359 | + } |
| 360 | + |
| 361 | + public Map<String, Object> getVariables() { |
| 362 | + return variables; |
| 363 | + } |
| 364 | + |
| 365 | + public void setVariables(Map<String, Object> variables) { |
| 366 | + this.variables = variables; |
| 367 | + } |
| 368 | + |
| 369 | + public String getOperationName() { |
| 370 | + return operationName; |
| 371 | + } |
| 372 | + |
| 373 | + public void setOperationName(String operationName) { |
| 374 | + this.operationName = operationName; |
| 375 | + } |
355 | 376 | } |
356 | 377 |
|
357 | 378 | protected interface RequestHandler extends BiConsumer<HttpServletRequest, HttpServletResponse> { |
|
0 commit comments