码迷,mamicode.com
首页 > 其他好文 > 详细

jax-rs示例

时间:2017-09-20 19:27:14      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:server   ide   param   cto   .com   try   new   filename   cat   

 

compile ‘org.glassfish.jersey.core:jersey-client:2.9.1‘

 

@Path("/{appId}/{env}/downloadSDK")
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
Response downloadSDK(@PathParam("appId") String appId, @PathParam("env") Integer env, @DefaultValue("javascript") String language);

 

@Override
public Response downloadSDK(String appId, Integer env, String language) {
    //swagger json url 待处理
    return generateSDK.generateSDK("http://petstore.swagger.io/v2/swagger.json", language);
}

 

public Response generateSDK(String swaggerjsonUrl, String language) {
    GeneratorInput generatorInput = new GeneratorInput();
    generatorInput.setSwaggerUrl(swaggerjsonUrl);
    try {
        String fileName = Generator.generateClient(language, generatorInput);
        if (StringUtils.isNotEmpty(fileName)) {
            File file = new java.io.File(fileName);
            byte[] bytes = org.apache.commons.io.FileUtils.readFileToByteArray(file);
            try {
                FileUtils.deleteDirectory(file.getParentFile());
            } catch (Exception e) {
                System.out.println("failed to delete file " + file.getAbsolutePath());
            }
            return Response
                    .ok(bytes, "application/zip")
                    .header("Content-Disposition",
                            "attachment; filename=\"" + language + "-client-generated.zip\"")
                    .header("Accept-Range", "bytes").header("Content-Length", bytes.length).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}

 

jax-rs示例

标签:server   ide   param   cto   .com   try   new   filename   cat   

原文地址:http://www.cnblogs.com/hujunzheng/p/7553405.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!