com.sap.portal.httpconnectivity.transformationservice.xmlsource
Class HTTPStreamSource

java.lang.Object
  |
  +--javax.xml.transform.stream.StreamSource
        |
        +--com.sap.portal.httpconnectivity.transformationservice.xmlsource.HTTPStreamSource
All Implemented Interfaces:
ICachedSource, javax.xml.transform.Source

public class HTTPStreamSource
extends javax.xml.transform.stream.StreamSource
implements ICachedSource

Delegation class between URLFetcherService and transformation source.
Supplies methods for loading XML data through the HTTP connectivity framework.
There are two ways of instantiate this class:
1. Inserting properties directly: The user must supply the URL, HTTP method and server caching level in the constructor, then set the portal request object before inserting this class to the transformation service.
Example:


                   // Getting source according to the XML iView properties related to current request.
           HTTPStreamSource source = new HTTPStreamSource(request);
                  // Setting result stream
           StreamResult strm = new StreamResult(response.getWriter());
                   // Transforming using the transformation service.
           tService.transform(source, trns, paramsArray, context, null, strm);
 
2. Initializing properties from PCD: this option is for URL and XML iViews that hold the connection properties in the PCD.
Using this class enables proxy setting, user mapping and better performance.
Example:

                   // Getting source file - the SDN weblogs.
           HTTPStreamSource source = new HTTPStreamSource(request,
                             "http://weblogs.sdn.sap.com/pub/q/weblogs_rss?x-ver=1.0",
                             IConstants.Method.GET,
                             IConstants.CachingLevel.SHARED);
                  // Setting result stream
           StreamResult strm = new StreamResult(response.getWriter());

                   // Transforming using the transformation service.
           tService.transform(source, trns, paramsArray, context, null, strm);
 

The data is loaded and cached only when the method getInputStream() is called. When using this class with the transformation service, getInputStream() is called right before transformation is activated.
Caching: By default the cache is disabled. When initilizing the parameters from the XML iView properties the default cache value is SHARED.
Important: HTTP Proxy settings must be set in the portal before using this class.

Since:
EP 6.0 SP7
See Also:
IURLFetcherService, IURLFetcherProperties

Field Summary
static com.sap.tc.logging.Category HTTP_STRM_SRC_CATEGORY
          Constant value - Category of the log file.
static com.sap.tc.logging.Location HTTP_STRM_SRC_LOCATION
          Constant value - The location in the log file.
 
Fields inherited from class javax.xml.transform.stream.StreamSource
FEATURE
 
Constructor Summary
HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request)
          Creates a new HTTPStreamSource object from the XML iView properties stored in portal data.
HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request, com.sap.portal.httpconnectivity.urlfetcherservice.IURLFetcherProperties sourceProperties)
          Creates a new HTTPStreamSource object using fetcher properties that were already initialized.
HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request, java.lang.String URL)
          Creates a new HTTPStreamSource object for a specific URL with no other HTTP properties definitions.
HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request, java.lang.String URL, com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.Method method, com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel cacheLevel)
          Creates a new HTTPStreamSource object for a specific URL and with specific HTTP method and caching level.
 
Method Summary
 void addParameter(java.lang.String paramName, java.lang.String paramValue)
          Adds parameter to the http call.
 void closeConnection()
          Closes the already opened HTTP connection to the remote server.
 com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel getCachingLevel()
          Gets the caching level of the source
 java.io.InputStream getInputStream()
          Gets the input stream from the fecher service.
 java.lang.Exception getLastError()
          Gets the last error that occured.
 com.sap.portal.httpconnectivity.urlfetcherservice.params.IURLParameters getParameters()
          Gets the parameters of the http call.
 java.lang.String getPublicId()
           
 com.sapportals.portal.prt.component.IPortalComponentRequest getRequest()
          Gets the portal request object associated with the HTTP call.
protected  java.lang.Object getSourceFromCache()
          Gets the source of the XML stream source from the cache.
 java.lang.String getSystemId()
           
protected  void putSourceToCache()
          Puts the data that was loaded in the stream source to the cache.
 void setCacheStatus(boolean enabled)
          Sets the status of the cached source.
 void setCachingLevel(com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel cacheLevel)
          Sets the caching level of the source.
 void setParameters(com.sap.portal.httpconnectivity.urlfetcherservice.params.IURLParameters parameters)
          Sets the URL parameters of the http call.
 void setPublicId(java.lang.String url)
           
 void setSystemId(java.lang.String url)
           
 
Methods inherited from class javax.xml.transform.stream.StreamSource
getReader, setInputStream, setReader, setSystemId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_STRM_SRC_LOCATION

public static final com.sap.tc.logging.Location HTTP_STRM_SRC_LOCATION
Constant value - The location in the log file. Has the same value as the transformation service location.

HTTP_STRM_SRC_CATEGORY

public static final com.sap.tc.logging.Category HTTP_STRM_SRC_CATEGORY
Constant value - Category of the log file.
Constructor Detail

HTTPStreamSource

public HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request,
                        com.sap.portal.httpconnectivity.urlfetcherservice.IURLFetcherProperties sourceProperties)
Creates a new HTTPStreamSource object using fetcher properties that were already initialized.
Parameters:
request - the current portal request object
sourceProperties - URL fetcher properties that will initialize the HTTP connection * @since EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request,
                        java.lang.String URL,
                        com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.Method method,
                        com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel cacheLevel)
Creates a new HTTPStreamSource object for a specific URL and with specific HTTP method and caching level.
Parameters:
request - the current portal request object
URL - the URL to the http source
method - HTTP method to be used
cacheLevel - caching level
Since:
EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request,
                        java.lang.String URL)
Creates a new HTTPStreamSource object for a specific URL with no other HTTP properties definitions.
Parameters:
request - the current portal request object
URL - the URL to the http source
Since:
EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(com.sapportals.portal.prt.component.IPortalComponentRequest request)
Creates a new HTTPStreamSource object from the XML iView properties stored in portal data. When using this options the default cache value is SHARED.
Parameters:
request - the current portal request object
Since:
EP 6.0 SP7
Method Detail

getRequest

public com.sapportals.portal.prt.component.IPortalComponentRequest getRequest()
Gets the portal request object associated with the HTTP call.
Returns:
the associated portal request object
Since:
EP 6.0 SP7

getInputStream

public java.io.InputStream getInputStream()
Gets the input stream from the fecher service. Uses IHTTPRequest to manage the InputStream and the connection.
This method is called by the @link com.sap.portal.httpconnectivity.transformationservice.ITransformerService before the transformation. Note: Make sure you close the input stream and call #closeConnection() method when done useing the input stream.
All IO Exceptions will caught and stored. Use #getLastError method to retrieve the last error raised.
Overrides:
getInputStream in class javax.xml.transform.stream.StreamSource
Returns:
the input stream of this http source or null if cannot create input stream object
Since:
EP 6.0 SP7
See Also:
closeConnection()

getParameters

public com.sap.portal.httpconnectivity.urlfetcherservice.params.IURLParameters getParameters()
Gets the parameters of the http call. After modifying the returned IURLParameters object make sure to use setParameters in-order to set the modified parameters.
Returns:
the http call URL parameters
Since:
EP 6.0 SP7

setParameters

public void setParameters(com.sap.portal.httpconnectivity.urlfetcherservice.params.IURLParameters parameters)
Sets the URL parameters of the http call.
Parameters:
parameters - the URL parameters
Since:
EP 6.0 SP7

addParameter

public void addParameter(java.lang.String paramName,
                         java.lang.String paramValue)
                  throws TransformationServiceException
Adds parameter to the http call.
Parameters:
paramName - the parameter name
paramValue - the value of the parameter
Throws:
TransformationServiceException - when cannot add parameters to the fetcher information
Since:
EP 6.0 SP7

getPublicId

public java.lang.String getPublicId()
Overrides:
getPublicId in class javax.xml.transform.stream.StreamSource

setPublicId

public void setPublicId(java.lang.String url)
Overrides:
setPublicId in class javax.xml.transform.stream.StreamSource

getSystemId

public java.lang.String getSystemId()
Overrides:
getSystemId in class javax.xml.transform.stream.StreamSource

setSystemId

public void setSystemId(java.lang.String url)
Overrides:
setSystemId in class javax.xml.transform.stream.StreamSource

closeConnection

public void closeConnection()
                     throws java.io.IOException
Closes the already opened HTTP connection to the remote server. Cleans up memory usage and places the loaded data to the cache, if cache is enabled.
Throws:
java.io.IOException - when cannot close the HTTP connection
Since:
EP 6.0 SP7

getLastError

public java.lang.Exception getLastError()
Gets the last error that occured.
Returns:
Exception object holding the information about the last error
Since:
EP 6.0 SP7

getSourceFromCache

protected java.lang.Object getSourceFromCache()
Gets the source of the XML stream source from the cache.
Returns:
Object holding the data
Since:
EP 6.0 SP7

setCacheStatus

public void setCacheStatus(boolean enabled)
Description copied from interface: ICachedSource
Sets the status of the cached source.
Specified by:
setCacheStatus in interface ICachedSource
Following copied from interface: com.sap.portal.httpconnectivity.transformationservice.xmlsource.ICachedSource
Parameters:
enabled - defines whether to enable cache.

putSourceToCache

protected void putSourceToCache()
                         throws java.io.IOException
Puts the data that was loaded in the stream source to the cache. This method is called when the #closeConnection() methos is called.
Throws:
java.io.IOException - when the data stream cannot be accessed
Since:
EP 6.0 SP7

getCachingLevel

public com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel getCachingLevel()
Description copied from interface: ICachedSource
Gets the caching level of the source
Specified by:
getCachingLevel in interface ICachedSource
Following copied from interface: com.sap.portal.httpconnectivity.transformationservice.xmlsource.ICachedSource
Returns:
the caching level of the source

setCachingLevel

public void setCachingLevel(com.sap.portal.httpconnectivity.urlfetcherservice.IConstants.CachingLevel cacheLevel)
Description copied from interface: ICachedSource
Sets the caching level of the source. Must be set before the data is loaded.
Specified by:
setCachingLevel in interface ICachedSource
Following copied from interface: com.sap.portal.httpconnectivity.transformationservice.xmlsource.ICachedSource
Parameters:
cacheLevel - the caching level of the source