Search in sources :

Example 16 with ServletContext

use of javax.servlet.ServletContext in project head by mifos.

the class BatchjobsController method produceModelAndView.

private ModelAndView produceModelAndView(HttpServletRequest request, List<String> errorMessages) {
    ServletContext context = request.getSession().getServletContext();
    List<BatchjobsDto> batchjobs;
    BatchjobsSchedulerDto batchjobsScheduler;
    try {
        batchjobs = batchjobsServiceFacade.getBatchjobs(context);
    } catch (Exception tse) {
        errorMessages.add("Error when retrieving batch jobs information: " + tse.getMessage());
        batchjobs = new ArrayList<BatchjobsDto>();
    }
    try {
        batchjobsScheduler = batchjobsServiceFacade.getBatchjobsScheduler(context);
    } catch (Exception tse) {
        errorMessages.add("Error when retrieving batch jobs information: " + tse.getMessage());
        batchjobsScheduler = new BatchjobsSchedulerDto(false);
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("request", request);
    model.put("batchjobs", batchjobs);
    if (batchjobsScheduler == null) {
        model.put("scheduler", "");
    } else {
        model.put("scheduler", batchjobsScheduler.isStatus());
    }
    model.put("date0", new Date(0));
    model.put("executedTasks", rawJobList);
    if (rawJobList.length > 0) {
        rawJobList = new String[0];
    }
    Map<String, Object> status = new HashMap<String, Object>();
    status.put("errorMessages", errorMessages);
    ModelAndView modelAndView = new ModelAndView("batchjobs", "model", model);
    modelAndView.addObject("status", status);
    return modelAndView;
}
Also used : HashMap(java.util.HashMap) BatchjobsSchedulerDto(org.mifos.application.admin.servicefacade.BatchjobsSchedulerDto) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) ServletContext(javax.servlet.ServletContext) BatchjobsDto(org.mifos.application.admin.servicefacade.BatchjobsDto) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Date(java.util.Date)

Example 17 with ServletContext

use of javax.servlet.ServletContext in project head by mifos.

the class BatchjobsDetailsController method processFormSubmit.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView processFormSubmit(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>();
    List<String> errorMessages = new ArrayList<String>();
    ServletContext context = request.getSession().getServletContext();
    List<BatchjobsDto> batchjobs;
    try {
        batchjobs = batchjobsServiceFacade.getBatchjobs(context);
    } catch (Exception tse) {
        errorMessages.add("Error when retrieving batch jobs information: " + tse.getMessage());
        batchjobs = new ArrayList<BatchjobsDto>();
    }
    model.put("batchjobs", batchjobs);
    String[] jobFailNames = request.getParameterValues("jobFailName");
    if (jobFailNames != null && jobFailNames.length > 0) {
        model.put("jobFailName", jobFailNames[0]);
    } else {
        model.put("jobFailName", "");
    }
    Map<String, Object> status = new HashMap<String, Object>();
    status.put("errorMessages", errorMessages);
    ModelAndView modelAndView = new ModelAndView("batchjobsdetails", "model", model);
    modelAndView.addObject("status", status);
    return modelAndView;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) ServletContext(javax.servlet.ServletContext) BatchjobsDto(org.mifos.application.admin.servicefacade.BatchjobsDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with ServletContext

use of javax.servlet.ServletContext in project jersey by jersey.

the class FreemarkerMvcFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    final Configuration config = context.getConfiguration();
    if (!config.isRegistered(FreemarkerViewProcessor.class)) {
        // Template Processor.
        Configuration configuration = injectionManager.getInstance(Configuration.class);
        ServletContext servletContext = injectionManager.getInstance(ServletContext.class);
        context.register(new FreemarkerViewProcessor(configuration, servletContext, injectionManager::createAndInitialize));
        // MvcFeature.
        if (!config.isRegistered(MvcFeature.class)) {
            context.register(MvcFeature.class);
        }
        return true;
    }
    return false;
}
Also used : Configuration(javax.ws.rs.core.Configuration) ServletContext(javax.servlet.ServletContext) MvcFeature(org.glassfish.jersey.server.mvc.MvcFeature)

Example 19 with ServletContext

use of javax.servlet.ServletContext in project jersey by jersey.

the class Include method doTag.

public void doTag() throws JspException, IOException {
    final JspContext jspContext = getJspContext();
    final Class<?> resolvingClass = (Class<?>) jspContext.getAttribute(RequestDispatcherWrapper.RESOLVING_CLASS_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE);
    final String basePath = (String) jspContext.getAttribute(RequestDispatcherWrapper.BASE_PATH_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE);
    final ServletConfig servletConfig = (ServletConfig) getPageObject(PageContext.CONFIG);
    final ServletContext servletContext = servletConfig.getServletContext();
    for (Class<?> clazz = resolvingClass; clazz != Object.class; clazz = clazz.getSuperclass()) {
        final String template = basePath + TemplateHelper.getAbsolutePath(clazz, page, '/');
        if (servletContext.getResource(template) != null) {
            // Tomcat returns a RequestDispatcher even if the JSP file doesn't exist so check if the resource exists first.
            final RequestDispatcher dispatcher = servletContext.getRequestDispatcher(template);
            if (dispatcher != null) {
                try {
                    final HttpServletRequest request = (HttpServletRequest) getPageObject(PageContext.REQUEST);
                    final HttpServletResponse response = (HttpServletResponse) getPageObject(PageContext.RESPONSE);
                    dispatcher.include(request, new Wrapper(response, new PrintWriter(jspContext.getOut())));
                } catch (ServletException e) {
                    throw new JspException(e);
                }
                return;
            }
        }
    }
    throw new JspException(LocalizationMessages.UNABLE_TO_FIND_PAGE_FOR_RESOLVING_CLASS(page, resolvingClass));
}
Also used : HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) JspContext(javax.servlet.jsp.JspContext) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestDispatcher(javax.servlet.RequestDispatcher) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) ServletContext(javax.servlet.ServletContext) PrintWriter(java.io.PrintWriter)

Example 20 with ServletContext

use of javax.servlet.ServletContext in project hadoop by apache.

the class JMXJsonServlet method doGet.

/**
   * Process a GET request for the specified resource.
   * 
   * @param request
   *          The servlet request we are processing
   * @param response
   *          The servlet response we are creating
   */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    try {
        // If user is a static user and auth Type is null, that means
        // there is a non-security environment and no need authorization,
        // otherwise, do the authorization.
        final ServletContext servletContext = getServletContext();
        if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) && !isInstrumentationAccessAllowed(request, response)) {
            return;
        }
        JsonGenerator jg = null;
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            response.setContentType("application/json; charset=utf8");
            response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET");
            response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
            jg = jsonFactory.createGenerator(writer);
            jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
            jg.useDefaultPrettyPrinter();
            jg.writeStartObject();
            // query per mbean attribute
            String getmethod = request.getParameter("get");
            if (getmethod != null) {
                String[] splitStrings = getmethod.split("\\:\\:");
                if (splitStrings.length != 2) {
                    jg.writeStringField("result", "ERROR");
                    jg.writeStringField("message", "query format is not as expected.");
                    jg.flush();
                    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    return;
                }
                listBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1], response);
                return;
            }
            // query per mbean
            String qry = request.getParameter("qry");
            if (qry == null) {
                qry = "*:*";
            }
            listBeans(jg, new ObjectName(qry), null, response);
        } finally {
            if (jg != null) {
                jg.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
    } catch (IOException e) {
        LOG.error("Caught an exception while processing JMX request", e);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (MalformedObjectNameException e) {
        LOG.error("Caught an exception while processing JMX request", e);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ServletContext(javax.servlet.ServletContext) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) ObjectName(javax.management.ObjectName)

Aggregations

ServletContext (javax.servlet.ServletContext)1111 Test (org.junit.Test)259 HttpServletRequest (javax.servlet.http.HttpServletRequest)186 HttpServletResponse (javax.servlet.http.HttpServletResponse)143 IOException (java.io.IOException)136 ServletException (javax.servlet.ServletException)101 ServletConfig (javax.servlet.ServletConfig)79 File (java.io.File)78 FilterConfig (javax.servlet.FilterConfig)66 HashMap (java.util.HashMap)64 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)50 URL (java.net.URL)48 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)39 Locale (java.util.Locale)38 List (java.util.List)33 PrintWriter (java.io.PrintWriter)32 LinkedHashMap (java.util.LinkedHashMap)30