クラス MockHttpServletRequest
- 実装されているすべてのインターフェース:
HttpServletRequestEE,ServletRequestEE
- 既知の直属サブクラス
MockMultipartHttpServletRequest
HttpServletRequestEE インターフェースのモック実装。 このリクエストによってモックされたサーバーのデフォルトの優先 LocaleSE は Locale.ENGLISHSE です。この値は、addPreferredLocale(java.util.Locale) または setPreferredLocales(java.util.List<java.util.Locale>) を介して変更できます。
Spring 6.0 以降、このモックのセットは Servlet 6.0 ベースラインに基づいて設計されています。
- 導入:
- 1.0.2
- 作成者:
- Juergen Hoeller, Rod Johnson, Rick Evans, Mark Fisher, Chris Beams, Sam Brannen, Brian Clozel
フィールドのサマリー
フィールド修飾子と型フィールド説明static final StringSEデフォルトのプロトコル: 'HTTP/1.1'.static final StringSEデフォルトのリモートアドレス: '127.0.0.1'.static final StringSEデフォルトのリモートホスト: "localhost"。static final StringSEデフォルトのスキーム: "http"。static final StringSEデフォルトのサーバーアドレス: '127.0.0.1'.static final StringSEデフォルトのサーバー名: "localhost"。static final intデフォルトのサーバーポート: '80'.インターフェース jakarta.servlet.http.HttpServletRequestEE から継承されたフィールド
BASIC_AUTHEE, CLIENT_CERT_AUTHEE, DIGEST_AUTHEE, FORM_AUTHEEコンストラクターの概要
コンストラクターコンストラクター説明デフォルトのMockServletContextで新しいMockHttpServletRequestを作成します。MockHttpServletRequest(ServletContextEE servletContext) 提供されたServletContextEE で新しいMockHttpServletRequestを作成します。MockHttpServletRequest(ServletContextEE servletContext, StringSE method, StringSE requestURI) MockHttpServletRequest(StringSE method, StringSE requestURI) デフォルトのMockServletContextで新しいMockHttpServletRequestを作成します。メソッドのサマリー
修飾子と型メソッド説明void指定された名前の HTTP ヘッダーエントリを追加します。voidaddParameter(StringSE name, StringSE value) 指定された HTTP パラメーターに単一の値を追加します。voidaddParameter(StringSE name, StringSE... values) 指定された HTTP パラメーターの値の配列を追加します。voidaddParameters(MapSE<StringSE, ?> params) 既存の値を 置き換えることなく、提供されたすべてのパラメーターを 追加します。voidvoidaddPreferredLocale(LocaleSE locale) 既存のロケールの前に、新しい優先ロケールを追加します。voidaddUserRole(StringSE role) booleanauthenticate(HttpServletResponseEE response) この(Servlet 3.1+)メソッドの実装は、セッションがモックセッションの場合、MockHttpSession.changeSessionId()を呼び出します。protected voidこのリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを確認し、アクティブでない場合は IllegalStateException をスローします。voidこのリクエストのすべての属性をクリアします。voidclose()このリクエストを完了済みとしてマークし、その状態を維持します。getAttribute(StringSE name) byte[]リクエスト本文のコンテンツをバイト配列として取得します。構成された文字エンコードを使用して、Stringとしてリクエスト本文のコンテンツを取得します。intlongCookieEE[]longgetDateHeader(StringSE name) 指定されたnameを持つ日付ヘッダーの長いタイムスタンプを返します。getHeaders(StringSE name) intgetIntHeader(StringSE name) このモックリクエストで設定された最初の優先ロケールを返SEします。intgetParameter(StringSE name) StringSE[]getParameterValues(StringSE name) getParts()intgetRequestDispatcher(StringSE path) intこのリクエストが関連付けられている ServletContext を返します。getSession(boolean create) voidこのリクエストを無効にして、その状態をクリアします。booleanisActive()このリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを返します。booleanbooleanbooleanbooleanbooleanbooleanisSecure()booleanisUserInRole(StringSE role) voidvoidlogout()void既存のパラメーターをすべて削除します。voidremoveAttribute(StringSE name) voidremoveHeader(StringSE name) 指定された HTTP ヘッダーの登録済みエントリがある場合は削除します。voidremoveParameter(StringSE name) 指定された HTTP パラメーターの登録済みの値がある場合は削除します。voidsetAsyncContext(MockAsyncContext asyncContext) voidsetAsyncStarted(boolean asyncStarted) voidsetAsyncSupported(boolean asyncSupported) voidsetAttribute(StringSE name, ObjectSE value) voidsetAuthType(StringSE authType) voidsetCharacterEncoding(StringSE characterEncoding) voidsetContent(byte[] content) リクエスト本文のコンテンツをバイト配列として設定します。voidsetContentType(StringSE contentType) voidsetContextPath(StringSE contextPath) voidsetCookies(CookieEE... cookies) voidsetDispatcherType(DispatcherTypeEE dispatcherType) voidsetHttpServletMapping(HttpServletMappingEE httpServletMapping) voidsetLocalAddr(StringSE localAddr) voidsetLocalName(StringSE localName) voidsetLocalPort(int localPort) voidvoidsetParameter(StringSE name, StringSE value) 指定された HTTP パラメーターに単一の値を設定します。voidsetParameter(StringSE name, StringSE... values) 指定された HTTP パラメーターの値の配列を設定します。voidsetParameters(MapSE<StringSE, ?> params) 指定されたパラメーター名の既存の値を置き換えて、指定されたすべてのパラメーターを設定します。voidsetPathInfo(StringSE pathInfo) voidsetPreferredLocales(ListSE<LocaleSE> locales) 優先ロケールのリストを降順で設定し、既存のロケールを効果的に置き換えます。voidsetProtocol(StringSE protocol) voidsetQueryString(StringSE queryString) voidsetRemoteAddr(StringSE remoteAddr) voidsetRemoteHost(StringSE remoteHost) voidsetRemotePort(int remotePort) voidsetRemoteUser(StringSE remoteUser) voidsetRequestedSessionId(StringSE requestedSessionId) voidsetRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie) voidsetRequestedSessionIdFromURL(boolean requestedSessionIdFromURL) voidsetRequestedSessionIdValid(boolean requestedSessionIdValid) voidsetRequestURI(StringSE requestURI) voidvoidsetSecure(boolean secure) HTTPS などのセキュアチャネルを使用してモックリクエストが行われたかどうかを示すブールsecureフラグを設定します。voidsetServerName(StringSE serverName) voidsetServerPort(int serverPort) voidsetServletPath(StringSE servletPath) voidsetSession(HttpSessionEE session) voidsetUserPrincipal(PrincipalSE userPrincipal) startAsync(ServletRequestEE request, ServletResponseEE response) <T extends HttpUpgradeHandlerEE>
Tクラス java.lang.ObjectSE から継承されたメソッド
clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSEインターフェース jakarta.servlet.http.HttpServletRequestEE から継承されたメソッド
getTrailerFieldsEE, isTrailerFieldsReadyEE, newPushBuilderEE
フィールドの詳細
DEFAULT_PROTOCOL
デフォルトのプロトコル: 'HTTP/1.1'.- 導入:
- 4.3.7
- 関連事項:
DEFAULT_SCHEME
デフォルトのスキーム: "http"。- 導入:
- 4.3.7
- 関連事項:
DEFAULT_SERVER_ADDR
デフォルトのサーバーアドレス: '127.0.0.1'.- 関連事項:
DEFAULT_SERVER_NAME
デフォルトのサーバー名: "localhost"。- 関連事項:
DEFAULT_SERVER_PORT
public static final int DEFAULT_SERVER_PORTデフォルトのサーバーポート: '80'.- 関連事項:
DEFAULT_REMOTE_ADDR
デフォルトのリモートアドレス: '127.0.0.1'.- 関連事項:
DEFAULT_REMOTE_HOST
デフォルトのリモートホスト: "localhost"。- 関連事項:
コンストラクターの詳細
MockHttpServletRequest
public MockHttpServletRequest()デフォルトのMockServletContextで新しいMockHttpServletRequestを作成します。MockHttpServletRequest
デフォルトのMockServletContextで新しいMockHttpServletRequestを作成します。- パラメーター:
method- リクエストメソッド (nullの場合があります)requestURI- リクエスト URI (nullの場合があります)- 関連事項:
MockHttpServletRequest
提供されたServletContextEE で新しいMockHttpServletRequestを作成します。- パラメーター:
servletContext- リクエストが実行される ServletContext (デフォルトのMockServletContextを使用するnullの場合があります)- 関連事項:
MockHttpServletRequest
public MockHttpServletRequest(@Nullable ServletContextEE servletContext, @Nullable StringSE method, @Nullable StringSE requestURI) 指定されたServletContextEE、method、requestURIで新しいMockHttpServletRequestを作成します。優先ロケールは
Locale.ENGLISHSE に設定されます。- パラメーター:
servletContext- リクエストが実行される ServletContext (デフォルトのMockServletContextを使用するnullの場合があります)method- リクエストメソッド (nullの場合があります)requestURI- リクエスト URI (nullの場合があります)- 関連事項:
メソッドの詳細
getServletContext
このリクエストが関連付けられている ServletContext を返します。(何らかの理由で、標準の HttpServletRequest インターフェースでは使用できません。)- 次で指定:
- インターフェース
ServletRequestEEのgetServletContextEE
isActive
public boolean isActive()このリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを返します。close
public void close()このリクエストを完了済みとしてマークし、その状態を維持します。invalidate
public void invalidate()このリクエストを無効にして、その状態をクリアします。checkActive
このリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを確認し、アクティブでない場合は IllegalStateException をスローします。getAttribute
- 次で指定:
- インターフェース
ServletRequestEEのgetAttributeEE
getAttributeNames
- 次で指定:
- インターフェース
ServletRequestEEのgetAttributeNamesEE
getCharacterEncoding
- 次で指定:
- インターフェース
ServletRequestEEのgetCharacterEncodingEE
setCharacterEncoding
- 次で指定:
- インターフェース
ServletRequestEEのsetCharacterEncodingEE
setContent
リクエスト本文のコンテンツをバイト配列として設定します。指定されたバイト配列が XML や JSON などのテキストを表す場合、
character encodingも通常設定する必要があります。getContentAsByteArray
リクエスト本文のコンテンツをバイト配列として取得します。- 戻り値:
- バイト配列としてのコンテンツ (潜在的に
null) - 導入:
- 5.0
- 関連事項:
getContentAsString
@Nullable public StringSE getContentAsString() throws IllegalStateExceptionSE, UnsupportedEncodingExceptionSE構成された文字エンコードを使用して、Stringとしてリクエスト本文のコンテンツを取得します。- 戻り値:
Stringとしてのコンテンツ、潜在的にnull- 例外:
IllegalStateExceptionSE- 文字エンコーディングが設定されていない場合UnsupportedEncodingExceptionSE- 文字エンコードがサポートされていない場合- 導入:
- 5.0
- 関連事項:
getContentLength
public int getContentLength()- 次で指定:
- インターフェース
ServletRequestEEのgetContentLengthEE
getContentLengthLong
public long getContentLengthLong()- 次で指定:
- インターフェース
ServletRequestEEのgetContentLengthLongEE
setContentType
getContentType
- 次で指定:
- インターフェース
ServletRequestEEのgetContentTypeEE
getInputStream
- 次で指定:
- インターフェース
ServletRequestEEのgetInputStreamEE
setParameter
指定された HTTP パラメーターに単一の値を設定します。指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、置き換えられます。
setParameter
指定された HTTP パラメーターの値の配列を設定します。指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、置き換えられます。
setParameters
指定されたパラメーター名の既存の値を置き換えて、指定されたすべてのパラメーターを設定します。既存の値を置き換えずに追加するには、addParameters(java.util.Map)を使用します。addParameter
指定された HTTP パラメーターに単一の値を追加します。指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、指定された値はリストの最後に追加されます。
addParameter
指定された HTTP パラメーターの値の配列を追加します。指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、指定された値はリストの最後に追加されます。
addParameters
既存の値を 置き換えずに、提供されたすべてのパラメーターを 追加します。既存の値を置き換えるには、setParameters(java.util.Map)を使用します。removeParameter
指定された HTTP パラメーターの登録済みの値がある場合は削除します。removeAllParameters
public void removeAllParameters()既存のパラメーターをすべて削除します。getParameter
- 次で指定:
- インターフェース
ServletRequestEEのgetParameterEE
getParameterNames
- 次で指定:
- インターフェース
ServletRequestEEのgetParameterNamesEE
getParameterValues
- 次で指定:
- インターフェース
ServletRequestEEのgetParameterValuesEE
getParameterMap
- 次で指定:
- インターフェース
ServletRequestEEのgetParameterMapEE
setProtocol
getProtocol
- 次で指定:
- インターフェース
ServletRequestEEのgetProtocolEE
setScheme
getScheme
- 次で指定:
- インターフェース
ServletRequestEEのgetSchemeEE
setServerName
getServerName
- 次で指定:
- インターフェース
ServletRequestEEのgetServerNameEE
setServerPort
public void setServerPort(int serverPort) getServerPort
public int getServerPort()- 次で指定:
- インターフェース
ServletRequestEEのgetServerPortEE
getReader
- 次で指定:
- インターフェース
ServletRequestEEのgetReaderEE - 例外:
UnsupportedEncodingExceptionSE
setRemoteAddr
getRemoteAddr
- 次で指定:
- インターフェース
ServletRequestEEのgetRemoteAddrEE
setRemoteHost
getRemoteHost
- 次で指定:
- インターフェース
ServletRequestEEのgetRemoteHostEE
setAttribute
- 次で指定:
- インターフェース
ServletRequestEEのsetAttributeEE
removeAttribute
- 次で指定:
- インターフェース
ServletRequestEEのremoveAttributeEE
clearAttributes
public void clearAttributes()このリクエストのすべての属性をクリアします。addPreferredLocale
既存のロケールの前に、新しい優先ロケールを追加します。setPreferredLocales
優先ロケールのリストを降順で設定し、既存のロケールを効果的に置き換えます。- 導入:
- 3.2
- 関連事項:
getLocale
このモックリクエストで設定された最初の優先ロケールを返SEします。明示的に構成されたロケールがない場合、このリクエストによってモックされたサーバーのデフォルトの優先
LocaleSE はLocale.ENGLISHSE です。サーブレット仕様とは対照的に、このモック実装では、
Accept-Languageヘッダーを介して指定されたロケールは考慮されません。getLocales
このモックリクエストで設定された優先ロケールのSE列挙SEを返します。明示的に構成されたロケールがない場合、このリクエストによってモックされたサーバーのデフォルトの優先
LocaleSE はLocale.ENGLISHSE です。サーブレット仕様とは対照的に、このモック実装では、
Accept-Languageヘッダーを介して指定されたロケールは考慮されません。setSecure
public void setSecure(boolean secure) HTTPS などのセキュアチャネルを使用してモックリクエストが行われたかどうかを示すブールsecureフラグを設定します。isSecure
public boolean isSecure()- 次で指定:
- インターフェース
ServletRequestEEのisSecureEE - 関連事項:
getRequestDispatcher
- 次で指定:
- インターフェース
ServletRequestEEのgetRequestDispatcherEE
setRemotePort
public void setRemotePort(int remotePort) getRemotePort
public int getRemotePort()- 次で指定:
- インターフェース
ServletRequestEEのgetRemotePortEE
setLocalName
getLocalName
- 次で指定:
- インターフェース
ServletRequestEEのgetLocalNameEE
setLocalAddr
getLocalAddr
- 次で指定:
- インターフェース
ServletRequestEEのgetLocalAddrEE
setLocalPort
public void setLocalPort(int localPort) getLocalPort
public int getLocalPort()- 次で指定:
- インターフェース
ServletRequestEEのgetLocalPortEE
startAsync
- 次で指定:
- インターフェース
ServletRequestEEのstartAsyncEE
startAsync
- 次で指定:
- インターフェース
ServletRequestEEのstartAsyncEE
setAsyncStarted
public void setAsyncStarted(boolean asyncStarted) isAsyncStarted
public boolean isAsyncStarted()- 次で指定:
- インターフェース
ServletRequestEEのisAsyncStartedEE
setAsyncSupported
public void setAsyncSupported(boolean asyncSupported) isAsyncSupported
public boolean isAsyncSupported()- 次で指定:
- インターフェース
ServletRequestEEのisAsyncSupportedEE
setAsyncContext
getAsyncContext
- 次で指定:
- インターフェース
ServletRequestEEのgetAsyncContextEE
setDispatcherType
getDispatcherType
- 次で指定:
- インターフェース
ServletRequestEEのgetDispatcherTypeEE
getRequestId
- 次で指定:
- インターフェース
ServletRequestEEのgetRequestIdEE
getProtocolRequestId
- 次で指定:
- インターフェース
ServletRequestEEのgetProtocolRequestIdEE
getServletConnection
- 次で指定:
- インターフェース
ServletRequestEEのgetServletConnectionEE
setAuthType
getAuthType
- 次で指定:
- インターフェース
HttpServletRequestEEのgetAuthTypeEE
setCookies
getCookies
- 次で指定:
- インターフェース
HttpServletRequestEEのgetCookiesEE
addHeader
指定された名前の HTTP ヘッダーエントリを追加します。このメソッドは任意の
Objectをパラメーターとして取ることができますが、以下の型を使用することをお勧めします。toString()を使用して変換される文字列または任意のオブジェクト。getHeader(java.lang.String)を参照してください。- 日付ヘッダーの文字列、数値、日付。
getDateHeader(java.lang.String)を参照してください。 - 整数ヘッダーの文字列または数値。
getIntHeader(java.lang.String)を参照してください。 String[]またはCollection<String>(複数の値の場合)。getHeaders(java.lang.String)を参照してください。
removeHeader
指定された HTTP ヘッダーの登録済みエントリがある場合は削除します。- 導入:
- 4.3.20
getDateHeader
指定されたnameを持つ日付ヘッダーの長いタイムスタンプを返します。内部値表現が文字列である場合、このメソッドは、サポートされている日付形式を使用して日付として解析しようとします。
- 「EEE、dd MMM yyyy HH:mm:ss zzz」
- 「EEE、dd-MMM-yy HH:mm:ss zzz」
- "EEE MMM dd HH:mm:ss yyyy"
- 次で指定:
- インターフェース
HttpServletRequestEEのgetDateHeaderEE - パラメーター:
name- ヘッダー名- 関連事項:
getHeader
- 次で指定:
- インターフェース
HttpServletRequestEEのgetHeaderEE
getHeaders
- 次で指定:
- インターフェース
HttpServletRequestEEのgetHeadersEE
getHeaderNames
- 次で指定:
- インターフェース
HttpServletRequestEEのgetHeaderNamesEE
getIntHeader
- 次で指定:
- インターフェース
HttpServletRequestEEのgetIntHeaderEE
setMethod
getMethod
- 次で指定:
- インターフェース
HttpServletRequestEEのgetMethodEE
setPathInfo
getPathInfo
- 次で指定:
- インターフェース
HttpServletRequestEEのgetPathInfoEE
getPathTranslated
- 次で指定:
- インターフェース
HttpServletRequestEEのgetPathTranslatedEE
setContextPath
getContextPath
- 次で指定:
- インターフェース
HttpServletRequestEEのgetContextPathEE
setQueryString
getQueryString
- 次で指定:
- インターフェース
HttpServletRequestEEのgetQueryStringEE
setRemoteUser
getRemoteUser
- 次で指定:
- インターフェース
HttpServletRequestEEのgetRemoteUserEE
addUserRole
isUserInRole
- 次で指定:
- インターフェース
HttpServletRequestEEのisUserInRoleEE
setUserPrincipal
getUserPrincipal
- 次で指定:
- インターフェース
HttpServletRequestEEのgetUserPrincipalEE
setRequestedSessionId
getRequestedSessionId
- 次で指定:
- インターフェース
HttpServletRequestEEのgetRequestedSessionIdEE
setRequestURI
getRequestURI
- 次で指定:
- インターフェース
HttpServletRequestEEのgetRequestURIEE
getRequestURL
- 次で指定:
- インターフェース
HttpServletRequestEEのgetRequestURLEE
setServletPath
getServletPath
- 次で指定:
- インターフェース
HttpServletRequestEEのgetServletPathEE
setSession
getSession
- 次で指定:
- インターフェース
HttpServletRequestEEのgetSessionEE
getSession
- 次で指定:
- インターフェース
HttpServletRequestEEのgetSessionEE
changeSessionId
この(Servlet 3.1+)メソッドの実装は、セッションがモックセッションの場合、MockHttpSession.changeSessionId()を呼び出します。それ以外の場合は、単に現在のセッション ID を返します。- 次で指定:
- インターフェース
HttpServletRequestEEのchangeSessionIdEE - 導入:
- 4.0.3
setRequestedSessionIdValid
public void setRequestedSessionIdValid(boolean requestedSessionIdValid) isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()- 次で指定:
- インターフェース
HttpServletRequestEEのisRequestedSessionIdValidEE
setRequestedSessionIdFromCookie
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie) isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()- 次で指定:
- インターフェース
HttpServletRequestEEのisRequestedSessionIdFromCookieEE
setRequestedSessionIdFromURL
public void setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL) isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()- 次で指定:
- インターフェース
HttpServletRequestEEのisRequestedSessionIdFromURLEE
authenticate
public boolean authenticate(HttpServletResponseEE response) throws IOExceptionSE, ServletExceptionEE - 次で指定:
- インターフェース
HttpServletRequestEEのauthenticateEE - 例外:
IOExceptionSEServletExceptionEE
login
- 次で指定:
- インターフェース
HttpServletRequestEEのloginEE - 例外:
ServletExceptionEE
logout
- 次で指定:
- インターフェース
HttpServletRequestEEのlogoutEE - 例外:
ServletExceptionEE
addPart
getPart
- 次で指定:
- インターフェース
HttpServletRequestEEのgetPartEE - 例外:
IOExceptionSEServletExceptionEE
getParts
- 次で指定:
- インターフェース
HttpServletRequestEEのgetPartsEE - 例外:
IOExceptionSEServletExceptionEE
setHttpServletMapping
getHttpServletMapping
- 次で指定:
- インターフェース
HttpServletRequestEEのgetHttpServletMappingEE
upgrade
public <T extends HttpUpgradeHandlerEE> T upgrade(ClassSE<T> handlerClass) throws IOExceptionSE, ServletExceptionEE - 次で指定:
- インターフェース
HttpServletRequestEEのupgradeEE - 例外:
IOExceptionSEServletExceptionEE