Revision 8588
Added by ben leinfelder about 10 years ago
MetacatHandler.java | ||
---|---|---|
40 | 40 |
import java.io.StringReader; |
41 | 41 |
import java.io.UnsupportedEncodingException; |
42 | 42 |
import java.io.Writer; |
43 |
import java.math.BigInteger; |
|
44 | 43 |
import java.net.MalformedURLException; |
45 | 44 |
import java.net.URL; |
46 | 45 |
import java.sql.PreparedStatement; |
... | ... | |
71 | 70 |
import org.apache.commons.io.IOUtils; |
72 | 71 |
import org.apache.commons.io.input.XmlStreamReader; |
73 | 72 |
import org.apache.log4j.Logger; |
74 |
import org.dataone.client.CNode; |
|
75 |
import org.dataone.client.D1Client; |
|
76 |
import org.dataone.service.exceptions.NotAuthorized; |
|
77 |
import org.dataone.service.exceptions.ServiceFailure; |
|
78 | 73 |
import org.dataone.service.types.v1.AccessPolicy; |
79 | 74 |
import org.dataone.service.types.v1.Event; |
80 | 75 |
import org.dataone.service.types.v1.Identifier; |
... | ... | |
336 | 331 |
/** |
337 | 332 |
* Handle the login request. Create a new session object. Do user |
338 | 333 |
* authentication through the session. |
334 |
* @throws IOException |
|
339 | 335 |
*/ |
340 |
public void handleLoginAction(PrintWriter out, Hashtable<String, String[]> params,
|
|
341 |
HttpServletRequest request, HttpServletResponse response) { |
|
336 |
public void handleLoginAction(Writer out, Hashtable<String, String[]> params, |
|
337 |
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
342 | 338 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class); |
343 | 339 |
AuthSession sess = null; |
344 | 340 |
|
345 | 341 |
if(params.get("username") == null){ |
346 | 342 |
response.setContentType("text/xml"); |
347 |
out.println("<?xml version=\"1.0\"?>");
|
|
348 |
out.println("<error>");
|
|
349 |
out.println("Username not specified");
|
|
350 |
out.println("</error>");
|
|
343 |
out.write("<?xml version=\"1.0\"?>");
|
|
344 |
out.write("<error>");
|
|
345 |
out.write("Username not specified");
|
|
346 |
out.write("</error>");
|
|
351 | 347 |
return; |
352 | 348 |
} |
353 | 349 |
|
... | ... | |
355 | 351 |
|
356 | 352 |
if(params.get("password") == null){ |
357 | 353 |
response.setContentType("text/xml"); |
358 |
out.println("<?xml version=\"1.0\"?>");
|
|
359 |
out.println("<error>");
|
|
360 |
out.println("Password not specified");
|
|
361 |
out.println("</error>");
|
|
354 |
out.write("<?xml version=\"1.0\"?>");
|
|
355 |
out.write("<error>");
|
|
356 |
out.write("Password not specified");
|
|
357 |
out.write("</error>");
|
|
362 | 358 |
return; |
363 | 359 |
} |
364 | 360 |
|
... | ... | |
377 | 373 |
String errorMsg = "MetacatServlet.handleLoginAction - Problem in MetacatServlet.handleLoginAction() authenicating session: " |
378 | 374 |
+ e.getMessage(); |
379 | 375 |
logMetacat.error(errorMsg); |
380 |
out.println(errorMsg);
|
|
376 |
out.write(errorMsg);
|
|
381 | 377 |
e.printStackTrace(System.out); |
382 | 378 |
return; |
383 | 379 |
} |
... | ... | |
405 | 401 |
String errorMsg = "MetacatServlet.handleLoginAction - service problem registering session: " |
406 | 402 |
+ se.getMessage(); |
407 | 403 |
logMetacat.error("MetacatHandler.handleLoginAction - " + errorMsg); |
408 |
out.println(errorMsg);
|
|
404 |
out.write(errorMsg);
|
|
409 | 405 |
se.printStackTrace(System.out); |
410 | 406 |
return; |
411 | 407 |
} |
... | ... | |
414 | 410 |
// format and transform the output |
415 | 411 |
if (qformat.equals("xml")) { |
416 | 412 |
response.setContentType("text/xml"); |
417 |
out.println(sess.getMessage());
|
|
413 |
out.write(sess.getMessage());
|
|
418 | 414 |
} else { |
419 | 415 |
try { |
420 | 416 |
DBTransform trans = new DBTransform(); |
... | ... | |
432 | 428 |
|
433 | 429 |
/** |
434 | 430 |
* Handle the logout request. Close the connection. |
431 |
* @throws IOException |
|
435 | 432 |
*/ |
436 |
public void handleLogoutAction(PrintWriter out, Hashtable<String, String[]> params,
|
|
437 |
HttpServletRequest request, HttpServletResponse response) { |
|
433 |
public void handleLogoutAction(Writer out, Hashtable<String, String[]> params, |
|
434 |
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
438 | 435 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class); |
439 | 436 |
String qformat = "xml"; |
440 | 437 |
if(params.get("qformat") != null){ |
... | ... | |
464 | 461 |
//format and transform the output |
465 | 462 |
if (qformat.equals("xml")) { |
466 | 463 |
response.setContentType("text/xml"); |
467 |
out.println(output.toString());
|
|
464 |
out.write(output.toString());
|
|
468 | 465 |
} else { |
469 | 466 |
try { |
470 | 467 |
DBTransform trans = new DBTransform(); |
... | ... | |
2252 | 2249 |
/** |
2253 | 2250 |
* Handle the "getprincipals" action. Read all principals from |
2254 | 2251 |
* authentication scheme in XML format |
2252 |
* @throws IOException |
|
2255 | 2253 |
*/ |
2256 |
protected void handleGetPrincipalsAction(PrintWriter out, String user,
|
|
2257 |
String password) { |
|
2254 |
protected void handleGetPrincipalsAction(Writer out, String user, |
|
2255 |
String password) throws IOException {
|
|
2258 | 2256 |
try { |
2259 | 2257 |
AuthSession auth = new AuthSession(); |
2260 | 2258 |
String principals = auth.getPrincipals(user, password); |
2261 |
out.println(principals);
|
|
2259 |
out.write(principals);
|
|
2262 | 2260 |
|
2263 | 2261 |
} catch (Exception e) { |
2264 |
out.println("<?xml version=\"1.0\"?>");
|
|
2265 |
out.println("<error>");
|
|
2266 |
out.println(e.getMessage());
|
|
2267 |
out.println("</error>");
|
|
2262 |
out.write("<?xml version=\"1.0\"?>");
|
|
2263 |
out.write("<error>");
|
|
2264 |
out.write(e.getMessage());
|
|
2265 |
out.write("</error>");
|
|
2268 | 2266 |
} |
2269 | 2267 |
} |
2270 | 2268 |
|
Also available in: Unified diff
allow utf-8 user first/last names to be used in responses for: login, logout, validatesession, getprincipals.