Search in sources :

Example 96 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project bil372-proje by mertserezli.

the class TaskDescriptionServlet method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    TaskBean task = new TaskBean();
    RequestDispatcher dispatcher;
    ServletContext context = getServletContext();
    int tid = Integer.parseInt(request.getParameter("tid"));
    task.setTid(tid);
    try {
        task = TaskDAO.getTask(task);
        request.setAttribute("task", task);
        dispatcher = context.getNamedDispatcher("task");
        dispatcher.forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServletContext(javax.servlet.ServletContext) TaskBean(models.TaskBean) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 97 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project bil372-proje by mertserezli.

the class TaskTreeServlet method doGet.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
    ProjectBean project = new ProjectBean();
    RequestDispatcher dispatcher;
    ServletContext context = getServletContext();
    int pid = Integer.parseInt(request.getParameter("pid"));
    project.setPid(pid);
    try {
        project = ProjectDAO.getProject(project);
        if (!project.getTitle().equals("Project Not Found")) {
            String tree = getTreeHTML(project);
            ArrayList<UserBean> employeeList = ProjectDAO.getEmployees(project);
            request.setAttribute("employeeList", employeeList);
            request.setAttribute("tree", tree);
            request.setAttribute("project", project);
            dispatcher = context.getNamedDispatcher("taskTree");
            dispatcher.forward(request, response);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserBean(models.UserBean) ProjectBean(models.ProjectBean) ServletContext(javax.servlet.ServletContext) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 98 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project ovirt-engine by oVirt.

the class VersionFilter method doFilter.

private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    // Get a reference to the object that stores the information of the current request:
    Current current = CurrentManager.get();
    // Get the remote address, as we need it for several things:
    String remoteAddress = request.getRemoteAddr();
    // First try to extract the version from the request path:
    String version = null;
    VersionSource source = null;
    String path = current.getPath();
    Matcher matcher = VERSION_PATTERN.matcher(path);
    if (matcher.matches()) {
        version = matcher.group(VERSION_GROUP);
        path = matcher.group(PATH_GROUP);
        source = VersionSource.URL;
    }
    // If the version hasn't been determined yet, then try to extract it from the headers:
    if (version == null || version.isEmpty()) {
        version = request.getHeader(VERSION_HEADER);
        if (version != null && !version.isEmpty()) {
            source = VersionSource.HEADER;
        }
    }
    // Finally, if the version hasn't been determined, then use the default:
    if (version == null || version.isEmpty()) {
        version = defaultVersion;
        source = VersionSource.DEFAULT;
    }
    // Check that the version is supported, and return an HTTP error response if it isn't:
    if (!supportedVersions.contains(version)) {
        log.error("Client \"{}\" is requesting unsupported version \"{}\", will send a 400 error code.", remoteAddress, version);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    // Check if the version is deprecated, if it is then send a message to the audit log:
    if (deprecatedVersionsSet.contains(version)) {
        DeprecatedVersionInfo versionInfo = deprecatedVersionsMap.get(version);
        AddDeprecatedApiEventParameters parameters = new AddDeprecatedApiEventParameters(version, remoteAddress, versionInfo.getDeprecating(), versionInfo.getRemoving());
        backend.runAction(ActionType.AddDeprecatedApiEvent, parameters);
    }
    // Copy the version, the source and the path to the object that stores information to the current request:
    current.setVersion(version);
    current.setVersionSource(source);
    current.setPath(path);
    // modified request.
    if (source == VersionSource.URL) {
        chain.doFilter(request, response);
    } else {
        String prefix = current.getPrefix();
        String uri = request.getRequestURI();
        StringBuilder buffer = new StringBuilder(2 + version.length() + (uri.length() - prefix.length()));
        buffer.append("/v");
        buffer.append(version);
        buffer.append(uri, prefix.length(), uri.length());
        path = buffer.toString();
        RequestDispatcher dispatcher = request.getRequestDispatcher(path);
        if (dispatcher == null) {
            log.error("Can't find dispatcher for path \"{}\", as requested by client \"{}\", will send a 404 error code.", path, remoteAddress);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } else {
            dispatcher.forward(request, response);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) AddDeprecatedApiEventParameters(org.ovirt.engine.core.common.action.AddDeprecatedApiEventParameters) DeprecatedVersionInfo(org.ovirt.engine.api.restapi.DeprecatedVersionInfo) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 99 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project ovirt-engine by oVirt.

the class GwtDynamicHostPageServlet method doGet.

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
    final String engineSessionId = getEngineSessionId(request);
    // Set attribute for selector script
    request.setAttribute(MD5Attributes.ATTR_SELECTOR_SCRIPT.getKey(), getSelectorScriptName());
    // Set the messages that need to be replaced.
    request.setAttribute(MD5Attributes.ATTR_MESSAGES.getKey(), getBrandingMessages(getApplicationTypeFromRequest(request), getLocaleFromRequest(request)));
    request.setAttribute(MD5Attributes.ATTR_BASE_CONTEXT_PATH.getKey(), getValueObject(ServletUtils.getBaseContextPath(request)));
    request.setAttribute(MD5Attributes.ATTR_DISPLAY_UNCAUGHT_UI_EXCEPTIONS.getKey(), getDisplayUncaughtUIExceptions() ? BooleanNode.TRUE : BooleanNode.FALSE);
    // Set attributes for userInfo object
    DbUser loggedInUser = getLoggedInUser(engineSessionId);
    if (loggedInUser != null) {
        String ssoToken = getSsoToken(engineSessionId);
        request.setAttribute(MD5Attributes.ATTR_USER_INFO.getKey(), getUserInfoObject(loggedInUser, ssoToken));
    }
    // Set attribute for engineRpmVersion object
    String engineRpmVersion = getEngineRpmVersion(engineSessionId);
    request.setAttribute(MD5Attributes.ATTR_ENGINE_RPM_VERSION.getKey(), getValueObject(engineRpmVersion));
    try {
        // Calculate MD5 for use with If-None-Match request header
        String md5sum = getMd5Sum(request);
        if (request.getHeader(IF_NONE_MATCH_HEADER) != null && request.getHeader(IF_NONE_MATCH_HEADER).equals(md5sum)) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        } else {
            RequestDispatcher dispatcher = request.getRequestDispatcher(HOST_JSP);
            response.setContentType(UTF_CONTENT_TYPE);
            response.addHeader(ETAG_HEADER, md5sum);
            if (dispatcher != null) {
                dispatcher.include(request, response);
            }
        }
    } catch (NoSuchAlgorithmException ex) {
        throw new ServletException(ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RequestDispatcher(javax.servlet.RequestDispatcher) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 100 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project dataverse by IQSS.

the class ApiRouter method doFilter.

@Override
public void doFilter(ServletRequest req, ServletResponse sr1, FilterChain fc) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    String requestUri = request.getRequestURI();
    if (requestUri.startsWith("/api/v1/")) {
        fc.doFilter(req, sr1);
    } else {
        String newRequestUri = "/api/v1" + requestUri.substring(4);
        RequestDispatcher dsp = request.getRequestDispatcher(newRequestUri);
        dsp.forward(req, sr1);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) 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