use of core.framework.web.Request in project core-ng-project by neowu.
the class WebServiceControllerBuilder method buildMethod.
private String buildMethod() {
CodeBuilder builder = new CodeBuilder();
builder.append("public {} execute({} request) throws Exception {\n", type(Response.class), type(Request.class));
List<String> params = Lists.newArrayList();
Annotation[][] annotations = method.getParameterAnnotations();
Type[] paramTypes = method.getGenericParameterTypes();
for (int i = 0; i < annotations.length; i++) {
Type paramType = paramTypes[i];
String paramTypeLiteral = type(paramType);
PathParam pathParam = Params.annotation(annotations[i], PathParam.class);
if (pathParam != null) {
params.add(pathParam.value());
builder.indent(1).append("{} {} = ({}) request.pathParam(\"{}\", {});\n", paramTypeLiteral, pathParam.value(), paramTypeLiteral, pathParam.value(), variable(paramType));
} else {
params.add("bean");
builder.indent(1).append("{} bean = ({}) request.bean({});\n", paramTypeLiteral, paramTypeLiteral, variable(paramType));
}
}
if (void.class == method.getReturnType()) {
builder.indent(1).append("delegate.{}(", method.getName());
} else {
builder.indent(1).append("{} response = delegate.{}(", type(method.getReturnType()), method.getName());
}
builder.appendCommaSeparatedValues(params).append(");\n");
if (void.class.equals(method.getReturnType())) {
builder.indent(1).append("return {}.empty().status({});\n", Response.class.getCanonicalName(), variable(responseStatus));
} else {
builder.indent(1).append("return {}.bean(response).status({});\n", Response.class.getCanonicalName(), variable(responseStatus));
}
builder.append("}");
return builder.build();
}
use of core.framework.web.Request in project core-ng-project by neowu.
the class WebSecurityInterceptor method intercept.
@Override
public Response intercept(Invocation invocation) throws Exception {
Request request = invocation.context().request();
if (!"https".equals(request.scheme())) {
return Response.redirect(redirectURL(request), HTTPStatus.MOVED_PERMANENTLY);
} else {
Response response = invocation.proceed();
response.header("Strict-Transport-Security", "max-age=31536000");
response.contentType().ifPresent(contentType -> {
if (ContentType.TEXT_HTML.mediaType().equals(contentType.mediaType())) {
response.header("X-Frame-Options", "DENY");
response.header("X-XSS-Protection", "1; mode=block");
}
response.header("X-Content-Type-Options", "nosniff");
});
return response;
}
}
Aggregations