org.openid4java.discovery.yadis
Class YadisResolver

java.lang.Object
  extended by org.openid4java.discovery.yadis.YadisResolver

public class YadisResolver
extends java.lang.Object

Yadis discovery protocol implementation.

Yadis discovery protocol returns a Yadis Resource Descriptor (XRDS) document associated with a Yadis Identifier (YadisID)

YadisIDs can be any type of identifiers that are resolvable to a URL form, and in addition the URL form uses a HTTP or a HTTPS schema. Such an URL is defined by the Yadis speficification as a YadisURL. This functionality is implemented by the YadisURL helper class.

The discovery of the XRDS document is performed by the discover method on a YadisUrl.

Internal parameters used during the discovery process :

Author:
Marius Scurtescu, Johnny Bufu

Field Summary
private  int _connTimeout
          HTTP connect timeout, in milliseconds.
private static org.apache.commons.logging.Log _log
           
private  int _maxHtmlSize
          Maximum length (in bytes) to read when parsing a HTML response.
private  int _maxRedirects
          Maximum number of redirects to be followed for the HTTP calls.
private  int _maxXmlSize
          Maximum size in bytes for the XRDS document.
private  int _socketTimeout
          HTTP socket (read) timeout, in milliseconds.
private static boolean DEBUG
           
private static java.lang.String YADIS_ACCEPT_HEADER
           
private static java.lang.String YADIS_CONTENT_TYPE
           
private static java.lang.String YADIS_XRDS_LOCATION
           
 
Constructor Summary
YadisResolver()
          Instantiates a YadisResolver with default values for the internal parameters.
 
Method Summary
 YadisResult discover(java.lang.String url)
          Performs Yadis discovery on the YadisURL.
 YadisResult discover(java.lang.String url, int maxRedirects)
          Performs Yadis discovery on the YadisURL.
 int getConnTimeout()
          Gets the HTTP connect timeout, in milliseconds.
private  java.lang.String getHtmlMeta(java.io.InputStream input)
          Parses the HTML input stream and scans for the Yadis XRDS location in the HTML HEAD Meta tags.
 int getMaxHtmlSize()
          Gets the aximum length (in bytes) to read when parsing a HTML response.
 int getMaxRedirects()
          Gets the internal limit configured for the maximum number of redirects to be followed for the HTTP calls.
 int getMaxXmlSize()
          Gets the maximum size in bytes for the XRDS document.
 int getSocketTimeout()
          Gets the HTTP socket (read) timeout, in milliseconds.
private  void getXrds(org.apache.commons.httpclient.HttpClient client, YadisResult result, boolean secondCall)
          Tries to retrieve the XRDS document via a GET call on the provided URL.
private  void headXrdsUrl(org.apache.commons.httpclient.HttpClient client, YadisUrl url, YadisResult result)
          Tries to retrieve the XRDS location url by performing a cheap HEAD call on the YadisURL.
private  org.openxri.xml.XRDS parseXrds(java.io.InputStream input)
          Parses the input stream and build a XRDS document from it.
 void setConnTimeout(int connTimeout)
          Sets the HTTP connect timeout, in milliseconds.
 void setMaxHtmlSize(int maxHtmlSize)
          Sets maximum length (in bytes) to read when parsing a HTML response.
 void setMaxRedirects(int maxRedirects)
          Sets the maximum number of redirects to be followed for the HTTP calls.
 void setMaxXmlSize(int maxXmlSize)
          Sets the maximum size in bytes for the XRDS document.
 void setSocketTimeout(int socketTimeout)
          Sets HTTP socket (read) timeout, in milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

private static org.apache.commons.logging.Log _log

DEBUG

private static final boolean DEBUG

YADIS_XRDS_LOCATION

private static final java.lang.String YADIS_XRDS_LOCATION
See Also:
Constant Field Values

YADIS_CONTENT_TYPE

private static final java.lang.String YADIS_CONTENT_TYPE
See Also:
Constant Field Values

YADIS_ACCEPT_HEADER

private static final java.lang.String YADIS_ACCEPT_HEADER
See Also:
Constant Field Values

_maxRedirects

private int _maxRedirects
Maximum number of redirects to be followed for the HTTP calls. Defalut 10.


_maxHtmlSize

private int _maxHtmlSize
Maximum length (in bytes) to read when parsing a HTML response.


_maxXmlSize

private int _maxXmlSize
Maximum size in bytes for the XRDS document.


_connTimeout

private int _connTimeout
HTTP connect timeout, in milliseconds.


_socketTimeout

private int _socketTimeout
HTTP socket (read) timeout, in milliseconds.

Constructor Detail

YadisResolver

public YadisResolver()
Instantiates a YadisResolver with default values for the internal parameters.

Method Detail

getMaxRedirects

public int getMaxRedirects()
Gets the internal limit configured for the maximum number of redirects to be followed for the HTTP calls.


setMaxRedirects

public void setMaxRedirects(int maxRedirects)
Sets the maximum number of redirects to be followed for the HTTP calls.


getMaxHtmlSize

public int getMaxHtmlSize()
Gets the aximum length (in bytes) to read when parsing a HTML response.


setMaxHtmlSize

public void setMaxHtmlSize(int maxHtmlSize)
Sets maximum length (in bytes) to read when parsing a HTML response.


getMaxXmlSize

public int getMaxXmlSize()
Gets the maximum size in bytes for the XRDS document.


setMaxXmlSize

public void setMaxXmlSize(int maxXmlSize)
Sets the maximum size in bytes for the XRDS document.


getConnTimeout

public int getConnTimeout()
Gets the HTTP connect timeout, in milliseconds.


setConnTimeout

public void setConnTimeout(int connTimeout)
Sets the HTTP connect timeout, in milliseconds.


getSocketTimeout

public int getSocketTimeout()
Gets the HTTP socket (read) timeout, in milliseconds.


setSocketTimeout

public void setSocketTimeout(int socketTimeout)
Sets HTTP socket (read) timeout, in milliseconds.


discover

public YadisResult discover(java.lang.String url)
                     throws YadisException
Performs Yadis discovery on the YadisURL.

The maximum number of redirects that are followed is determined by the #_maxRedirects member field.

Parameters:
url - YadisURL on which discovery will be performed
Returns:
YadisResult containing discovered information, which includes the XRDS document associated with the Yadis URL and additional meta-information
Throws:
YadisException
See Also:
YadisResult, #discover(String, int)

discover

public YadisResult discover(java.lang.String url,
                            int maxRedirects)
                     throws YadisException
Performs Yadis discovery on the YadisURL.

Parameters:
url - YadisURL on which discovery will be performed
maxRedirects - The maximum number of redirects to be followed.
Returns:
YadisResult containing discovered information, which includes the XRDS document associated with the Yadis URL and additional meta-information
Throws:
YadisException
See Also:
YadisResult

getXrds

private void getXrds(org.apache.commons.httpclient.HttpClient client,
                     YadisResult result,
                     boolean secondCall)
              throws YadisException
Tries to retrieve the XRDS document via a GET call on the provided URL.

Parameters:
client - The HttpClient object to use for placing the call
result - The YadisResult object where discovery results will be stored
secondCall - true on the second (recursive) call
Throws:
YadisException - (hard-fail) if:
  • there's a transport error
  • the returned status code is different than SC_OK

getHtmlMeta

private java.lang.String getHtmlMeta(java.io.InputStream input)
                              throws YadisException
Parses the HTML input stream and scans for the Yadis XRDS location in the HTML HEAD Meta tags.

Parameters:
input - input data stream
Returns:
String the XRDS location URL, or null if not found
Throws:
YadisException - on parsing errors or Yadis protocal violations

parseXrds

private org.openxri.xml.XRDS parseXrds(java.io.InputStream input)
                                throws YadisException
Parses the input stream and build a XRDS document from it.

Parameters:
input - input data stream
Returns:
XRDS Yadis Resource Descriptor (XRDS) document
Throws:
YadisException - if the input stream does not contain a valid XRDS

headXrdsUrl

private void headXrdsUrl(org.apache.commons.httpclient.HttpClient client,
                         YadisUrl url,
                         YadisResult result)
                  throws YadisException
Tries to retrieve the XRDS location url by performing a cheap HEAD call on the YadisURL.

The returned string should be validated before being used as a XRDS-Location URL.

Parameters:
client - The HttpClient object to use for placing the call
url - The YadisURL
result - The location of the XRDS document and the normalized Url will be returned in the YadisResult object.

The location of the XRDS document will be null if:

  • the returned status code is different than SC_OK
  • the Yadis header is not present
  • there was an HTTP-level error (allows fallback to GET + HTML response)
Throws:
YadisException - if:
  • there's a (lower level) transport error
  • there are more than one Yadis headers present


Copyright 2006-2007 Sxip Identity Corporation