Skip to content

Commit

Permalink
add missing filter wrappers (#331)
Browse files Browse the repository at this point in the history
Co-authored-by: d.klysch <[email protected]>
  • Loading branch information
d0mmi and d.klysch authored Sep 4, 2024
1 parent a4523df commit c87bb6a
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.apache.felix.http.jakartawrappers;


import java.io.IOException;

import javax.servlet.FilterChain;

import org.apache.felix.http.javaxwrappers.ServletRequestWrapper;
import org.apache.felix.http.javaxwrappers.ServletResponseWrapper;
import org.jetbrains.annotations.NotNull;

/**
* Jakarta filter chain based on a javax filter chain
*/
public class FilterChainWrapper implements jakarta.servlet.FilterChain
{
private final FilterChain filterChain;


/**
* Create new chain
*
* @param chain Wrapped chain
*/
public FilterChainWrapper(@NotNull final FilterChain chain)
{
this.filterChain = chain;
}


@Override
public void doFilter(final jakarta.servlet.ServletRequest request, final jakarta.servlet.ServletResponse response)
throws IOException, jakarta.servlet.ServletException
{
try
{
filterChain.doFilter(ServletRequestWrapper.getWrapper(request),
ServletResponseWrapper.getWrapper(response));
}
catch (final javax.servlet.ServletException e)
{
throw ServletExceptionUtil.getServletException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.apache.felix.http.jakartawrappers;


import java.util.Enumeration;

import javax.servlet.FilterConfig;

import org.jetbrains.annotations.NotNull;


/**
* Filter config wrapper
*/
public class FilterConfigWrapper implements jakarta.servlet.FilterConfig
{

private final FilterConfig filterConfig;


/**
* Create config
*
* @param filterConfig wrapped config
*/
public FilterConfigWrapper(@NotNull final FilterConfig filterConfig)
{
this.filterConfig = filterConfig;
}


@Override
public String getFilterName()
{
return this.filterConfig.getFilterName();
}


@Override
public jakarta.servlet.ServletContext getServletContext()
{
return new ServletContextWrapper(this.filterConfig.getServletContext());
}


@Override
public String getInitParameter(final String name)
{
return this.filterConfig.getInitParameter(name);
}


@Override
public Enumeration<String> getInitParameterNames()
{
return this.filterConfig.getInitParameterNames();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.apache.felix.http.javaxwrappers;


import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.jetbrains.annotations.NotNull;

/**
* Javax Filter based on a jakarta filter
*/
public class FilterWrapper implements Filter
{

private final jakarta.servlet.Filter filter;


/**
* Create new filter
*
* @param filter wrapped filter
*/
public FilterWrapper(@NotNull final jakarta.servlet.Filter filter)
{
this.filter = filter;
}


@Override
public void init(final FilterConfig filterConfig) throws ServletException
{
try
{
this.filter.init(new org.apache.felix.http.jakartawrappers.FilterConfigWrapper(filterConfig));
}
catch (final jakarta.servlet.ServletException e)
{
throw ServletExceptionUtil.getServletException(e);
}
}


@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
try
{
this.filter.doFilter(org.apache.felix.http.jakartawrappers.ServletRequestWrapper.getWrapper(request),
org.apache.felix.http.jakartawrappers.ServletResponseWrapper.getWrapper(response),
new org.apache.felix.http.jakartawrappers.FilterChainWrapper(chain));
}
catch (final jakarta.servlet.ServletException e)
{
throw ServletExceptionUtil.getServletException(e);
}
}


@Override
public void destroy()
{
this.filter.destroy();
}


/**
* Get the filter
*
* @return The filter
*/
public @NotNull jakarta.servlet.Filter getFilter()
{
return this.filter;
}
}

0 comments on commit c87bb6a

Please sign in to comment.