Skip to content
Snippets Groups Projects
Commit 5752cd47 authored by Jeff Burke's avatar Jeff Burke
Browse files

s1696: availability app to query web services and update status file

parents 6ce4bdb8 6e303f47
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment