net.geant.edugain.meta.query
Class MetaDataRequester

java.lang.Object
  extended by net.geant.edugain.meta.query.MetaDataRequester

public class MetaDataRequester
extends java.lang.Object

This class implements a HTTP client which opens a (secure) connection to the provided Metadata Service (MDS) URL and retrieves the server response in the form of a String object.

Author:
Manuela Stanica

Field Summary
private static org.slf4j.Logger log
          Class logger.
private  java.net.HttpURLConnection mdsConnection
          The connection to the MDS server
private  MetaDataUnmarshaller mdUnmarshaller
          Unmarshaller object used for unmarshalling the received metadata
private  int queryRespCode
          The REST response code received from the MDS for the current metadata query
private  java.lang.String queryRespMessage
          The REST response message received from the MDS for the current metadata query
 
Constructor Summary
MetaDataRequester()
          Constructor
 
Method Summary
 java.lang.String buildQueryString(java.util.ArrayList<HomeLocator> homelocators)
          Builds the query string to be included in the MDS URL based on the provided home locators
 java.lang.StringBuffer extractXMLData(java.lang.StringBuffer sb, java.lang.String root)
          Extracts the XML data associated to the provided root element from a given string
 BEMetaData getBEMetaData(org.opensaml.xml.XMLObject root)
          If the root of the received metadata document is an EntityDescriptor, this method maps it to an eduGAINMeta BEMetaData object
 FederationMetaData getFedMetaData(org.opensaml.xml.XMLObject root)
          If the root of the received metadata document is an EntitiesDescriptor, this method maps it to an eduGAINMeta FederationMetaData object
 int getQueryRespCode()
          Gets the query REST/HTTP response code
 java.lang.String getQueryRespMessage()
          Gets the query REST/HTTP response message
 org.opensaml.xml.XMLObject getXMLMetaData(java.net.URL url, java.lang.String root)
          Gets the metadata response from the server and marhsalls it to an XML DOM object
 java.lang.StringBuffer readContents()
          Reads the server answer from the connection input stream into a string
 java.lang.StringBuffer readXMLFile(java.lang.String fullPathFilename)
          Reads the metadata from an xml file on the local file system into a StringBuffer
 java.lang.StringBuffer requestMetaData(java.net.URL url)
          Sends a GET request to the given URL and provides the server response, performing redirection if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mdsConnection

private java.net.HttpURLConnection mdsConnection
The connection to the MDS server


queryRespCode

private int queryRespCode
The REST response code received from the MDS for the current metadata query


queryRespMessage

private java.lang.String queryRespMessage
The REST response message received from the MDS for the current metadata query


mdUnmarshaller

private MetaDataUnmarshaller mdUnmarshaller
Unmarshaller object used for unmarshalling the received metadata


log

private static org.slf4j.Logger log
Class logger.

Constructor Detail

MetaDataRequester

public MetaDataRequester()
Constructor

Method Detail

getXMLMetaData

public org.opensaml.xml.XMLObject getXMLMetaData(java.net.URL url,
                                                 java.lang.String root)
                                          throws MetaQueryException
Gets the metadata response from the server and marhsalls it to an XML DOM object

Parameters:
url - the MDS server URL
root - a String representing the root the xml representation to be obtained
Returns:
the xml root element of the metadata document obtained from the server
Throws:
MetaQueryException

getFedMetaData

public FederationMetaData getFedMetaData(org.opensaml.xml.XMLObject root)
                                  throws MetaQueryException
If the root of the received metadata document is an EntitiesDescriptor, this method maps it to an eduGAINMeta FederationMetaData object

Parameters:
root - the XMLObject representing the root of the metadata document
Returns:
a FederationMetaData object
Throws:
MetaQueryException

getBEMetaData

public BEMetaData getBEMetaData(org.opensaml.xml.XMLObject root)
                         throws MetaQueryException
If the root of the received metadata document is an EntityDescriptor, this method maps it to an eduGAINMeta BEMetaData object

Parameters:
root - the XMLObject representing the root of the metadata document
Returns:
a BEMetaData object
Throws:
MetaQueryException

requestMetaData

public java.lang.StringBuffer requestMetaData(java.net.URL url)
                                       throws MetaQueryException
Sends a GET request to the given URL and provides the server response, performing redirection if necessary.

Parameters:
url - the MDS server URL
Returns:
the server response
Throws:
edMetaQueryException
MetaQueryException

readContents

public java.lang.StringBuffer readContents()
Reads the server answer from the connection input stream into a string

Returns:
the string containing the answer from server

readXMLFile

public java.lang.StringBuffer readXMLFile(java.lang.String fullPathFilename)
                                   throws java.io.IOException
Reads the metadata from an xml file on the local file system into a StringBuffer

Returns:
the string containing the answer from server
Throws:
java.io.IOException

extractXMLData

public java.lang.StringBuffer extractXMLData(java.lang.StringBuffer sb,
                                             java.lang.String root)
                                      throws MetaQueryException
Extracts the XML data associated to the provided root element from a given string

Parameters:
sb - the StringBuffer containing the data
root - the root element of the xml representation to be obtained
Returns:
a string(buffer) containing the xml representaion for the given root element
Throws:
eduGAIMetaQueryException
MetaQueryException

buildQueryString

public java.lang.String buildQueryString(java.util.ArrayList<HomeLocator> homelocators)
Builds the query string to be included in the MDS URL based on the provided home locators

Parameters:
homelocators - the list of home locator objects
Returns:
the query string

getQueryRespCode

public int getQueryRespCode()
Gets the query REST/HTTP response code

Returns:
the response code

getQueryRespMessage

public java.lang.String getQueryRespMessage()
Gets the query REST/HTTP response message

Returns:
a string containing the response message