blob: c7d262ba62e40249549846d030ac06b3e1658b86 [file] [log] [blame]
/*
* Copyright (c) 2005, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.s1asdev.deployment.ejb30.web.jsp;
import java.io.IOException;
import jakarta.annotation.Resource;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
public class MyFilter implements Filter {
private @Resource DataSource ds1;
private @Resource(name="myDataSource2") DataSource ds2;
private DataSource ds3;
private @Resource(name="jdbc/__default") DataSource ds4;
@Resource(name="jdbc/myDataSource3")
private void setDataSource(DataSource ds) {
ds3 = ds;
}
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext sc = filterConfig.getServletContext();
try {
int loginTimeout = ds1.getLoginTimeout();
sc.log("ds1-login-timeout=" + loginTimeout);
loginTimeout = ds2.getLoginTimeout();
sc.log(",ds2-login-timeout=" + loginTimeout);
loginTimeout = ds3.getLoginTimeout();
sc.log(",ds3-login-timeout=" + loginTimeout);
loginTimeout = ds4.getLoginTimeout();
sc.log(",ds4-login-timeout=" + loginTimeout);
} catch (Exception e) {
throw new ServletException(e);
}
}
public void doFilter (ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
int loginTimeout = 0;
try {
loginTimeout = ds1.getLoginTimeout();
} catch(Exception ex) {
ex.printStackTrace();
throw new IOException(ex.toString());
}
HttpServletRequest httpRequest = (HttpServletRequest)request;
HttpSession httpSession = httpRequest.getSession(true);
httpSession.setAttribute("deployment.ejb30.web.jsp", "Hello World: " + loginTimeout);
chain.doFilter(request, response);
}
public void destroy() {
// do nothing
}
}