Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.function

pack-priv Class ResourceHandlerFunction

extends Object
implements HandlerFunction<ServerResponse>
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.function.HandlerFunction
Imports
java.io.ByteArrayInputStream, .File, .IOException, .InputStream, java.net.URI, .URL, java.util.Set, java.util.function.BiConsumer, org.springframework.core.io.Resource, org.springframework.http.HttpHeaders, .HttpMethod, .HttpStatus, org.springframework.lang.Nullable

Resource-based implementation of HandlerFunction.
Author
Arjen Poutsma
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final BiConsumer<Resource, HttpHeaders>
private final Resource
private static final Set<HttpMethod>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ServerResponse
handle(ServerRequest
the request to handle
request
)

Implements org.springframework.web.servlet.function.HandlerFunction.handle.

Handle the given request.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

headersConsumerback to summary
private final BiConsumer<Resource, HttpHeaders> headersConsumer
resourceback to summary
private final Resource resource
SUPPORTED_METHODSback to summary
private static final Set<HttpMethod> SUPPORTED_METHODS

Constructor Detail

ResourceHandlerFunctionback to summary
public ResourceHandlerFunction(Resource resource, BiConsumer<Resource, HttpHeaders> headersConsumer)

Method Detail

handleback to summary
public ServerResponse handle(ServerRequest request)

Implements org.springframework.web.servlet.function.HandlerFunction.handle.

Doc from org.springframework.web.servlet.function.HandlerFunction.handle.

Handle the given request.

Parameters
request:ServerRequest

the request to handle

Returns:ServerResponse

the response

Annotations
@Override
org.springframework.web.servlet.function back to summary

private Class ResourceHandlerFunction.HeadMethodResource

extends Object
implements Resource
Class Inheritance
  • java.lang.Object
  • org.springframework.web.servlet.function.ResourceHandlerFunction.HeadMethodResource
All Implemented Interfaces
org.springframework.core.io.Resource, org.springframework.core.io.InputStreamSource

Field Summary

Modifier and TypeField and Description
private final Resource
private static final byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public long
contentLength()

Implements org.springframework.core.io.Resource.contentLength.

Determine the content length for this resource.

public Resource
createRelative(String
the relative path (relative to this resource)
relativePath
)

Implements org.springframework.core.io.Resource.createRelative.

Create a resource relative to this resource.

public boolean
exists()

Implements org.springframework.core.io.Resource.exists.

Determine whether this resource actually exists in physical form.

public String
getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Return a description for this resource, to be used for error output when working with the resource.

public File
getFile()

Implements org.springframework.core.io.Resource.getFile.

Return a File handle for this resource.

public String
getFilename()

Implements org.springframework.core.io.Resource.getFilename.

Determine the filename for this resource — typically the last part of the path — for example, "myfile.txt".

public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream for the content of an underlying resource.

public URI
getURI()

Implements org.springframework.core.io.Resource.getURI.

Return a URI handle for this resource.

public URL
getURL()

Implements org.springframework.core.io.Resource.getURL.

Return a URL handle for this resource.

public long
lastModified()

Implements org.springframework.core.io.Resource.lastModified.

Determine the last-modified timestamp for this resource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final Resource delegate
EMPTYback to summary
private static final byte[] EMPTY

Constructor Detail

HeadMethodResourceback to summary
public HeadMethodResource(Resource delegate)

Method Detail

contentLengthback to summary
public long contentLength() throws IOException

Implements org.springframework.core.io.Resource.contentLength.

Doc from org.springframework.core.io.Resource.contentLength.

Determine the content length for this resource.

Annotations
@Override
Exceptions
IOException:
if the resource cannot be resolved (in the file system or as some other known physical resource type)
createRelativeback to summary
public Resource createRelative(String relativePath) throws IOException

Implements org.springframework.core.io.Resource.createRelative.

Doc from org.springframework.core.io.Resource.createRelative.

Create a resource relative to this resource.

Parameters
relativePath:String

the relative path (relative to this resource)

Returns:Resource

the resource handle for the relative resource

Annotations
@Override
Exceptions
IOException:
if the relative resource cannot be determined
existsback to summary
public boolean exists()

Implements org.springframework.core.io.Resource.exists.

Doc from org.springframework.core.io.Resource.exists.

Determine whether this resource actually exists in physical form.

This method performs a definitive existence check, whereas the existence of a Resource handle only guarantees a valid descriptor handle.

Annotations
@Override
getDescriptionback to summary
public String getDescription()

Implements org.springframework.core.io.Resource.getDescription.

Doc from org.springframework.core.io.Resource.getDescription.

Return a description for this resource, to be used for error output when working with the resource.

Implementations are also encouraged to return this value from their toString method.

Annotations
@Override
getFileback to summary
public File getFile() throws IOException

Implements org.springframework.core.io.Resource.getFile.

Doc from org.springframework.core.io.Resource.getFile.

Return a File handle for this resource.

Annotations
@Override
Exceptions
IOException:
in case of general resolution/reading failures
getFilenameback to summary
public String getFilename()

Implements org.springframework.core.io.Resource.getFilename.

Doc from org.springframework.core.io.Resource.getFilename.

Determine the filename for this resource — typically the last part of the path — for example, "myfile.txt".

Returns null if this type of resource does not have a filename.

Implementations are encouraged to return the filename unencoded.

Annotations
@Override
@Nullable
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

Return an InputStream for the content of an underlying resource.

It is expected that each call creates a fresh stream.

This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

Returns:InputStream

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:
if the content stream could not be opened
getURIback to summary
public URI getURI() throws IOException

Implements org.springframework.core.io.Resource.getURI.

Doc from org.springframework.core.io.Resource.getURI.

Return a URI handle for this resource.

Annotations
@Override
Exceptions
IOException:
if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
getURLback to summary
public URL getURL() throws IOException

Implements org.springframework.core.io.Resource.getURL.

Doc from org.springframework.core.io.Resource.getURL.

Return a URL handle for this resource.

Annotations
@Override
Exceptions
IOException:
if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
lastModifiedback to summary
public long lastModified() throws IOException

Implements org.springframework.core.io.Resource.lastModified.

Doc from org.springframework.core.io.Resource.lastModified.

Determine the last-modified timestamp for this resource.

Annotations
@Override
Exceptions
IOException:
if the resource cannot be resolved (in the file system or as some other known physical resource type)