Revision 1822
Added by Matt Jones over 20 years ago
MetacatClient.java | ||
---|---|---|
48 | 48 |
/** The URL string for the metacat server */ |
49 | 49 |
private String metacatUrl; |
50 | 50 |
|
51 |
/** The session identifier for the session */ |
|
52 |
private String sessionId; |
|
53 |
|
|
51 | 54 |
/** |
52 | 55 |
* Constructor to create a new instance. Protected because instances |
53 | 56 |
* should only be created by the factory MetacatFactory. |
54 | 57 |
*/ |
55 | 58 |
protected MetacatClient() |
56 | 59 |
{ |
60 |
this.metacatUrl = null; |
|
61 |
this.sessionId = null; |
|
57 | 62 |
} |
58 | 63 |
|
59 | 64 |
/** |
... | ... | |
64 | 69 |
* |
65 | 70 |
* @param username the username of the user, like an LDAP DN |
66 | 71 |
* @param password the password for that user for authentication |
72 |
* @return the response string from metacat in XML format |
|
67 | 73 |
* @throws MetacatAuthException when the username/password could |
68 | 74 |
* not be authenticated |
69 | 75 |
*/ |
70 |
public void login(String username, String password)
|
|
76 |
public String login(String username, String password)
|
|
71 | 77 |
throws MetacatAuthException, MetacatInaccessibleException |
72 | 78 |
{ |
73 | 79 |
Properties prop = new Properties(); |
... | ... | |
86 | 92 |
if (response.indexOf("<login>") == -1) { |
87 | 93 |
HttpMessage.setCookie(null); |
88 | 94 |
throw new MetacatAuthException(response); |
95 |
} else { |
|
96 |
int start = response.indexOf("<sessionId>"); |
|
97 |
int end = response.indexOf("</sessionId>"); |
|
98 |
if ((start != -1) && (end != -1)) { |
|
99 |
sessionId = response.substring(start,end); |
|
100 |
} |
|
89 | 101 |
} |
102 |
return response; |
|
90 | 103 |
} |
91 | 104 |
|
92 | 105 |
/** |
93 |
* Method used to log out a metacat server. When Metacat server will end
|
|
94 |
* the session when this call is invoken.
|
|
106 |
* Method used to log out a metacat server. The Metacat server will end
|
|
107 |
* the session when this call is invoked.
|
|
95 | 108 |
* |
109 |
* @return the response string from metacat in XML format |
|
96 | 110 |
* @throws MetacatInaccessibleException when the metacat server can not be |
97 | 111 |
* reached or does not respond |
98 | 112 |
*/ |
99 |
public void logout() throws MetacatInaccessibleException, MetacatException
|
|
113 |
public String logout() throws MetacatInaccessibleException, MetacatException
|
|
100 | 114 |
{ |
101 | 115 |
Properties prop = new Properties(); |
102 | 116 |
prop.put("action", "logout"); |
... | ... | |
112 | 126 |
if (response.indexOf("<logout>") == -1) { |
113 | 127 |
throw new MetacatException(response); |
114 | 128 |
} |
129 |
this.sessionId = null; |
|
130 |
return response; |
|
115 | 131 |
} |
116 | 132 |
|
117 |
|
|
118 | 133 |
/** |
119 | 134 |
* Read an XML document from the metacat server session, accessed by docid, |
120 | 135 |
* and returned as a Reader. |
... | ... | |
372 | 387 |
this.metacatUrl = metacatUrl; |
373 | 388 |
} |
374 | 389 |
|
390 |
/** |
|
391 |
* Get the session identifier for this session. This is only valid if |
|
392 |
* the login methods has been called successfully for this Metacat object |
|
393 |
* beforehand. |
|
394 |
* |
|
395 |
* @returns the sessionId as a String, or null if the session is invalid |
|
396 |
*/ |
|
397 |
public String getSessionId() |
|
398 |
{ |
|
399 |
return this.sessionId; |
|
400 |
} |
|
401 |
|
|
375 | 402 |
/************************************************************************ |
376 | 403 |
* PRIVATE METHODS |
377 | 404 |
************************************************************************/ |
Also available in: Unified diff
Modified metacat to now provide the session identifier in the response
xml message when a login is called. This has not been fully tested.
I removed the HttpMessage class from metacat in favor of using the version
of that class that is found in the utilities module. This may cause some
unforeseen problems. We'll see.