Class BlueMindRestSession

java.lang.Object
org.exoplatform.caldav.client.bluemind.BlueMindRestSession

@Component public class BlueMindRestSession extends Object
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 /api root BlueMind serves its REST API under (RestServiceApiDescriptionParser.java prefixes every path with /api; bluemind-vhosts.conf proxies location /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 exactly Content-Type: application/json — what BlueMind's own client proxy sends (ClientProxyGenerator.java, ByMimeTypeCodec.encode); BlueMind picks the body codec by the exact Content-Type value (DefaultBodyParameterCodecs.java), so a text/plain carrying a charset parameter would be read as JSON, refused with a 500 and logged by BlueMind with the password in it — answers a LoginResponse whose authKey travels in the X-BM-ApiKey header (parent/core/net.bluemind.core.rest/.../base/RestRootHandler.java reads it, BasicClientProxy.java sends it); the key is used for the calls and POST /api/auth/logout is 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.
  • Field Details

    • API_KEY_HEADER

      public static final String API_KEY_HEADER
      The header BlueMind's REST API reads a session key from.
      See Also:
    • JSON_MEDIA_TYPE

      public static final String JSON_MEDIA_TYPE
      The media type BlueMind's REST API reads and answers.
      See Also:
  • Constructor Details

    • BlueMindRestSession

      @Autowired public BlueMindRestSession(CaldavCredentialsResolver caldavCredentialsResolver)
      The transport Spring builds: no redirects, bounded timeouts.
      Parameters:
      caldavCredentialsResolver - the seam producing the account's credentials
  • Method Details

    • acceptsCredentials

      public boolean acceptsCredentials(CalDavEndpoint endpoint)
      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

      public <T> T call(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.
      Type Parameters:
      T - what the job produces
      Parameters:
      endpoint - the account's DAV endpoint, minted from the registry
      job - the calls to make with the session
      Returns:
      what the job produced
      Throws:
      UnsupportedOperationException - when the configured credentials are not a login and password
      CalDavAuthenticationException - when BlueMind refuses the login
      CalDavUnreachableException - when the server cannot be reached
      CalDavException - 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 of call(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

      public tools.jackson.databind.JsonNode parse(String body, URI uri)
      Parses a JSON answer.
      Parameters:
      body - the body
      uri - the request, for the message
      Returns:
      the tree
      Throws:
      CalDavException - when the body is not JSON
    • textOf

      public static String textOf(tools.jackson.databind.JsonNode node, String name)
      One text member of a JSON object.
      Parameters:
      node - the object
      name - the member
      Returns:
      its text, or null when absent, null or not a value
    • encodeSegment

      public static String encodeSegment(String segment)
      One path segment, percent-encoded outside the unreserved set.
      Parameters:
      segment - the decoded segment
      Returns:
      the encoded segment