@Test public void testUploadDataSet() throws IOException, URISyntaxException, ResponseStatusException { final String data_id = "data-id=00987123"; mockServer .expect(requestTo( "https: .andExpect(method(HttpMethod.PUT)).andRespond(withCreatedEntity( new URI("https: final File file = new File(getClass().getResource("/data-test.zip").getFile()); final String response = strategy.uploadDataSet(config, file); Assert.assertEquals(data_id, response); }
@Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays.asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException("HttpStatus " + status.toString() + " response received. File upload failed."); } }
RestPublishingStrategy implements PublishingStrategy { @Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays.asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException("HttpStatus " + status.toString() + " response received. File upload failed."); } } }
RestPublishingStrategy implements PublishingStrategy { @Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays.asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException("HttpStatus " + status.toString() + " response received. File upload failed."); } }  }
RestPublishingStrategy implements PublishingStrategy { @Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays.asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException("HttpStatus " + status.toString() + " response received. File upload failed."); } }  @Override String uploadDataSet(final InstanceConfig config, final File file); @Override URI triggerDataLoad(final InstanceConfig config, final String dataId); @Override String checkStatus(final InstanceConfig config, final URI triggerUrl); RestTemplateProvider getRestTemplateProvider(); @Required void setRestTemplateProvider(final RestTemplateProvider restTemplateProvider); }
RestPublishingStrategy implements PublishingStrategy { @Override public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(file != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final String checkSum = createCheckSum(file); final List<NameValuePair> params = Arrays.asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) }); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), UPLOAD_PATH, params); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("application/zip")); final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getBody().trim(); } else { throw new ResponseStatusException("HttpStatus " + status.toString() + " response received. File upload failed."); } }  @Override String uploadDataSet(final InstanceConfig config, final File file); @Override URI triggerDataLoad(final InstanceConfig config, final String dataId); @Override String checkStatus(final InstanceConfig config, final URI triggerUrl); RestTemplateProvider getRestTemplateProvider(); @Required void setRestTemplateProvider(final RestTemplateProvider restTemplateProvider);  }