Revision 648
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
26 | 26 |
import java.util.Enumeration; |
27 | 27 |
import java.util.Hashtable; |
28 | 28 |
import java.util.ResourceBundle; |
29 |
import java.util.Random; |
|
29 | 30 |
import java.util.PropertyResourceBundle; |
30 | 31 |
import java.net.URL; |
31 | 32 |
import java.net.MalformedURLException; |
... | ... | |
229 | 230 |
// other than "login" and "logout" |
230 | 231 |
String username = null; |
231 | 232 |
String groupname = null; |
233 |
String sess_id = null; |
|
232 | 234 |
|
233 | 235 |
// handle login action |
234 | 236 |
if (action.equals("login")) { |
... | ... | |
250 | 252 |
} else { |
251 | 253 |
username = (String)sess.getAttribute("username"); |
252 | 254 |
groupname = (String)sess.getAttribute("groupname"); |
255 |
try |
|
256 |
{ |
|
257 |
sess_id = (String)sess.getId(); |
|
258 |
} |
|
259 |
catch(IllegalStateException ise) |
|
260 |
{ |
|
261 |
System.out.println("error in handleGetOrPost: this shouldn't " + |
|
262 |
"happen: the session should be valid: " + |
|
263 |
ise.getMessage()); |
|
264 |
} |
|
253 | 265 |
} |
254 | 266 |
} |
255 | 267 |
|
... | ... | |
326 | 338 |
} else if (action.equals("getdoctypes")) { |
327 | 339 |
PrintWriter out = response.getWriter(); |
328 | 340 |
handleGetDoctypesAction(out, params, response); |
341 |
} else if (action.equals("getdataport")) { |
|
342 |
PrintWriter out = response.getWriter(); |
|
343 |
handleGetDataPortAction(out, params, response, username, groupname, |
|
344 |
sess_id); |
|
329 | 345 |
} else if (action.equals("getdataguide")) { |
330 | 346 |
PrintWriter out = response.getWriter(); |
331 | 347 |
handleGetDataGuideAction(out, params, response); |
... | ... | |
414 | 430 |
return "error"; |
415 | 431 |
} |
416 | 432 |
} |
433 |
|
|
434 |
/** |
|
435 |
* sends the port number that the data socket is running on. This is a |
|
436 |
* parameter set in the metacat.properties file. |
|
437 |
*/ |
|
438 |
private void handleGetDataPortAction(PrintWriter out, Hashtable params, |
|
439 |
HttpServletResponse response, |
|
440 |
String username, String groupname, |
|
441 |
String sess_id) |
|
442 |
{ |
|
443 |
int port; |
|
444 |
String filedir = null; |
|
445 |
try |
|
446 |
{ |
|
447 |
filedir = util.getOption("datafilepath"); |
|
448 |
|
|
449 |
Random r = new Random(); |
|
450 |
port = r.nextInt(65000); //pick a random port between 0-65000 |
|
451 |
//System.out.println("random port is: " + port); |
|
452 |
while(!DataFileServer.portIsAvailable(port)) |
|
453 |
{ |
|
454 |
port = r.nextInt(65000); |
|
455 |
//System.out.println("next port used: " + port); |
|
456 |
} |
|
457 |
DataFileServer dfs = new DataFileServer(port, username, sess_id); |
|
458 |
dfs.start(); |
|
459 |
|
|
460 |
//System.out.println("filedir: " + filedir); |
|
461 |
//System.out.println("port: " + port); |
|
462 |
response.setContentType("text/xml"); |
|
463 |
out.println("<?xml version=\"1.0\"?>"); |
|
464 |
out.println("<port>"); |
|
465 |
out.print(port); |
|
466 |
out.print("</port>"); |
|
467 |
|
|
468 |
} |
|
469 |
catch (Exception e) |
|
470 |
{ |
|
471 |
System.out.println("error in handleGetDataPortAction: " + e.getMessage()); |
|
472 |
} |
|
473 |
} |
|
417 | 474 |
|
418 | 475 |
/** |
419 | 476 |
* Handle the login request. Create a new session object. |
Also available in: Unified diff
added support for data file upload via a random, authenticated socket.
The action added to metacatServlet is getdataport. A client can send a getdataport request. the server returns a random port number and starts a thread to handle the request on the given random port. The thread will only accept requests from the client that has the session id equal to that of the user that made the getdataport request. the user must be authenticated and logged in to make a getdataport request. Once the port number is received by the client the connection can be made. The first two parameters in the data stream must be the filename, followed by session id. (note that it only wants the session id not the whole cookie and the "JSESSION=" must be stripped from the text.) If the session number is correct, the upload is allowed, the file is written and xml_documents is updated with the new data file information.