Project

General

Profile

« Previous | Next » 

Revision 1830

Added by skrish about 21 years ago

  • empty log message ***

View differences:

src/edu/ucsb/nceas/metacat/harvesterClient/MetUpload.java
9 9
import javax.servlet.http.HttpUtils;
10 10
import javax.servlet.ServletOutputStream;
11 11

  
12
import org.ecoinformatics.eml.EMLParser;
12
//import org.ecoinformatics.eml.EMLParser;
13 13

  
14 14
import java.io.*;
15 15
import java.util.*;
......
19 19
import com.oreilly.servlet.multipart.ParamPart;
20 20
import com.oreilly.servlet.multipart.Part;
21 21

  
22
import edu.ucsb.nceas.metacat.client.*;
23
import edu.ucsb.nceas.utilities.IOUtil;
24
//import edu.ucsb.nceas.metacat.*;
25
//import edu.ucsb.nceas.metacat.MetaCatUtil;
22 26

  
23
import edu.ucsb.nceas.metacat.*;
24
import edu.ucsb.nceas.metacat.MetaCatUtil;
25 27

  
26

  
27 28
public class MetUpload extends HttpServlet
28 29
{
30
	 private String insertXML = "";
31
	 private String metacatUrl =
32
	 	 "http://knb.lternet.edu:8098/knb/servlet/metacat";
33
	 private Metacat m;
29 34
public void service(HttpServletRequest request, HttpServletResponse response)
30 35
        throws IOException
31 36
{
......
36 41
		out = response.getWriter();
37 42

  
38 43
  		String file = new String("");
39
		DBConnection dbconn = null;
40
		DBConnectionPool connPool = null;
41
	 	File dataDirectory = null;
42
	 	MetaCatUtil util = null;
43
		String datafilepath = null;
44 44
		String fileName = null;
45 45
		FilePart fPart = null;
46 46
      		MultipartParser parser = new MultipartParser((HttpServletRequest)request, 1024 * 1024);
47 47
      		//MultipartParser parser = new MultipartParser(request, 1024 * 1024);
48 48
      		Part aPart;
49
		DocumentImplWrapper documentWrapper = null;
50 49
		String eml_filename=" ",docid=" ";
51
		StringReader xml = null;
52
		/*String eml_filename=" ",docid=" ";*/
53 50
	    	Hashtable formElements = new Hashtable();
54 51
 	    	while( (aPart = parser.readNextPart()) != null ) {
55 52
	      		if( aPart.isParam() == true ) {
......
72 69
		        		//write the image to a file
73 70
		        		String dir = "/tmp/Upload_data";  
74 71
		        		File theFile = new File(dir, fileName);
75
					/*fPart.writeTo(theFile);
72
					fPart.writeTo(theFile);
76 73
					eml_filename = dir+"/"+fileName;
77
		        		formElements.put(field, fileName);*/
74
		        		formElements.put(field, fileName);
78 75
					break;
79 76
           			}
80 77
        		}
81 78
      		}
82
	//	out.println( formElements );
83
		//out.println( docid + " " + eml_filename );
84
    	//	out.println("EML File uploaded");
85 79
/*****************************************************/
86 80

  
87 81

  
88 82
/* Change for input to metacat */
89 83

  
90
		util = new MetaCatUtil();
91
		datafilepath = util.getOption("datafilepath");
92
		dataDirectory = new File(datafilepath);
93 84
	HttpSession sess = request.getSession(true);
94
	String username = null;
95
	username = (String)sess.getAttribute("username");
85
	String username = null,password=null;
86
	username = (String)sess.getAttribute("Musername");
87
	password = (String)sess.getAttribute("Mpassword");
96 88

  
97 89
	 //out.println(username);
98 90
	 out.println("Username is "+username+" <BR>");
99
	 
91
	try {
92
	       FileReader fr = new FileReader(eml_filename);
93
	      insertXML = IOUtil.getAsString(fr, true);
94
	       } catch (IOException ioe) {
95
	          out.println("Can't read test data to run the test: " + eml_filename);
96
	    }
100 97

  
98
	 try {
99
	       m = MetacatFactory.createMetacatConnection(metacatUrl);
100
	    } catch (MetacatInaccessibleException mie) {
101
	             out.println("Metacat connection failed." + mie.getMessage());
102
	   }
103
	try {
104
	           String identifier = docid + ".1";
105
		   m.login(username, password);
106
	           String response1 = m.insert(identifier,
107
	           new StringReader(insertXML), null);
108
	           out.println(response1);
101 109

  
102
	 //initial DBConnection pool
103
	      connPool = DBConnectionPool.getInstance();
104
	 
105
	/*
106
dbconn=DBConnectionPool.getDBConnection("DocumentImpl.main");
110
           } catch (Exception e) {
111
	                out.println("General exception:\n" + e.getMessage());
112
       }
107 113

  
108
		documentWrapper = new DocumentImplWrapper("", false);
109
/*String newdocid = DocumentImpl.write(dbconn, eml_filename, null,
110
                                   "null", "INSERT", docid,
111
                                   null, null);*/
112
	/*xml = new StringReader(eml_filename);
113
String newdocid = documentWrapper.write(dbconn, xml, null,
114
                                   null, "INSERT", docid,
115
                                   null, null);
116
if ((docid != null) && (!docid.equals(newdocid))) {
117
         
118
            System.out.println("New document ID generated!!! ");
119
          }*/
120 114

  
121
 if (DocumentImpl.getDataFileLockGrant(docid))
122
 {
123
	 //out.println(docid);
124
	 DocumentImpl.registerDocument(fileName, "BIN", docid, username);
125 115

  
126
	 // Save the data file to disk using "docid" as the name
127
	 dataDirectory.mkdirs();
128
	 File newFile = new File(dataDirectory, docid);
129

  
130
	 long size = fPart.writeTo(newFile);
131

  
132
	 //out.println(docid);
133
	 ForceReplicationHandler frh = new ForceReplicationHandler
134
	 				(docid, "insert", false, null);
135

  
136

  
137
	 // set content type and other response header fields first
138
	 out.println(" EML file uploaded successfully with docid as "+docid+"<BR>" );
139
}
140
else 
141
	
142
	 out.println(" EML file upload with docid as "+docid+" failed<br>");
143

  
144

  
145

  
146 116
/****************************************************/
147 117

  
148 118

  
src/edu/ucsb/nceas/metacat/harvesterClient/LoginServlet.java
12 12
import javax.servlet.http.HttpUtils;
13 13
import javax.servlet.ServletOutputStream;
14 14

  
15
import edu.ucsb.nceas.metacat.AuthSession;
16

  
15 17
public class LoginServlet extends HttpServlet {
16 18

  
17 19

  
......
43 45
{
44 46

  
45 47
	String user="skr";
46
	String group="skr";
48
//	String group="skr";
47 49
	String passwd="skr";
50
	AuthSession sess =null;
48 51

  
49 52
		user = request.getParameter("user");
50
		group = request.getParameter("group");
53
//		group = request.getParameter("group");
51 54
		passwd = request.getParameter("passwd");
55
	
56
	try{
57
		sess = new AuthSession();
58
	} catch (Exception e) {
59
		System.out.println("Error in LoginServlet.handleGetorPost Authsession" +
60
				e.getMessage());
61
		return;
62
	}
52 63

  
53 64

  
65
	boolean isValid = sess.authenticate(request, user,passwd);
66
		PrintWriter out1 = response.getWriter();
67
	System.out.println("Sess.authenticate "+sess.getMessage());
68
	out1.println("Sess.authenticate "+sess.getMessage());
54 69

  
55
		HttpSession sess = request.getSession(true);
70

  
71

  
72
/*****************************************************/
73
		HttpSession sess1 = request.getSession(true);
56 74
	
57 75
		/*if (sess.isNew()) {*/
58
		 sess.putValue("username",user);
59
		 sess.putValue("password",passwd);
60
			 sess.putValue("groupnames", group);
76
		 sess1.putValue("Musername",user);
77
		 sess1.putValue("Mpassword",passwd);
78
//			 sess.putValue("groupnames", group);
61 79

  
62 80
		//}
63 81

  
64 82
		
65 83
	//	PrintWriter out = response.getWriter();
66 84
	//	out.println(sess.getValue("username"));
85
/*****************************************************/
67 86
	response.sendRedirect("../uploademl.html");
68 87

  
69 88

  

Also available in: Unified diff