diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDao.java index 40b1430768f38f50130f189bbc5d39a37688840d..5080a113fdf0e496b1f60c3824644cb62ade30bb 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/DocumentDao.java @@ -30,7 +30,7 @@ public class DocumentDao extends BaseDao<DBDocument> { * Method returns the document for the resource * * @param dbResource resource - * @return + * @return document for the resource or empty if not found */ public Optional<DBDocument> getDocumentForResource(DBResource dbResource) { try { @@ -67,7 +67,10 @@ public class DocumentDao extends BaseDao<DBDocument> { query.setParameter(PARAM_SUBRESOURCE_ID, subresource.getId()); return Optional.of(query.getSingleResult()); } catch (NonUniqueResultException e) { - throw new SMPRuntimeException(ErrorCode.RESOURCE_DOCUMENT_ERROR, subresource.getIdentifierValue(), subresource.getIdentifierScheme(), + DBResource resource = subresource.getResource(); + throw new SMPRuntimeException(ErrorCode.SUBRESOURCE_DOCUMENT_ERROR, + subresource.getIdentifierValue(), subresource.getIdentifierScheme(), + resource.getIdentifierValue(), resource.getIdentifierScheme(), "Multiple documents for subresource"); } catch (NoResultException e) { return Optional.empty(); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java index 6ea193026d2d2c686e265e285b60dab3208da275..4770be0ba2d18372b8a616eab9329c98ba97d8b0 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java @@ -70,13 +70,9 @@ public enum ErrorCode { MAIL_SUBMISSION_ERROR (500,"SMP:550",ErrorBusinessCode.TECHNICAL, "Mail submission error: %s!"), RESOURCE_DOCUMENT_MISSING(500,"SMP:180",ErrorBusinessCode.TECHNICAL, "Empty document for the resource: [id: '%s', sch.: '%s']!"), - RESOURCE_DOCUMENT_ERROR(500,"SMP:180",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the resource document: [id: '%s', sch.: '%s']! Error [%s]"), - - - - - - // + RESOURCE_DOCUMENT_ERROR(500,"SMP:181",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the resource document: [id: '%s', sch.: '%s']! Error [%s]"), + SUBRESOURCE_DOCUMENT_MISSING(500,"SMP:182",ErrorBusinessCode.TECHNICAL, "Empty document for the subresource: [docId: '%s', docSch.: '%s'] of the resource [id: '%s', sch.: '%s']"), + SUBRESOURCE_DOCUMENT_ERROR(500,"SMP:183",ErrorBusinessCode.TECHNICAL, "Error occurred while reading the subresource document: : [docId: '%s', docSch.: '%s'] of the resource[id: '%s', sch: '%s']! Error [%s]"), ; private final int httpCode; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/AbstractResourceHandler.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/AbstractResourceHandler.java index e6710ab21399f3903ad651fce1b8934130755747..28595b752d3cee79ce78608259281b3ddb2b2d1b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/AbstractResourceHandler.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/resource/AbstractResourceHandler.java @@ -105,10 +105,15 @@ public class AbstractResourceHandler { public RequestData buildRequestDataForSubResource(DBDomain domain, DBResource resource, DBSubresource subresource) { byte[] content = resourceStorage.getDocumentContentForSubresource(subresource); + if (content==null || content.length == 0) { + throw new SMPRuntimeException(ErrorCode.SUBRESOURCE_DOCUMENT_MISSING, + subresource.getIdentifierValue(), subresource.getIdentifierScheme(), + resource.getIdentifierValue(), resource.getIdentifierScheme()); + } return new SpiRequestData(domain.getDomainCode(), SPIUtils.toUrlIdentifier(resource), SPIUtils.toUrlIdentifier(subresource), - new ByteArrayInputStream(content == null?new byte[]{}:content)); + new ByteArrayInputStream(content)); } public RequestData buildRequestDataForSubResource(DBDomain domain, DBResource resource, DBSubresource subresource, InputStream inputStream) { @@ -124,7 +129,7 @@ public class AbstractResourceHandler { if (StringUtils.isNotBlank(responseData.getContentType())) { resourceResponse.setContentType(responseData.getContentType()); } - responseData.getHttpHeaders().entrySet().stream() + responseData.getHttpHeaders().entrySet() .forEach(entry -> resourceResponse.setHttpHeader(entry.getKey(), entry.getValue())); } catch (ResourceException e) {