Revision 5030
Added by daigle over 14 years ago
MetaCatServlet.java | ||
---|---|---|
78 | 78 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
79 | 79 |
import edu.ucsb.nceas.metacat.database.DatabaseService; |
80 | 80 |
import edu.ucsb.nceas.metacat.dataquery.DataQuery; |
81 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
82 |
import edu.ucsb.nceas.metacat.properties.SkinPropertyService; |
|
81 | 83 |
import edu.ucsb.nceas.metacat.replication.ForceReplicationHandler; |
82 | 84 |
import edu.ucsb.nceas.metacat.replication.ReplicationService; |
83 | 85 |
import edu.ucsb.nceas.metacat.scheduler.SchedulerService; |
84 |
import edu.ucsb.nceas.metacat.service.PropertyService; |
|
85 | 86 |
import edu.ucsb.nceas.metacat.service.ServiceService; |
86 | 87 |
import edu.ucsb.nceas.metacat.service.SessionService; |
87 |
import edu.ucsb.nceas.metacat.service.SkinPropertyService; |
|
88 | 88 |
import edu.ucsb.nceas.metacat.service.XMLSchemaService; |
89 |
import edu.ucsb.nceas.metacat.shared.BaseException; |
|
89 | 90 |
import edu.ucsb.nceas.metacat.shared.HandlerException; |
90 | 91 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
91 | 92 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
... | ... | |
97 | 98 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
98 | 99 |
import edu.ucsb.nceas.metacat.util.MetacatUtil; |
99 | 100 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
101 |
import edu.ucsb.nceas.metacat.util.ResponseUtil; |
|
100 | 102 |
import edu.ucsb.nceas.metacat.util.SystemUtil; |
101 | 103 |
import edu.ucsb.nceas.metacat.util.SessionData; |
104 |
import edu.ucsb.nceas.metacat.workflow.WorkflowSchedulerClient; |
|
102 | 105 |
import edu.ucsb.nceas.utilities.FileUtil; |
103 | 106 |
import edu.ucsb.nceas.utilities.GeneralPropertyException; |
104 | 107 |
import edu.ucsb.nceas.utilities.LSIDUtil; |
... | ... | |
294 | 297 |
private static final String FALSE = "false"; |
295 | 298 |
private static final String TRUE = "true"; |
296 | 299 |
private static String LOG_CONFIG_NAME = null; |
300 |
public static final String APPLICATION_NAME = "metacat"; |
|
297 | 301 |
|
298 | 302 |
/** |
299 | 303 |
* Initialize the servlet by creating appropriate database connections |
... | ... | |
308 | 312 |
super.init(config); |
309 | 313 |
|
310 | 314 |
ServletContext context = config.getServletContext(); |
315 |
context.setAttribute("APPLICATION_NAME", APPLICATION_NAME); |
|
311 | 316 |
|
312 | 317 |
ServiceService serviceService = ServiceService.getInstance(context); |
313 | 318 |
logMetacat.debug("ServiceService singleton created " + serviceService); |
... | ... | |
319 | 324 |
PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME); |
320 | 325 |
|
321 | 326 |
// Register preliminary services |
322 |
ServiceService.registerService("PropertyService", PropertyService.getInstance()); |
|
327 |
ServiceService.registerService("PropertyService", PropertyService.getInstance(context));
|
|
323 | 328 |
ServiceService.registerService("SkinPropertyService", SkinPropertyService.getInstance()); |
324 | 329 |
ServiceService.registerService("SessionService", SessionService.getInstance()); |
325 | 330 |
|
... | ... | |
701 | 706 |
String ctype = request.getContentType(); |
702 | 707 |
if (ctype != null && ctype.startsWith("multipart/form-data")) { |
703 | 708 |
handleMultipartForm(request, response); |
704 |
} else { |
|
709 |
return; |
|
710 |
} |
|
705 | 711 |
|
706 |
String name = null;
|
|
707 |
String[] value = null;
|
|
708 |
String[] docid = new String[3];
|
|
709 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>();
|
|
712 |
String name = null; |
|
713 |
String[] value = null; |
|
714 |
String[] docid = new String[3]; |
|
715 |
Hashtable<String, String[]> params = new Hashtable<String, String[]>(); |
|
710 | 716 |
|
711 |
// Check if this is a simple read request that doesn't use the |
|
712 |
// "action" syntax |
|
713 |
// These URLs are of the form: |
|
714 |
// http://localhost:8180/knb/metacat/docid/skinname |
|
715 |
// e.g., http://localhost:8180/knb/metacat/test.1.1/knb |
|
716 |
String pathInfo = request.getPathInfo(); |
|
717 |
if (pathInfo != null) { |
|
718 |
String[] path = pathInfo.split("/"); |
|
719 |
if (path.length > 1) { |
|
720 |
String docidToRead = path[1]; |
|
721 |
String docs[] = new String[1]; |
|
722 |
docs[0] = docidToRead; |
|
723 |
logMetacat.debug("READING DOCID FROM PATHINFO: " + docs[0]); |
|
724 |
params.put("docid", docs); |
|
725 |
String skin = null; |
|
726 |
if (path.length > 2) { |
|
727 |
skin = path[2]; |
|
728 |
String skins[] = new String[1]; |
|
729 |
skins[0] = skin; |
|
730 |
params.put("qformat", skins); |
|
731 |
} |
|
732 |
handleReadAction(params, request, response, "public", null, null); |
|
733 |
return; |
|
717 |
// Check if this is a simple read request that doesn't use the |
|
718 |
// "action" syntax |
|
719 |
// These URLs are of the form: |
|
720 |
// http://localhost:8180/knb/metacat/docid/skinname |
|
721 |
// e.g., http://localhost:8180/knb/metacat/test.1.1/knb |
|
722 |
String pathInfo = request.getPathInfo(); |
|
723 |
if (pathInfo != null) { |
|
724 |
String[] path = pathInfo.split("/"); |
|
725 |
if (path.length > 1) { |
|
726 |
String docidToRead = path[1]; |
|
727 |
String docs[] = new String[1]; |
|
728 |
docs[0] = docidToRead; |
|
729 |
logMetacat.debug("READING DOCID FROM PATHINFO: " + docs[0]); |
|
730 |
params.put("docid", docs); |
|
731 |
String skin = null; |
|
732 |
if (path.length > 2) { |
|
733 |
skin = path[2]; |
|
734 |
String skins[] = new String[1]; |
|
735 |
skins[0] = skin; |
|
736 |
params.put("qformat", skins); |
|
734 | 737 |
} |
738 |
handleReadAction(params, request, response, "public", null, null); |
|
739 |
return; |
|
735 | 740 |
} |
741 |
} |
|
736 | 742 |
|
737 |
Enumeration<String> paramlist =(Enumeration<String>)request.getParameterNames(); |
|
738 |
while (paramlist.hasMoreElements()) { |
|
743 |
Enumeration<String> paramlist = |
|
744 |
(Enumeration<String>) request.getParameterNames(); |
|
745 |
while (paramlist.hasMoreElements()) { |
|
739 | 746 |
|
740 |
name = paramlist.nextElement();
|
|
741 |
value = request.getParameterValues(name);
|
|
747 |
name = paramlist.nextElement(); |
|
748 |
value = request.getParameterValues(name); |
|
742 | 749 |
|
743 |
// Decode the docid and mouse click information |
|
744 |
// THIS IS OBSOLETE -- I THINK -- REMOVE THIS BLOCK |
|
745 |
// 4/12/2007d |
|
746 |
// MBJ |
|
747 |
if (name.endsWith(".y")) { |
|
748 |
docid[0] = name.substring(0, name.length() - 2); |
|
749 |
params.put("docid", docid); |
|
750 |
name = "ypos"; |
|
751 |
} |
|
752 |
if (name.endsWith(".x")) { |
|
753 |
name = "xpos"; |
|
754 |
} |
|
755 |
|
|
756 |
params.put(name, value); |
|
750 |
// Decode the docid and mouse click information |
|
751 |
// THIS IS OBSOLETE -- I THINK -- REMOVE THIS BLOCK |
|
752 |
// 4/12/2007d |
|
753 |
// MBJ |
|
754 |
if (name.endsWith(".y")) { |
|
755 |
docid[0] = name.substring(0, name.length() - 2); |
|
756 |
params.put("docid", docid); |
|
757 |
name = "ypos"; |
|
757 | 758 |
} |
758 |
|
|
759 |
// handle param is emptpy |
|
760 |
if (params.isEmpty() || params == null) { |
|
761 |
return; |
|
759 |
if (name.endsWith(".x")) { |
|
760 |
name = "xpos"; |
|
762 | 761 |
} |
763 | 762 |
|
764 |
// if the user clicked on the input images, decode which image |
|
765 |
// was clicked then set the action. |
|
766 |
if (params.get("action") == null) { |
|
767 |
PrintWriter out = response.getWriter(); |
|
768 |
response.setContentType("text/xml"); |
|
769 |
out.println("<?xml version=\"1.0\"?>"); |
|
770 |
out.println("<error>"); |
|
771 |
out.println("Action not specified"); |
|
772 |
out.println("</error>"); |
|
773 |
out.close(); |
|
774 |
return; |
|
775 |
} |
|
763 |
params.put(name, value); |
|
764 |
} |
|
776 | 765 |
|
777 |
String action = (params.get("action"))[0]; |
|
778 |
logMetacat.info("Action is: " + action); |
|
766 |
// handle param is emptpy |
|
767 |
if (params.isEmpty() || params == null) { |
|
768 |
return; |
|
769 |
} |
|
779 | 770 |
|
780 |
// This block handles session management for the servlet |
|
781 |
// by looking up the current session information for all actions |
|
782 |
// other than "login" and "logout" |
|
783 |
String userName = null; |
|
784 |
String password = null; |
|
785 |
String[] groupNames = null; |
|
786 |
String sessionId = null; |
|
787 |
name = null; |
|
771 |
// if the user clicked on the input images, decode which image |
|
772 |
// was clicked then set the action. |
|
773 |
if (params.get("action") == null) { |
|
774 |
PrintWriter out = response.getWriter(); |
|
775 |
response.setContentType("text/xml"); |
|
776 |
out.println("<?xml version=\"1.0\"?>"); |
|
777 |
out.println("<error>"); |
|
778 |
out.println("Action not specified"); |
|
779 |
out.println("</error>"); |
|
780 |
out.close(); |
|
781 |
return; |
|
782 |
} |
|
788 | 783 |
|
789 |
// handle login action |
|
790 |
if (action.equals("login")) { |
|
791 |
PrintWriter out = response.getWriter(); |
|
792 |
handleLoginAction(out, params, request, response); |
|
793 |
out.close(); |
|
784 |
String action = (params.get("action"))[0]; |
|
785 |
logMetacat.info("Action is: " + action); |
|
794 | 786 |
|
795 |
// handle logout action |
|
796 |
} else if (action.equals("logout")) { |
|
797 |
PrintWriter out = response.getWriter(); |
|
798 |
handleLogoutAction(out, params, request, response); |
|
799 |
out.close(); |
|
787 |
// This block handles session management for the servlet |
|
788 |
// by looking up the current session information for all actions |
|
789 |
// other than "login" and "logout" |
|
790 |
String userName = null; |
|
791 |
String password = null; |
|
792 |
String[] groupNames = null; |
|
793 |
String sessionId = null; |
|
794 |
name = null; |
|
800 | 795 |
|
801 |
// handle shrink DBConnection request |
|
802 |
} else if (action.equals("shrink")) { |
|
803 |
PrintWriter out = response.getWriter(); |
|
804 |
boolean success = false; |
|
805 |
// If all DBConnection in the pool are free and DBConnection pool |
|
806 |
// size is greater than initial value, shrink the connection pool |
|
807 |
// size to initial value |
|
808 |
success = DBConnectionPool.shrinkConnectionPoolSize(); |
|
809 |
if (success) { |
|
810 |
// if successfully shrink the pool size to initial value |
|
811 |
out.println("DBConnection Pool shrunk successfully."); |
|
812 |
}// if |
|
813 |
else { |
|
814 |
out.println("DBConnection pool not shrunk successfully."); |
|
815 |
} |
|
816 |
// close out put |
|
817 |
out.close(); |
|
796 |
// handle login action |
|
797 |
if (action.equals("login")) { |
|
798 |
PrintWriter out = response.getWriter(); |
|
799 |
handleLoginAction(out, params, request, response); |
|
800 |
out.close(); |
|
818 | 801 |
|
819 |
// aware of session expiration on every request |
|
820 |
} else { |
|
821 |
SessionData sessionData = RequestUtil.getSessionData(request); |
|
822 |
|
|
823 |
userName = sessionData.getUserName(); |
|
824 |
password = sessionData.getPassword(); |
|
825 |
groupNames = sessionData.getGroupNames(); |
|
826 |
sessionId = sessionData.getId(); |
|
802 |
// handle logout action |
|
803 |
} else if (action.equals("logout")) { |
|
804 |
PrintWriter out = response.getWriter(); |
|
805 |
handleLogoutAction(out, params, request, response); |
|
806 |
out.close(); |
|
827 | 807 |
|
828 |
logMetacat.info("The user is : " + userName); |
|
808 |
// handle shrink DBConnection request |
|
809 |
} else if (action.equals("shrink")) { |
|
810 |
PrintWriter out = response.getWriter(); |
|
811 |
boolean success = false; |
|
812 |
// If all DBConnection in the pool are free and DBConnection |
|
813 |
// pool |
|
814 |
// size is greater than initial value, shrink the connection |
|
815 |
// pool |
|
816 |
// size to initial value |
|
817 |
success = DBConnectionPool.shrinkConnectionPoolSize(); |
|
818 |
if (success) { |
|
819 |
// if successfully shrink the pool size to initial value |
|
820 |
out.println("DBConnection Pool shrunk successfully."); |
|
821 |
}// if |
|
822 |
else { |
|
823 |
out.println("DBConnection pool not shrunk successfully."); |
|
829 | 824 |
} |
830 |
// Now that we know the session is valid, we can delegate the |
|
831 |
// request to a particular action handler |
|
832 |
if (action.equals("query")) { |
|
833 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
834 |
PrintWriter out = new PrintWriter(streamOut); |
|
835 |
handleQuery(out, params, response, userName, groupNames, sessionId); |
|
836 |
out.close(); |
|
837 |
} else if (action.equals("squery")) { |
|
838 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
839 |
PrintWriter out = new PrintWriter(streamOut); |
|
840 |
if (params.containsKey("query")) { |
|
841 |
handleSQuery(out, params, response, userName, groupNames, sessionId); |
|
842 |
out.close(); |
|
843 |
} else { |
|
844 |
out.println("Illegal action squery without \"query\" parameter"); |
|
845 |
out.close(); |
|
846 |
} |
|
847 |
} else if (action.trim().equals("spatial_query")) { |
|
825 |
// close out put |
|
826 |
out.close(); |
|
848 | 827 |
|
849 |
logMetacat |
|
850 |
.debug("******************* SPATIAL QUERY ********************"); |
|
851 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
852 |
PrintWriter out = new PrintWriter(streamOut); |
|
853 |
handleSpatialQuery(out, params, response, userName, groupNames, |
|
854 |
sessionId); |
|
855 |
out.close(); |
|
828 |
// aware of session expiration on every request |
|
829 |
} else { |
|
830 |
SessionData sessionData = RequestUtil.getSessionData(request); |
|
856 | 831 |
|
857 |
} |
|
858 |
else if (action.trim().equals("dataquery")) { |
|
832 |
userName = sessionData.getUserName(); |
|
833 |
password = sessionData.getPassword(); |
|
834 |
groupNames = sessionData.getGroupNames(); |
|
835 |
sessionId = sessionData.getId(); |
|
859 | 836 |
|
860 |
logMetacat |
|
861 |
.debug("******************* DATA QUERY ********************"); |
|
862 |
handleDataquery(params, response, sessionId); |
|
837 |
logMetacat.info("The user is : " + userName); |
|
838 |
} |
|
839 |
// Now that we know the session is valid, we can delegate the |
|
840 |
// request to a particular action handler |
|
841 |
if (action.equals("query")) { |
|
842 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
843 |
PrintWriter out = new PrintWriter(streamOut); |
|
844 |
handleQuery(out, params, response, userName, groupNames, sessionId); |
|
845 |
out.close(); |
|
846 |
} else if (action.equals("squery")) { |
|
847 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
848 |
PrintWriter out = new PrintWriter(streamOut); |
|
849 |
if (params.containsKey("query")) { |
|
850 |
handleSQuery(out, params, response, userName, groupNames, sessionId); |
|
851 |
out.close(); |
|
852 |
} else { |
|
853 |
out.println("Illegal action squery without \"query\" parameter"); |
|
854 |
out.close(); |
|
863 | 855 |
} |
864 |
else if (action.trim().equals("editcart")) { |
|
865 |
logMetacat |
|
866 |
.debug("******************* EDIT CART ********************"); |
|
867 |
handleEditCart(params, response, sessionId); |
|
868 |
} |
|
869 |
else if (action.equals("export")) { |
|
856 |
} else if (action.trim().equals("spatial_query")) { |
|
870 | 857 |
|
871 |
handleExportAction(params, response, userName, groupNames, password); |
|
872 |
} else if (action.equals("read")) { |
|
873 |
if (params.get("archiveEntryName") != null) { |
|
874 |
ArchiveHandler.getInstance().readArchiveEntry(params, request, response, |
|
875 |
userName, password,groupNames); |
|
876 |
} else { |
|
877 |
handleReadAction(params, request, response, userName, password, |
|
878 |
groupNames); |
|
879 |
} |
|
880 |
} else if (action.equals("readinlinedata")) { |
|
881 |
handleReadInlineDataAction(params, request, response, userName, |
|
882 |
password, groupNames); |
|
883 |
} else if (action.equals("insert") || action.equals("update")) { |
|
884 |
PrintWriter out = response.getWriter(); |
|
885 |
if ((userName != null) && !userName.equals("public")) { |
|
886 |
handleInsertOrUpdateAction(request, response, out, params, |
|
887 |
userName, groupNames); |
|
888 |
} else { |
|
889 |
response.setContentType("text/xml"); |
|
890 |
out.println("<?xml version=\"1.0\"?>"); |
|
891 |
out.println("<error>"); |
|
892 |
out.println("Permission denied for user " + userName + " " |
|
893 |
+ action); |
|
894 |
out.println("</error>"); |
|
895 |
} |
|
896 |
out.close(); |
|
897 |
} else if (action.equals("delete")) { |
|
898 |
PrintWriter out = response.getWriter(); |
|
899 |
if ((userName != null) && !userName.equals("public")) { |
|
900 |
handleDeleteAction(out, params, request, response, userName, |
|
901 |
groupNames); |
|
902 |
} else { |
|
903 |
response.setContentType("text/xml"); |
|
904 |
out.println("<?xml version=\"1.0\"?>"); |
|
905 |
out.println("<error>"); |
|
906 |
out.println("Permission denied for " + action); |
|
907 |
out.println("</error>"); |
|
908 |
} |
|
909 |
out.close(); |
|
910 |
} else if (action.equals("validate")) { |
|
911 |
PrintWriter out = response.getWriter(); |
|
912 |
handleValidateAction(out, params); |
|
913 |
out.close(); |
|
914 |
} else if (action.equals("setaccess")) { |
|
915 |
PrintWriter out = response.getWriter(); |
|
916 |
handleSetAccessAction(out, params, userName); |
|
917 |
out.close(); |
|
918 |
} else if (action.equals("getaccesscontrol")) { |
|
919 |
PrintWriter out = response.getWriter(); |
|
920 |
handleGetAccessControlAction(out, params, response, userName, |
|
858 |
logMetacat |
|
859 |
.debug("******************* SPATIAL QUERY ********************"); |
|
860 |
ServletOutputStream streamOut = response.getOutputStream(); |
|
861 |
PrintWriter out = new PrintWriter(streamOut); |
|
862 |
handleSpatialQuery(out, params, response, userName, groupNames, sessionId); |
|
863 |
out.close(); |
|
864 |
|
|
865 |
} else if (action.trim().equals("dataquery")) { |
|
866 |
|
|
867 |
logMetacat.debug("******************* DATA QUERY ********************"); |
|
868 |
handleDataquery(params, response, sessionId); |
|
869 |
} else if (action.trim().equals("editcart")) { |
|
870 |
logMetacat.debug("******************* EDIT CART ********************"); |
|
871 |
handleEditCart(params, response, sessionId); |
|
872 |
} else if (action.equals("export")) { |
|
873 |
|
|
874 |
handleExportAction(params, response, userName, groupNames, password); |
|
875 |
} else if (action.equals("read")) { |
|
876 |
if (params.get("archiveEntryName") != null) { |
|
877 |
ArchiveHandler.getInstance().readArchiveEntry(params, request, |
|
878 |
response, userName, password, groupNames); |
|
879 |
} else { |
|
880 |
handleReadAction(params, request, response, userName, password, |
|
921 | 881 |
groupNames); |
922 |
out.close(); |
|
923 |
} else if (action.equals("getprincipals")) { |
|
924 |
PrintWriter out = response.getWriter(); |
|
925 |
handleGetPrincipalsAction(out, userName, password); |
|
926 |
out.close(); |
|
927 |
} else if (action.equals("getdoctypes")) { |
|
928 |
PrintWriter out = response.getWriter(); |
|
929 |
handleGetDoctypesAction(out, params, response); |
|
930 |
out.close(); |
|
931 |
} else if (action.equals("getdtdschema")) { |
|
932 |
PrintWriter out = response.getWriter(); |
|
933 |
handleGetDTDSchemaAction(out, params, response); |
|
934 |
out.close(); |
|
935 |
} else if (action.equals("getlastdocid")) { |
|
936 |
PrintWriter out = response.getWriter(); |
|
937 |
handleGetMaxDocidAction(out, params, response); |
|
938 |
out.close(); |
|
939 |
} else if (action.equals("getalldocids")) { |
|
940 |
PrintWriter out = response.getWriter(); |
|
941 |
handleGetAllDocidsAction(out, params, response); |
|
942 |
out.close(); |
|
943 |
} else if (action.equals("isregistered")) { |
|
944 |
PrintWriter out = response.getWriter(); |
|
945 |
handleIdIsRegisteredAction(out, params, response); |
|
946 |
out.close(); |
|
947 |
} else if (action.equals("getrevisionanddoctype")) { |
|
948 |
PrintWriter out = response.getWriter(); |
|
949 |
handleGetRevisionAndDocTypeAction(out, params); |
|
950 |
out.close(); |
|
951 |
} else if (action.equals("getversion")) { |
|
882 |
} |
|
883 |
} else if (action.equals("readinlinedata")) { |
|
884 |
handleReadInlineDataAction(params, request, response, userName, password, |
|
885 |
groupNames); |
|
886 |
} else if (action.equals("insert") || action.equals("update")) { |
|
887 |
PrintWriter out = response.getWriter(); |
|
888 |
if ((userName != null) && !userName.equals("public")) { |
|
889 |
handleInsertOrUpdateAction(request, response, out, params, userName, |
|
890 |
groupNames); |
|
891 |
} else { |
|
952 | 892 |
response.setContentType("text/xml"); |
953 |
PrintWriter out = response.getWriter(); |
|
954 |
out.println(MetacatVersion.getVersionAsXml()); |
|
955 |
out.close(); |
|
956 |
} else if (action.equals("getlog")) { |
|
957 |
handleGetLogAction(params, request, response, userName, groupNames); |
|
958 |
} else if (action.equals("getloggedinuserinfo")) { |
|
959 |
PrintWriter out = response.getWriter(); |
|
960 |
response.setContentType("text/xml"); |
|
961 | 893 |
out.println("<?xml version=\"1.0\"?>"); |
962 |
out.println("\n<user>\n"); |
|
963 |
out.println("\n<username>\n"); |
|
964 |
out.println(userName); |
|
965 |
out.println("\n</username>\n"); |
|
966 |
if (name != null) { |
|
967 |
out.println("\n<name>\n"); |
|
968 |
out.println(name); |
|
969 |
out.println("\n</name>\n"); |
|
970 |
} |
|
971 |
if (AuthUtil.isAdministrator(userName, groupNames)) { |
|
972 |
out.println("<isAdministrator></isAdministrator>\n"); |
|
973 |
} |
|
974 |
if (AuthUtil.isModerator(userName, groupNames)) { |
|
975 |
out.println("<isModerator></isModerator>\n"); |
|
976 |
} |
|
977 |
out.println("\n</user>\n"); |
|
978 |
out.close(); |
|
979 |
} else if (action.equals("buildindex")) { |
|
980 |
handleBuildIndexAction(params, request, response, userName, |
|
894 |
out.println("<error>"); |
|
895 |
out.println("Permission denied for user " + userName + " " + action); |
|
896 |
out.println("</error>"); |
|
897 |
} |
|
898 |
out.close(); |
|
899 |
} else if (action.equals("delete")) { |
|
900 |
PrintWriter out = response.getWriter(); |
|
901 |
if ((userName != null) && !userName.equals("public")) { |
|
902 |
handleDeleteAction(out, params, request, response, userName, |
|
981 | 903 |
groupNames); |
982 |
} else if (action.equals("login") || action.equals("logout")) { |
|
983 |
/* |
|
984 |
* } else if (action.equals("protocoltest")) { String |
|
985 |
* testURL = "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; |
|
986 |
* try { testURL = ((String[]) params.get("url"))[0]; } |
|
987 |
* catch (Throwable t) { } String phandler = System |
|
988 |
* .getProperty("java.protocol.handler.pkgs"); |
|
989 |
* response.setContentType("text/html"); PrintWriter out = |
|
990 |
* response.getWriter(); out.println("<body |
|
991 |
* bgcolor=\"white\">"); out.println("<p>Handler property: |
|
992 |
* <code>" + phandler + "</code></p>"); out.println("<p>Starting |
|
993 |
* test for:<br>"); out.println(" " + testURL + "</p>"); |
|
994 |
* try { URL u = new URL(testURL); out.println("<pre>"); |
|
995 |
* out.println("Protocol: " + u.getProtocol()); |
|
996 |
* out.println(" Host: " + u.getHost()); out.println(" Port: " + |
|
997 |
* u.getPort()); out.println(" Path: " + u.getPath()); |
|
998 |
* out.println(" Ref: " + u.getRef()); String pquery = |
|
999 |
* u.getQuery(); out.println(" Query: " + pquery); |
|
1000 |
* out.println(" Params: "); if (pquery != null) { Hashtable |
|
1001 |
* qparams = MetacatUtil.parseQuery(u.getQuery()); for |
|
1002 |
* (Enumeration en = qparams.keys(); en .hasMoreElements();) { |
|
1003 |
* String pname = (String) en.nextElement(); String pvalue = |
|
1004 |
* (String) qparams.get(pname); out.println(" " + pname + ": " + |
|
1005 |
* pvalue); } } out.println("</pre>"); out.println("</body>"); |
|
1006 |
* out.close(); } catch (MalformedURLException mue) { |
|
1007 |
* System.out.println( "bad url from |
|
1008 |
* MetacatServlet.handleGetOrPost"); |
|
1009 |
* out.println(mue.getMessage()); mue.printStackTrace(out); |
|
1010 |
* out.close(); } |
|
1011 |
*/ |
|
1012 |
} else if (action.equals("refreshServices")) { |
|
1013 |
// TODO MCD this interface is for testing. It should go through a |
|
1014 |
// ServiceService class and only work for an admin user. Move to the |
|
1015 |
// MetacatAdminServlet |
|
1016 |
ServiceService.refreshService("XMLSchemaService"); |
|
1017 |
return; |
|
1018 |
// } else if (action.equals("scheduleWorkflow")) { |
|
1019 |
// try { |
|
1020 |
// WorkflowScheduler.getInstance().scheduleJob(request, response, params, |
|
1021 |
// userName, groupNames); |
|
1022 |
// return; |
|
1023 |
// } catch (BaseException be) { |
|
1024 |
// ResponseUtil.sendErrorXML(response, ResponseUtil.SCHEDULE_WORKFLOW_ERROR, be); |
|
1025 |
// return; |
|
1026 |
// } |
|
1027 |
// } else if (action.equals("unscheduleWorkflow")) { |
|
1028 |
// try { |
|
1029 |
// WorkflowScheduler.getInstance().unScheduleJob(request, response, params, |
|
1030 |
// userName, groupNames); |
|
1031 |
// return; |
|
1032 |
// } catch (BaseException be) { |
|
1033 |
// ResponseUtil.sendErrorXML(response, ResponseUtil.UNSCHEDULE_WORKFLOW_ERROR, be); |
|
1034 |
// return; |
|
1035 |
// } |
|
1036 |
// } else if (action.equals("rescheduleWorkflow")) { |
|
1037 |
// try { |
|
1038 |
// WorkflowScheduler.getInstance().reScheduleJob(request, response, params, |
|
1039 |
// userName, groupNames); |
|
1040 |
// return; |
|
1041 |
// } catch (BaseException be) { |
|
1042 |
// ResponseUtil.sendErrorXML(response, ResponseUtil.RESCHEDULE_WORKFLOW_ERROR, be); |
|
1043 |
// return; |
|
1044 |
// } |
|
1045 |
// } else if (action.equals("getScheduledWorkflow")) { |
|
1046 |
// try { |
|
1047 |
// WorkflowScheduler.getInstance().getJobs(request, response, params, |
|
1048 |
// userName, groupNames); |
|
1049 |
// return; |
|
1050 |
// } catch (BaseException be) { |
|
1051 |
// ResponseUtil.sendErrorXML(response, ResponseUtil.GET_SCHEDULED_WORKFLOW_ERROR, be); |
|
1052 |
// return; |
|
1053 |
// } |
|
1054 |
// } else if (action.equals("deleteScheduledWorkflow")) { |
|
1055 |
// try { |
|
1056 |
// WorkflowScheduler.getInstance().deleteJob(request, response, params, |
|
1057 |
// userName, groupNames); |
|
1058 |
// return; |
|
1059 |
// } catch (BaseException be) { |
|
1060 |
// ResponseUtil.sendErrorXML(response, ResponseUtil.DELETE_SCHEDULED_WORKFLOW_ERROR, be); |
|
1061 |
// return; |
|
1062 |
// } |
|
1063 | 904 |
} else { |
1064 |
PrintWriter out = response.getWriter();
|
|
905 |
response.setContentType("text/xml");
|
|
1065 | 906 |
out.println("<?xml version=\"1.0\"?>"); |
1066 | 907 |
out.println("<error>"); |
1067 |
out.println("Error: action not registered. Please report this error.");
|
|
908 |
out.println("Permission denied for " + action);
|
|
1068 | 909 |
out.println("</error>"); |
1069 |
out.close(); |
|
1070 | 910 |
} |
911 |
out.close(); |
|
912 |
} else if (action.equals("validate")) { |
|
913 |
PrintWriter out = response.getWriter(); |
|
914 |
handleValidateAction(out, params); |
|
915 |
out.close(); |
|
916 |
} else if (action.equals("setaccess")) { |
|
917 |
PrintWriter out = response.getWriter(); |
|
918 |
handleSetAccessAction(out, params, userName); |
|
919 |
out.close(); |
|
920 |
} else if (action.equals("getaccesscontrol")) { |
|
921 |
PrintWriter out = response.getWriter(); |
|
922 |
handleGetAccessControlAction(out, params, response, userName, groupNames); |
|
923 |
out.close(); |
|
924 |
} else if (action.equals("getprincipals")) { |
|
925 |
PrintWriter out = response.getWriter(); |
|
926 |
handleGetPrincipalsAction(out, userName, password); |
|
927 |
out.close(); |
|
928 |
} else if (action.equals("getdoctypes")) { |
|
929 |
PrintWriter out = response.getWriter(); |
|
930 |
handleGetDoctypesAction(out, params, response); |
|
931 |
out.close(); |
|
932 |
} else if (action.equals("getdtdschema")) { |
|
933 |
PrintWriter out = response.getWriter(); |
|
934 |
handleGetDTDSchemaAction(out, params, response); |
|
935 |
out.close(); |
|
936 |
} else if (action.equals("getlastdocid")) { |
|
937 |
PrintWriter out = response.getWriter(); |
|
938 |
handleGetMaxDocidAction(out, params, response); |
|
939 |
out.close(); |
|
940 |
} else if (action.equals("getalldocids")) { |
|
941 |
PrintWriter out = response.getWriter(); |
|
942 |
handleGetAllDocidsAction(out, params, response); |
|
943 |
out.close(); |
|
944 |
} else if (action.equals("isregistered")) { |
|
945 |
PrintWriter out = response.getWriter(); |
|
946 |
handleIdIsRegisteredAction(out, params, response); |
|
947 |
out.close(); |
|
948 |
} else if (action.equals("getrevisionanddoctype")) { |
|
949 |
PrintWriter out = response.getWriter(); |
|
950 |
handleGetRevisionAndDocTypeAction(out, params); |
|
951 |
out.close(); |
|
952 |
} else if (action.equals("getversion")) { |
|
953 |
response.setContentType("text/xml"); |
|
954 |
PrintWriter out = response.getWriter(); |
|
955 |
out.println(MetacatVersion.getVersionAsXml()); |
|
956 |
out.close(); |
|
957 |
} else if (action.equals("getlog")) { |
|
958 |
handleGetLogAction(params, request, response, userName, groupNames); |
|
959 |
} else if (action.equals("getloggedinuserinfo")) { |
|
960 |
PrintWriter out = response.getWriter(); |
|
961 |
response.setContentType("text/xml"); |
|
962 |
out.println("<?xml version=\"1.0\"?>"); |
|
963 |
out.println("\n<user>\n"); |
|
964 |
out.println("\n<username>\n"); |
|
965 |
out.println(userName); |
|
966 |
out.println("\n</username>\n"); |
|
967 |
if (name != null) { |
|
968 |
out.println("\n<name>\n"); |
|
969 |
out.println(name); |
|
970 |
out.println("\n</name>\n"); |
|
971 |
} |
|
972 |
if (AuthUtil.isAdministrator(userName, groupNames)) { |
|
973 |
out.println("<isAdministrator></isAdministrator>\n"); |
|
974 |
} |
|
975 |
if (AuthUtil.isModerator(userName, groupNames)) { |
|
976 |
out.println("<isModerator></isModerator>\n"); |
|
977 |
} |
|
978 |
out.println("\n</user>\n"); |
|
979 |
out.close(); |
|
980 |
} else if (action.equals("buildindex")) { |
|
981 |
handleBuildIndexAction(params, request, response, userName, groupNames); |
|
982 |
} else if (action.equals("login") || action.equals("logout")) { |
|
983 |
/* |
|
984 |
* } else if (action.equals("protocoltest")) { String testURL = |
|
985 |
* "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; try { testURL = |
|
986 |
* ((String[]) params.get("url"))[0]; } catch (Throwable t) { } |
|
987 |
* String phandler = System |
|
988 |
* .getProperty("java.protocol.handler.pkgs"); |
|
989 |
* response.setContentType("text/html"); PrintWriter out = |
|
990 |
* response.getWriter(); out.println("<body |
|
991 |
* bgcolor=\"white\">"); out.println("<p>Handler property: |
|
992 |
* <code>" + phandler + "</code></p>"); out.println("<p>Starting |
|
993 |
* test for:<br>"); out.println(" " + testURL + "</p>"); try { |
|
994 |
* URL u = new URL(testURL); out.println("<pre>"); |
|
995 |
* out.println("Protocol: " + u.getProtocol()); out.println(" |
|
996 |
* Host: " + u.getHost()); out.println(" Port: " + u.getPort()); |
|
997 |
* out.println(" Path: " + u.getPath()); out.println(" Ref: " + |
|
998 |
* u.getRef()); String pquery = u.getQuery(); out.println(" |
|
999 |
* Query: " + pquery); out.println(" Params: "); if (pquery != |
|
1000 |
* null) { Hashtable qparams = |
|
1001 |
* MetacatUtil.parseQuery(u.getQuery()); for (Enumeration en = |
|
1002 |
* qparams.keys(); en .hasMoreElements();) { String pname = |
|
1003 |
* (String) en.nextElement(); String pvalue = (String) |
|
1004 |
* qparams.get(pname); out.println(" " + pname + ": " + pvalue); } } |
|
1005 |
* out.println("</pre>"); out.println("</body>"); |
|
1006 |
* out.close(); } catch (MalformedURLException mue) { |
|
1007 |
* System.out.println( "bad url from |
|
1008 |
* MetacatServlet.handleGetOrPost"); |
|
1009 |
* out.println(mue.getMessage()); mue.printStackTrace(out); |
|
1010 |
* out.close(); } |
|
1011 |
*/ |
|
1012 |
} else if (action.equals("refreshServices")) { |
|
1013 |
// TODO MCD this interface is for testing. It should go through |
|
1014 |
// a |
|
1015 |
// ServiceService class and only work for an admin user. Move to |
|
1016 |
// the |
|
1017 |
// MetacatAdminServlet |
|
1018 |
ServiceService.refreshService("XMLSchemaService"); |
|
1019 |
return; |
|
1020 |
} else if (action.equals("scheduleWorkflow")) { |
|
1021 |
try { |
|
1022 |
WorkflowSchedulerClient.getInstance().scheduleJob(request, response, |
|
1023 |
params, userName, groupNames); |
|
1024 |
return; |
|
1025 |
} catch (BaseException be) { |
|
1026 |
ResponseUtil.sendErrorXML(response, |
|
1027 |
ResponseUtil.SCHEDULE_WORKFLOW_ERROR, be); |
|
1028 |
return; |
|
1029 |
} |
|
1030 |
} else if (action.equals("unscheduleWorkflow")) { |
|
1031 |
try { |
|
1032 |
WorkflowSchedulerClient.getInstance().unScheduleJob(request, |
|
1033 |
response, params, userName, groupNames); |
|
1034 |
return; |
|
1035 |
} catch (BaseException be) { |
|
1036 |
ResponseUtil.sendErrorXML(response, |
|
1037 |
ResponseUtil.UNSCHEDULE_WORKFLOW_ERROR, be); |
|
1038 |
return; |
|
1039 |
} |
|
1040 |
} else if (action.equals("rescheduleWorkflow")) { |
|
1041 |
try { |
|
1042 |
WorkflowSchedulerClient.getInstance().reScheduleJob(request, |
|
1043 |
response, params, userName, groupNames); |
|
1044 |
return; |
|
1045 |
} catch (BaseException be) { |
|
1046 |
ResponseUtil.sendErrorXML(response, |
|
1047 |
ResponseUtil.RESCHEDULE_WORKFLOW_ERROR, be); |
|
1048 |
return; |
|
1049 |
} |
|
1050 |
} else if (action.equals("getScheduledWorkflow")) { |
|
1051 |
try { |
|
1052 |
WorkflowSchedulerClient.getInstance().getJobs(request, response, |
|
1053 |
params, userName, groupNames); |
|
1054 |
return; |
|
1055 |
} catch (BaseException be) { |
|
1056 |
ResponseUtil.sendErrorXML(response, |
|
1057 |
ResponseUtil.GET_SCHEDULED_WORKFLOW_ERROR, be); |
|
1058 |
return; |
|
1059 |
} |
|
1060 |
} else if (action.equals("deleteScheduledWorkflow")) { |
|
1061 |
try { |
|
1062 |
WorkflowSchedulerClient.getInstance().deleteJob(request, response, |
|
1063 |
params, userName, groupNames); |
|
1064 |
return; |
|
1065 |
} catch (BaseException be) { |
|
1066 |
ResponseUtil.sendErrorXML(response, |
|
1067 |
ResponseUtil.DELETE_SCHEDULED_WORKFLOW_ERROR, be); |
|
1068 |
return; |
|
1069 |
} |
|
1071 | 1070 |
|
1072 |
// util.closeConnections(); |
|
1073 |
// Close the stream to the client |
|
1074 |
// out.close(); |
|
1071 |
} else { |
|
1072 |
PrintWriter out = response.getWriter(); |
|
1073 |
out.println("<?xml version=\"1.0\"?>"); |
|
1074 |
out.println("<error>"); |
|
1075 |
out.println("Error: action not registered. Please report this error."); |
|
1076 |
out.println("</error>"); |
|
1077 |
out.close(); |
|
1078 |
} |
|
1075 | 1079 |
|
1076 |
// Schedule the sitemap generator to run periodically |
|
1077 |
scheduleSitemapGeneration(request); |
|
1078 |
} |
|
1080 |
// util.closeConnections(); |
|
1081 |
// Close the stream to the client |
|
1082 |
// out.close(); |
|
1083 |
|
|
1084 |
// Schedule the sitemap generator to run periodically |
|
1085 |
scheduleSitemapGeneration(request); |
|
1086 |
|
|
1087 |
|
|
1079 | 1088 |
} catch (PropertyNotFoundException pnfe) { |
1080 | 1089 |
String errorString = "Critical property not found: " + pnfe.getMessage(); |
1081 | 1090 |
logMetacat.error(errorString); |
Also available in: Unified diff
Change location of PropertyService to properties directory