-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: d.klysch <[email protected]>
- Loading branch information
Showing
3 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/FilterChainWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/FilterConfigWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/FilterWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |