
org.brandao.brutos.web.DispatcherServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brutos-web Show documentation
Show all versions of brutos-web Show documentation
Brutos application framework is a MVC controller.
/*
* Brutos Web MVC http://www.brutosframework.com.br/
* Copyright (C) 2009 Afonso Brandao. ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.brandao.brutos.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.brandao.brutos.BrutosConstants;
import org.brandao.brutos.ConfigurableApplicationContext;
/**
*
* @author Afonso Brandao
*/
public class DispatcherServlet extends HttpServlet {
private WebApplicationContext webApplicationContext;
private WebInvoker invoker;
public void init() throws ServletException{
super.init();
webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
if( webApplicationContext == null ){
throw new IllegalStateException(
"Unable to initialize the servlet was not configured for the application context root - " +
"make sure you have defined in your web.xml ContextLoader!"
);
}
else
invoker = (WebInvoker)((ConfigurableApplicationContext)webApplicationContext).getInvoker();
Throwable ex = (Throwable)getServletContext().getAttribute( BrutosConstants.EXCEPTION );
if( ex != null )
throw new ServletException( ex );
}
public void destroy(){
super.destroy();
}
protected void processRequest(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
invoker.invoker(request, response, null);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Brutos Servlet";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy