@Override public ServletContext getServletContext() { return this.context.getServletContext(); }
Tomcat.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
Tomcat.addServlet(context, "dispatcher", new DispatcherServlet()); context.addServletMapping("/*", "dispatcher"); ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
getServingLayer().getContext().getServletContext().getAttribute(OryxResource.INPUT_PRODUCER_KEY);
@Test public void testKMeansServingModel() throws Exception { Map<String,Object> overlayConfig = new HashMap<>(); overlayConfig.put("oryx.serving.application-resources", "\"com.cloudera.oryx.app.serving," + "com.cloudera.oryx.app.serving.clustering," + "com.cloudera.oryx.app.serving.kmeans\""); overlayConfig.put("oryx.serving.model-manager-class", KMeansServingModelManager.class.getName()); overlayConfig.put("oryx.input-schema.feature-names", "[\"x\",\"y\"]"); overlayConfig.put("oryx.input-schema.categorical-features", "[]"); Config config = ConfigUtils.overlayOn(overlayConfig, getConfig()); startMessaging(); startServer(config); startUpdateTopics(new MockKMeansModelGenerator(), 10); // Let updates finish sleepSeconds(5); KMeansServingModelManager manager = (KMeansServingModelManager) getServingLayer().getContext().getServletContext().getAttribute(OryxResource.MODEL_MANAGER_KEY); assertNotNull("Manager must initialize in web context", manager); KMeansServingModel model = manager.getModel(); log.debug("{}", model); assertNotNull(model); assertEquals(3, model.getNumClusters()); assertCluster(model.getCluster(0), 0, new double[] { 9.0, 9.0 }, 9); assertCluster(model.getCluster(1), 1, new double[] { 7.0, 7.0 }, 7); assertCluster(model.getCluster(2), 2, new double[] { 8.0, 8.0 }, 8); }
@Test public void testALSServingModel() throws Exception { Map<String,Object> overlayConfig = new HashMap<>(); overlayConfig.put("oryx.serving.application-resources", "\"com.cloudera.oryx.app.serving,com.cloudera.oryx.app.serving.als\""); overlayConfig.put("oryx.serving.model-manager-class", ALSServingModelManager.class.getName()); Config config = ConfigUtils.overlayOn(overlayConfig, getConfig()); startMessaging(); startServer(config); startUpdateTopics(new MockALSModelUpdateGenerator(), 10); // Let updates finish sleepSeconds(5); ALSServingModelManager manager = (ALSServingModelManager) getServingLayer().getContext().getServletContext().getAttribute(OryxResource.MODEL_MANAGER_KEY); assertNotNull("Manager must initialize in web context", manager); ALSServingModel model = manager.getModel(); log.debug("{}", model); assertNotNull(model); assertEquals(2, model.getFeatures()); assertTrue(model.isImplicit()); assertContainsSame(MockALSModelUpdateGenerator.Y.keySet(), model.getAllItemIDs()); assertNotNull(model.getYTYSolver()); MockALSModelUpdateGenerator.X.forEach((id, vector) -> assertArrayEquals(vector, model.getUserVector(id))); MockALSModelUpdateGenerator.Y.forEach((id, vector) -> assertArrayEquals(vector, model.getItemVector(id))); MockALSModelUpdateGenerator.A.forEach((id, expected) -> assertContainsSame(expected, model.getKnownItems(id))); }
/** * Exclude from total. * * @param ctx the ctx * @return true, if successful */ private boolean excludeFromTotal(Context ctx) { return isSelfIgnored() && getServletContext().equals(ctx.getServletContext()); }
getServingLayer().getContext().getServletContext().getAttribute(OryxResource.MODEL_MANAGER_KEY);
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String attrName = ServletRequestUtils.getStringParameter(request, "attr"); context.getServletContext().removeAttribute(attrName); return new ModelAndView(new RedirectView( request.getContextPath() + getViewName() + "?" + request.getQueryString())); }
/** * Gets the application attributes. * * @param context the context * @return the application attributes */ public static List<Attribute> getApplicationAttributes(Context context) { List<Attribute> attrs = new ArrayList<>(); ServletContext servletCtx = context.getServletContext(); for (String attrName : Collections.list(servletCtx.getAttributeNames())) { Object attrValue = servletCtx.getAttribute(attrName); Attribute attr = new Attribute(); attr.setName(attrName); attr.setValue(attrValue); attr.setType(ClassUtils.getQualifiedName(attrValue.getClass())); attrs.add(attr); } return attrs; }
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { if (downloadTarget == null) { throw new RuntimeException("Download target is not set for " + getClass().getName()); } String xmlPath; if (TARGET_WEB_XML.equals(downloadTarget)) { ServletContext sctx = context.getServletContext(); xmlPath = sctx.getRealPath("/WEB-INF/web.xml"); } else if (TARGET_CONTEXT_XML.equals(downloadTarget)) { xmlPath = this.getContainerWrapper().getTomcatContainer().getConfigFile(context).getPath(); } else { throw new RuntimeException("Unknown download target " + getDownloadTarget()); } if (xmlPath != null) { File xmlFile = new File(xmlPath); if (xmlFile.exists()) { Utils.sendFile(request, response, xmlFile); } else { logger.debug("File {} of {} application does not exists.", xmlPath, contextName); } } else { logger.debug("Cannot determine path to {} file of {} application.", getDownloadTarget(), contextName); } return null; }
ServletContext servletCtx = context.getServletContext(); for (String paramName : Collections.list(servletCtx.getInitParameterNames())) { ApplicationParam param = new ApplicationParam();
ServletContext servletCtx = context.getServletContext(); for (String paramName : Collections.list(servletCtx.getInitParameterNames())) { ApplicationParam param = new ApplicationParam();
ServletContext servletCtx = context.getServletContext(); for (String paramName : Collections.list(servletCtx.getInitParameterNames())) { ApplicationParam param = new ApplicationParam();
ServletContext servletCtx = context.getServletContext(); for (String paramName : Collections.list(servletCtx.getInitParameterNames())) { ApplicationParam param = new ApplicationParam();
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String jspName = ServletRequestUtils.getStringParameter(request, "source", null); ServletContext sctx = context.getServletContext(); ServletConfig scfg = (ServletConfig) context.findChild("jsp"); Options opt = new EmbeddedServletOptions(scfg, sctx); String encoding = opt.getJavaEncoding(); String content = null; if (jspName != null) { String servletName = getContainerWrapper().getTomcatContainer().getServletFileNameForJsp(context, jspName); if (servletName != null) { File servletFile = new File(servletName); if (servletFile.exists()) { try (InputStream fis = Files.newInputStream(servletFile.toPath())) { content = Utils.highlightStream(jspName, fis, "java", encoding); } } } } return new ModelAndView(getViewName(), "content", content); }
@Override public String getServletFileNameForJsp(Context context, String jspName) { String servletName = null; ServletConfig servletConfig = (ServletConfig) context.findChild("jsp"); if (servletConfig != null) { ServletContext sctx = context.getServletContext(); Options opt = new EmbeddedServletOptions(servletConfig, sctx); JspRuntimeContext jrctx = new JspRuntimeContext(sctx, opt); JspCompilationContext jcctx = createJspCompilationContext(jspName, opt, sctx, jrctx, null); servletName = jcctx.getServletJavaFileName(); } else { logger.error(NO_JSP_SERVLET, context.getName()); } return servletName; }
if (servletConfig != null) { synchronized (servletConfig) { ServletContext sctx = context.getServletContext(); Options opt = new EmbeddedServletOptions(servletConfig, sctx);
new Log4J2WebLoggerContextUtilsAccessor(classLoader); Log4J2LoggerContextAccessor loggerContextAccessor = webLoggerContextUtilsAccessor.getWebLoggerContext(ctx.getServletContext()); List<Object> loggerContexts = getLoggerContexts(classLoader); Object loggerConfig = null;
context.getServletContext().setAttribute(PIPPO_APPLICATION, getApplication());