use of javax.servlet.RequestDispatcher in project knox by apache.
the class GatewayForwardingServletTest method testRedirectDefaults.
@Test
public void testRedirectDefaults() throws ServletException, IOException {
IMocksControl mockControl = EasyMock.createControl();
ServletConfig config = (ServletConfig) mockControl.createMock(ServletConfig.class);
ServletContext context = (ServletContext) mockControl.createMock(ServletContext.class);
HttpServletRequest request = (HttpServletRequest) mockControl.createMock(HttpServletRequest.class);
HttpServletResponse response = (HttpServletResponse) mockControl.createMock(HttpServletResponse.class);
RequestDispatcher dispatcher = (RequestDispatcher) mockControl.createMock(RequestDispatcher.class);
// setup expectations
EasyMock.expect(config.getServletName()).andStubReturn("default");
EasyMock.expect(config.getServletContext()).andStubReturn(context);
EasyMock.expect(config.getInitParameter("redirectTo")).andReturn("/gateway/sandbox");
EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes();
EasyMock.expect(request.getPathInfo()).andReturn("/webhdfs/v1/tmp").anyTimes();
EasyMock.expect(request.getQueryString()).andReturn("op=LISTSTATUS");
EasyMock.expect(response.getStatus()).andReturn(200).anyTimes();
EasyMock.expect(context.getContext("/gateway/sandbox")).andReturn(context);
EasyMock.expect(context.getRequestDispatcher("/webhdfs/v1/tmp?op=LISTSTATUS")).andReturn(dispatcher);
dispatcher.forward(request, response);
EasyMock.expectLastCall().once();
// logging
context.log((String) EasyMock.anyObject());
EasyMock.expectLastCall().anyTimes();
// run the test
mockControl.replay();
GatewayForwardingServlet servlet = new GatewayForwardingServlet();
servlet.init(config);
servlet.service(request, response);
mockControl.verify();
}
use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.
the class LoginController method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Login.jsp");
dispatcher.forward(request, response);
}
use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.
the class ProfileController method doPost.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// get parameters
String email = request.getParameter("email");
String ps = request.getParameter("password");
Connection c = null;
try {
String url = "jdbc:mysql://cs3.calstatela.edu/cs3220stu49";
String username = "cs3220stu49";
String password = "#Enwva2#";
c = DriverManager.getConnection(url, username, password);
// change name of database
String sql = "select * from Users2 where email = ? and password = ?";
PreparedStatement pstmt = c.prepareStatement(sql);
pstmt.setString(1, email);
pstmt.setString(2, ps);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Profile.jsp");
dispatcher.forward(request, response);
return;
}
response.sendRedirect("Login");
return;
} catch (SQLException e) {
throw new ServletException(e);
} finally {
try {
if (c != null)
c.close();
} catch (SQLException e) {
throw new ServletException(e);
}
}
}
use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.
the class SignUpController method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/SignUp.jsp");
dispatcher.forward(request, response);
}
use of javax.servlet.RequestDispatcher in project iaf by ibissource.
the class Download method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
if (session != null) {
String url = (String) session.getAttribute(URL_KEY);
if (url != null) {
String parameters = null;
Map params = (Map) session.getAttribute(PARAMETERS_KEY);
for (Iterator it = params.keySet().iterator(); it.hasNext(); ) {
String name = (String) it.next();
String[] values = (String[]) params.get(name);
for (int i = 0; i < values.length; i++) {
if (parameters == null) {
parameters = "?";
} else {
parameters += "&";
}
parameters += name + "=" + URLEncoder.encode(values[i], response.getCharacterEncoding());
}
}
if (parameters != null) {
url += parameters;
}
String context = request.getContextPath();
if (url.startsWith(context)) {
url = url.substring(context.length());
}
url = response.encodeURL(url);
if (log.isDebugEnabled())
log.debug("dispatching to [" + url + "]");
String contenttype = (String) session.getAttribute(CONTENTTYPE_KEY);
String filename = (String) session.getAttribute(FILENAME_KEY);
session.removeAttribute(URL_KEY);
session.removeAttribute(PARAMETERS_KEY);
session.removeAttribute(CONTENTTYPE_KEY);
session.removeAttribute(FILENAME_KEY);
response.setContentType(contenttype);
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
RequestDispatcher rd = request.getRequestDispatcher(url);
rd.include(request, response);
}
}
}
Aggregations