Class LocalTestWebServer
java.lang.Object
org.springframework.boot.test.http.server.LocalTestWebServer
Provides details of a locally running test web server which may have been started on a
dynamic port.
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDetails of the base URI to the local test web server.static interfaceInternal strategy used to provide the runningLocalTestWebServer.static enumSupported HTTP schemes. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable LocalTestWebServerget(org.springframework.context.ApplicationContext applicationContext) Return theLocalTestWebServerinstance provided from theApplicationContextornullof no local server is started or could be provided.static LocalTestWebServerobtain(org.springframework.context.ApplicationContext applicationContext) Obtain theLocalTestWebServerinstance provided from theApplicationContext.static LocalTestWebServerof(LocalTestWebServer.Scheme scheme, int port) Factory method to create a newLocalTestWebServerinstance.static LocalTestWebServerof(LocalTestWebServer.Scheme scheme, int port, @Nullable String contextPath) Factory method to create a newLocalTestWebServerinstance.static LocalTestWebServerof(LocalTestWebServer.Scheme scheme, Supplier<LocalTestWebServer.BaseUriDetails> baseUriDetailsSupplier) Factory method to create a newLocalTestWebServerinstance.scheme()Return if URI scheme used for the request.uri()Return the URI of the running local test server.Return the URI of the running local test server taking into account the givenuri.org.springframework.web.util.UriBuilderuriBuilder(@Nullable String uri) Return a newUriBuilderwith the base URI template initialized from the local serveruri().org.springframework.web.util.UriBuilderFactoryReturn a newUriBuilderFactorywith the base URI template initialized from the local serveruri().Return a newLocalTestWebServerinstance that applies the givenpath.
-
Method Details
-
scheme
Return if URI scheme used for the request. This method can be safely called before the local test server is fully running.- Returns:
- if the web server uses an HTTPS address
-
uri
Return the URI of the running local test server. This method should only be called once the local test server is fully running.- Returns:
- the URI of the server
-
uri
-
uriBuilder
Return a newUriBuilderwith the base URI template initialized from the local serveruri(). This method should only be called once the local test server is fully running.- Parameters:
uri- a URI template for the builder ornull- Returns:
- a new
UriBuilderinstance
-
uriBuilderFactory
public org.springframework.web.util.UriBuilderFactory uriBuilderFactory()Return a newUriBuilderFactorywith the base URI template initialized from the local serveruri(). Methods of the return UriBuilderFactory should only be called once the local test server is fully running.- Returns:
- a new
UriBuilderFactory
-
withPath
Return a newLocalTestWebServerinstance that applies the givenpath.- Parameters:
path- a path to append- Returns:
- a new instance with the path added
-
of
Factory method to create a newLocalTestWebServerinstance.- Parameters:
scheme- the URL schemeport- the port of the running server- Returns:
- a new
LocalTestWebServerinstance
-
of
public static LocalTestWebServer of(LocalTestWebServer.Scheme scheme, int port, @Nullable String contextPath) Factory method to create a newLocalTestWebServerinstance.- Parameters:
scheme- the URL schemeport- the port of the running servercontextPath- the context path of the running server- Returns:
- a new
LocalTestWebServerinstance
-
of
public static LocalTestWebServer of(LocalTestWebServer.Scheme scheme, Supplier<LocalTestWebServer.BaseUriDetails> baseUriDetailsSupplier) Factory method to create a newLocalTestWebServerinstance.- Parameters:
scheme- the URL schemebaseUriDetailsSupplier- a supplier to provide the details of the base URI- Returns:
- a new
LocalTestWebServerinstance
-
obtain
public static LocalTestWebServer obtain(org.springframework.context.ApplicationContext applicationContext) Obtain theLocalTestWebServerinstance provided from theApplicationContext.- Parameters:
applicationContext- the application context- Returns:
- the local test web server (never
null)
-
get
public static @Nullable LocalTestWebServer get(org.springframework.context.ApplicationContext applicationContext) Return theLocalTestWebServerinstance provided from theApplicationContextornullof no local server is started or could be provided.- Parameters:
applicationContext- the application context- Returns:
- the local test web server or
null
-