public class WebContentInterceptor extends WebContentGenerator implements HandlerInterceptor
キャッシュ設定は、addCacheMapping(CacheControl, String...)
および setCacheMappings(Properties)
を使用したパスパターンを介して特定の URL に構成でき、WebContentGenerator.setCacheControl(CacheControl)
を介したすべての URL のデフォルト設定にフォールバックします。
パターンマッチングは、PathMatcher
または解析された PathPattern
で実行できます。構文はほぼ同じですが、後者は Web での使用に合わせてカスタマイズされており、より効率的です。選択は、resolved
String
lookupPath または ServletRequestPathUtils.parseAndCache(javax.servlet.http.HttpServletRequest)
解析済み } RequestPath
の存在によって決まり、これは現在のリクエストに一致した HandlerMapping
によって決まります。
このインターセプターでサポートされるすべての設定は、AbstractController
でも設定できます。このインターセプターは、主に HandlerMapping によってマップされたコントローラーのセットにチェックと準備を適用することを目的としています。
PathMatcher
, AntPathMatcher
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
logger
コンストラクターと説明 |
---|
WebContentInterceptor() PathPatternParser.defaultInstance を使用したデフォルトのコンストラクター。 |
WebContentInterceptor(PathPatternParser parser) パターンを解析する PathPatternParser を持つコンストラクター。 |
修飾子と型 | メソッドと説明 |
---|---|
void | addCacheMapping(CacheControl cacheControl, StringSE... paths) 特定の URL パスを特定の CacheControl にマップします。 |
void | afterCompletion(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler, ExceptionSE ex) この実装は空です。 |
protected CacheControl | lookupCacheControl(PathContainer path) 指定された解析済み path の CacheControl インスタンスを検索します。 |
protected CacheControl | lookupCacheControl(StringSE lookupPath) 指定された文字列 lookupPath の CacheControl インスタンスを検索します。 |
protected IntegerSE | lookupCacheSeconds(PathContainer path) 指定された解析済み path の cacheSeconds 値を検索します。 |
protected IntegerSE | lookupCacheSeconds(StringSE lookupPath) 指定された文字列 lookupPath の cacheSeconds インスタンスを検索します。 |
void | postHandle(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler, ModelAndView modelAndView) この実装は空です。 |
boolean | preHandle(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler) ハンドラーの実行前のインターセプトポイント。 |
void | setAlwaysUseFullPath(boolean alwaysUseFullPath) 使用すべきではありません。 5.3 以降、パスは外部で解決され、 ServletRequestPathUtils.getCachedPathValue(ServletRequest) で取得されます |
void | setCacheMappings(PropertiesSE cacheMappings) キャッシュ秒の設定をパターンを介して特定の URL パスにマップします。 |
void | setPathMatcher(PathMatcher pathMatcher) PathMatcher を構成して、URL パスを登録済みの URL パターンと照合し、リクエストのキャッシュ設定を選択します。 |
void | setUrlDecode(boolean urlDecode) 使用すべきではありません。 5.3 以降、パスは外部で解決され、 ServletRequestPathUtils.getCachedPathValue(ServletRequest) で取得されます |
void | setUrlPathHelper(UrlPathHelper urlPathHelper) 使用すべきではありません。 5.3 以降、パスは外部で解決され、 ServletRequestPathUtils.getCachedPathValue(ServletRequest) で取得されます |
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public WebContentInterceptor()
PathPatternParser.defaultInstance
を使用したデフォルトのコンストラクター。public WebContentInterceptor(PathPatternParser parser)
PathPatternParser
を持つコンストラクター。@DeprecatedSE public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
で取得されます。UrlPathHelper
上の same property
へのショートカット。@DeprecatedSE public void setUrlDecode(boolean urlDecode)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
で取得されます。UrlPathHelper
上の same property
へのショートカット。@DeprecatedSE public void setUrlPathHelper(UrlPathHelper urlPathHelper)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
で取得されます。public void setPathMatcher(PathMatcher pathMatcher)
これは、カスタマイズされた AntPathMatcher
またはカスタム PathMatcher が必要な場合にのみ使用する必要がある高度なプロパティです。
デフォルトでは、これは AntPathMatcher
です。
注意 : PathMatcher
を設定すると、parsed
RequestPath
が使用可能な場合でも、文字列パターンマッチングの使用が強制されます。
public void setCacheMappings(PropertiesSE cacheMappings)
このインターセプターのデフォルトのキャッシュ秒設定をオーバーライドします。"-1" を指定して、デフォルトのキャッシュから URL パスを除外できます。
パターン構文については、AntPathMatcher
と PathPattern
、およびそれぞれが使用される場合の詳細については、クラスレベルの Javadoc を参照してください。構文は、Web での使用に合わせて調整された PathPattern
とほぼ同じです。
注意 : パスパターンは重複することはありません。リクエストが複数のマッピングに一致する場合、どのマッピングが適用されるかは実質的に未定義です(java.util.Properties
にキーの順序付けがないため)。
cacheMappings
- URL パス(キーとして)とキャッシュの秒数の間のマッピング (値として、整数解析可能にする必要があります)WebContentGenerator.setCacheSeconds(int)
public void addCacheMapping(CacheControl cacheControl, StringSE... paths)
CacheControl
にマップします。 このインターセプターのデフォルトのキャッシュ秒設定をオーバーライドします。空の CacheControl
インスタンスを指定して、デフォルトのキャッシュから URL パスを除外できます。
パターン構文については、AntPathMatcher
と PathPattern
、およびそれぞれが使用される場合の詳細については、クラスレベルの Javadoc を参照してください。構文は、Web での使用に合わせて調整された PathPattern
とほぼ同じです。
注意 : パスパターンは重複することはありません。リクエストが複数のマッピングに一致する場合、どれが適用されるかは事実上未定義です(基になる java.util.HashMap
のキーの順序付けがないため)。
cacheControl
- 使用する CacheControl
paths
- 指定された CacheControl
にマップされる URL パス WebContentGenerator.setCacheSeconds(int)
public boolean preHandle(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler) throws ServletExceptionEE
HandlerInterceptor
DispatcherServlet は、任意の数のインターセプターで構成される実行チェーンでハンドラーを処理し、ハンドラー自体を最後に処理します。このメソッドを使用すると、各インターセプターはチェーンの実行を中止することを決定でき、通常は HTTP エラーを送信するか、カスタムレスポンスを作成します。
注意 : 非同期リクエスト処理には特別な考慮事項が適用されます。詳細については、AsyncHandlerInterceptor
を参照してください。
デフォルトの実装は true
を返します。
HandlerInterceptor
の preHandle
request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス handler
- 型および / またはインスタンス評価のために、実行するために選択されたハンドラー true
。そうでない場合、DispatcherServlet は、このインターセプターがすでにレスポンス自体を処理していると想定します。ServletExceptionEE
@Nullable protected CacheControl lookupCacheControl(PathContainer path)
path
- 一致するパス CacheControl
、または一致しない場合は null
@Nullable protected CacheControl lookupCacheControl(StringSE lookupPath)
CacheControl
インスタンスを検索します。これは、HandlerMapping
が PathMatcher
との文字列パターンマッチングに依存している場合に使用されます。lookupPath
- 一致するパス CacheControl
、または一致しない場合は null
@Nullable protected IntegerSE lookupCacheSeconds(PathContainer path)
path
- 一致するパス null
@Nullable protected IntegerSE lookupCacheSeconds(StringSE lookupPath)
HandlerMapping
が PathMatcher
との文字列パターンマッチングに依存している場合に使用されます。lookupPath
- 一致するパス null
public void postHandle(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler, @Nullable ModelAndView modelAndView) throws ExceptionSE
HandlerInterceptor
の postHandle
request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス handler
- 型やインスタンスの検査のために、非同期実行を開始したハンドラー(または HandlerMethod
)modelAndView
- ハンドラーが返した ModelAndView
(null
にすることもできます)ExceptionSE
- エラーの場合 public void afterCompletion(HttpServletRequestEE request, HttpServletResponseEE response, ObjectSE handler, @Nullable ExceptionSE ex) throws ExceptionSE
HandlerInterceptor
の afterCompletion
request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス handler
- 型やインスタンスの検査のために、非同期実行を開始したハンドラー(または HandlerMethod
)ex
- ハンドラーの実行時にスローされる例外(ある場合)。これには、例外リゾルバーを介して処理された例外は含まれません ExceptionSE
- エラーの場合