• jax-rs示例


    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();
        }
    }
  • 相关阅读:
    ubuntu install gobgp
    ubunut install golang
    Using GoBGP as an IXP connecting router
    400 行 C 代码实现一个虚拟机
    IPv6 Segment Routing (SRv6)
    How to Install VPP in ubuntu x86 or arm64
    mpls + sr + bgp
    ospf sr
    520了,用32做个简单的小程序
    FPGA设计经验总结
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/7553405.html
Copyright © 2020-2023  润新知