@Override public Object resolve(RoutingContext context, RequestBody annotation, Class<?> resultClass) { String body = context.getBodyAsString(); if (resultClass.equals(String.class)) { return body; } String contentType = ContentTypeProcessor.getContentType(context); if (contentType == null) { log.error("No suitable Content-Type found, request body can't be read"); return null; } if (contentType.equals("application/json") && resultClass.equals(JsonObject.class)) { return new JsonObject(body); } PayloadMarshaller marshaller = marshallers.get(contentType); if (marshaller == null) { log.error( "No marshaller found for Content-Type : " + contentType + ", request body can't be read"); return null; } try { return marshaller.unmarshallPayload(body, resultClass); } catch (MarshallingException me) { context.fail(me); return null; } }
private void addOne(RoutingContext routingContext) { FactorizationTask task = Json.decodeValue(routingContext.getBodyAsString(), FactorizationTask.class); task = service.create(task.getNumber()); routingContext .response() .setStatusCode(201) .putHeader("content-type", "application/json; charset=utf-8") .end(Json.encodePrettily(task)); }
private void postRoutine(RoutingContext routingContext) { String body = routingContext.getBodyAsString(); String res; try (JShellEvaluator evaluator = new JShellEvaluator()) { res = evaluator.evalSnippets(JShellParser.parseToSnippets(body)); } catch (IOException e) { res = "Unable to evaluation the code"; } routingContext.response().setChunked(true).putHeader("content-type", "text/html").write(res); routingContext.response().end(); }
public void PostChoir(RoutingContext rc) { Choir choir = TestUtility.toChoirFromJson(rc.getBodyAsString()); rc.response().end(choir.toJson(false)); }