クラス MockHttpServletRequest

java.lang.ObjectSE
org.springframework.mock.web.MockHttpServletRequest
実装されているすべてのインターフェース:
jakarta.servlet.http.HttpServletRequest, jakarta.servlet.ServletRequest
既知の直属サブクラス
MockMultipartHttpServletRequest

public class MockHttpServletRequest extends ObjectSE implements jakarta.servlet.http.HttpServletRequest
HttpServletRequest インターフェースのモック実装。

このリクエストによってモックされたサーバーのデフォルトの優先 LocaleSELocale.ENGLISHSE です。この値は、addPreferredLocale(Locale) または setPreferredLocales(List) を介して変更できます。

Spring 7.0 以降、このモックのセットは Servlet 6.1 ベースラインに基づいて設計されています。

導入:
1.0.2
作成者:
Juergen Hoeller, Rod Johnson, Rick Evans, Mark Fisher, Chris Beams, Sam Brannen, Brian Clozel
  • フィールドの詳細

  • コンストラクターの詳細

  • メソッドの詳細

    • getServletContext

      public jakarta.servlet.ServletContext getServletContext()
      このリクエストが関連付けられている ServletContext を返します。(何らかの理由で、標準の HttpServletRequest インターフェースでは使用できません。)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetServletContext 
    • isActive

      public boolean isActive()
      このリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを返します。
    • close

      public void close()
      このリクエストを完了済みとしてマークし、その状態を維持します。
    • invalidate

      public void invalidate()
      このリクエストを無効にして、その状態をクリアします。
    • checkActive

      protected void checkActive() throws IllegalStateExceptionSE
      このリクエストがまだアクティブである(つまり、まだ完了していない)かどうかを確認し、アクティブでない場合は IllegalStateException をスローします。
      例外:
      IllegalStateExceptionSE
    • getAttribute

      public @Nullable ObjectSE getAttribute(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetAttribute 
    • getAttributeNames

      public EnumerationSE<StringSE> getAttributeNames()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetAttributeNames 
    • getCharacterEncoding

      public @Nullable StringSE getCharacterEncoding()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetCharacterEncoding 
    • setCharacterEncoding

      public void setCharacterEncoding(@Nullable StringSE characterEncoding)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestsetCharacterEncoding 
    • setContent

      public void setContent(byte @Nullable [] content)
      リクエスト本文のコンテンツをバイト配列として設定します。

      指定されたバイト配列が XML や JSON などのテキストを表す場合、character encoding も通常設定する必要があります。

      関連事項:
    • getContentAsByteArray

      public byte @Nullable [] getContentAsByteArray()
      リクエスト本文のコンテンツをバイト配列として取得します。
      戻り値:
      バイト配列としてのコンテンツ (潜在的に null)
      導入:
      5.0
      関連事項:
    • getContentAsString

      構成された文字エンコードを使用して、String としてリクエスト本文のコンテンツを取得します。
      戻り値:
      String としてのコンテンツ、潜在的に null
      例外:
      IllegalStateExceptionSE - 文字エンコーディングが設定されていない場合
      UnsupportedEncodingExceptionSE - 文字エンコードがサポートされていない場合
      導入:
      5.0
      関連事項:
    • getContentLength

      public int getContentLength()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetContentLength 
    • getContentLengthLong

      public long getContentLengthLong()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetContentLengthLong 
    • setContentType

      public void setContentType(@Nullable StringSE contentType)
    • getContentType

      public @Nullable StringSE getContentType()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetContentType 
    • getInputStream

      public jakarta.servlet.ServletInputStream getInputStream()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetInputStream 
    • setParameter

      public void setParameter(StringSE name, StringSE value)
      指定された HTTP パラメーターに単一の値を設定します。

      指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、置き換えられます。

    • setParameter

      public void setParameter(StringSE name, StringSE... values)
      指定された HTTP パラメーターの値の配列を設定します。

      指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、置き換えられます。

    • setParameters

      public void setParameters(MapSE<StringSE,?> params)
      指定されたパラメーター名の既存の値を置き換えて、指定されたすべてのパラメーターを設定します。既存の値を置き換えずに追加するには、addParameters(java.util.Map) を使用します。
    • addParameter

      public void addParameter(StringSE name, @Nullable StringSE value)
      指定された HTTP パラメーターに単一の値を追加します。

      指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、指定された値はリストの最後に追加されます。

    • addParameter

      public void addParameter(StringSE name, StringSE... values)
      指定された HTTP パラメーターの値の配列を追加します。

      指定されたパラメーター名にすでに 1 つ以上の値が登録されている場合、指定された値はリストの最後に追加されます。

    • addParameters

      public void addParameters(MapSE<StringSE,?> params)
      既存の値を 置き換えずに、提供されたすべてのパラメーターを 追加します。既存の値を置き換えるには、setParameters(java.util.Map) を使用します。
    • removeParameter

      public void removeParameter(StringSE name)
      指定された HTTP パラメーターの登録済みの値がある場合は削除します。
    • removeAllParameters

      public void removeAllParameters()
      既存のパラメーターをすべて削除します。
    • getParameter

      public @Nullable StringSE getParameter(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetParameter 
    • getParameterNames

      public EnumerationSE<StringSE> getParameterNames()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetParameterNames 
    • getParameterValues

      public StringSE @Nullable [] getParameterValues(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetParameterValues 
    • getParameterMap

      public MapSE<StringSE,StringSE[]> getParameterMap()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetParameterMap 
    • setProtocol

      public void setProtocol(StringSE protocol)
    • getProtocol

      public StringSE getProtocol()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetProtocol 
    • setScheme

      public void setScheme(StringSE scheme)
    • getScheme

      public StringSE getScheme()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetScheme 
    • setServerName

      public void setServerName(StringSE serverName)
    • getServerName

      public StringSE getServerName()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetServerName 
    • setServerPort

      public void setServerPort(int serverPort)
    • getServerPort

      public int getServerPort()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetServerPort 
    • getReader

      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetReader 
      例外:
      UnsupportedEncodingExceptionSE
    • setRemoteAddr

      public void setRemoteAddr(StringSE remoteAddr)
    • getRemoteAddr

      public StringSE getRemoteAddr()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetRemoteAddr 
    • setRemoteHost

      public void setRemoteHost(StringSE remoteHost)
    • getRemoteHost

      public StringSE getRemoteHost()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetRemoteHost 
    • setAttribute

      public void setAttribute(StringSE name, @Nullable ObjectSE value)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestsetAttribute 
    • removeAttribute

      public void removeAttribute(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestremoveAttribute 
    • clearAttributes

      public void clearAttributes()
      このリクエストのすべての属性をクリアします。
    • addPreferredLocale

      public void addPreferredLocale(LocaleSE locale)
      既存のロケールの前に、新しい優先ロケールを追加します。
      関連事項:
    • setPreferredLocales

      public void setPreferredLocales(ListSE<LocaleSE> locales)
      優先ロケールのリストを降順で設定し、既存のロケールを効果的に置き換えます。
      導入:
      3.2
      関連事項:
    • getLocale

      public LocaleSE getLocale()
      このモックリクエストで設定された最初の優先ロケールを返SEします。

      明示的に構成されたロケールがない場合、このリクエストによってモックされたサーバーのデフォルトの優先 LocaleSELocale.ENGLISHSE です。

      サーブレット仕様とは対照的に、このモック実装では、Accept-Language ヘッダーを介して指定されたロケールは考慮されません。

      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetLocale 
      関連事項:
    • getLocales

      public EnumerationSE<LocaleSE> getLocales()
      このモックリクエストで設定された優先ロケールのSE列挙SEを返します。

      明示的に構成されたロケールがない場合、このリクエストによってモックされたサーバーのデフォルトの優先 LocaleSELocale.ENGLISHSE です。

      サーブレット仕様とは対照的に、このモック実装では、Accept-Language ヘッダーを介して指定されたロケールは考慮されません。

      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetLocales 
      関連事項:
    • setSecure

      public void setSecure(boolean secure)
      HTTPS などのセキュアチャネルを使用してモックリクエストが行われたかどうかを示すブール secure フラグを設定します。
      関連事項:
    • isSecure

      public boolean isSecure()
      secure フラグが true に設定されている場合、または scheme が https の場合、true を返します。
      次で指定:
      インターフェース jakarta.servlet.ServletRequestisSecure 
      関連事項:
      • ServletRequest.isSecure()
    • getRequestDispatcher

      public jakarta.servlet.RequestDispatcher getRequestDispatcher(StringSE path)
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetRequestDispatcher 
    • setRemotePort

      public void setRemotePort(int remotePort)
    • getRemotePort

      public int getRemotePort()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetRemotePort 
    • setLocalName

      public void setLocalName(StringSE localName)
    • getLocalName

      public StringSE getLocalName()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetLocalName 
    • setLocalAddr

      public void setLocalAddr(StringSE localAddr)
    • getLocalAddr

      public StringSE getLocalAddr()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetLocalAddr 
    • setLocalPort

      public void setLocalPort(int localPort)
    • getLocalPort

      public int getLocalPort()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetLocalPort 
    • startAsync

      public jakarta.servlet.AsyncContext startAsync()
      次で指定:
      インターフェース jakarta.servlet.ServletRequeststartAsync 
    • startAsync

      public jakarta.servlet.AsyncContext startAsync(jakarta.servlet.ServletRequest request, @Nullable jakarta.servlet.ServletResponse response)
      次で指定:
      インターフェース jakarta.servlet.ServletRequeststartAsync 
    • setAsyncStarted

      public void setAsyncStarted(boolean asyncStarted)
    • isAsyncStarted

      public boolean isAsyncStarted()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestisAsyncStarted 
    • setAsyncSupported

      public void setAsyncSupported(boolean asyncSupported)
    • isAsyncSupported

      public boolean isAsyncSupported()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestisAsyncSupported 
    • setAsyncContext

      public void setAsyncContext(@Nullable MockAsyncContext asyncContext)
    • getAsyncContext

      public @Nullable jakarta.servlet.AsyncContext getAsyncContext()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetAsyncContext 
    • setDispatcherType

      public void setDispatcherType(jakarta.servlet.DispatcherType dispatcherType)
    • getDispatcherType

      public jakarta.servlet.DispatcherType getDispatcherType()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetDispatcherType 
    • getRequestId

      public StringSE getRequestId()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetRequestId 
    • getProtocolRequestId

      public StringSE getProtocolRequestId()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetProtocolRequestId 
    • getServletConnection

      public jakarta.servlet.ServletConnection getServletConnection()
      次で指定:
      インターフェース jakarta.servlet.ServletRequestgetServletConnection 
    • setAuthType

      public void setAuthType(@Nullable StringSE authType)
    • getAuthType

      public @Nullable StringSE getAuthType()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetAuthType 
    • setCookies

      public void setCookies(jakarta.servlet.http.Cookie @Nullable ... cookies)
    • getCookies

      public jakarta.servlet.http.Cookie @Nullable [] getCookies()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetCookies 
    • addHeader

      public void addHeader(StringSE name, ObjectSE value)
      指定された名前の HTTP ヘッダーエントリを追加します。

      このメソッドは任意の Object をパラメーターとして取ることができますが、以下の型を使用することをお勧めします。

      • toString() を使用して変換される文字列または任意のオブジェクト。getHeader(String) を参照してください。
      • 日付ヘッダーの文字列、数値、日付。getDateHeader(String) を参照してください。
      • 整数ヘッダーの文字列または数値。getIntHeader(String) を参照してください。
      • String[] または Collection<String> (複数の値の場合)。getHeaders(String) を参照してください。
      関連事項:
    • removeHeader

      public void removeHeader(StringSE name)
      指定された HTTP ヘッダーの登録済みエントリがある場合は削除します。
      導入:
      4.3.20
    • getDateHeader

      public long getDateHeader(StringSE name)
      指定された name を持つ日付ヘッダーの長いタイムスタンプを返します。

      内部値表現が文字列である場合、このメソッドは、サポートされている日付形式を使用して日付として解析しようとします。

      • 「EEE、dd MMM yyyy HH:mm:ss zzz」
      • 「EEE、dd-MMM-yy HH:mm:ss zzz」
      • "EEE MMM dd HH:mm:ss yyyy"
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetDateHeader 
      パラメーター:
      name - ヘッダー名
      関連事項:
    • getHeader

      public @Nullable StringSE getHeader(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetHeader 
    • getHeaders

      public EnumerationSE<StringSE> getHeaders(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetHeaders 
    • getHeaderNames

      public EnumerationSE<StringSE> getHeaderNames()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetHeaderNames 
    • getIntHeader

      public int getIntHeader(StringSE name)
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetIntHeader 
    • setMethod

      public void setMethod(@Nullable StringSE method)
    • getMethod

      public @Nullable StringSE getMethod()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetMethod 
    • setPathInfo

      public void setPathInfo(@Nullable StringSE pathInfo)
    • getPathInfo

      public @Nullable StringSE getPathInfo()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetPathInfo 
    • getPathTranslated

      public @Nullable StringSE getPathTranslated()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetPathTranslated 
    • setContextPath

      public void setContextPath(StringSE contextPath)
    • getContextPath

      public StringSE getContextPath()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetContextPath 
    • setQueryString

      public void setQueryString(@Nullable StringSE queryString)
    • getQueryString

      public @Nullable StringSE getQueryString()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetQueryString 
    • setRemoteUser

      public void setRemoteUser(@Nullable StringSE remoteUser)
    • getRemoteUser

      public @Nullable StringSE getRemoteUser()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetRemoteUser 
    • addUserRole

      public void addUserRole(StringSE role)
    • isUserInRole

      public boolean isUserInRole(StringSE role)
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestisUserInRole 
    • setUserPrincipal

      public void setUserPrincipal(@Nullable PrincipalSE userPrincipal)
    • getUserPrincipal

      public @Nullable PrincipalSE getUserPrincipal()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetUserPrincipal 
    • setRequestedSessionId

      public void setRequestedSessionId(@Nullable StringSE requestedSessionId)
    • getRequestedSessionId

      public @Nullable StringSE getRequestedSessionId()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetRequestedSessionId 
    • setUriTemplate

      public void setUriTemplate(@Nullable StringSE uriTemplate)
      リクエストを準備するために使用された元の URI テンプレートを設定します (存在する場合)。
      パラメーター:
      uriTemplate - リクエストを設定するために使用された URI テンプレート(存在する場合)
      導入:
      6.2
    • getUriTemplate

      public @Nullable StringSE getUriTemplate()
      リクエストの準備に使用された元の URI テンプレートがあれば、それを返します。
      導入:
      6.2
    • setRequestURI

      public void setRequestURI(@Nullable StringSE requestURI)
    • getRequestURI

      public @Nullable StringSE getRequestURI()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetRequestURI 
    • getRequestURL

      public StringBufferSE getRequestURL()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetRequestURL 
    • setServletPath

      public void setServletPath(StringSE servletPath)
    • getServletPath

      public StringSE getServletPath()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetServletPath 
    • setSession

      public void setSession(jakarta.servlet.http.HttpSession session)
    • getSession

      public @Nullable jakarta.servlet.http.HttpSession getSession(boolean create)
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetSession 
    • getSession

      public @Nullable jakarta.servlet.http.HttpSession getSession()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetSession 
    • changeSessionId

      public StringSE changeSessionId()
      この(Servlet 3.1+)メソッドの実装は、セッションがモックセッションの場合、MockHttpSession.changeSessionId() を呼び出します。それ以外の場合は、単に現在のセッション ID を返します。
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestchangeSessionId 
      導入:
      4.0.3
    • setRequestedSessionIdValid

      public void setRequestedSessionIdValid(boolean requestedSessionIdValid)
    • isRequestedSessionIdValid

      public boolean isRequestedSessionIdValid()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestisRequestedSessionIdValid 
    • setRequestedSessionIdFromCookie

      public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie)
    • isRequestedSessionIdFromCookie

      public boolean isRequestedSessionIdFromCookie()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestisRequestedSessionIdFromCookie 
    • setRequestedSessionIdFromURL

      public void setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL)
    • isRequestedSessionIdFromURL

      public boolean isRequestedSessionIdFromURL()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestisRequestedSessionIdFromURL 
    • authenticate

      public boolean authenticate(jakarta.servlet.http.HttpServletResponse response) throws IOExceptionSE, jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestauthenticate 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException
    • login

      public void login(StringSE username, StringSE password) throws jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestlogin 
      例外:
      jakarta.servlet.ServletException
    • logout

      public void logout() throws jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestlogout 
      例外:
      jakarta.servlet.ServletException
    • addPart

      public void addPart(jakarta.servlet.http.Part part)
    • getPart

      public @Nullable jakarta.servlet.http.Part getPart(StringSE name) throws IOExceptionSE, jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetPart 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException
    • getParts

      public CollectionSE<jakarta.servlet.http.Part> getParts() throws IOExceptionSE, jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetParts 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException
    • setHttpServletMapping

      public void setHttpServletMapping(@Nullable jakarta.servlet.http.HttpServletMapping httpServletMapping)
    • getHttpServletMapping

      public jakarta.servlet.http.HttpServletMapping getHttpServletMapping()
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestgetHttpServletMapping 
    • upgrade

      public <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade(ClassSE<T> handlerClass) throws IOExceptionSE, jakarta.servlet.ServletException
      次で指定:
      インターフェース jakarta.servlet.http.HttpServletRequestupgrade 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException