use of org.apache.tapestry5.annotations.RequestBody in project tapestry-5 by apache.
the class OnEventWorker method createRequestBodyProvider.
@SuppressWarnings({ "unchecked", "rawtypes" })
private EventHandlerMethodParameterProvider createRequestBodyProvider(PlasticMethod method, final int parameterIndex, final String parameterTypeName, final boolean allowEmpty) {
final String methodIdentifier = method.getMethodIdentifier();
return (event) -> {
Invokable<Object> operation = () -> {
Class parameterType = classCache.forName(parameterTypeName);
Optional result = restSupport.getRequestBodyAs(parameterType);
if (!allowEmpty && !result.isPresent()) {
throw new RuntimeException(String.format("The request has an empty body and %s has one parameter with @RequestBody(allowEmpty=false)", methodIdentifier));
}
return result.orElse(null);
};
return operationTracker.invoke("Converting HTTP request body for @RequestBody parameter", operation);
};
}
use of org.apache.tapestry5.annotations.RequestBody in project tapestry-5 by apache.
the class DefaultOpenApiDescriptionGenerator method processRequestBody.
private void processRequestBody(Method method, final String uri, final String httpMethod, final JSONObject methodDescription, JSONArray parametersAsJsonArray, Parameter parameter) {
JSONObject requestBodyDescription = new JSONObject();
requestBodyDescription.put("required", !(parameter.getAnnotation(RequestBody.class).allowEmpty()));
getValue(method, uri, httpMethod, "requestbody.description").ifPresent((v) -> requestBodyDescription.put("description", v));
RestInfo restInfo = method.getAnnotation(RestInfo.class);
if (restInfo != null) {
JSONObject contentDescription = new JSONObject();
for (String contentType : restInfo.consumes()) {
JSONObject schemaDescription = new JSONObject();
typeDescriber.describe(schemaDescription, parameter);
schemaDescription.remove("required");
contentDescription.put(contentType, schemaDescription);
}
requestBodyDescription.put("content", contentDescription);
}
methodDescription.put("requestBody", requestBodyDescription);
}
use of org.apache.tapestry5.annotations.RequestBody in project tapestry-5 by apache.
the class Index method onHttpPut.
@RestInfo(consumes = "application/json")
public Object onHttpPut(@RequestBody User user) throws UnsupportedEncodingException {
HttpStatus status;
if (!USERS.contains(user)) {
USERS.add(user);
status = HttpStatus.created();
} else {
status = HttpStatus.ok();
}
return status.withContentLocation(pageRenderLinkSource.createPageRenderLinkWithContext(Index.class, user.getEmail()));
}
Aggregations