io.micronaut.http.annotation.Body Java Examples
The following examples show how to use
io.micronaut.http.annotation.Body.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkillController.java From micronaut-aws with Apache License 2.0 | 8 votes |
/** * Handles a POST request. Based on the request parameters, invokes the right method on the {@code Skill}. * * @param httpHeaders HTTP Headers * @param body HTTP Request Body byte array * @return response object that contains the response the servlet sends to the client */ @Post public HttpResponse doPost(HttpHeaders httpHeaders, @Body String body) { try { byte[] serializedRequestEnvelope = body.getBytes(AskHttpServerConstants.CHARACTER_ENCODING); final RequestEnvelope requestEnvelope = objectMapper.readValue(serializedRequestEnvelope, RequestEnvelope.class); requestEnvelopeVerificationService.verify(httpHeaders, serializedRequestEnvelope, requestEnvelope); ResponseEnvelope responseEnvelope = requestEnvelopeService.process(requestEnvelope); if (responseEnvelope != null) { return HttpResponse.ok(responseEnvelope); } } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error("Unable to parse a byte array to RequestEnvelope"); } } return HttpResponse.badRequest(); }
Example #2
Source File: RequestBodyAnnotationMapping.java From micronaut-spring with Apache License 2.0 | 5 votes |
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>(); final boolean required = annotation.get("required", boolean.class).orElse(true); final AnnotationValueBuilder<?> builder = AnnotationValue.builder(Body.class); final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class); mappedAnnotations.add(builder.build()); mappedAnnotations.add(bindableBuilder.build()); if (!required) { mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build()); } return mappedAnnotations; }
Example #3
Source File: GreetController.java From tutorials with MIT License | 4 votes |
@Post(value = "/{name}", consumes = MediaType.TEXT_PLAIN) public String setGreeting(@Body String name) { return greetingService.getGreeting() + name; }
Example #4
Source File: ReactiveController.java From micronaut-gcp with Apache License 2.0 | 4 votes |
@Post(value = "/jsonArray", processes = "application/json") Flowable<Person> jsonArray(@Body Flowable<Person> flowable) { return flowable; }
Example #5
Source File: JsonRpcController.java From consensusj with Apache License 2.0 | 4 votes |
@Post(produces = MediaType.APPLICATION_JSON) public CompletableFuture<JsonRpcResponse<Object>> index(@Body JsonRpcRequest req) { log.debug("JSON-RPC call: {}", req.getMethod()); return jsonRpcService.call(req); }
Example #6
Source File: JsonRpcController.java From consensusj with Apache License 2.0 | 4 votes |
@Post(produces = MediaType.APPLICATION_JSON) public CompletableFuture<JsonRpcResponse<Object>> index(@Body JsonRpcRequest req) { log.info("JSON-RPC call: {}", req.getMethod()); return jsonRpcService.call(req); }
Example #7
Source File: SlackAppController.java From java-slack-sdk with MIT License | 4 votes |
@Post(value = "/events", consumes = {MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON}) public HttpResponse<String> dispatch(HttpRequest<String> request, @Body String body) throws Exception { Request<?> slackRequest = adapter.toSlackRequest(request, body); return adapter.toMicronautResponse(slackApp.run(slackRequest)); }
Example #8
Source File: GraphQLController.java From micronaut-graphql with Apache License 2.0 | 4 votes |
/** * Handles GraphQL {@code POST} requests. * * @param query the GraphQL query * @param operationName the GraphQL operation name * @param variables the GraphQL variables * @param body the GraphQL request body * @param httpRequest the HTTP request * @return the GraphQL response */ @Post(consumes = ALL, produces = APPLICATION_JSON, single = true) public Publisher<String> post( @Nullable @QueryValue("query") String query, @Nullable @QueryValue("operationName") String operationName, @Nullable @QueryValue("variables") String variables, @Nullable @Body String body, HttpRequest httpRequest) { Optional<MediaType> opt = httpRequest.getContentType(); MediaType contentType = opt.orElse(null); if (body == null) { body = ""; } // https://graphql.org/learn/serving-over-http/#post-request // // A standard GraphQL POST request should use the application/json content type, // and include a JSON-encoded body of the following form: // // { // "query": "...", // "operationName": "...", // "variables": { "myVariable": "someValue", ... } // } if (APPLICATION_JSON_TYPE.equals(contentType)) { GraphQLRequestBody request = graphQLJsonSerializer.deserialize(body, GraphQLRequestBody.class); if (request.getQuery() == null) { request.setQuery(""); } return executeRequest(request.getQuery(), request.getOperationName(), request.getVariables(), httpRequest); } // In addition to the above, we recommend supporting two additional cases: // // * If the "query" query string parameter is present (as in the GET example above), // it should be parsed and handled in the same way as the HTTP GET case. if (query != null) { return executeRequest(query, operationName, convertVariablesJson(variables), httpRequest); } // * If the "application/graphql" Content-Type header is present, // treat the HTTP POST body contents as the GraphQL query string. if (APPLICATION_GRAPHQL_TYPE.equals(contentType)) { return executeRequest(body, null, null, httpRequest); } throw new HttpStatusException(UNPROCESSABLE_ENTITY, "Could not process GraphQL request"); }
Example #9
Source File: DashboardGatewayClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Override @Post("/agentssales") GetAgentsSalesQueryResult queryAgentsSales(@Body GetAgentsSalesQuery query);
Example #10
Source File: DashboardGatewayClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Override @Post("/trends") GetSalesTrendsQueryResult querySalesTrends(@Body GetSalesTrendsQuery query);
Example #11
Source File: DashboardGatewayClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Override @Post("/totalsales") GetTotalSalesQueryResult queryTotalSales(@Body GetTotalSalesQuery query);
Example #12
Source File: PolicyGatewayClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/offers") CreateOfferResult createOffer(@Body @NotNull CreateOfferCommand cmd);
Example #13
Source File: DashboardGatewayController.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/agentssales") GetAgentsSalesQueryResult queryAgentsSales(@Body GetAgentsSalesQuery query){ return client.queryAgentsSales(query); }
Example #14
Source File: DashboardGatewayController.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/trends") GetSalesTrendsQueryResult querySalesTrends(@Body GetSalesTrendsQuery query){ return client.querySalesTrends(query); }
Example #15
Source File: DashboardGatewayController.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/totalsales") GetTotalSalesQueryResult queryTotalSales(@Body GetTotalSalesQuery query){ return client.queryTotalSales(query); }
Example #16
Source File: PolicyOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/terminate") TerminatePolicyResult terminate(@Body @NotNull TerminatePolicyCommand cmd);
Example #17
Source File: PolicyOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post CreatePolicyResult create(@Body @NotNull CreatePolicyCommand cmd);
Example #18
Source File: OfferOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/") CreateOfferResult create(@Body @NotNull CreateOfferCommand cmd);
Example #19
Source File: PolicyTestClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/terminate") TerminatePolicyResult terminate(@Body TerminatePolicyCommand cmd);
Example #20
Source File: PolicyTestClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/") CreatePolicyResult create(@Body CreatePolicyCommand cmd);
Example #21
Source File: PricingOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/calculate") CalculatePriceResult calculatePrice(@Body @NotNull CalculatePriceCommand cmd);
Example #22
Source File: DashboardOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/agentssales") GetAgentsSalesQueryResult queryAgentsSales(@Body GetAgentsSalesQuery query);
Example #23
Source File: DashboardOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/trends") GetSalesTrendsQueryResult querySalesTrends(@Body GetSalesTrendsQuery query);
Example #24
Source File: DashboardOperations.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/totalsales") GetTotalSalesQueryResult queryTotalSales(@Body GetTotalSalesQuery query);
Example #25
Source File: PricingTestClient.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
@Post("/calculate") CalculatePriceResult calculatePrice(@Body @NotNull CalculatePriceCommand cmd);
Example #26
Source File: KafkaBodyBinder.java From micronaut-kafka with Apache License 2.0 | 4 votes |
@Override public Class<Body> annotationType() { return Body.class; }
Example #27
Source File: IsbnValidatorClient.java From micronaut-aws with Apache License 2.0 | 4 votes |
@Named("isbn-validator") Single<IsbnValidationResponse> validate(@Body IsbnValidationRequest request);