Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.sip.xcap
Class BaseHttpXCapClient

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.sip.xcap.BaseHttpXCapClient
All Implemented Interfaces:
HttpXCapClient
Direct Known Subclasses:
XCapClientImpl

public abstract class BaseHttpXCapClient
extends Object
implements HttpXCapClient

Base HTTP XCAP client implementation.

Compliant with rfc4825

Author:
Grigorii Balutsel

Field Summary
static String HEADER_CONTENT_TYPE
          HTTP Content-Type header.
static String HEADER_ETAG
          HTTP ETag header.
static String HEADER_IF_NONE_MATCH
          HTTP If-None-Match header.
protected  URI uri
          Current server uri.
protected  javax.sip.address.Address userAddress
          Current user.
static String XCAP_ERROR_CONTENT_TYPE
          XCap-error content type.
 
Constructor Summary
BaseHttpXCapClient()
          Creates an instance of this XCAP client.
 
Method Summary
protected  void assertConnected()
          Utility method throwing an exception if the user is not connected.
 void connect(URI uri, javax.sip.address.Address userAddress, String username, String password)
          Connects user to XCap server.
 XCapHttpResponse delete(XCapResourceId resourceId)
          Deletes the resource from the server.
 void disconnect()
          Disconnects user from the XCAP server.
protected  XCapHttpResponse get(URI uri)
          Gets resource from the server.
 XCapHttpResponse get(XCapResourceId resourceId)
          Gets the resource from the server.
protected  URI getResourceURI(XCapResourceId resourceId)
          Gets resource uri from XCAP resource identifier.
protected static String getSingleHeaderValue(org.apache.http.HttpResponse response, String headerName)
          Gets HTTP header value.
 int getTimeout()
          Gets operation timeout.The deffault value is 10 seconds.
 URI getUri()
          Gets server uri.
 String getUserName()
          Gets user name.
protected  String getXCapErrorMessage(XCapHttpResponse response)
          Analyzes the response and returns xcap error or null if response doesn't have it.
 boolean isConnected()
          Checks if user is connected to the XCAP server.
 XCapHttpResponse put(XCapResource resource)
          Puts the resource to the server.
 void setTimeout(int timeout)
          Sets operation timeout.
(package private) static void showError(Exception ex, String title, String message)
          Shows an error and a short description.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER_CONTENT_TYPE

public static final String HEADER_CONTENT_TYPE
HTTP Content-Type header.

See Also:
Constant Field Values

HEADER_ETAG

public static final String HEADER_ETAG
HTTP ETag header.

See Also:
Constant Field Values

HEADER_IF_NONE_MATCH

public static final String HEADER_IF_NONE_MATCH
HTTP If-None-Match header.

See Also:
Constant Field Values

XCAP_ERROR_CONTENT_TYPE

public static final String XCAP_ERROR_CONTENT_TYPE
XCap-error content type.

See Also:
Constant Field Values

uri

protected URI uri
Current server uri.


userAddress

protected javax.sip.address.Address userAddress
Current user.

Constructor Detail

BaseHttpXCapClient

public BaseHttpXCapClient()
Creates an instance of this XCAP client.

Method Detail

connect

public void connect(URI uri,
                    javax.sip.address.Address userAddress,
                    String username,
                    String password)
             throws XCapException
Connects user to XCap server.

Specified by:
connect in interface HttpXCapClient
Parameters:
uri - the server location.
userAddress - the URI of the user used for requests
username - the user name.
password - the user password.
Throws:
XCapException - if there is some error during operation.

isConnected

public boolean isConnected()
Checks if user is connected to the XCAP server.

Specified by:
isConnected in interface HttpXCapClient
Returns:
true if user is connected.

disconnect

public void disconnect()
Disconnects user from the XCAP server.

Specified by:
disconnect in interface HttpXCapClient

get

public XCapHttpResponse get(XCapResourceId resourceId)
                     throws XCapException
Gets the resource from the server.

Specified by:
get in interface HttpXCapClient
Parameters:
resourceId - resource identifier.
Returns:
the server response.
Throws:
IllegalStateException - if the user has not been connected.
XCapException - if there is some error during operation.

get

protected XCapHttpResponse get(URI uri)
                        throws XCapException
Gets resource from the server.

Parameters:
uri - the resource uri.
Returns:
the server response.
Throws:
XCapException - if there is error during reading the resource's content.

showError

static void showError(Exception ex,
                      String title,
                      String message)
Shows an error and a short description.

Parameters:
ex - the exception

put

public XCapHttpResponse put(XCapResource resource)
                     throws XCapException
Puts the resource to the server.

Specified by:
put in interface HttpXCapClient
Parameters:
resource - the resource to be saved on the server.
Returns:
the server response.
Throws:
IllegalStateException - if the user has not been connected.
XCapException - if there is some error during operation.

delete

public XCapHttpResponse delete(XCapResourceId resourceId)
                        throws XCapException
Deletes the resource from the server.

Specified by:
delete in interface HttpXCapClient
Parameters:
resourceId - resource identifier.
Returns:
the server response.
Throws:
IllegalStateException - if the user has not been connected.
XCapException - if there is some error during operation.

getUserName

public String getUserName()
Gets user name.

Specified by:
getUserName in interface HttpXCapClient
Returns:
the user name.

getUri

public URI getUri()
Gets server uri.

Specified by:
getUri in interface HttpXCapClient
Returns:
the server uri.

getTimeout

public int getTimeout()
Gets operation timeout.The deffault value is 10 seconds.

Specified by:
getTimeout in interface HttpXCapClient
Returns:
operation timeout.

setTimeout

public void setTimeout(int timeout)
Sets operation timeout. The deffault value is 10 seconds.

Specified by:
setTimeout in interface HttpXCapClient
Parameters:
timeout - operation timeout.

assertConnected

protected void assertConnected()
Utility method throwing an exception if the user is not connected.

Throws:
IllegalStateException - if the user is not connected.

getResourceURI

protected URI getResourceURI(XCapResourceId resourceId)
Gets resource uri from XCAP resource identifier.

Parameters:
resourceId - the resource identifier.
Returns:
the resource uri.

getSingleHeaderValue

protected static String getSingleHeaderValue(org.apache.http.HttpResponse response,
                                             String headerName)
Gets HTTP header value.

Parameters:
response - the HTTP response.
headerName - the header name.
Returns:
the header value.

getXCapErrorMessage

protected String getXCapErrorMessage(XCapHttpResponse response)
Analyzes the response and returns xcap error or null if response doesn't have it.

Parameters:
response - the server response.
Returns:
xcap error or null.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.