public abstract class AbstractHttpTransport extends Object implements IHttpTransport, IConfigModifier, IShutdownListener, IDependenciesListener
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractHttpTransport.FeatureListResourceFactory
Resource factory for serving the featureMap JavaScript resource containing the
dynamically generated list of dependent features.
|
protected class |
AbstractHttpTransport.LoaderExtensionResource
Implementation of an
IResource that aggregates the various
sources (dynamic and static content) of the loader extension
javascript for this transport |
IHttpTransport.LayerContributionType, IHttpTransport.ModuleInfo, IHttpTransport.OptimizationLevel
IExtensionInitializer.IExtensionRegistrar
ASSERTNONLS_REQATTRNAME, CACHEBUST_REQATTRNAME, CONFIGVARNAME_REQATTRNAME, DEPENDENCYEXPANSIONLOGGING_REQATTRNAME, EXPANDREQLOGGING_REQATTRNAME, EXPANDREQUIRELISTS_REQATTRNAME, EXPORTMODULENAMES_REQATTRNAME, FEATUREMAP_REQATTRNAME, GENERATESOURCEMAPS_REQATTRNAME, INCLUDEREQUIREDEPS_REQATTRNAME, INCLUDEUNDEFINEDFEATUREDEPS_REQATTRNAME, NOADDMODULES_REQATTRNAME, NOCACHE_REQATTRNAME, NOTEXTADORN_REQATTRNAME, OPTIMIZATIONLEVEL_REQATTRNAME, REQUESTEDLOCALES_REQATTRNAME, REQUESTEDMODULENAMES_REQATTRNAME, SERVEREXPANDLAYERS_REQATTRNAME, SHOWFILENAMES_REQATTRNAME
Constructor and Description |
---|
AbstractHttpTransport()
default constructor
|
Modifier and Type | Method and Description |
---|---|
protected String |
clientRegisterSyntheticModules()
Returns the JavaScript code for calling the client-side module name id registration function
to register name ids for the transport synthetic modules.
|
protected void |
contributeBootLayerDeps(StringBuffer sb,
javax.servlet.http.HttpServletRequest request) |
void |
contributeLoaderExtensionJavaScript(String contribution)
Called by aggregator extensions to contribute JavaScript that will be
included in the loader extension JavaScript module that is loaded by the
client.
|
protected IResource |
createFeatureListResource(List<String> list,
URI uri,
long lastmod)
Creates an
IResource object for the dependent feature list AMD
module |
void |
decorateRequest(javax.servlet.http.HttpServletRequest request)
Called to parse the HTTP request and decorate the request with the
request attributes defined in this interface.
|
void |
dependenciesLoaded(IDependencies deps,
long sequence)
This method is called when dependencies are loaded/reloaded/validated.
|
protected void |
generateModuleIdMap(IDependencies deps)
Generates the module id map used by the transport to encode/decode module names
using assigned module name ids.
|
protected IAggregator |
getAggregator()
Returns the aggregator instance that created this transport
|
abstract List<ICacheKeyGenerator> |
getCacheKeyGenerators()
Returns a cache key generator for the JavaScript contained in the
loader extension JavaScript and output by
IHttpTransport.getLayerContribution(HttpServletRequest, LayerContributionType, Object)
. |
protected URI |
getComboUri()
Returns the URI to the folder containing the javascript resources
for this transport.
|
protected String |
getDynamicLoaderExtensionJavaScript(javax.servlet.http.HttpServletRequest request)
Returns the dynamic portion of the loader extension javascript for this transport.
|
protected List<String> |
getExtensionContributions()
Returns the extension contributions that have been registered with this
transport
|
protected URI |
getFeatureListResourceUri()
Default implementation that returns null URI.
|
protected Features |
getFeaturesFromRequest(javax.servlet.http.HttpServletRequest request)
Returns a map containing the has-condition/value pairs specified in the request
|
protected Features |
getFeaturesFromRequestEncoded(javax.servlet.http.HttpServletRequest request,
Features defaultFeatures)
Returns the has conditions specified in the request as a base64 encoded
trit map of feature values where each trit (three state value - 0, 1 and
don't care) represents the state of a feature in the list of
deendentFeatures that was sent to the client in the featureMap JavaScript
resource served by
AbstractHttpTransport.FeatureListResourceFactory . |
protected String |
getHasConditionsFromRequest(javax.servlet.http.HttpServletRequest request)
This method checks the request for the has conditions which may either be contained in URL
query arguments or in a cookie sent from the client.
|
String |
getLayerContribution(javax.servlet.http.HttpServletRequest request,
IHttpTransport.LayerContributionType type,
Object arg)
Returns a string value that will be added to the layer in the location
specified by
type , or null if the transport has no contribution
to make. |
protected List<String> |
getModuleIdList()
Returns the module id list used to map module name ids to module names.
|
Map<String,Integer> |
getModuleIdMap()
Returns a map of module name to module id pairs that can be used to encode the module names
when requesting modules.
|
String |
getModuleIdRegFunctionName()
Returns the name of the client side registration function used to register module-name/module-id
mappings.
|
protected IHttpTransport.OptimizationLevel |
getOptimizationLevelFromRequest(javax.servlet.http.HttpServletRequest request)
Returns the requested optimization level from the request.
|
protected static String |
getParameter(javax.servlet.http.HttpServletRequest request,
String[] aliases)
Returns the value of the requested parameter from the request, or null
|
protected Collection<String> |
getRequestedLocales(javax.servlet.http.HttpServletRequest request)
Returns the requested locales as a collection of locale strings
|
protected String |
getResourcePathId()
Returns the resource (combo) path id specified by the transport's
plugin extension
path attribute |
protected Collection<String> |
getSyntheticModuleNames()
Returns a collection of the names of synthetic modules that may be used by the transport.
|
protected String |
getTransportId()
Returns the unique id for the transport.
|
void |
initialize(IAggregator aggregator,
IAggregatorExtension extension,
IExtensionInitializer.IExtensionRegistrar reg)
Called immediately after the extension is created to set the aggregator
instance that this extension object was created for.
|
abstract boolean |
isServerExpandable(javax.servlet.http.HttpServletRequest request,
String mid)
Returns true if the specified module can be included in a server expanded
layer (i.e.
|
void |
modifyConfig(IAggregator aggregator,
Object configObj)
Called whenever the config is loaded/reloaded
|
protected AbstractHttpTransport.FeatureListResourceFactory |
newFeatureListResourceFactory(URI resourceUri)
Returns an instance of a FeatureMapJSResourceFactory.
|
protected void |
putDeps(List<Map<String,String>> depMaps,
List<String> depList) |
protected com.ibm.jaggr.core.impl.transport.RequestedModuleNames |
setRequestedModuleNames(javax.servlet.http.HttpServletRequest request) |
void |
shutdown(IAggregator aggregator)
This method is called from within the aggregator's
GenericServlet.destroy() method to notify listeners that the servlet
is shutting down. |
protected void |
validateLayerContributionState(javax.servlet.http.HttpServletRequest request,
IHttpTransport.LayerContributionType type,
Object arg)
Validate the
IHttpTransport.LayerContributionType and argument type specified
in a call to
getLayerContribution(HttpServletRequest, com.ibm.jaggr.core.transport.IHttpTransport.LayerContributionType, Object) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAggregatorTextPluginName
public static final String PATHS_PROPNAME
public static final String REQUESTEDMODULES_REQPARAM
public static final String REQUESTEDMODULEIDS_REQPARAM
public static final String REQUESTEDMODULESCOUNT_REQPARAM
public static final String EXCLUDEENC_REQPARAM
public static final String EXCLUDEIDS_REQPARAM
public static final String CONSOLE_WARNING_MSG_FMT
public static final String SCRIPTS_REQPARAM
public static final String DEPS_REQPARAM
public static final String REQUIRED_REQPARAM
DEPS_REQPARAM
public static final String PRELOADS_REQPARAM
public static final String EXCLUDES_REQPARAM
deps or preloads
request parameters
public static final String FEATUREMAP_REQPARAM
public static final String FEATUREMAPHASH_REQPARAM
public static final String[] INCLUDEREQUIREDEPS_REQPARAM
public static final String[] INCLUDEUNDEFINEDFEATUREDEPS_REQPARAM
public static final String[] ASSERTNONLS_REQPARAM
public static final String[] OPTIMIZATIONLEVEL_REQPARAMS
public static final String[] EXPANDREQUIRELISTS_REQPARAMS
public static final String[] EXPORTMODULENAMES_REQPARAMS
public static final String[] SHOWFILENAMES_REQPARAMS
public static final String[] NOCACHE_REQPARAMS
public static final String[] REQUESTEDLOCALES_REQPARAMS
public static final String[] CACHEBUST_REQPARAMS
public static final String[] SERVEREXPANDLAYERS_REQPARAMS
public static final String[] DEPENDENCYEXPANSIONLOGGING_REQPARAMS
public static final String[] GENERATESOURCEMAPS_REQPARAMS
public static final String CONFIGVARNAME_REQPARAM
public static final String LAYERCONTRIBUTIONSTATE_REQATTRNAME
public static final String ENCODED_FEATURE_MAP_REQPARAM
protected static String FEATUREMAP_JS_NAME
public static final String FEATURE_LIST_PRELUDE
public static final String FEATURE_LIST_PROLOGUE
protected URI getComboUri()
public void decorateRequest(javax.servlet.http.HttpServletRequest request) throws IOException
IHttpTransport
decorateRequest
in interface IHttpTransport
request
- The HTTP requestIOException
public Map<String,Integer> getModuleIdMap()
IHttpTransport
getModuleIdMap
in interface IHttpTransport
protected List<String> getModuleIdList()
public String getModuleIdRegFunctionName()
IHttpTransport
[ [ ["module1", "module2", "module3"], ["module4"], ["module5", "module6"] ], [ [1,2,3], [4], [5,6] ] ]
The JavaScript module builder emits code to register module-ids for expanded dependencies on the client, using the string arrays (the first element) both to specify the expanded dependencies and as part of the id mappings.
The id mappings are used by the client to encode requested module names when requesting modules from the aggregator in order to minimize URL lengths.
getModuleIdRegFunctionName
in interface IHttpTransport
protected com.ibm.jaggr.core.impl.transport.RequestedModuleNames setRequestedModuleNames(javax.servlet.http.HttpServletRequest request) throws IOException
IOException
protected Collection<String> getRequestedLocales(javax.servlet.http.HttpServletRequest request)
request
- the request objectprotected Features getFeaturesFromRequest(javax.servlet.http.HttpServletRequest request) throws IOException
request
- The http request objectIOException
protected String getHasConditionsFromRequest(javax.servlet.http.HttpServletRequest request) throws IOException
request
- the request objectIOException
UnsupportedEncodingException
protected static String getParameter(javax.servlet.http.HttpServletRequest request, String[] aliases)
request
- the request objectaliases
- array of query arg names by which the request may be specifiedprotected IHttpTransport.OptimizationLevel getOptimizationLevelFromRequest(javax.servlet.http.HttpServletRequest request)
request
- the request objectpublic void modifyConfig(IAggregator aggregator, Object configObj)
IConfigModifier
modifyConfig
in interface IConfigModifier
aggregator
- The aggregator that this config is associated withconfigObj
- The implementation specific raw config object from the config JavaScript. See
IConfig.getRawConfig()
for a description of this object. Implementors of
this method may modify the config object as needed.public void initialize(IAggregator aggregator, IAggregatorExtension extension, IExtensionInitializer.IExtensionRegistrar reg)
IExtensionInitializer
initialize
in interface IExtensionInitializer
aggregator
- The aggregator that this extension was created for.extension
- The extension objectreg
- A registrar object that can be used to register additional
aggregator extendablespublic void shutdown(IAggregator aggregator)
IShutdownListener
GenericServlet.destroy()
method to notify listeners that the servlet
is shutting down.shutdown
in interface IShutdownListener
aggregator
- The aggregator that is shutting downprotected String getTransportId()
protected URI getFeatureListResourceUri()
protected IAggregator getAggregator()
protected String getResourcePathId()
path
attributepublic void contributeLoaderExtensionJavaScript(String contribution)
IHttpTransport
The loader extension JavaScript is loaded before the AMD loader. Code contributed to the loader extension JavaScript may modify or augment the loader config, such as adding paths or aliases, etc.
In addition, this interface defines the property
urlProcessors
which is in scope when the JavaScript
contributed by this method is run. This property is an array of functions
that are each called just before a request is sent to the aggregator. The
function takes a single parameter which is the aggregator URL and it
returns the same or updated URL. Extensions wishing to contribute query
args to aggregator URLs, or otherwise modify the URL, may do so by adding
a url processor function to this array in the JavaScript contribution as
shown in the following example:
urlProcessors.push(function(url) {return url+'&foo=bar'});
The mechanism by which the loader extension JavaScript is delivered to
the client is outside the scope of this interface. A typical implementation
will register an IResourceFactory
which returns an IResource
object that will deliver the loader extension JavaScript when the AMD module
which has been mapped to the resource URI for the loader extension JavaScript
is requested.
contributeLoaderExtensionJavaScript
in interface IHttpTransport
contribution
- The JavaScript being contributed.public String getLayerContribution(javax.servlet.http.HttpServletRequest request, IHttpTransport.LayerContributionType type, Object arg)
IHttpTransport
type
, or null if the transport has no contribution
to make. This method is provided to allow the transport to inject
scaffolding JavaScript that may be required by the AMD loader.getLayerContribution
in interface IHttpTransport
request
- The request objecttype
- The layer contribution typearg
- This parameter specifies a IHttpTransport.ModuleInfo
object for the following
type
values:
IHttpTransport.LayerContributionType.BEFORE_FIRST_MODULE
IHttpTransport.LayerContributionType.BEFORE_SUBSEQUENT_MODULE
IHttpTransport.LayerContributionType.AFTER_MODULE
IHttpTransport.LayerContributionType.BEFORE_FIRST_LAYER_MODULE
IHttpTransport.LayerContributionType.BEFORE_SUBSEQUENT_LAYER_MODULE
IHttpTransport.LayerContributionType.AFTER_LAYER_MODULE
type
, arg
specifies
a Set<String>
of modules which are to be required by the
loader via a synthetically generated require() call.
IHttpTransport.LayerContributionType.BEGIN_LAYER_MODULES
IHttpTransport.LayerContributionType.END_LAYER_MODULES
type
, mid
is null.type
.public abstract boolean isServerExpandable(javax.servlet.http.HttpServletRequest request, String mid)
IHttpTransport
Excluded modules consist of those that specify a loader plugin that is not
included in IConfig.TEXTPLUGINDELEGATORS_CONFIGPARAM
or
IConfig.JSPLUGINDELEGATORS_CONFIGPARAM
, and modules that specify
an absolute or server relative URL.
isServerExpandable
in interface IHttpTransport
request
- The request objectmid
- The module idpublic abstract List<ICacheKeyGenerator> getCacheKeyGenerators()
IHttpTransport
IHttpTransport.getLayerContribution(HttpServletRequest, LayerContributionType, Object)
. If the output JavaScript is invariant with regard to the request for
the same set of modules, then this function may return null.getCacheKeyGenerators
in interface IHttpTransport
protected List<String> getExtensionContributions()
protected String getDynamicLoaderExtensionJavaScript(javax.servlet.http.HttpServletRequest request)
request
- The http request objectprotected void validateLayerContributionState(javax.servlet.http.HttpServletRequest request, IHttpTransport.LayerContributionType type, Object arg)
IHttpTransport.LayerContributionType
and argument type specified
in a call to
getLayerContribution(HttpServletRequest, com.ibm.jaggr.core.transport.IHttpTransport.LayerContributionType, Object)
request
- The http request objecttype
- The layer contribution (see
IHttpTransport.LayerContributionType
)arg
- The argument valueprotected Features getFeaturesFromRequestEncoded(javax.servlet.http.HttpServletRequest request, Features defaultFeatures) throws IOException
AbstractHttpTransport.FeatureListResourceFactory
.
Each byte from the base64 decoded byte array encodes 5 trits (3**5 = 243 states out of the 256 possible states).
request
- The http request objectdefaultFeatures
- The default features from the configIOException
protected AbstractHttpTransport.FeatureListResourceFactory newFeatureListResourceFactory(URI resourceUri)
resourceUri
- the resource URI
protected IResource createFeatureListResource(List<String> list, URI uri, long lastmod)
IResource
object for the dependent feature list AMD
modulelist
- the dependent features listuri
- the resource URIlastmod
- the last modified time of the resourceIResource
object for the modulepublic void dependenciesLoaded(IDependencies deps, long sequence)
IDependenciesListener
IDependencies.getLastModified()
to detect when the dependencies
have changed.dependenciesLoaded
in interface IDependenciesListener
deps
- The dependencies object. Note that changes to the dependencies
may occur in-place, using the same IDependencies object with
updated values, or may result in a new IDependencies object.
This interface does not specify which approach is used by an
implementation.sequence
- The sequence number. Notifications for different listener
events (options, config, dependencies) that have the same cause
have the same sequence number. Notifications resulting from
servlet initialization have the sequence number 1. The sequence
number is incremented for subsequent event causes, but there
is no guarantee about the the values for subsequent notifications
other than that they will be increasing.protected Collection<String> getSyntheticModuleNames()
Synthetic modules are those which don't have physical source files that will be discovered when building the dependency map.
protected String clientRegisterSyntheticModules()
protected void generateModuleIdMap(IDependencies deps) throws IOException
deps
- The dependencies objectIOException
protected void contributeBootLayerDeps(StringBuffer sb, javax.servlet.http.HttpServletRequest request)
Copyright © 2011-2015 IBM. All Rights Reserved.