Package org.restlet.client
Class Client
- java.lang.Object
-
- org.restlet.client.Restlet
-
- org.restlet.client.Connector
-
- org.restlet.client.Client
-
- All Implemented Interfaces:
Uniform
public class Client extends Connector
Connector acting as a generic client. It internally uses one of the available connector helpers registered with the Restlet engine.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
For advanced cases, it is possible to obtained the wrappedRestletHelper
instance that is used by this client to handle the calls via the "org.restlet.client.engine.helper" attribute stored in theContext
object.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description Client(java.lang.String protocolName)
Constructor.Client(java.util.List<Protocol> protocols)
Constructor.Client(Context context, java.util.List<Protocol> protocols)
Constructor.Client(Context context, java.util.List<Protocol> protocols, java.lang.String helperClass)
Constructor.Client(Context context, Protocol protocol)
Constructor.Client(Protocol protocol)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
handle(Request request, Response response)
Handles a call.boolean
isAvailable()
Indicates the underlying connector helper is available.void
start()
Starts the Restlet.void
stop()
Stops the Restlet.-
Methods inherited from class org.restlet.client.Connector
getProtocols, setProtocols
-
Methods inherited from class org.restlet.client.Restlet
finalize, getAuthor, getContext, getDescription, getLogger, getName, getOwner, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner
-
-
-
-
Constructor Detail
-
Client
public Client(Context context, java.util.List<Protocol> protocols)
Constructor.- Parameters:
context
- The context.protocols
- The connector protocols.
-
Client
public Client(Context context, java.util.List<Protocol> protocols, java.lang.String helperClass)
Constructor.- Parameters:
context
- The context.protocols
- The connector protocols.helperClass
- Optional helper class name.
-
Client
public Client(Context context, Protocol protocol)
Constructor.- Parameters:
context
- The context.protocol
- The connector protocol.
-
Client
public Client(java.util.List<Protocol> protocols)
Constructor.- Parameters:
protocols
- The connector protocols.
-
Client
public Client(Protocol protocol)
Constructor.- Parameters:
protocol
- The connector protocol.
-
Client
public Client(java.lang.String protocolName)
Constructor.- Parameters:
protocolName
- The connector protocol.
-
-
Method Detail
-
handle
public void handle(Request request, Response response)
Description copied from class:Restlet
Handles a call. The default behavior is to initialize the Restlet by setting the current context using theContext#setCurrent(Context)
method and by attempting to start it, unless it was already started. If an exception is thrown during the start action, then the response status is set toStatus.SERVER_ERROR_INTERNAL
.Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.
-
isAvailable
public boolean isAvailable()
Indicates the underlying connector helper is available.- Specified by:
isAvailable
in classConnector
- Returns:
- True if the underlying connector helper is available.
-
start
public void start() throws java.lang.Exception
Description copied from class:Restlet
Starts the Restlet. By default its only sets "started" internal property to true. WARNING: this method must be called at the end of the starting process by subclasses otherwise concurrent threads could enter into the call handling logic too early.
-
stop
public void stop() throws java.lang.Exception
Description copied from class:Restlet
Stops the Restlet. By default its only sets "started" internal property to false. WARNING: this method must be called at the beginning of the stopping process by subclasses otherwise concurrent threads could continue to (improperly) handle calls.
-
-