org.nuiton.io.rest
Class RestClient

java.lang.Object
  extended by org.nuiton.io.rest.RestClient

public abstract class RestClient
extends Object

Abtract REST client.

Since:
1.0.3
Author:
tchemit

Field Summary
protected  RestClientConfiguration configuration
          rest client configuration
protected  Map<String,RestRequestBuilder> requestBuilders
          registred requests
protected  RestSession session
          rest session
 
Constructor Summary
RestClient()
           
RestClient(RestClientConfiguration configuration)
           
 
Method Summary
protected abstract  void addDefaultRequests()
          Add the default available requests for this client.
 void addRequestBuilder(RestRequestBuilder builder)
          Add a request into the client.
 InputStream askData(RestRequest request)
          Ask some data from the server
 void close()
          Close the client.
protected abstract  void close(RestSession session)
          Close the client.
 RestClientConfiguration getConfiguration()
           
 RestRequest getRequest(String id, Object... args)
          Obtain a request given his id and the args given.
 RestSession getSession()
           
 boolean isOpen()
          Is the client opened ?
 void open()
          Open the client.
protected abstract  void open(RestSession session)
          Open the client.
 InputStream sendData(RestRequest request)
          Send some datas to the server.
 void setConfiguration(RestClientConfiguration configuration)
          Use a new configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected RestClientConfiguration configuration
rest client configuration


session

protected RestSession session
rest session


requestBuilders

protected final Map<String,RestRequestBuilder> requestBuilders
registred requests

Constructor Detail

RestClient

public RestClient()

RestClient

public RestClient(RestClientConfiguration configuration)
Method Detail

addDefaultRequests

protected abstract void addDefaultRequests()
Add the default available requests for this client.

Note: This method is invoked in the constructor of the client.


open

protected abstract void open(RestSession session)
                      throws IOException
Open the client.

Note: At the end of this method, if every thing is ok, then the method isOpen() must returns true.

Parameters:
session - the rest session
Throws:
IOException - if any pb

close

protected abstract void close(RestSession session)
                       throws IOException
Close the client.

Note: At the end of this method, if every thing is ok, then the method isOpen() must returns false.

Parameters:
session - the rest session
Throws:
IOException - if any pb

addRequestBuilder

public void addRequestBuilder(RestRequestBuilder builder)
Add a request into the client.

Parameters:
builder - the new request to add

getRequest

public RestRequest getRequest(String id,
                              Object... args)
Obtain a request given his id and the args given.

Parameters:
id - id of the request
args - args passed to build the request
Returns:
the new request

askData

public InputStream askData(RestRequest request)
                    throws RestException
Ask some data from the server

Parameters:
request - request used for asking data
Returns:
the stream of the response
Throws:
RestException - if any pb while asking data

sendData

public InputStream sendData(RestRequest request)
                     throws RestException
Send some datas to the server.

Parameters:
request - the request used for sending data
Returns:
the stream of the response
Throws:
RestException - if any pb while sending data

open

public void open()
          throws RestException
Open the client.

Note: this method will instanciate the session and invoke the method open(RestSession).

Throws:
RestException - if any pb while opening session

close

public void close()
           throws RestException
Close the client.

Note: this method will erase the session and invoke the method close(RestSession).

Throws:
RestException - if any pb while closing session

isOpen

public boolean isOpen()
Is the client opened ?

Returns:
true if the internal session is opened, false otherwise.

getSession

public RestSession getSession()
Returns:
the internal rest session

getConfiguration

public RestClientConfiguration getConfiguration()
Returns:
the internal configuration

setConfiguration

public void setConfiguration(RestClientConfiguration configuration)
Use a new configuration.

TODO : this method should check client is not opened!

Parameters:
configuration - the new configuration


Copyright © 2009-2011 CodeLutin. All Rights Reserved.