public class ServletRequestAttributes extends AbstractRequestAttributes
RequestAttributes
インターフェースのサーブレットベースの実装。「セッション」と「グローバルセッション」を区別せずに、サーブレットリクエストと HTTP セッションスコープからオブジェクトにアクセスします。
ServletRequest.getAttribute(java.lang.String)
EE, HttpSession.getAttribute(java.lang.String)
EE修飾子と型 | フィールドと説明 |
---|---|
static StringSE | DESTRUCTION_CALLBACK_NAME_PREFIX HttpSession EE に格納されるときに破棄コールバックの名前の前に付加される String SE を識別する定数。 |
protected static SetSE<ClassSE<?>> | immutableValueTypes |
requestDestructionCallbacks
REFERENCE_REQUEST, REFERENCE_SESSION, SCOPE_REQUEST, SCOPE_SESSION
コンストラクターと説明 |
---|
ServletRequestAttributes(HttpServletRequestEE request) 指定されたリクエストの新しい ServletRequestAttributes インスタンスを作成します。 |
ServletRequestAttributes(HttpServletRequestEE request, HttpServletResponseEE response) 指定されたリクエストの新しい ServletRequestAttributes インスタンスを作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
ObjectSE | getAttribute(StringSE name, int scope) 指定された名前のスコープ付き属性の値を返します(ある場合)。 |
StringSE[] | getAttributeNames(int scope) スコープ内のすべての属性の名前を取得します。 |
HttpServletRequestEE | getRequest() ラップしているネイティブ HttpServletRequest EE を公開します。 |
HttpServletResponseEE | getResponse() ラップしているネイティブ HttpServletResponse EE(存在する場合)を公開します。 |
protected HttpSessionEE | getSession(boolean allowCreate) ラップしている HttpSession EE を公開します。 |
StringSE | getSessionId() 現在の基本的なセッションの ID を返します。 |
ObjectSE | getSessionMutex() 基盤となるセッションで利用可能な最良のミューテックス、つまり、基盤となるセッションで同期するオブジェクトを公開します。 |
protected boolean | isImmutableSessionAttribute(StringSE name, ObjectSE value) 指定された値が不変のセッション属性と見なされるかどうかを決定します。つまり、その値は内部で意味のある変更ができないため、 session.setAttribute を介して再設定する必要はありません。 |
void | registerDestructionCallback(StringSE name, RunnableSE callback, int scope) 指定されたスコープ内の指定された属性の破棄時に実行されるコールバックを登録します。 |
protected void | registerSessionDestructionCallback(StringSE name, RunnableSE callback) セッション終了後に実行されるように、指定されたコールバックを登録します。 |
void | removeAttribute(StringSE name, int scope) 指定された名前のスコープ属性が存在する場合は削除します。 |
ObjectSE | resolveReference(StringSE key) 指定されたキーのコンテキスト参照を解決します(ある場合)。 |
void | setAttribute(StringSE name, ObjectSE value, int scope) 指定された名前のスコープ属性の値を設定し、既存の値(存在する場合)を置き換えます。 |
StringSE | toString() |
protected void | updateAccessedSessionAttributes() アクセスされたすべてのセッション属性を session.setAttribute 呼び出しで更新し、変更された可能性があることをコンテナーに明示的に示します。 |
isRequestActive, registerRequestDestructionCallback, removeRequestDestructionCallback, requestCompleted
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public static final StringSE DESTRUCTION_CALLBACK_NAME_PREFIX
HttpSession
EE に格納されるときに破棄コールバックの名前の前に付加される String
SE を識別する定数。public ServletRequestAttributes(HttpServletRequestEE request)
request
- 現在の HTTP リクエスト public ServletRequestAttributes(HttpServletRequestEE request, @Nullable HttpServletResponseEE response)
request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス (オプションの露出用)public final HttpServletRequestEE getRequest()
HttpServletRequest
EE を公開します。@Nullable public final HttpServletResponseEE getResponse()
HttpServletResponse
EE(存在する場合)を公開します。@Nullable protected final HttpSessionEE getSession(boolean allowCreate)
HttpSession
EE を公開します。allowCreate
- まだセッションが存在しない場合、新しいセッションの作成を許可するかどうか public ObjectSE getAttribute(StringSE name, int scope)
RequestAttributes
name
- 属性の名前 scope
- スコープ識別子 null
public void setAttribute(StringSE name, ObjectSE value, int scope)
RequestAttributes
name
- 属性の名前 value
- 属性の値 scope
- スコープ識別子 public void removeAttribute(StringSE name, int scope)
RequestAttributes
実装では、指定された属性に登録されている破棄コールバックも削除する必要があることに注意してください。ただし、この場合、登録された破棄コールバックを実行する必要はありません。オブジェクトが呼び出し側によって破棄されるためです(該当する場合)。
name
- 属性の名前 scope
- スコープ識別子 public StringSE[] getAttributeNames(int scope)
RequestAttributes
scope
- スコープ識別子 public void registerDestructionCallback(StringSE name, RunnableSE callback, int scope)
RequestAttributes
実装は、適切なときに、つまり、それぞれリクエストの補完時またはセッションの終了時にコールバックを実行するために最善を尽くす必要があります。そのようなコールバックが基本的なランタイム環境でサポートされていない場合は、コールバックを無視して、対応する警告をログに記録する必要があります。
「破棄」は通常、スコープ全体の破棄に対応し、アプリケーションによって明示的に削除された個々の属性には対応しないことに注意してください。このファサードの RequestAttributes.removeAttribute(String, int)
メソッドを介して属性が削除された場合、削除されたオブジェクトが再利用されるか手動で破棄されると想定して、登録されている破棄コールバックも無効にする必要があります。
注意 : コールバックオブジェクトは、セッションスコープに登録されている場合、通常は直列化可能である必要があります。そうしないと、コールバック(またはセッション全体)が Web アプリの再起動に耐えられない可能性があります。
name
- コールバックを登録する属性の名前 callback
- 実行される破棄コールバック scope
- スコープ識別子 public ObjectSE resolveReference(StringSE key)
RequestAttributes
最低でも: キー「リクエスト」の HttpServletRequest リファレンス、およびキー「セッション」の HttpSession リファレンス。
key
- コンテキストキー null
public StringSE getSessionId()
RequestAttributes
null
)public ObjectSE getSessionMutex()
RequestAttributes
null
)protected void updateAccessedSessionAttributes()
session.setAttribute
呼び出しで更新し、変更された可能性があることをコンテナーに明示的に示します。protected boolean isImmutableSessionAttribute(StringSE name, @Nullable ObjectSE value)
session.setAttribute
を介して再設定する必要はありません。 デフォルトの実装では、String
、Character
、Boolean
の true
および標準の Number
値を返します。
name
- 属性の名前 value
- チェックする対応する値 true
。それ以外の場合は false
updateAccessedSessionAttributes()
protected void registerSessionDestructionCallback(StringSE name, RunnableSE callback)
メモ: コールバックオブジェクトは、Web アプリの再起動後も存続させるために直列化可能である必要があります。
name
- コールバックを登録する属性の名前 callback
- 破棄のために実行されるコールバック public StringSE toString()
ObjectSE
の toStringSE