use of com.luastar.swift.http.server.HttpService in project swift by luastar.
the class HttpHandlerMapping method getMappingForMethod.
/**
* Provide the mapping for a handler method. A method for which no
* mapping can be provided is not a handler method.
*
* @param method the method to provide a mapping for
* @param handlerType the handler type, possibly a sub-type of the method's
* declaring class
* @return the mapping, or {@code null} if the method is not mapped
*/
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = null;
HttpService methodAnnotation = AnnotationUtils.findAnnotation(method, HttpService.class);
if (methodAnnotation != null) {
info = createRequestMappingInfo(methodAnnotation);
HttpService typeAnnotation = AnnotationUtils.findAnnotation(handlerType, HttpService.class);
if (typeAnnotation != null) {
info = createRequestMappingInfo(typeAnnotation).combine(info);
}
}
return info;
}
use of com.luastar.swift.http.server.HttpService in project swift by luastar.
the class TestController method validateJson.
@HttpService("/validate/json")
public void validateJson(HttpRequest request, HttpResponse response) {
Book book = request.getBodyObject(Book.class);
logger.info(book.toString());
// response
response.setResponseContentTypePlain();
response.setResult(book.toString());
}
use of com.luastar.swift.http.server.HttpService in project swift by luastar.
the class TestController method download.
@HttpService("/download")
public void download(HttpRequest request, HttpResponse response) {
try {
Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("sheet1");
Row row = sheet.createRow((short) 0);
row.createCell(0).setCellValue(createHelper.createRichTextString("aaa"));
row.createCell(1).setCellValue(createHelper.createRichTextString("bbb"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
wb.write(outputStream);
response.setResponseContentTypeStream("aaa.xlsx");
response.setOutputStream(outputStream);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
use of com.luastar.swift.http.server.HttpService in project swift by luastar.
the class TestController method upload.
@HttpService("/upload")
public void upload(HttpRequest request, HttpResponse response) {
logger.info("----------come into TestCtrl[upload]");
for (Map.Entry<String, FileUpload> file : request.getFileMap().entrySet()) {
logger.info("request parameter : {}={}", file.getKey(), file.getValue().getFilename());
try {
File saveFile = new File("/Users/zhuminghua/Downloads/" + file.getValue().getFilename());
FileUtils.copyInputStreamToFile(request.getFileInputStream(file.getValue()), saveFile);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
// response
response.setResponseContentTypePlain();
response.setResult("TestCtrl[upload] OK !");
}
use of com.luastar.swift.http.server.HttpService in project swift by luastar.
the class TestController method validateForm.
@HttpService("/validate/form")
public void validateForm(HttpRequest request, HttpResponse response) {
Book book = request.bindObj(new Book());
logger.info(book.toString());
// response
response.setResponseContentTypePlain();
response.setResult(book.toString());
}
Aggregations