com.sap.portal.httpconnectivity.transformationservice.xmlsource

Class HTTPStreamSource

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

public class HTTPStreamSource
extends StreamSource
implements ICachedSource

A delegation class between com.sap.portal.httpconnectivity.urlfetcherserviceURLFetcherService and the transformation source.
Provides methods for loading XML data through the HTTP connectivity framework.
There are two ways to instantiate this class:


The following is an example of how to instantiate this class by inserting the properties directly:

   // 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);
 

The following is an example of how to instantiate this class by initializing the properties from the PCD:

    // 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 immediately before the transformation is activated.
By default the cache is disabled. When initializing the parameters from the XML iView properties, the default cache value is SHARED.
Note: 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
          The category of the log file.
static com.sap.tc.logging.Location HTTP_STRM_SRC_LOCATION
          The location in the log file.
 
Fields inherited from class javax.xml.transform.stream.StreamSource
FEATURE
 
Constructor Summary
HTTPStreamSource(IPortalComponentRequest request)
          A constructor that creates a new HTTPStreamSource object from the XML iView properties stored in the portal.
HTTPStreamSource(IPortalComponentRequest request, IURLFetcherProperties sourceProperties)
          A constructor that creates a new HTTPStreamSource object using fetcher properties that were already initialized.
HTTPStreamSource(IPortalComponentRequest request, String URL)
          A constructor that creates a new HTTPStreamSource object for a specified URL with no other HTTP properties definitions.
HTTPStreamSource(IPortalComponentRequest request, String URL, IConstants.Method method, IConstants.CachingLevel cacheLevel)
          A constructor that creates a new HTTPStreamSource object for a specified URL and using a specified HTTP method and caching level.
 
Method Summary
 void addParameter(String paramName, String paramValue)
          Adds a parameter to the HTTP call.
 void closeConnection()
          Closes the open HTTP connection to the remote server.
 IConstants.CachingLevel getCachingLevel()
          Gets the caching level of the source XML.
 InputStream getInputStream()
          Gets the input stream from the fecher service.
 Exception getLastError()
          Gets the last error thrown.
 IURLParameters getParameters()
          Gets the parameters of the HTTP call.
 String getPublicId()
           
 IPortalComponentRequest getRequest()
          Gets the portal request object associated with the HTTP call.
protected  Object getSourceFromCache()
          Gets the source of the XML input stream from the cache.
 String getSystemId()
           
protected  void putSourceToCache()
          Places the data loaded from the input stream into the cache.
 void setCacheStatus(boolean enabled)
          Enables (true) or disables (false) the cache of the source XML.
 void setCachingLevel(IConstants.CachingLevel cacheLevel)
          Sets the caching level of the source XML.
 void setParameters(IURLParameters parameters)
          Sets the URL parameters of the HTTP call.
 void setPublicId(String url)
           
 void setSystemId(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
The location in the log file.


HTTP_STRM_SRC_CATEGORY

public static final com.sap.tc.logging.Category HTTP_STRM_SRC_CATEGORY
The category of the log file.

Constructor Detail

HTTPStreamSource

public HTTPStreamSource(IPortalComponentRequest request,
                        IURLFetcherProperties sourceProperties)
A constructor that creates a new HTTPStreamSource object using fetcher properties that were already initialized.

Parameters:
request - the current portal request object
sourceProperties - URL fetcher properties that initialize the HTTP connection * @since EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(IPortalComponentRequest request,
                        String URL,
                        IConstants.Method method,
                        IConstants.CachingLevel cacheLevel)
A constructor that creates a new HTTPStreamSource object for a specified URL and using a specified HTTP method and caching level.

Parameters:
request - the current portal request object
URL - the URL for the HTTP source
method - HTTP method
cacheLevel - caching level
Since:
EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(IPortalComponentRequest request,
                        String URL)
A constructor that creates a new HTTPStreamSource object for a specified URL with no other HTTP properties definitions.

Parameters:
request - the current portal request object
URL - the URL for the HTTP source
Since:
EP 6.0 SP7

HTTPStreamSource

public HTTPStreamSource(IPortalComponentRequest request)
A constructor that creates a new HTTPStreamSource object from the XML iView properties stored in the portal. The default cache value is SHARED.

Parameters:
request - the current portal request object
Since:
EP 6.0 SP7
Method Detail

getRequest

public 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 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 ITransformerService before the transformation.
Note: Make sure you close the input stream and call the #closeConnection() method when you are finished using the input stream.
All IO exceptions are caught and stored. Use the #getLastError() method to retrieve the last error thrown.

Overrides:
getInputStream in class StreamSource
Returns:
the input stream of this HTTP source or null if it can't create the input stream object
Since:
EP 6.0 SP7
See Also:
closeConnection()

getParameters

public IURLParameters getParameters()
Gets the parameters of the HTTP call. After modifying the returned IURLParameters object, make sure to use the #setParameters() method to set the modified parameters.

Returns:
the HTTP call URL parameters
Since:
EP 6.0 SP7

setParameters

public void setParameters(IURLParameters parameters)
Sets the URL parameters of the HTTP call.

Parameters:
parameters - the URL parameters
Since:
EP 6.0 SP7

addParameter

public void addParameter(String paramName,
                         String paramValue)
                  throws TransformationServiceException
Adds a parameter to the HTTP call.

Parameters:
paramName - the parameter name
paramValue - the value of the parameter
Throws:
TransformationServiceException - if the source data is corrupt, if it cannot write to the result, if one of the transformers doesn't exist or if an error occurs during the transformation
Since:
EP 6.0 SP7

getPublicId

public String getPublicId()
Overrides:
getPublicId in class StreamSource

setPublicId

public void setPublicId(String url)
Overrides:
setPublicId in class StreamSource

getSystemId

public String getSystemId()
Specified by:
getSystemId in interface Source
Overrides:
getSystemId in class StreamSource

setSystemId

public void setSystemId(String url)
Specified by:
setSystemId in interface Source
Overrides:
setSystemId in class StreamSource

closeConnection

public void closeConnection()
                     throws IOException
Closes the open HTTP connection to the remote server. Cleans up memory usage. If the cache is enabled, places the loaded data in the cache.

Throws:
IOException - if it cannot close the HTTP connection
Since:
EP 6.0 SP7

getLastError

public Exception getLastError()
Gets the last error thrown.

Returns:
the last error
Since:
EP 6.0 SP7

getSourceFromCache

protected Object getSourceFromCache()
Gets the source of the XML input stream from the cache.

Returns:
the source data
Since:
EP 6.0 SP7

setCacheStatus

public void setCacheStatus(boolean enabled)
Description copied from interface: ICachedSource
Enables (true) or disables (false) the cache of the source XML.

Specified by:
setCacheStatus in interface ICachedSource
Parameters:
enabled - enables/disables the cache

putSourceToCache

protected void putSourceToCache()
                         throws IOException
Places the data loaded from the input stream into the cache. This method is called when the closeConnection() method is called.

Throws:
IOException - if the operation fails
Since:
EP 6.0 SP7

getCachingLevel

public IConstants.CachingLevel getCachingLevel()
Description copied from interface: ICachedSource
Gets the caching level of the source XML.

Specified by:
getCachingLevel in interface ICachedSource
Returns:
the caching level of the source

setCachingLevel

public void setCachingLevel(IConstants.CachingLevel cacheLevel)
Description copied from interface: ICachedSource
Sets the caching level of the source XML. The caching level must be set before the source data is loaded.

Specified by:
setCachingLevel in interface ICachedSource
Parameters:
cacheLevel - the caching level of the source
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] EP-ADMIN [sap.com] tc/ep/admin/api/extd api EP-PIN


Copyright 2011 SAP AG Complete Copyright Notice