Search in sources :

Example 1 with ProgressEntityWrapper

use of io.videofirst.capture.http.ProgressEntityWrapper in project vft-capture by videofirst.

the class DefaultUploadService method getHttpPost.

/**
 * Prepare HTTP Post upload call
 */
private HttpPost getHttpPost(Capture capture) {
    // Get capture file and data file
    File videoFile = validateExists(capture.getVideoFile());
    File dataFile = validateExists(capture.getDataFile());
    HttpPost httpPost = new HttpPost(uploadConfig.getUrl());
    uploadConfig.getHeaders().entrySet().stream().forEach(e -> httpPost.setHeader(e.getKey(), e.getValue()));
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody(PARAM_VIDEO, videoFile, ContentType.DEFAULT_BINARY, videoFile.getName());
    builder.addBinaryBody(PARAM_DATA, dataFile, ContentType.DEFAULT_BINARY, dataFile.getName());
    HttpEntity multipart = builder.build();
    ProgressListener pListener = new VideoUploadProgressListener(captureDao, capture, DAO_UPDATE_INTERVAL_MILLIS);
    httpPost.setEntity(new ProgressEntityWrapper(multipart, pListener));
    return httpPost;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) HttpEntity(org.apache.http.HttpEntity) ProgressListener(io.videofirst.capture.http.ProgressListener) File(java.io.File) ProgressEntityWrapper(io.videofirst.capture.http.ProgressEntityWrapper)

Example 2 with ProgressEntityWrapper

use of io.videofirst.capture.http.ProgressEntityWrapper in project vft-capture by videofirst.

the class MockUploadController method main.

/**
 * Manually hit an end-point.
 */
public static void main(String[] args) throws IOException {
    String dir = "src/test/resources/videos/acme/moon-rocket/ui/bob-feature/dave-scenario/2018-02-15_12-14-02_n3jwzb/";
    File videoFile = new File(dir + "2018-02-15_12-14-02_n3jwzb.avi");
    File dataFile = new File(dir + "2018-02-15_12-14-02_n3jwzb.json");
    CloseableHttpClient client = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("http://localhost:1357/mock-upload");
    httpPost.setHeader("Authorization", "Basic dGVzdDpwYXNzd29yZA==");
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    builder.addBinaryBody("video", videoFile, ContentType.DEFAULT_BINARY, videoFile.getName());
    builder.addBinaryBody("data", dataFile, ContentType.DEFAULT_BINARY, dataFile.getName());
    HttpEntity multipart = builder.build();
    ProgressListener pListener = (transferredBytes, totalBytes) -> System.out.println("transferredBytes [ " + transferredBytes + " ] , totalBytes [ " + totalBytes + " ] ");
    httpPost.setEntity(new ProgressEntityWrapper(multipart, pListener));
    System.out.println("Posting");
    CloseableHttpResponse response = client.execute(httpPost);
    System.out.println(response.getStatusLine().getStatusCode());
    client.close();
    System.out.println("Done");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) PostMapping(org.springframework.web.bind.annotation.PostMapping) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RequestParam(org.springframework.web.bind.annotation.RequestParam) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IOException(java.io.IOException) Profile(org.springframework.context.annotation.Profile) RestController(org.springframework.web.bind.annotation.RestController) File(java.io.File) ProgressEntityWrapper(io.videofirst.capture.http.ProgressEntityWrapper) ProgressListener(io.videofirst.capture.http.ProgressListener) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) HttpClients(org.apache.http.impl.client.HttpClients) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) HttpEntity(org.apache.http.HttpEntity) ProgressListener(io.videofirst.capture.http.ProgressListener) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ProgressEntityWrapper(io.videofirst.capture.http.ProgressEntityWrapper)

Aggregations

ProgressEntityWrapper (io.videofirst.capture.http.ProgressEntityWrapper)2 ProgressListener (io.videofirst.capture.http.ProgressListener)2 File (java.io.File)2 HttpEntity (org.apache.http.HttpEntity)2 HttpPost (org.apache.http.client.methods.HttpPost)2 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)2 IOException (java.io.IOException)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 ContentType (org.apache.http.entity.ContentType)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpClients (org.apache.http.impl.client.HttpClients)1 Profile (org.springframework.context.annotation.Profile)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RequestParam (org.springframework.web.bind.annotation.RequestParam)1 RestController (org.springframework.web.bind.annotation.RestController)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1