Commit 696e2e8b authored by Adrien's avatar Adrien

and an endpoint to test the return of the file

parent 4af2fc11
......@@ -47,6 +47,7 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.springframework.boot:spring-boot-starter-web:$spring_boot_version"
compile "org.springframework.boot:spring-boot-starter-test:$spring_boot_version"
compile "org.apache.commons:commons-io:1.3.2"
testCompile 'org.jetbrains.spek:spek-api:1.1.5'
testCompile 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
testCompile 'org.junit.platform:junit-platform-runner:1.0.0'
......
......@@ -14,6 +14,7 @@
*/
package org.bonitasoft.releng
import org.apache.commons.io.IOUtils
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.bonitasoft.exception.BuildDmgException
......@@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
import java.io.File
import java.io.FileInputStream
import java.lang.RuntimeException
import java.nio.file.Files
import javax.servlet.http.HttpServletResponse
......@@ -36,6 +38,31 @@ class CodeSigningRestController {
var windowsCodeSign = WindowsCodeSign()
var macCodeSign = MacCodeSign()
@PostMapping("/test")
fun signProduct(response: HttpServletResponse): StreamingResponseBody {
val file : File = File("/Users/codesign/Downloads/BonitaStudioCommunity-7.8.9-SNAPSHOT-x86.exe")
response.setContentType("application/octet-stream")
response.setHeader("Content-Disposition", "attachment; filename='${file.name}'")
logger.info("returning file " + file.name +"...")
return StreamingResponseBody { outputStream ->
FileInputStream(file.canonicalFile).use { inputStream ->
try {
val bytesCopied: Int = IOUtils.copy(inputStream, outputStream)
logger.info(bytesCopied.toString() + " have been copied")
} catch (e: Exception) {
logger.error("An error occured during stream copy", e)
} catch (e: RuntimeException) {
logger.error("An error occured during stream copy", e)
}
outputStream.flush()
outputStream.close()
}
}
}
@PostMapping("/sign")
fun signProduct(@RequestParam("exeFile") file: MultipartFile,
response: HttpServletResponse): StreamingResponseBody {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment