diff --git a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java index 3110cecc1b1150ac889800c102574dad9ac1301a..62ce3cf0eb8b8760f70a626cc1632a068544eb8c 100644 --- a/src/main/java/it/inaf/oats/vospace/CreateNodeController.java +++ b/src/main/java/it/inaf/oats/vospace/CreateNodeController.java @@ -15,7 +15,6 @@ import it.inaf.oats.vospace.exception.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.ivoa.xml.vospace.v2.Property; -import java.util.List; @RestController public class CreateNodeController extends BaseNodeController { diff --git a/src/main/java/it/inaf/oats/vospace/UriService.java b/src/main/java/it/inaf/oats/vospace/UriService.java index 0461b97835d5568d4f242b49a6509f9e209b62a7..68df3167f64ef5b0514ea7e06379ba4dcc388592 100644 --- a/src/main/java/it/inaf/oats/vospace/UriService.java +++ b/src/main/java/it/inaf/oats/vospace/UriService.java @@ -11,6 +11,7 @@ import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.persistence.LocationDAO; import it.inaf.oats.vospace.persistence.NodeDAO; import it.inaf.oats.vospace.persistence.model.Location; +import it.inaf.oats.vospace.persistence.model.LocationType; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -78,21 +79,19 @@ public class UriService { Node node = nodeDao.listNode(relativePath).orElseThrow(() -> new NodeNotFoundException(relativePath)); - Location location = locationDAO.getNodeLocation(relativePath).orElseThrow(() - -> new InternalFaultException("No registered location found for vos_path " + relativePath)); + Location location = locationDAO.getNodeLocation(relativePath).orElse(null); String endpoint; - switch (location.getType()) { - case PORTAL: - String fileName = nodeDao.getNodeOsName(relativePath); - endpoint = "http://" + location.getSource().getHostname() + location.getSource().getBasePath(); - if (!endpoint.endsWith("/")) { - endpoint += "/"; - } - endpoint += fileName; - break; - default: - endpoint = fileServiceUrl + urlEncodePath(relativePath); + + if (location != null && location.getType() == LocationType.PORTAL) { + String fileName = nodeDao.getNodeOsName(relativePath); + endpoint = "http://" + location.getSource().getHostname() + location.getSource().getBasePath(); + if (!endpoint.endsWith("/")) { + endpoint += "/"; + } + endpoint += fileName; + } else { + endpoint = fileServiceUrl + urlEncodePath(relativePath); } endpoint += "?jobId=" + job.getJobId(); diff --git a/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java b/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java index 5e4143e9a543b830075e642e2d51f751b573c7a3..63e95eabfa89542bf8bd5bd2b9faf05715dbb0c7 100644 --- a/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java +++ b/src/main/java/it/inaf/oats/vospace/exception/ErrorController.java @@ -1,5 +1,6 @@ package it.inaf.oats.vospace.exception; +import java.nio.charset.StandardCharsets; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -23,7 +24,11 @@ public class ErrorController extends AbstractErrorController { public void errorText(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> errors = super.getErrorAttributes(request, true); response.setContentType("text/plain;charset=UTF-8"); - response.getOutputStream().print((String) errors.get("message")); + response.setCharacterEncoding("UTF-8"); + String errorMessage = (String) errors.get("message"); + if (errorMessage != null) { + response.getOutputStream().write(errorMessage.getBytes(StandardCharsets.UTF_8)); + } } @Override