Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Unable to implement @WebFilter #123

Open
shivangtripathii opened this issue Jan 1, 2020 · 0 comments
Open

Unable to implement @WebFilter #123

shivangtripathii opened this issue Jan 1, 2020 · 0 comments

Comments

@shivangtripathii
Copy link

shivangtripathii commented Jan 1, 2020

Trying this:
import java.io.IOException
import javax.servlet.*
import javax.servlet.annotation.WebFilter

/**
*
/
@webfilter(urlPatterns = ["/
"])
class SimpleServletFilter(private var filterConfig: FilterConfig) : Filter {

@Throws(ServletException::class)
override fun init(filterConfig: FilterConfig) {
    print("init called..")
    this.filterConfig = filterConfig;
}

@Throws(IOException::class, ServletException::class)
override fun doFilter(
    request: ServletRequest, response: ServletResponse,
    filterChain: FilterChain
) {
    println("here..")
}

override fun destroy() {}

}

but the request does not pass through the filter.

Also tried:

import javax.ws.rs.container.ContainerRequestContext
import javax.ws.rs.container.ContainerResponseContext
import javax.ws.rs.container.ContainerResponseFilter
import javax.ws.rs.ext.Provider


@Provider
class CORSFilter : ContainerResponseFilter {
    override fun filter(requestContext: ContainerRequestContext?, responseContext: ContainerResponseContext?) {
        responseContext!!.headers.add("Access-Control-Allow-Origin", "*")
        responseContext.headers.add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
        responseContext.headers.add("Access-Control-Allow-Credentials", "true")
        responseContext.headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
        responseContext.headers.add("Access-Control-Max-Age", "1209600")
    }
}

No luck there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant