Package de.freaklamarsch.systarest
Class CorsFilter
java.lang.Object
de.freaklamarsch.systarest.CorsFilter
- All Implemented Interfaces:
jakarta.ws.rs.container.ContainerResponseFilter
@Provider
public class CorsFilter
extends java.lang.Object
implements jakarta.ws.rs.container.ContainerResponseFilter
A filter that adds Cross-Origin Resource Sharing (CORS) headers to HTTP responses.
This allows client-side JavaScript to make fetch calls to the server without being blocked by the browser's
same-origin policy.
Without this filter, browsers like Chrome will block fetch attempts with messages like: "Access to fetch at 'http://systapi:1337/SystaREST/rawdata' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
-
Constructor Summary
Constructors Constructor Description CorsFilter()
-
Method Summary
Modifier and Type Method Description void
filter(jakarta.ws.rs.container.ContainerRequestContext requestContext, jakarta.ws.rs.container.ContainerResponseContext responseContext)
Adds CORS headers to the HTTP response to allow cross-origin requests.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
CorsFilter
public CorsFilter()
-
-
Method Details
-
filter
public void filter(jakarta.ws.rs.container.ContainerRequestContext requestContext, jakarta.ws.rs.container.ContainerResponseContext responseContext) throws java.io.IOExceptionAdds CORS headers to the HTTP response to allow cross-origin requests.- Specified by:
filter
in interfacejakarta.ws.rs.container.ContainerResponseFilter
- Parameters:
requestContext
- the context of the incoming HTTP requestresponseContext
- the context of the outgoing HTTP response- Throws:
java.io.IOException
- if an I/O error occurs
-