Class BlueMindRestSession
java.lang.Object
org.exoplatform.caldav.client.bluemind.BlueMindRestSession
The one way eXo talks to BlueMind's own REST API: a short session opened
with the account's stored login and password, every call carrying the key
it answered, and the session always closed afterwards.
Extracted from BlueMindAclClient (EXO-90253) when a second
conversation needed it (EXO-90307, the ICS import channel), so that both
share one transport, one authentication path and one set of rules:
- Same server, never another. The REST root is the scheme, host
and port of the endpoint minted from the server registry for the DAV calls,
with the
/apiroot BlueMind serves its REST API under (RestServiceApiDescriptionParser.javaprefixes every path with/api;bluemind-vhosts.confproxieslocation /api/). Nothing a caller passes can name a host; redirects are never followed. - The account's own credentials, from storage. The login and password are the ones the configured credentials provider produces for the account's DAV requests, taken from its Basic header; a provider producing anything else is not a login this API accepts.
- A session for one job.
POST /api/auth/login?login=…with the password as a JSON string under exactlyContent-Type: application/json— what BlueMind's own client proxy sends (ClientProxyGenerator.java,ByMimeTypeCodec.encode); BlueMind picks the body codec by the exactContent-Typevalue (DefaultBodyParameterCodecs.java), so atext/plaincarrying a charset parameter would be read as JSON, refused with a 500 and logged by BlueMind with the password in it — answers aLoginResponsewhoseauthKeytravels in theX-BM-ApiKeyheader (parent/core/net.bluemind.core.rest/.../base/RestRootHandler.javareads it,BasicClientProxy.javasends it); the key is used for the calls andPOST /api/auth/logoutis always sent after them. The key and the password are never logged, never stored, and never part of an exception message. - Bounded answers. Every body is read up to a fixed size and refused beyond it: nothing this add-on reads from this API is large.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn answer: status and body text.final classAn open session: the REST root and the key every call carries. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBlueMindRestSession(CaldavCredentialsResolver caldavCredentialsResolver) The transport Spring builds: no redirects, bounded timeouts. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptsCredentials(CalDavEndpoint endpoint) Whether the account's configured credentials are a login and password this API can take, without calling the server.<T> Tcall(CalDavEndpoint endpoint, Function<BlueMindRestSession.Session, T> job) Runs one job inside a REST session opened as the account: log in, hand the open session to the job, log out whatever the job did.static StringencodeSegment(String segment) One path segment, percent-encoded outside the unreserved set.open(CalDavEndpoint endpoint) Opens a REST session as the account, for as many calls as one service call needs;BlueMindRestSession.Session.close()logs it out.tools.jackson.databind.JsonNodeParses a JSON answer.static StringOne text member of a JSON object.
-
Field Details
-
API_KEY_HEADER
The header BlueMind's REST API reads a session key from.- See Also:
-
JSON_MEDIA_TYPE
The media type BlueMind's REST API reads and answers.- See Also:
-
-
Constructor Details
-
BlueMindRestSession
The transport Spring builds: no redirects, bounded timeouts.- Parameters:
caldavCredentialsResolver- the seam producing the account's credentials
-
-
Method Details
-
acceptsCredentials
Whether the account's configured credentials are a login and password this API can take, without calling the server.- Parameters:
endpoint- the account's endpoint, minted from the registry- Returns:
- true when the provider produces a Basic login and password
-
call
Runs one job inside a REST session opened as the account: log in, hand the open session to the job, log out whatever the job did.- Type Parameters:
T- what the job produces- Parameters:
endpoint- the account's DAV endpoint, minted from the registryjob- the calls to make with the session- Returns:
- what the job produced
- Throws:
UnsupportedOperationException- when the configured credentials are not a login and passwordCalDavAuthenticationException- when BlueMind refuses the loginCalDavUnreachableException- when the server cannot be reachedCalDavException- when the login answers anything else
-
open
Opens a REST session as the account, for as many calls as one service call needs;BlueMindRestSession.Session.close()logs it out. The exceptions are those ofcall(CalDavEndpoint, Function)for the login half.A refused login tells the configured provider, once, that the material it produced was refused, so a caching provider does not hand it out again until it expires. Only a refusal: an unreachable server or any other answer says nothing about the material.
- Parameters:
endpoint- the account's DAV endpoint, minted from the registry- Returns:
- the session, to close
-
parse
Parses a JSON answer.- Parameters:
body- the bodyuri- the request, for the message- Returns:
- the tree
- Throws:
CalDavException- when the body is not JSON
-
textOf
One text member of a JSON object.- Parameters:
node- the objectname- the member- Returns:
- its text, or null when absent, null or not a value
-
encodeSegment
One path segment, percent-encoded outside the unreserved set.- Parameters:
segment- the decoded segment- Returns:
- the encoded segment
-