@ ReadOperation public WebEndpointResponse < Resource > exportServices ( ) throws Exception { val date = new SimpleDateFormat ( "yyyy-MM-dd-HH-mm" ) . format ( new Date ( ) ) ; val file = File . createTempFile ( "services-" + date , ".zip" ) ; Files . deleteIfExists ( file . toPath ( ) ) ; val env = new HashMap < String , Object > ( ) ; env . put ( "create" , "true" ) ; env . put ( "encoding" , StandardCharsets . UTF_8 . name ( ) ) ; try ( val zipfs = FileSystems . newFileSystem ( URI . create ( "jar:" + file . toURI ( ) . toString ( ) ) , env ) ) { val serializer = new RegisteredServiceJsonSerializer ( ) ; val services = this . servicesManager . load ( ) ; services . forEach ( Unchecked . consumer ( service -> { val fileName = String . format ( "%s-%s" , service . getName ( ) , service . getId ( ) ) ; val sourceFile = File . createTempFile ( fileName , ".json" ) ; serializer . to ( sourceFile , service ) ; if ( sourceFile . exists ( ) ) { val pathInZipfile = zipfs . getPath ( "/" . concat ( sourceFile . getName ( ) ) ) ; Files . copy ( sourceFile . toPath ( ) , pathInZipfile , StandardCopyOption . REPLACE_EXISTING ) ; } } ) ) ; } val resource = new TemporaryFileSystemResource ( file ) ; return new WebEndpointResponse ( resource ) ; }
Export services web endpoint response .