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;
}
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;
}
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;
}
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));
}
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);
}
}
Aggregations