Skip to content
Snippets Groups Projects
Unverified Commit 04d6f6e2 authored by Martin Weise's avatar Martin Weise
Browse files

Added integration tests for file upload, all pass

parent c7a97b9f
Branches
Tags
3 merge requests!81New stable release,!43Merge dev to master,!27Draft: Resolve "Zenodo Sandbox integration for PID (e.g. DOI)"
Showing
with 145613 additions and 105 deletions
package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
@Getter
......
......@@ -42,6 +42,11 @@ public abstract class BaseUnitTest {
public final static String FILE_1_CHECKSUM = "d393c7fa1240c18473133793f7901aaa";
public final static Long FILE_1_SIZE = 34614L;
public final static String FILE_2_ID = "deadbeef-deafdeed";
public final static String FILE_2_NAME = "testdata-weather.csv";
public final static String FILE_2_CHECKSUM = "a65cf8b8719b1a65db4f361eeec18457";
public final static Long FILE_2_SIZE = 14094055L;
public final static Long DEPOSIT_2_ID = 2L;
public final static String DEPOSIT_2_TITLE = "Test Document " + RandomStringUtils.randomAlphanumeric(10);
public final static String DEPOSIT_2_DESCRIPTION = "Test Description " + RandomStringUtils.randomAlphanumeric(100);
......
package at.tuwien.service;
import at.tuwien.BaseUnitTest;
import at.tuwien.api.zenodo.deposit.DepositChangeRequestDto;
import at.tuwien.api.zenodo.deposit.DepositChangeResponseDto;
import at.tuwien.api.zenodo.deposit.FileRequestDto;
import at.tuwien.api.zenodo.files.FileResponseDto;
import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoFileTooLargeException;
import at.tuwien.exception.ZenodoNotFoundException;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.ResourceUtils;
import org.springframework.web.client.RestTemplate;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@SpringBootTest
@ExtendWith(SpringExtension.class)
......@@ -46,15 +35,29 @@ public class FileServiceIntegrationTest extends BaseUnitTest {
private ZenodoMetadataService metadataService;
@Test
public void createResource_succeeds() throws IOException, ZenodoApiException, ZenodoNotFoundException, ZenodoAuthenticationException {
// final DepositChangeResponseDto deposit = metadataService.storeCitation();
final byte[] file = FileUtils.readFileToByteArray(ResourceUtils.getFile("classpath:testdata.csv"));
public void createResource_succeeds() throws IOException, ZenodoApiException, ZenodoNotFoundException,
ZenodoAuthenticationException, ZenodoFileTooLargeException {
final DepositChangeResponseDto deposit = metadataService.storeCitation();
final File file = ResourceUtils.getFile("classpath:csv/testdata.csv");
/* test */
final FileResponseDto response = fileService.createResource(1L, FILE_1_NAME, file);
final FileResponseDto response = fileService.createResource(deposit.getId(), FILE_1_NAME, file);
assertEquals(FILE_1_NAME, response.getFilename());
assertEquals(FILE_1_CHECKSUM, response.getChecksum());
assertEquals(FILE_1_SIZE, response.getFilesize());
}
@Test
public void createResource_largeFile_succeeds() throws IOException, ZenodoApiException, ZenodoNotFoundException,
ZenodoAuthenticationException, ZenodoFileTooLargeException {
final DepositChangeResponseDto deposit = metadataService.storeCitation();
final File file = ResourceUtils.getFile("classpath:csv/weatherAUS.csv");
/* test */
final FileResponseDto response = fileService.createResource(deposit.getId(), FILE_2_NAME, file);
assertEquals(FILE_2_NAME, response.getFilename());
assertEquals(FILE_2_CHECKSUM, response.getChecksum());
assertEquals(FILE_2_SIZE, response.getFilesize());
}
}
\ No newline at end of file
package at.tuwien.service;
import at.tuwien.BaseUnitTest;
import at.tuwien.api.zenodo.deposit.*;
import at.tuwien.api.zenodo.files.FileResponseDto;
import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoFileTooLargeException;
import at.tuwien.exception.ZenodoNotFoundException;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
......@@ -20,12 +18,12 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ResourceUtils;
import org.springframework.web.client.RestTemplate;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
......@@ -45,17 +43,21 @@ public class FileServiceUnitTest extends BaseUnitTest {
private ZenodoFileService fileService;
@MockBean
private RestTemplate zenodoTemplate;
private RestTemplate apiTemplate;
@Test
public void createResource_succeeds() throws IOException, ZenodoApiException, ZenodoNotFoundException,
ZenodoAuthenticationException {
final byte[] file = FileUtils.readFileToByteArray(ResourceUtils.getFile("classpath:testdata.csv"));
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.any(),
ZenodoAuthenticationException, ZenodoFileTooLargeException {
/* mock */
when(apiTemplate.postForEntity(anyString(), Mockito.<MultiValueMap<String, HttpEntity<?>>>any(),
eq(FileResponseDto.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.body(FILE_1));
/* request */
final File file = ResourceUtils.getFile("classpath:csv/testdata.csv");
/* test */
final FileResponseDto response = fileService.createResource(DEPOSIT_1_ID, FILE_1_NAME, file);
assertEquals(FILE_1_NAME, response.getFilename());
......@@ -65,12 +67,16 @@ public class FileServiceUnitTest extends BaseUnitTest {
@Test
public void createResource_notExists_fails() throws IOException {
final byte[] file = FileUtils.readFileToByteArray(ResourceUtils.getFile("classpath:testdata.csv"));
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.any(),
/* mock */
when(apiTemplate.postForEntity(anyString(), Mockito.<MultiValueMap<String, HttpEntity<?>>>any(),
eq(FileResponseDto.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* request */
final File file = ResourceUtils.getFile("classpath:csv/testdata.csv");
/* test */
assertThrows(ZenodoNotFoundException.class, () -> {
fileService.createResource(DEPOSIT_1_ID, FILE_1_NAME, file);
......
......@@ -34,18 +34,20 @@ import static org.mockito.Mockito.*;
@ExtendWith(SpringExtension.class)
public class MetadataServiceUnitTest extends BaseUnitTest {
@MockBean
private ReadyConfig readyConfig;
@Autowired
private ZenodoMetadataService zenodoService;
@MockBean
private RestTemplate zenodoTemplate;
private ReadyConfig readyConfig;
@MockBean
private RestTemplate apiTemplate;
@Test
public void listCitations_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositResponseDto[].class), anyString()))
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.GET), Mockito.any(), eq(DepositResponseDto[].class), anyString()))
.thenReturn(ResponseEntity.ok(new DepositResponseDto[]{DEPOSIT_2}));
/* test */
......@@ -55,7 +57,9 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void listCitations_empty_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositResponseDto[].class), anyString()))
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.GET), Mockito.any(), eq(DepositResponseDto[].class), anyString()))
.thenReturn(ResponseEntity.ok().build());
/* test */
......@@ -66,7 +70,9 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void storeCitation_succeed() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositChangeResponseDto.class), anyString()))
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositChangeResponseDto.class), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.body(DEPOSIT_1));
......@@ -78,7 +84,9 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void deleteCitation_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(String.class), anyLong(), anyString()))
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.DELETE), Mockito.any(), eq(String.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.build());
......@@ -88,7 +96,9 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void deleteCitation_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.DELETE), eq(null), eq(String.class), anyLong(), anyString()))
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.DELETE), Mockito.any(), eq(String.class), anyLong(), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.build());
......@@ -101,12 +111,16 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void updateCitation_succeeds() throws ZenodoApiException, ZenodoAuthenticationException,
ZenodoNotFoundException {
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.body(DEPOSIT_1));
/* request */
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(METADATA_1)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.OK)
.body(DEPOSIT_1));
/* test */
zenodoService.updateCitation(DEPOSIT_1_ID, request);
......@@ -114,14 +128,18 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void updateCitation_only1orcid_fails() {
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* request */
final MetadataDto m = METADATA_1;
m.getCreators()[1].setOrcid(null);
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(m)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* test */
assertThrows(ZenodoNotFoundException.class, () -> {
......@@ -131,12 +149,16 @@ public class MetadataServiceUnitTest extends BaseUnitTest {
@Test
public void updateCitation_notExists_fails() {
/* mocks */
when(apiTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* request */
final DepositChangeRequestDto request = DepositChangeRequestDto.builder()
.metadata(METADATA_1)
.build();
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.PUT), Mockito.<HttpEntity<DepositChangeRequestDto>>any(), eq(DepositChangeResponseDto.class), eq(DEPOSIT_1_ID), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST)
.build());
/* test */
assertThrows(ZenodoNotFoundException.class, () -> {
......
......@@ -17,4 +17,4 @@ spring.jpa.show-sql=false
fda.mapping.path: /tmp
fda.table.path: /tmp
zenodo.endpoint: http://sandbox.zenodo.org/
\ No newline at end of file
zenodo.endpoint: https://sandbox.zenodo.org/
\ No newline at end of file
This diff is collapsed.
......@@ -2,7 +2,6 @@ package at.tuwien.config;
import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.utils.ApiTemplateInterceptor;
import at.tuwien.utils.UploadTemplateInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
......@@ -48,24 +47,12 @@ public class ZenodoConfig {
.registerModule(new Jdk8Module());
}
@Bean("apiTemplate")
@Bean
public RestTemplate apiTemplate() {
final UriBuilderFactory factory = new DefaultUriBuilderFactory(zenodoEndpoint);
final RestTemplate template = new RestTemplateBuilder()
.uriTemplateHandler(factory)
.build();
template.setInterceptors(List.of(new ApiTemplateInterceptor()));
return template;
}
@Bean("uploadTemplate")
public RestTemplate uploadTemplate() {
final UriBuilderFactory factory = new DefaultUriBuilderFactory(zenodoEndpoint);
final RestTemplate template = new RestTemplateBuilder()
return new RestTemplateBuilder()
.uriTemplateHandler(factory)
.build();
template.setInterceptors(List.of(new UploadTemplateInterceptor()));
return template;
}
}
package at.tuwien.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.UNPROCESSABLE_ENTITY)
public class ZenodoFileTooLargeException extends Exception {
public ZenodoFileTooLargeException(String msg) {
super(msg);
}
public ZenodoFileTooLargeException(String msg, Throwable thr) {
super(msg, thr);
}
public ZenodoFileTooLargeException(Throwable thr) {
super(thr);
}
}
package at.tuwien.mapper;
import at.tuwien.api.zenodo.deposit.FileBinaryRequestDto;
import at.tuwien.api.zenodo.deposit.FileRequestDto;
import org.apache.commons.io.FileUtils;
import org.mapstruct.Mapper;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Mapper(componentModel = "spring")
public interface ZenodoMapper {
default HttpEntity<MultiValueMap<String, Object>> resourceToHttpEntity(String name, byte[] resource) {
default MultiValueMap<String, HttpEntity<?>> resourceToHttpEntity(String name, File resource) throws IOException {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
final HttpHeaders parts = new HttpHeaders();
parts.setContentType(MediaType.TEXT_PLAIN);
final ByteArrayResource byteArrayResource = new ByteArrayResource(resource) {
final ByteArrayResource byteArrayResource = new ByteArrayResource(FileUtils.readFileToByteArray(resource)) {
@Override
public String getFilename() {
return name;
}
};
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", new HttpEntity<>(byteArrayResource, parts));
body.add("data", new HttpEntity<>(name, parts));
return new HttpEntity<>(body, headers);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("file", byteArrayResource);
bodyBuilder.part("name", name);
return bodyBuilder.build();
}
}
......@@ -3,12 +3,16 @@ package at.tuwien.service;
import at.tuwien.api.zenodo.files.FileResponseDto;
import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoFileTooLargeException;
import at.tuwien.exception.ZenodoNotFoundException;
import org.springframework.stereotype.Service;
import java.io.File;
@Service
public interface FileService {
FileResponseDto createResource(Long id, String name, byte[] resource)
throws ZenodoAuthenticationException, ZenodoApiException, ZenodoNotFoundException;
FileResponseDto createResource(Long id, String name, File resource)
throws ZenodoAuthenticationException, ZenodoApiException, ZenodoNotFoundException,
ZenodoFileTooLargeException;
}
......@@ -4,6 +4,7 @@ import at.tuwien.api.zenodo.files.FileResponseDto;
import at.tuwien.config.ZenodoConfig;
import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import at.tuwien.exception.ZenodoFileTooLargeException;
import at.tuwien.exception.ZenodoNotFoundException;
import at.tuwien.mapper.ZenodoMapper;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -11,6 +12,10 @@ import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.io.IOException;
import java.util.List;
@Service
public class ZenodoFileService implements FileService {
......@@ -29,11 +34,19 @@ public class ZenodoFileService implements FileService {
}
@Override
public FileResponseDto createResource(Long id, String name, byte[] resource)
throws ZenodoAuthenticationException, ZenodoApiException, ZenodoNotFoundException {
final ResponseEntity<FileResponseDto> response = uploadTemplate.exchange("/api/deposit/depositions/{deposit_id}/files?access_token={token}",
HttpMethod.POST, zenodoMapper.resourceToHttpEntity(name, resource), FileResponseDto.class, id,
zenodoConfig.getApiKey());
public FileResponseDto createResource(Long id, String name, File resource)
throws ZenodoAuthenticationException, ZenodoApiException, ZenodoNotFoundException,
ZenodoFileTooLargeException {
if (resource.getTotalSpace() > 50_1000_1000_1000L) {
throw new ZenodoFileTooLargeException("Only 50GB per file is allowed!");
}
final ResponseEntity<FileResponseDto> response;
try {
response = uploadTemplate.postForEntity("/api/deposit/depositions/{deposit_id}/files?access_token={token}",
zenodoMapper.resourceToHttpEntity(name, resource), FileResponseDto.class, id, zenodoConfig.getApiKey());
} catch (IOException e) {
throw new ZenodoApiException("Could not map file to byte array");
}
if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
throw new ZenodoAuthenticationException("Token is missing or invalid.");
}
......
......@@ -28,7 +28,7 @@ public class ZenodoMetadataService implements MetadataService {
@Override
public List<DepositResponseDto> listCitations() throws ZenodoAuthenticationException, ZenodoApiException {
final ResponseEntity<DepositResponseDto[]> response = apiTemplate.exchange("/api/deposit/depositions?access_token={token}",
HttpMethod.GET, null, DepositResponseDto[].class, zenodoConfig.getApiKey());
HttpMethod.GET, addHeaders(null), DepositResponseDto[].class, zenodoConfig.getApiKey());
if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
throw new ZenodoAuthenticationException("Token is missing or invalid.");
}
......@@ -41,7 +41,7 @@ public class ZenodoMetadataService implements MetadataService {
@Override
public DepositChangeResponseDto storeCitation() throws ZenodoAuthenticationException, ZenodoApiException {
final ResponseEntity<DepositChangeResponseDto> response = apiTemplate.exchange("/api/deposit/depositions?access_token={token}",
HttpMethod.POST, new HttpEntity<>("{}"), DepositChangeResponseDto.class, zenodoConfig.getApiKey());
HttpMethod.POST, addHeaders("{}"), DepositChangeResponseDto.class, zenodoConfig.getApiKey());
if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
throw new ZenodoAuthenticationException("Token is missing or invalid.");
}
......@@ -58,7 +58,7 @@ public class ZenodoMetadataService implements MetadataService {
public DepositChangeResponseDto updateCitation(Long id, DepositChangeRequestDto data) throws ZenodoAuthenticationException,
ZenodoApiException, ZenodoNotFoundException {
final ResponseEntity<DepositChangeResponseDto> response = apiTemplate.exchange("/api/deposit/depositions/{deposit_id}?access_token={token}",
HttpMethod.PUT, new HttpEntity<>(data), DepositChangeResponseDto.class, id, zenodoConfig.getApiKey());
HttpMethod.PUT, addHeaders(data), DepositChangeResponseDto.class, id, zenodoConfig.getApiKey());
if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
throw new ZenodoAuthenticationException("Token is missing or invalid.");
}
......@@ -77,7 +77,7 @@ public class ZenodoMetadataService implements MetadataService {
@Override
public void deleteCitation(Long id) throws ZenodoAuthenticationException, ZenodoApiException {
final ResponseEntity<String> response = apiTemplate.exchange("/api/deposit/depositions/{deposit_id}?access_token={token}",
HttpMethod.DELETE, null, String.class, id, zenodoConfig.getApiKey());
HttpMethod.DELETE, addHeaders(null), String.class, id, zenodoConfig.getApiKey());
if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
throw new ZenodoAuthenticationException("Token is missing or invalid.");
}
......@@ -85,4 +85,11 @@ public class ZenodoMetadataService implements MetadataService {
throw new ZenodoApiException("Could not delete the deposit");
}
}
private HttpEntity<Object> addHeaders(Object body) {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
return new HttpEntity<>(body, headers);
}
}
package at.tuwien.utils;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Service;
import java.io.IOException;
@Service
public class UploadTemplateInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
request.getHeaders().set("Content-Type", "multipart/form-data");
request.getHeaders().set("Accept", "application/json");
return execution.execute(request, body);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment