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

Unable to implement @WebFilter #123

Open
@shivangtripathii

Description

@shivangtripathii

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @shivangtripathii

        Issue actions

          Unable to implement @WebFilter · Issue #123 · Kotlin/kotlin-examples