我有以下ServletContextListener:
NSString * s = [[NSString alloc]initWithData:data encoding: NSUTF8StringEncoding];
}
并在web.xml中引用它,如下所示:
public class MyContextEventListener implements ServletContextListener {
...
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
Properties properties = new Properties();
try {
if (servletContextEvent.getServletContext().getContextPath().contains(CONTEXT_PATH)) {
final InputStream inputStream = servletContextEvent.getServletContext().getClassLoader()
.getResourceAsStream("my.properties");
properties.load(inputStream);
}
SSOAgentConfigs.initConfig(properties);
} catch (Exception e) {
// handle exceptions
}
}
我还有一个简单的虚拟过滤器,如下所示:
<listener>
<listener-class>com.my.domain.and.company.MyContextEventListener</listener-class>
</listener>
我得到以下例外:
public class WSO2SAMLSSOSessionBeanFilter extends SSOAgentFilter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
super.init(filterConfig);
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
super.doFilter(servletRequest, servletResponse, filterChain); // here the Exception occures
}
因此找不到 SSOAgentConfig - 我在 MyContextEventListener 中设置的对象。 有谁知道我能做什么才能在Filter中找到 SSOAgentConfig ?
[编辑]
在web.xml中引用了过滤器:
Stack Trace
org.wso2.carbon.identity.sso.agent.SSOAgentException: Cannot find
org.wso2.carbon.identity.sso.agent.SSOAgentConfig set a request attribute.
Unable to proceed further org.wso2.carbon.identity.sso.agent.SSOAgentFilter.doFilter(SSOAgentFilter.java:71)
答案 0 :(得分:0)
例外来自SSOAgentFilter
文件。 Here你可以找到来源。这是相关部分:
SSOAgentConfig ssoAgentConfig = (SSOAgentConfig) request.
getAttribute(SSOAgentConstants.CONFIG_BEAN_NAME);
if (ssoAgentConfig == null) {
throw new SSOAgentException("Cannot find " + SSOAgentConstants.CONFIG_BEAN_NAME +
" set a request attribute. Unable to proceed further");
}
所以你需要做的就是为这个常量设置一个请求属性:
public class WSO2SAMLSSOSessionBeanFilter extends SSOAgentFilter {
// ...
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
// TODO figure out the right config for the following line
servletRequest.setAttribute(SSOAgentConstants.CONFIG_BEAN_NAME, "the right config...");
super.doFilter(servletRequest, servletResponse, filterChain);
}
}
也许这个解决方案也有帮助:
public class WSO2SAMLSSOSessionBeanFilter extends CarbonSSOAgentFilter {
// ...
}