Search in sources :

Example 1 with HttpService

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;
}
Also used : HttpService(com.luastar.swift.http.server.HttpService)

Example 2 with HttpService

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());
}
Also used : Book(com.luastar.swift.demo.http.entity.Book) HttpService(com.luastar.swift.http.server.HttpService)

Example 3 with HttpService

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);
    }
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HttpService(com.luastar.swift.http.server.HttpService)

Example 4 with HttpService

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 !");
}
Also used : IOException(java.io.IOException) Map(java.util.Map) File(java.io.File) FileUpload(io.netty.handler.codec.http.multipart.FileUpload) HttpService(com.luastar.swift.http.server.HttpService)

Example 5 with HttpService

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());
}
Also used : Book(com.luastar.swift.demo.http.entity.Book) HttpService(com.luastar.swift.http.server.HttpService)

Aggregations

HttpService (com.luastar.swift.http.server.HttpService)6 IOException (java.io.IOException)3 Book (com.luastar.swift.demo.http.entity.Book)2 FileUpload (io.netty.handler.codec.http.multipart.FileUpload)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1