Commit 1b056b0f authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Merge branch 'master' of /srv/cadc/git/wopencadc into s1648

parents 6ce4bdb8 6e303f47
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -185,7 +185,9 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
                                  group.getUserAdmins(), 
                                  group.getGroupAdmins());
                LdapDAO.checkLdapResult(result.getResultCode());
                
                // AD: Search results sometimes come incomplete if
                // connection is not reset - not sure why.
                getConnection().reconnect();
                try
                {
                    return getGroup(group.getID());
+41 −19
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ import ca.nrc.cadc.uws.server.JobRunner;
import ca.nrc.cadc.uws.server.JobUpdater;
import ca.nrc.cadc.uws.server.SyncOutput;
import ca.nrc.cadc.uws.util.JobLogInfo;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

public class ACSearchRunner implements JobRunner
{
@@ -225,8 +228,15 @@ public class ACSearchRunner implements JobRunner

            PluginFactory factory = new PluginFactory();
            GroupPersistence dao = factory.getGroupPersistence();
            Collection<Group> groups = 
                dao.getGroups(rv.getPrincipal(), rv.getRole(), rv.getGroupID());
            Collection<Group> groups;
            try
            {
                groups = dao.getGroups(rv.getPrincipal(), rv.getRole(), rv.getGroupID());
            }
            catch(GroupNotFoundException ignore)
            {
                groups = new ArrayList<Group>();
            }
            syncOut.setResponseCode(HttpServletResponse.SC_OK);
            GroupsWriter.write(groups, syncOut.getOutputStream());
            
@@ -241,7 +251,7 @@ public class ACSearchRunner implements JobRunner
            log.error("FAIL", t);
            
            syncOut.setResponseCode(503);
            syncOut.setHeader("Content-Type", "text/plan");
            syncOut.setHeader("Content-Type", "text/plain");
            try
            {
                syncOut.getOutputStream().write(t.getMessage().getBytes());
@@ -266,12 +276,12 @@ public class ACSearchRunner implements JobRunner
        }
        catch (UserNotFoundException t)
        {
            logInfo.setSuccess(false);
            logInfo.setSuccess(true);
            logInfo.setMessage(t.getMessage());
            log.debug("FAIL", t);
            
            syncOut.setResponseCode(404);
            syncOut.setHeader("Content-Type", "text/plan");
            syncOut.setHeader("Content-Type", "text/plain");
            try
            {
                syncOut.getOutputStream().write(t.getMessage().getBytes());
@@ -294,14 +304,15 @@ public class ACSearchRunner implements JobRunner
//                log.debug("failed to set final error status after " + t, oops);
//            }
        }
        /*
        catch (GroupNotFoundException t)
        {
            logInfo.setSuccess(false);
            logInfo.setSuccess(true);
            logInfo.setMessage(t.getMessage());
            log.debug("FAIL", t);
            
            syncOut.setResponseCode(404);
            syncOut.setHeader("Content-Type", "text/plan");
            syncOut.setHeader("Content-Type", "text/plain");
            try
            {
                syncOut.getOutputStream().write(t.getMessage().getBytes());
@@ -324,14 +335,15 @@ public class ACSearchRunner implements JobRunner
//                log.debug("failed to set final error status after " + t, oops);
//            }
        }
        */
        catch (AccessControlException t)
        {
            logInfo.setSuccess(false);
            logInfo.setSuccess(true);
            logInfo.setMessage(t.getMessage());
            log.debug("FAIL", t);
            
            syncOut.setResponseCode(403);
            syncOut.setHeader("Content-Type", "text/plan");
            syncOut.setHeader("Content-Type", "text/plain");
            try
            {
                syncOut.getOutputStream().write(t.getMessage().getBytes());
@@ -360,16 +372,7 @@ public class ACSearchRunner implements JobRunner
            logInfo.setMessage(t.getMessage());
            log.error("FAIL", t);
            
            syncOut.setResponseCode(500);
            syncOut.setHeader("Content-Type", "text/plan");
            try
            {
                syncOut.getOutputStream().write(t.getMessage().getBytes());
            }
            catch (IOException e)
            {
                log.warn("Could not write response to output stream", e);
            }
            writeError(syncOut, 500, t);
            
//            ErrorSummary errorSummary =
//                new ErrorSummary(t.getMessage(), ErrorType.FATAL);
@@ -386,4 +389,23 @@ public class ACSearchRunner implements JobRunner
        }
    }
    
    private void writeError(SyncOutput syncOutput, int code, Throwable t)
    {
        try
        {
            syncOutput.setResponseCode(code);
            syncOut.setHeader("Content-Type", "text/plain");
            OutputStream ostream = syncOut.getOutputStream();
            if (ostream != null)
            {
                OutputStreamWriter w = new OutputStreamWriter(ostream);
                w.write(t.toString());
                w.flush();
            }
        }
        catch (IOException e)
        {
            log.warn("Could not write response to output stream", e);
        }
    }
}