public abstract class WebContentGenerator extends WebApplicationObjectSupport
AbstractController
や WebContentInterceptor
など、あらゆる種類の Web コンテンツジェネレーターに便利なスーパークラス。独自の HandlerAdapter
を持つカスタムハンドラーにも使用できます。HTTP キャッシュ制御オプションをサポートします。対応する HTTP ヘッダーの使用は、"cacheSeconds"
および "cacheControl"
プロパティを介して制御できます。
注意 : Spring 4.2 以降、setCacheSeconds(int)
のみを使用すると、このジェネレーターのデフォルトの動作が変更され、現在のブラウザーとプロキシの実装と一致する HTTP レスポンスヘッダーが送信されます(つまり、HTTP 1.0 ヘッダーはもうありません)。以前の動作に戻すには、新しく廃止されたメソッド setUseExpiresHeader(boolean)
、setUseCacheControlHeader(boolean)
、setUseCacheControlNoStore(boolean)
または setAlwaysMustRevalidate(boolean)
。
setCacheSeconds(int)
, setCacheControl(org.springframework.http.CacheControl)
, setRequireSession(boolean)
修飾子と型 | フィールドと説明 |
---|---|
protected static StringSE | HEADER_CACHE_CONTROL |
static StringSE | METHOD_GET HTTP メソッド "GET"。 |
static StringSE | METHOD_HEAD HTTP メソッド "HEAD"。 |
static StringSE | METHOD_POST HTTP メソッド "POST"。 |
logger
コンストラクターと説明 |
---|
WebContentGenerator() HTTP メソッド GET、HEAD、POST をデフォルトでサポートする新しい WebContentGenerator を作成します。 |
WebContentGenerator(boolean restrictDefaultSupportedMethods) 新しい WebContentGenerator を作成します。 |
WebContentGenerator(StringSE... supportedMethods) 新しい WebContentGenerator を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected void | applyCacheControl(HttpServletResponseEE response, CacheControl cacheControl) 指定された設定に従って HTTP Cache-Control ヘッダーを設定します。 |
protected void | applyCacheSeconds(HttpServletResponseEE response, int cacheSeconds) 指定されたキャッシュ秒を適用し、対応する HTTP ヘッダーを生成します。 |
protected void | applyCacheSeconds(HttpServletResponseEE response, int cacheSeconds, boolean mustRevalidate) 使用すべきではありません。 |
protected void | cacheForSeconds(HttpServletResponseEE response, int seconds) 使用すべきではありません。 |
protected void | cacheForSeconds(HttpServletResponseEE response, int seconds, boolean mustRevalidate) 使用すべきではありません。 |
protected void | checkAndPrepare(HttpServletRequestEE request, HttpServletResponseEE response, boolean lastModified) 使用すべきではありません。 4.2 の時点で、 lastModified フラグは事実上無視され、明示的に構成されている場合にのみ must-revalidate ヘッダーが生成されるため |
protected void | checkAndPrepare(HttpServletRequestEE request, HttpServletResponseEE response, int cacheSeconds, boolean lastModified) 使用すべきではありません。 4.2 の時点で、 lastModified フラグは事実上無視され、明示的に構成されている場合にのみ must-revalidate ヘッダーが生成されるため |
protected void | checkRequest(HttpServletRequestEE request) サポートされているメソッドと必要なセッションがある場合は、指定されたリクエストを確認してください。 |
protected StringSE | getAllowHeader() 構成済みの supported methods に基づく HTTP OPTIONS リクエストへのレスポンスで使用する "Allow" ヘッダー値を返します。サポートされるメソッドとして存在しない場合でも、リストに "OPTIONS" を自動的に追加します。 |
CacheControl | getCacheControl() Cache-Control HTTP レスポンスヘッダーを作成する CacheControl インスタンスを取得します。 |
int | getCacheSeconds() コンテンツがキャッシュされる秒数を返します。 |
StringSE[] | getSupportedMethods() このコンテンツジェネレーターがサポートする HTTP メソッドを返します。 |
StringSE[] | getVaryByRequestHeaders() "Vary" レスポンスヘッダーの構成済みリクエストヘッダー名を返します。 |
boolean | isAlwaysMustRevalidate() 使用すべきではありません。 4.2 現在、 getCacheControl() を推奨 |
boolean | isRequireSession() リクエストの処理にセッションが必要かどうかを返します。 |
boolean | isUseCacheControlHeader() 使用すべきではありません。 4.2 現在、 getCacheControl() を推奨 |
boolean | isUseCacheControlNoStore() 使用すべきではありません。 4.2 現在、 getCacheControl() を推奨 |
boolean | isUseExpiresHeader() 使用すべきではありません。 4.2 現在、 getCacheControl() を推奨 |
protected void | prepareResponse(HttpServletResponseEE response) このジェネレーターの設定に従って、指定されたレスポンスを準備します。 |
protected void | preventCaching(HttpServletResponseEE response) 使用すべきではありません。 |
void | setAlwaysMustRevalidate(boolean mustRevalidate) 使用すべきではありません。 |
void | setCacheControl(CacheControl cacheControl) CacheControl インスタンスを設定して、Cache-Control HTTP レスポンスヘッダーを構築します。 |
void | setCacheSeconds(int seconds) キャッシュ関連の HTTP ヘッダーをレスポンスに書き込むことにより、指定された秒数の間コンテンツをキャッシュします。秒 == -1(デフォルト値): 生成キャッシュ関連のヘッダーなし == 0: "Cache-Control:no-store" 秒を超えるキャッシュを防ぎます。> 0: "Cache-Control:max-age = seconds" はコンテンツのキャッシュを要求します |
void | setRequireSession(boolean requireSession) リクエストを処理するためにセッションが必要かどうかを設定します。 |
void | setSupportedMethods(StringSE... methods) このコンテンツジェネレーターがサポートする HTTP メソッドを設定します。 |
void | setUseCacheControlHeader(boolean useCacheControlHeader) 使用すべきではありません。 4.2 の時点で、今後は HTTP 1.1 キャッシュ制御ヘッダーが必要になり、HTTP 1.0 ヘッダーは消えます |
void | setUseCacheControlNoStore(boolean useCacheControlNoStore) 使用すべきではありません。 |
void | setUseExpiresHeader(boolean useExpiresHeader) 使用すべきではありません。 4.2 の時点で、今後は HTTP 1.1 キャッシュ制御ヘッダーが必要になり、HTTP 1.0 ヘッダーは消えます |
void | setVaryByRequestHeaders(StringSE... varyByRequestHeaders) 1 つ以上のリクエストヘッダー名を構成します(例: |
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 WebContentGenerator()
public WebContentGenerator(boolean restrictDefaultSupportedMethods)
restrictDefaultSupportedMethods
- このジェネレーターがデフォルトで HTTP メソッド GET、HEAD、POST をサポートする必要がある場合は true
、制限されていない場合は false
public WebContentGenerator(StringSE... supportedMethods)
supportedMethods
- このコンテンツジェネレーターでサポートされている HTTP メソッド public final void setSupportedMethods(@Nullable StringSE... methods)
デフォルトは、単純なフォームコントローラー型の GET、HEAD、POST です。一般的なコントローラーとインターセプターには制限がありません。
@Nullable public final StringSE[] getSupportedMethods()
@Nullable protected StringSE getAllowHeader()
supported methods
に基づく HTTP OPTIONS リクエストへのレスポンスで使用する "Allow" ヘッダー値を返します。サポートされるメソッドとして存在しない場合でも、リストに "OPTIONS" を自動的に追加します。これは、checkRequest(HttpServletRequest)
を呼び出す前に HTTP OPTIONS リクエストが処理される限り、サブクラスがサポートされているメソッドとして "OPTIONS" を明示的にリストする必要がないことを意味します。public final void setRequireSession(boolean requireSession)
public final boolean isRequireSession()
public final void setCacheControl(@Nullable CacheControl cacheControl)
CacheControl
インスタンスを設定して、Cache-Control HTTP レスポンスヘッダーを構築します。@Nullable public final CacheControl getCacheControl()
CacheControl
インスタンスを取得します。public final void setCacheSeconds(int seconds)
より具体的なニーズについては、カスタム CacheControl
を使用する必要があります。
public final int getCacheSeconds()
public final void setVaryByRequestHeaders(@Nullable StringSE... varyByRequestHeaders)
varyByRequestHeaders
- 1 つ以上のリクエストヘッダー名 @Nullable public final StringSE[] getVaryByRequestHeaders()
@DeprecatedSE public final void setUseExpiresHeader(boolean useExpiresHeader)
メモ: キャッシュヘッダーが適用されるのは、現在のリクエストでキャッシュが有効になっている(または明示的に禁止されている)場合のみです。
@DeprecatedSE public final boolean isUseExpiresHeader()
getCacheControl()
に置き換えられました。@DeprecatedSE public final void setUseCacheControlHeader(boolean useCacheControlHeader)
メモ: キャッシュヘッダーが適用されるのは、現在のリクエストでキャッシュが有効になっている(または明示的に禁止されている)場合のみです。
@DeprecatedSE public final boolean isUseCacheControlHeader()
getCacheControl()
に置き換えられました。@DeprecatedSE public final void setUseCacheControlNoStore(boolean useCacheControlNoStore)
setCacheControl(org.springframework.http.CacheControl)
に置き換えられました。@DeprecatedSE public final boolean isUseCacheControlNoStore()
getCacheControl()
に置き換えられました。@DeprecatedSE public final void setAlwaysMustRevalidate(boolean mustRevalidate)
setCacheControl(org.springframework.http.CacheControl)
に置き換えられました。WebRequest.checkNotModified(long)
に従って、最後に変更された計算をプログラムで実行できるアノテーション付きコントローラーメソッドで役立つ場合があります。デフォルトは「false」。
@DeprecatedSE public final boolean isAlwaysMustRevalidate()
getCacheControl()
に置き換えられました。protected final void checkRequest(HttpServletRequestEE request) throws ServletExceptionEE
request
- 現在の HTTP リクエスト ServletExceptionEE
- チェックが失敗したためにリクエストを処理できない場合 protected final void prepareResponse(HttpServletResponseEE response)
response
- 現在の HTTP レスポンス protected final void applyCacheControl(HttpServletResponseEE response, CacheControl cacheControl)
response
- 現在の HTTP レスポンス cacheControl
- 事前設定されたキャッシュ制御設定 protected final void applyCacheSeconds(HttpServletResponseEE response, int cacheSeconds)
response
- 現在の HTTP レスポンス cacheSeconds
- レスポンスがキャッシュ可能になる未来の正の秒数、キャッシュを防ぐための 0@DeprecatedSE protected final void checkAndPrepare(HttpServletRequestEE request, HttpServletResponseEE response, boolean lastModified) throws ServletExceptionEE
lastModified
フラグは事実上無視され、明示的に構成されている場合にのみ must-revalidate ヘッダーが生成されるため @DeprecatedSE protected final void checkAndPrepare(HttpServletRequestEE request, HttpServletResponseEE response, int cacheSeconds, boolean lastModified) throws ServletExceptionEE
lastModified
フラグは事実上無視され、明示的に構成されている場合にのみ must-revalidate ヘッダーが生成されるため @DeprecatedSE protected final void applyCacheSeconds(HttpServletResponseEE response, int cacheSeconds, boolean mustRevalidate)
applyCacheControl(javax.servlet.http.HttpServletResponse, org.springframework.http.CacheControl)
に置き換えられました。つまり、正の値の場合は指定された秒数の間キャッシュを許可し、0 の値が指定された場合はキャッシュを禁止し、そうでない場合は何もしません(つまり、キャッシュはクライアントに任せます)。
response
- 現在の HTTP レスポンス cacheSeconds
- レスポンスがキャッシュ可能であるべき将来の(正の)秒数。キャッシングを防ぐには 0。キャッシュをクライアントに残すための負の値。mustRevalidate
- クライアントがリソースを再検証する必要があるかどうか (通常、最後に変更されたサポートを持つコントローラーにのみ必要)@DeprecatedSE protected final void cacheForSeconds(HttpServletResponseEE response, int seconds)
applyCacheControl(javax.servlet.http.HttpServletResponse, org.springframework.http.CacheControl)
に置き換えられました。response
- 現在の HTTP レスポンス seconds
- レスポンスがキャッシュ可能な未来までの秒数 @DeprecatedSE protected final void cacheForSeconds(HttpServletResponseEE response, int seconds, boolean mustRevalidate)
applyCacheControl(javax.servlet.http.HttpServletResponse, org.springframework.http.CacheControl)
に置き換えられました。true
の場合、リソースを再検証するようにブラウザーに指示します。response
- 現在の HTTP レスポンス seconds
- レスポンスがキャッシュ可能な未来までの秒数 mustRevalidate
- クライアントがリソースを再検証する必要があるかどうか (通常、最後に変更されたサポートを持つコントローラーにのみ必要)@DeprecatedSE protected final void preventCaching(HttpServletResponseEE response)
applyCacheControl(javax.servlet.http.HttpServletResponse, org.springframework.http.CacheControl)
に置き換えられました。https://www.mnot.net/cache_docs
を参照してください。