com.gentics.contentnode.rest.client
Class RestClient

java.lang.Object
  extended by com.gentics.contentnode.rest.client.RestClient

public class RestClient
extends Object

This client provides wrappers, helper-methods and exception-handling to facilitate requests to the REST API. It is initialized with a URL pointing to the base-location providing the services. After a successful login, a WebResource-object can be retrieved that is then used to assemble and send requests; response-objects are returned from the server, containing the requested data and further information in the case of an error.

The Rest API client builds upon an underlying Jersey-client: detailed information about the use of the WebResource-object (base) to build requests can be found at http://jersey.java.net/ .


Constructor Summary
RestClient(String baseUrl)
          Initializes the REST-API client with a given base-URL and sets the necessary cookies; prepares the client for a subsequent login
 
Method Summary
 void assertMatchingVersion()
          Checks if the version of the REST API on the server is the same that is used by the client; if there is a mismatch between the two versions, a RestException is thrown
 void assertResponse(GenericResponse response)
          Analyzes the response of a finished request and asserts that it was executed without errors; if a problem occurred during the request, a specialized RestException is thrown
 com.sun.jersey.api.client.WebResource base()
          Provides access to the WebResource that is used as the base for all commands to the server
 com.sun.jersey.api.client.Client getJerseyClient()
          Get the underlying Jersey Client, used to define filters and configure advanced settings
 String getSid()
          Get the ID of the active session, as generated during login
 void login(String username, String password)
          Logs the specified user into the system using the password given
 void logout()
          Logs out the current user
 void ssologin()
          Performs login on an SSO system - before this works, necessary filters have to be defined
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RestClient

public RestClient(String baseUrl)
Initializes the REST-API client with a given base-URL and sets the necessary cookies; prepares the client for a subsequent login

Parameters:
baseUrl - An URL pointing to the base of the RESTful service provider (Example: http://[hostname]/CNPortletapp/rest/)
Method Detail

login

public void login(String username,
                  String password)
           throws RestException
Logs the specified user into the system using the password given

Parameters:
username - user name
password - password
Throws:
RestException - If the login failed

ssologin

public void ssologin()
              throws RestException
Performs login on an SSO system - before this works, necessary filters have to be defined

Throws:
RestException - If the login via SSO failed

logout

public void logout()
            throws RestException
Logs out the current user

Throws:
RestException - If the logout failed

assertResponse

public void assertResponse(GenericResponse response)
                    throws RestException
Analyzes the response of a finished request and asserts that it was executed without errors; if a problem occurred during the request, a specialized RestException is thrown

Parameters:
response - The response of the request that needs to be checked
Throws:
RestException - Thrown if the request was not successful, and contains further information of the reason of failure

assertMatchingVersion

public void assertMatchingVersion()
                           throws RestException
Checks if the version of the REST API on the server is the same that is used by the client; if there is a mismatch between the two versions, a RestException is thrown

Throws:
RestException

base

public com.sun.jersey.api.client.WebResource base()
                                           throws RestException
Provides access to the WebResource that is used as the base for all commands to the server

Returns:
The base resource, with the active SID already set
Throws:
RestException - If no valid SID is registered with the client

getSid

public String getSid()
Get the ID of the active session, as generated during login

Returns:
session ID

getJerseyClient

public com.sun.jersey.api.client.Client getJerseyClient()
Get the underlying Jersey Client, used to define filters and configure advanced settings

Returns:
Jersey Client


Copyright © 2013 Gentics Software GmbH. All Rights Reserved.