Commit 9547f0c0 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Handled error status codes in synctrans URL params convenience mode - #4129

parent 2bab0f98
Loading
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ import it.inaf.oats.vospace.exception.InvalidArgumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import it.inaf.oats.vospace.exception.VoSpaceErrorSummarizableException;
import it.inaf.oats.vospace.exception.VoSpaceErrorSummarizableException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;
@@ -204,8 +205,9 @@ public class JobService {
     * compliance with specifications
     * compliance with specifications
     *
     *
     */
     */
    public void createSyncJobResult(JobSummary job) {
    public Optional<VoSpaceErrorSummarizableException> createSyncJobResult(JobSummary job) {
        Transfer negotiatedTransfer = null;
        Transfer negotiatedTransfer = null;
        VoSpaceErrorSummarizableException exception = null;
        try {
        try {
            Transfer transfer = uriService.getTransfer(job);
            Transfer transfer = uriService.getTransfer(job);
            negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
            negotiatedTransfer = uriService.getNegotiatedTransfer(job, transfer);
@@ -216,14 +218,16 @@ public class JobService {
            job.setPhase(ExecutionPhase.ERROR);
            job.setPhase(ExecutionPhase.ERROR);
            stripProtocols(job, negotiatedTransfer);
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e));
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e));
            exception = e;
        } catch (Exception e) {
        } catch (Exception e) {
            job.setPhase(ExecutionPhase.ERROR);
            job.setPhase(ExecutionPhase.ERROR);
            stripProtocols(job, negotiatedTransfer);
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(
            exception = new InternalFaultException(e);
                    new InternalFaultException(e)));
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(exception));
        } finally {
        } finally {
            jobDAO.createJob(job, negotiatedTransfer);
            jobDAO.createJob(job, negotiatedTransfer);
        }
        }
        return Optional.ofNullable(exception);
    }
    }
    
    
    private void stripProtocols(JobSummary job, Transfer negotiatedTransfer) {
    private void stripProtocols(JobSummary job, Transfer negotiatedTransfer) {
+3 −7
Original line number Original line Diff line number Diff line
@@ -93,16 +93,12 @@ public class TransferController {
        }
        }


        JobSummary jobSummary = newJobSummary(transfer, principal);
        JobSummary jobSummary = newJobSummary(transfer, principal);
        jobService.createSyncJobResult(jobSummary);
        jobService.createSyncJobResult(jobSummary).ifPresent(ex -> {

        if (jobSummary.getErrorSummary() != null) {
            // TODO: decide how to hanlde HTTP error codes
            // If an error occurs with the synchronous convenience mode where the preferred endpoint
            // If an error occurs with the synchronous convenience mode where the preferred endpoint
            // is immediately returned as a redirect, the error information is returned directly in 
            // is immediately returned as a redirect, the error information is returned directly in 
            // the response body with the associated HTTP status code. 
            // the response body with the associated HTTP status code. 
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
            throw ex;
                    .body(jobSummary.getErrorSummary().getMessage());
        });
        }


        // Behaves as if REQUEST=redirect was set, for compatibility with CADC client
        // Behaves as if REQUEST=redirect was set, for compatibility with CADC client
        String endpoint = transfer.getProtocols().get(0).getEndpoint();
        String endpoint = transfer.getProtocols().get(0).getEndpoint();
+15 −0
Original line number Original line Diff line number Diff line
@@ -11,6 +11,7 @@ import it.inaf.oats.vospace.datamodel.NodeProperties;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.datamodel.Views;
import it.inaf.oats.vospace.exception.ErrorSummaryFactory;
import it.inaf.oats.vospace.exception.ErrorSummaryFactory;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.exception.PermissionDeniedException;
import it.inaf.oats.vospace.exception.ProtocolNotSupportedException;
import it.inaf.oats.vospace.persistence.JobDAO;
import it.inaf.oats.vospace.persistence.JobDAO;
import it.inaf.oats.vospace.persistence.LocationDAO;
import it.inaf.oats.vospace.persistence.LocationDAO;
import it.inaf.oats.vospace.persistence.NodeDAO;
import it.inaf.oats.vospace.persistence.NodeDAO;
@@ -427,6 +428,20 @@ public class TransferControllerTest {
                .andExpect(status().is3xxRedirection());
                .andExpect(status().is3xxRedirection());
    }
    }


    @Test
    public void testSyncTransferUrlParamsModeUnsupportedProtocol() throws Exception {

        Exception ex = mockMvc.perform(get("/synctrans")
                .header("Authorization", "Bearer user1_token")
                .param("TARGET", "vos://example.com!vospace/mynode")
                .param("DIRECTION", "pullFromVoSpace")
                .param("PROTOCOL", "ivo://ivoa.net/vospace/core#httpput"))
                .andExpect(status().isBadRequest())
                .andReturn().getResolvedException();

        assertTrue(ex instanceof ProtocolNotSupportedException);
    }
    
    private Jobs getFakeJobs() {
    private Jobs getFakeJobs() {
        Jobs jobs = new Jobs();
        Jobs jobs = new Jobs();
        jobs.setVersion("1.1");
        jobs.setVersion("1.1");