diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/MetadataBitstreamController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/MetadataBitstreamController.java index 7334d894bbd5..ac26a2c69551 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/MetadataBitstreamController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/MetadataBitstreamController.java @@ -1,4 +1,4 @@ -/** + /** * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at @@ -24,6 +24,7 @@ import org.apache.logging.log4j.Logger; import org.dspace.app.rest.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.UnprocessableEntityException; +import org.dspace.app.rest.model.BitstreamRest; import org.dspace.app.rest.utils.ContextUtil; import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.MissingLicenseAgreementException; @@ -54,7 +55,7 @@ * This CLARIN Controller download a single file or a ZIP file from the Item's bitstream. */ @RestController -@RequestMapping("/bitstream") +@RequestMapping("/api/" + BitstreamRest.CATEGORY + "/" + BitstreamRest.PLURAL_NAME) public class MetadataBitstreamController { private static Logger log = org.apache.logging.log4j.LogManager.getLogger(MetadataBitstreamController.class); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java index 2fbd4731fb9f..4f4ca065cdaa 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/MetadataBitstreamRestRepository.java @@ -36,6 +36,7 @@ import org.dspace.app.rest.converter.MetadataBitstreamWrapperConverter; import org.dspace.app.rest.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.UnprocessableEntityException; +import org.dspace.app.rest.model.BitstreamRest; import org.dspace.app.rest.model.MetadataBitstreamWrapperRest; import org.dspace.app.rest.model.wrapper.MetadataBitstreamWrapper; import org.dspace.app.util.Util; @@ -199,7 +200,11 @@ private List getFilePreviewContent(Context context, Bitstream bitstrea } catch (MissingLicenseAgreementException e) { /* Do nothing */ } if (Objects.nonNull(inputStream)) { - fileInfos = processInputStreamToFilePreview(context, bitstream, fileInfos, inputStream); + try { + fileInfos = processInputStreamToFilePreview(context, bitstream, fileInfos, inputStream); + } catch (IllegalStateException e) { + log.error("Cannot process Input Stream to file preview because: " + e.getMessage()); + } } return fileInfos; } @@ -252,7 +257,8 @@ private String composePreviewURL(Context context, Item item, Bitstream bitstream } else { identifier = "id/" + bitstream.getID(); } - String url = contextPath + "/bitstream/" + identifier; + String url = contextPath + "/api/" + BitstreamRest.CATEGORY + "/" + BitstreamRest.PLURAL_NAME + "/" + + identifier; try { if (bitstream.getName() != null) { url += "/" + Util.encodeBitstreamName(bitstream.getName(), "UTF-8"); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamControllerIT.java index fbf76442b18f..d397062e0200 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamControllerIT.java @@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; public class MetadataBitstreamControllerIT extends AbstractControllerIntegrationTest { - private static final String METADATABITSTREAM_ENDPOINT = "/bitstream/"; + private static final String METADATABITSTREAM_ENDPOINT = "/api/core/bitstreams/"; private static final String METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT = METADATABITSTREAM_ENDPOINT + "/handle"; private static final String METADATABITSTREAM_DOWNLOAD_ALL_ENDPOINT = METADATABITSTREAM_ENDPOINT + "/allzip"; private static final String AUTHOR = "Test author name"; @@ -77,7 +77,7 @@ public void setUp() throws Exception { @Test public void downloadSingleFileNullPathVariable() throws Exception { - getClient().perform(get(METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT)).andExpect(status().isNotFound()); + getClient().perform(get(METADATABITSTREAM_DOWNLOAD_SINGLE_ENDPOINT)).andExpect(status().is4xxClientError()); } @Test diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamRestRepositoryIT.java index c0de3540fc42..94f98998b8d3 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/MetadataBitstreamRestRepositoryIT.java @@ -161,7 +161,7 @@ private void composeURL() { } else { identifier = "id/" + bts.getID(); } - url = "/bitstream/" + identifier + "/"; + url = "/api/core/bitstreams/" + identifier + "/"; try { if (bts.getName() != null) { url += Util.encodeBitstreamName(bts.getName(), "UTF-8");