Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/SyncOutput.java 0 → 100644 +127 −0 Original line number Diff line number Diff line /* ************************************************************************ ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** * * (c) 2011. (c) 2011. * Government of Canada Gouvernement du Canada * National Research Council Conseil national de recherches * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 * All rights reserved Tous droits réservés * * NRC disclaims any warranties, Le CNRC dénie toute garantie * expressed, implied, or énoncée, implicite ou légale, * statutory, of any kind with de quelque nature que ce * respect to the software, soit, concernant le logiciel, * including without limitation y compris sans restriction * any warranty of merchantability toute garantie de valeur * or fitness for a particular marchande ou de pertinence * purpose. NRC shall not be pour un usage particulier. * liable in any event for any Le CNRC ne pourra en aucun cas * damages, whether direct or être tenu responsable de tout * indirect, special or general, dommage, direct ou indirect, * consequential or incidental, particulier ou général, * arising from the use of the accessoire ou fortuit, résultant * software. Neither the name de l'utilisation du logiciel. Ni * of the National Research le nom du Conseil National de * Council of Canada nor the Recherches du Canada ni les noms * names of its contributors may de ses participants ne peuvent * be used to endorse or promote être utilisés pour approuver ou * products derived from this promouvoir les produits dérivés * software without specific prior de ce logiciel sans autorisation * written permission. préalable et particulière * par écrit. * * This file is part of the Ce fichier fait partie du projet * OpenCADC project. OpenCADC. * * OpenCADC is free software: OpenCADC est un logiciel libre ; * you can redistribute it and/or vous pouvez le redistribuer ou le * modify it under the terms of modifier suivant les termes de * the GNU Affero General Public la “GNU Affero General Public * License as published by the License” telle que publiée * Free Software Foundation, par la Free Software Foundation * either version 3 of the : soit la version 3 de cette * License, or (at your option) licence, soit (à votre gré) * any later version. toute version ultérieure. * * OpenCADC is distributed in the OpenCADC est distribué * hope that it will be useful, dans l’espoir qu’il vous * but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE * without even the implied GARANTIE : sans même la garantie * warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ * or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF * PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence * General Public License for Générale Publique GNU Affero * more details. pour plus de détails. * * You should have received Vous devriez avoir reçu une * a copy of the GNU Affero copie de la Licence Générale * General Public License along Publique GNU Affero avec * with OpenCADC. If not, see OpenCADC ; si ce n’est * <http://www.gnu.org/licenses/>. pas le cas, consultez : * <http://www.gnu.org/licenses/>. * * $Revision: 5 $ * ************************************************************************ */ package ca.nrc.cadc.ac.server.web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** * * @author majorb */ public class SyncOutput { private static final Logger log = Logger.getLogger(SyncOutput.class); protected HttpServletResponse response; protected PrintWriter writer; public SyncOutput(HttpServletResponse response) { this.response = response; } public boolean isOpen() { return (writer != null); } public void setCode(int code) { if (writer != null) return; response.setStatus(code); } public void setHeader(String key, Object value) { if (writer != null) return; if (value == null) response.setHeader(key, null); else response.setHeader(key, value.toString()); } public PrintWriter getWriter() throws IOException { if (writer == null) { log.debug("opening writer"); writer = response.getWriter(); } return writer; } } projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/AbstractGroupAction.java +13 −19 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.ac.server.GroupPersistence; import ca.nrc.cadc.ac.server.PluginFactory; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.ac.server.web.SyncOutput; import ca.nrc.cadc.net.TransientException; public abstract class AbstractGroupAction implements PrivilegedExceptionAction<Object> Loading @@ -96,7 +97,7 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O private static final Logger log = Logger.getLogger(AbstractGroupAction.class); protected GroupLogInfo logInfo; protected HttpServletRequest request; protected HttpServletResponse response; protected SyncOutput syncOut; public AbstractGroupAction() { Loading @@ -114,9 +115,9 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O this.request = request; } void setHttpServletResponse(HttpServletResponse response) void setSyncOut(SyncOutput syncOut) { this.response = response; this.syncOut = syncOut; } public Object run() throws PrivilegedActionException Loading Loading @@ -206,26 +207,19 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O private void sendError(int responseCode, String message) { if (!this.response.isCommitted()) { this.response.setContentType("text/plain"); syncOut.setHeader("Content-Type", "text/plain"); if (message != null) { try { this.response.getWriter().write(message); syncOut.getWriter() .write(message); } catch (IOException e) { log.warn("Could not write error message to output stream"); } } this.response.setStatus(responseCode); } else { log.warn("Could not send error " + responseCode + " (" + message + ") because the response is already committed."); } syncOut.setCode(responseCode); } <T extends Principal> GroupPersistence<T> getGroupPersistence() Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/CreateGroupAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -94,9 +94,9 @@ public class CreateGroupAction extends AbstractGroupAction GroupReader groupReader = new GroupReader(); Group group = groupReader.read(this.inputStream); Group newGroup = groupPersistence.addGroup(group); this.response.setContentType("application/xml"); syncOut.setHeader("Content-Type", "application/xml"); GroupWriter groupWriter = new GroupWriter(); groupWriter.write(newGroup, this.response.getOutputStream()); groupWriter.write(newGroup, syncOut.getWriter()); List<String> addedMembers = null; if ((newGroup.getUserMembers().size() > 0) || (newGroup.getGroupMembers().size() > 0)) Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/GetGroupAction.java +2 −3 Original line number Diff line number Diff line Loading @@ -85,10 +85,9 @@ public class GetGroupAction extends AbstractGroupAction { GroupPersistence groupPersistence = getGroupPersistence(); Group group = groupPersistence.getGroup(this.groupName); this.response.setContentType("application/xml"); syncOut.setHeader("Content-Type", "application/xml"); GroupWriter groupWriter = new GroupWriter(); groupWriter.write(group, this.response.getOutputStream()); groupWriter.write(group, syncOut.getWriter()); } } projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/GetGroupNamesAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -91,9 +91,9 @@ public class GetGroupNamesAction extends AbstractGroupAction GroupPersistence groupPersistence = getGroupPersistence(); Collection<String> groups = groupPersistence.getGroupNames(); log.debug("Found " + groups.size() + " group names"); response.setContentType("text/plain"); syncOut.setHeader("Content-Type", "text/plain"); log.debug("Set content-type to text/plain"); Writer writer = response.getWriter(); Writer writer = syncOut.getWriter(); boolean start = true; for (final String group : groups) { Loading Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/SyncOutput.java 0 → 100644 +127 −0 Original line number Diff line number Diff line /* ************************************************************************ ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** * * (c) 2011. (c) 2011. * Government of Canada Gouvernement du Canada * National Research Council Conseil national de recherches * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 * All rights reserved Tous droits réservés * * NRC disclaims any warranties, Le CNRC dénie toute garantie * expressed, implied, or énoncée, implicite ou légale, * statutory, of any kind with de quelque nature que ce * respect to the software, soit, concernant le logiciel, * including without limitation y compris sans restriction * any warranty of merchantability toute garantie de valeur * or fitness for a particular marchande ou de pertinence * purpose. NRC shall not be pour un usage particulier. * liable in any event for any Le CNRC ne pourra en aucun cas * damages, whether direct or être tenu responsable de tout * indirect, special or general, dommage, direct ou indirect, * consequential or incidental, particulier ou général, * arising from the use of the accessoire ou fortuit, résultant * software. Neither the name de l'utilisation du logiciel. Ni * of the National Research le nom du Conseil National de * Council of Canada nor the Recherches du Canada ni les noms * names of its contributors may de ses participants ne peuvent * be used to endorse or promote être utilisés pour approuver ou * products derived from this promouvoir les produits dérivés * software without specific prior de ce logiciel sans autorisation * written permission. préalable et particulière * par écrit. * * This file is part of the Ce fichier fait partie du projet * OpenCADC project. OpenCADC. * * OpenCADC is free software: OpenCADC est un logiciel libre ; * you can redistribute it and/or vous pouvez le redistribuer ou le * modify it under the terms of modifier suivant les termes de * the GNU Affero General Public la “GNU Affero General Public * License as published by the License” telle que publiée * Free Software Foundation, par la Free Software Foundation * either version 3 of the : soit la version 3 de cette * License, or (at your option) licence, soit (à votre gré) * any later version. toute version ultérieure. * * OpenCADC is distributed in the OpenCADC est distribué * hope that it will be useful, dans l’espoir qu’il vous * but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE * without even the implied GARANTIE : sans même la garantie * warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ * or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF * PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence * General Public License for Générale Publique GNU Affero * more details. pour plus de détails. * * You should have received Vous devriez avoir reçu une * a copy of the GNU Affero copie de la Licence Générale * General Public License along Publique GNU Affero avec * with OpenCADC. If not, see OpenCADC ; si ce n’est * <http://www.gnu.org/licenses/>. pas le cas, consultez : * <http://www.gnu.org/licenses/>. * * $Revision: 5 $ * ************************************************************************ */ package ca.nrc.cadc.ac.server.web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; /** * * @author majorb */ public class SyncOutput { private static final Logger log = Logger.getLogger(SyncOutput.class); protected HttpServletResponse response; protected PrintWriter writer; public SyncOutput(HttpServletResponse response) { this.response = response; } public boolean isOpen() { return (writer != null); } public void setCode(int code) { if (writer != null) return; response.setStatus(code); } public void setHeader(String key, Object value) { if (writer != null) return; if (value == null) response.setHeader(key, null); else response.setHeader(key, value.toString()); } public PrintWriter getWriter() throws IOException { if (writer == null) { log.debug("opening writer"); writer = response.getWriter(); } return writer; } }
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/AbstractGroupAction.java +13 −19 Original line number Diff line number Diff line Loading @@ -89,6 +89,7 @@ import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.ac.server.GroupPersistence; import ca.nrc.cadc.ac.server.PluginFactory; import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.ac.server.web.SyncOutput; import ca.nrc.cadc.net.TransientException; public abstract class AbstractGroupAction implements PrivilegedExceptionAction<Object> Loading @@ -96,7 +97,7 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O private static final Logger log = Logger.getLogger(AbstractGroupAction.class); protected GroupLogInfo logInfo; protected HttpServletRequest request; protected HttpServletResponse response; protected SyncOutput syncOut; public AbstractGroupAction() { Loading @@ -114,9 +115,9 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O this.request = request; } void setHttpServletResponse(HttpServletResponse response) void setSyncOut(SyncOutput syncOut) { this.response = response; this.syncOut = syncOut; } public Object run() throws PrivilegedActionException Loading Loading @@ -206,26 +207,19 @@ public abstract class AbstractGroupAction implements PrivilegedExceptionAction<O private void sendError(int responseCode, String message) { if (!this.response.isCommitted()) { this.response.setContentType("text/plain"); syncOut.setHeader("Content-Type", "text/plain"); if (message != null) { try { this.response.getWriter().write(message); syncOut.getWriter() .write(message); } catch (IOException e) { log.warn("Could not write error message to output stream"); } } this.response.setStatus(responseCode); } else { log.warn("Could not send error " + responseCode + " (" + message + ") because the response is already committed."); } syncOut.setCode(responseCode); } <T extends Principal> GroupPersistence<T> getGroupPersistence() Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/CreateGroupAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -94,9 +94,9 @@ public class CreateGroupAction extends AbstractGroupAction GroupReader groupReader = new GroupReader(); Group group = groupReader.read(this.inputStream); Group newGroup = groupPersistence.addGroup(group); this.response.setContentType("application/xml"); syncOut.setHeader("Content-Type", "application/xml"); GroupWriter groupWriter = new GroupWriter(); groupWriter.write(newGroup, this.response.getOutputStream()); groupWriter.write(newGroup, syncOut.getWriter()); List<String> addedMembers = null; if ((newGroup.getUserMembers().size() > 0) || (newGroup.getGroupMembers().size() > 0)) Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/GetGroupAction.java +2 −3 Original line number Diff line number Diff line Loading @@ -85,10 +85,9 @@ public class GetGroupAction extends AbstractGroupAction { GroupPersistence groupPersistence = getGroupPersistence(); Group group = groupPersistence.getGroup(this.groupName); this.response.setContentType("application/xml"); syncOut.setHeader("Content-Type", "application/xml"); GroupWriter groupWriter = new GroupWriter(); groupWriter.write(group, this.response.getOutputStream()); groupWriter.write(group, syncOut.getWriter()); } }
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/web/groups/GetGroupNamesAction.java +2 −2 Original line number Diff line number Diff line Loading @@ -91,9 +91,9 @@ public class GetGroupNamesAction extends AbstractGroupAction GroupPersistence groupPersistence = getGroupPersistence(); Collection<String> groups = groupPersistence.getGroupNames(); log.debug("Found " + groups.size() + " group names"); response.setContentType("text/plain"); syncOut.setHeader("Content-Type", "text/plain"); log.debug("Set content-type to text/plain"); Writer writer = response.getWriter(); Writer writer = syncOut.getWriter(); boolean start = true; for (final String group : groups) { Loading