Search in sources :

Example 61 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project tesla by linking12.

the class AbstractAuthorizeHandler method submitLogin.

protected boolean submitLogin() throws ServletException, IOException {
    if (isSubmitLogin()) {
        try {
            UsernamePasswordToken token = createUsernamePasswordToken();
            SecurityUtils.getSubject().login(token);
            LOG.debug("Submit login successful");
            this.userFirstLogged = true;
            return false;
        } catch (Exception ex) {
            LOG.debug("Login failed, back to login page too", ex);
            final HttpServletRequest request = oauthRequest.request();
            request.setAttribute("oauth_login_error", ex.getMessage());
            RequestDispatcher dispatcher = request.getRequestDispatcher(OAUTH_LOGIN_VIEW);
            dispatcher.forward(request, response);
            return true;
        }
    }
    return false;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) RequestDispatcher(javax.servlet.RequestDispatcher) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 62 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project cxf by apache.

the class RequestDispatcherProvider method writeTo.

public void writeTo(Object o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException {
    ServletContext sc = getServletContext();
    HttpServletRequest servletRequest = getMessageContext().getHttpServletRequest();
    String path = getResourcePath(clazz, o);
    String theServletPath = servletPath != null ? servletPath : useCurrentServlet ? servletRequest.getServletPath() : "/";
    if (theServletPath.endsWith("/") && path != null && path.startsWith("/")) {
        theServletPath = theServletPath.length() == 1 ? "" : theServletPath.substring(0, theServletPath.length() - 1);
    } else if (!theServletPath.endsWith("/") && path != null && !path.startsWith("/")) {
        path = "/" + path;
    }
    RequestDispatcher rd = getRequestDispatcher(sc, clazz, theServletPath + path);
    try {
        if (!includeResource) {
            getMessageContext().put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.TRUE);
        }
        HttpServletRequestFilter requestFilter = new HttpServletRequestFilter(servletRequest, path, theServletPath, saveParametersAsAttributes);
        String attributeName = getBeanName(o);
        if (REQUEST_SCOPE.equals(scope)) {
            requestFilter.setAttribute(attributeName, o);
        } else if (SESSION_SCOPE.equals(scope)) {
            requestFilter.getSession(true).setAttribute(attributeName, o);
        }
        setRequestParameters(requestFilter);
        logRedirection(path, attributeName, o);
        if (includeResource) {
            rd.include(requestFilter, getMessageContext().getHttpServletResponse());
        } else {
            rd.forward(requestFilter, getMessageContext().getHttpServletResponse());
        }
    } catch (Throwable ex) {
        handleViewRenderingException(theServletPath + path, ex);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContext(javax.servlet.ServletContext) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 63 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project quickstart by wildfly.

the class MemberRegistrationServlet method doPost.

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    StringBuilder errorMessage = new StringBuilder();
    try {
        System.out.println("EMAIL='" + request.getParameter("email") + "'");
        Member member;
        while ((member = registrationService.getNewMember()) == null) {
            registrationService.initNewMember();
        }
        String value;
        if ((value = request.getParameter("name")).length() < 1) {
            errorMessage.append("Name can not be null\n");
        } else {
            member.setName(value);
            if ((value = request.getParameter("email")).length() < 1) {
                errorMessage.append("email required!\n");
            } else {
                member.setEmail(value);
                if ((value = request.getParameter("phoneNumber")).length() < 1) {
                    errorMessage.append("phoneNumber required \n");
                } else // all parameters are filled, register
                {
                    member.setPhoneNumber(value);
                    log("\n*****************Try Registration of Member=" + member);
                    registrationService.register();
                    request.setAttribute("infoMessage", member.getName() + " Registered!");
                }
            }
        }
    } catch (Exception e) {
        Throwable t = e;
        while ((t.getCause()) != null) {
            t = t.getCause();
        }
        errorMessage.append("Error========>" + t.getMessage());
        request.setAttribute("infoMessage", "");
        e.printStackTrace();
    } finally {
        request.setAttribute("errorMessage", errorMessage.toString());
        RequestDispatcher resultView = request.getRequestDispatcher("index.jsp");
        resultView.forward(request, response);
    }
}
Also used : Member(org.jboss.as.quickstarts.kitchensinkjsp.model.Member) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 64 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project jaffa-framework by jaffa-projects.

the class WebServiceController method doGet.

/**
 * @param req. The HttpServletRequest.
 * @param resp. The HttpServletResponse
 * @throws ServletException
 * @throws IOException
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String endPoint = (String) req.getAttribute("realEndPoint");
    String uri = "/" + endPoint;
    if (log.isDebugEnabled()) {
        log.debug("URI :" + uri);
    }
    RequestDispatcher dispatcher = req.getRequestDispatcher(uri);
    if (log.isDebugEnabled()) {
        log.debug("Dispatching Request");
    }
    dispatcher.forward(req, resp);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 65 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project identity-test-integration by wso2-incubator.

the class OAuth2ClientServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher dispatcher = req.getRequestDispatcher("oauth2.jsp");
    dispatcher.forward(req, resp);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)354 ServletException (javax.servlet.ServletException)98 HttpSession (javax.servlet.http.HttpSession)97 IOException (java.io.IOException)74 HttpServletRequest (javax.servlet.http.HttpServletRequest)56 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 SQLException (java.sql.SQLException)31 User (com.zyf.bean.User)28 ServletContext (javax.servlet.ServletContext)26 Properties (java.util.Properties)14 Test (org.junit.Test)14 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)13 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)12 PrintWriter (java.io.PrintWriter)12 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)11 Resource (org.apache.sling.api.resource.Resource)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 GenericValue (org.apache.ofbiz.entity.GenericValue)9 WebUser (org.compiere.util.WebUser)9