Java Code Examples for org.apache.catalina.startup.Tomcat#addWebapp()
The following examples show how to use
org.apache.catalina.startup.Tomcat#addWebapp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestValidator.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testTldVersions31() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.1"); // app dir is relative to server home tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/tld-versions.jsp"); String result = res.toString(); Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0); }
Example 2
Source File: TestValidator.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testTldVersions24() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-2.4"); // app dir is relative to server home tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/tld-versions.jsp"); String result = res.toString(); Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'01-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>02-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'03-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>04-hello world</p>") > 0); Assert.assertTrue(result.indexOf("<p>#{'05-hello world'}</p>") > 0); Assert.assertTrue(result.indexOf("<p>06-hello world</p>") > 0); }
Example 3
Source File: TestMapperWebapps.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testWelcomeFileStrict() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp"); StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); ctxt.setReplaceWelcomeFiles(true); ctxt.addWelcomeFile("index.jsp"); // Mapping for *.do is defined in web.xml ctxt.addWelcomeFile("index.do"); // Simulate STRICT_SERVLET_COMPLIANCE ctxt.setResourceOnlyServlets(""); tomcat.start(); ByteChunk bc = new ByteChunk(); int rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files", bc, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertTrue(bc.toString().contains("JSP")); rc = getUrl("http://localhost:" + getPort() + "/test/welcome-files/sub", bc, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); }
Example 4
Source File: TestApplicationContext.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testGetJspConfigDescriptor() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); // app dir is relative to server home StandardContext standardContext = (StandardContext) tomcat.addWebapp( null, "/test", appDir.getAbsolutePath()); ServletContext servletContext = standardContext.getServletContext(); Assert.assertNull(servletContext.getJspConfigDescriptor()); tomcat.start(); Assert.assertNotNull(servletContext.getJspConfigDescriptor()); }
Example 5
Source File: TestReplicatedContext.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug57425() throws LifecycleException, IOException { Tomcat tomcat = getTomcatInstance(); Host host = tomcat.getHost(); if (host instanceof StandardHost) { ((StandardHost) host).setContextClass(ReplicatedContext.class.getName()); } File root = new File("test/webapp"); Context context = tomcat.addWebapp(host, "", root.getAbsolutePath()); Tomcat.addServlet(context, "test", new AccessContextServlet()); context.addServletMappingDecoded("/access", "test"); tomcat.start(); ByteChunk result = getUrl("http://localhost:" + getPort() + "/access"); Assert.assertEquals("OK", result.toString()); }
Example 6
Source File: TestJspDocumentParser.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testBug54821() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); // app dir is relative to server home tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk bc = new ByteChunk(); int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug54821a.jspx", bc, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); bc.recycle(); rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug54821b.jspx", bc, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); }
Example 7
Source File: TestWebappClassLoader.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testGetCodePath() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); // Must have a real docBase - just use temp tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk out = new ByteChunk(); int rc = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug58096.jsp", out, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); // Build the expected location the same way the webapp base dir is built File f = new File("test/webapp-3.0/WEB-INF/classes"); Assert.assertEquals(f.toURI().toURL().toString(), out.toString().trim()); }
Example 8
Source File: TestWarDirContext.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testReservedJNDIFileNamesWithCache() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-fragments"); // app dir is relative to server home StandardContext ctxt = (StandardContext) tomcat.addWebapp( null, "/test", appDir.getAbsolutePath()); StandardRoot root = new StandardRoot(); root.setCachingAllowed(true); ctxt.setResources(root); tomcat.start(); // Should be found in resources.jar ByteChunk bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote.jsp"); Assert.assertEquals("<p>'singlequote.jsp in resources.jar</p>", bc.toString()); // Should be found in file system bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote2.jsp"); Assert.assertEquals("<p>'singlequote2.jsp in file system</p>", bc.toString()); }
Example 9
Source File: TestELInJsp.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testBug56147() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); // app dir is relative to server home StandardContext ctx = (StandardContext) tomcat.addWebapp( null, "/test", appDir.getAbsolutePath()); // This test needs the JSTL libraries File lib = new File("webapps/examples/WEB-INF/lib"); ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath()); tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug56147.jsp"); String result = res.toString(); assertEcho(result, "00-OK"); }
Example 10
Source File: TestELInJsp.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testBug47413() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); // app dir is relative to server home tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug47413.jsp"); String result = res.toString(); assertEcho(result, "00-hello world"); assertEcho(result, "01-hello world"); assertEcho(result, "02-3.22"); assertEcho(result, "03-3.22"); assertEcho(result, "04-17"); assertEcho(result, "05-17"); assertEcho(result, "06-hello world"); assertEcho(result, "07-hello world"); assertEcho(result, "08-0.0"); assertEcho(result, "09-0.0"); assertEcho(result, "10-0"); assertEcho(result, "11-0"); }
Example 11
Source File: LoadBalancerTest.java From TeaStore with Apache License 2.0 | 5 votes |
private void setupAndAddTestTomcat(int i) { Tomcat testTomcat = new Tomcat(); testTomcat.setPort(0); testTomcat.setBaseDir(testWorkingDir); Context context; try { context = testTomcat.addWebapp(CONTEXT, testWorkingDir); testTomcat.getEngine().setName("Catalina" + i); TestServlet testServlet = new TestServlet(); testServlet.setId(i); testTomcat.addServlet(CONTEXT, "notFoundServlet", new NotFoundServlet()); testTomcat.addServlet(CONTEXT, "timeoutStatusServlet", new TimeoutStatusServlet()); testTomcat.addServlet(CONTEXT, "timeoutingServlet", new SlowTimeoutingServlet()); testTomcat.addServlet(CONTEXT, "restServlet", testServlet); context.addServletMappingDecoded("/rest/" + ENDPOINT, "restServlet"); context.addServletMappingDecoded("/rest/" + ENDPOINT + "/*", "restServlet"); context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT, "notFoundServlet"); context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT + "/*", "notFoundServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT, "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT + "/*", "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT, "timeoutStatusServlet"); context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT + "/*", "timeoutStatusServlet"); testTomcats.add(testTomcat); } catch (ServletException e) { e.printStackTrace(); } }
Example 12
Source File: TestAbstractHttp11Processor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private void doTestWithTEChunked(boolean withCL) throws Exception { Tomcat tomcat = getTomcatInstance(); // Use the normal Tomcat ROOT context File root = new File("test/webapp-3.0"); tomcat.addWebapp("", root.getAbsolutePath()); tomcat.start(); String request = "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF + "Host: any" + SimpleHttpClient.CRLF + (withCL ? "Content-length: 1" + SimpleHttpClient.CRLF : "") + "Transfer-encoding: chunked" + SimpleHttpClient.CRLF + "Content-Type: application/x-www-form-urlencoded" + SimpleHttpClient.CRLF + "Connection: close" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF + "9" + SimpleHttpClient.CRLF + "test=data" + SimpleHttpClient.CRLF + "0" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF; Client client = new Client(tomcat.getConnector().getLocalPort()); client.setRequest(new String[] {request}); client.connect(); client.processRequest(); assertTrue(client.isResponse200()); assertTrue(client.getResponseBody().contains("test - data")); }
Example 13
Source File: EmbeddedServer.java From blog with MIT License | 5 votes |
public EmbeddedServer(int port, String contextPath) throws ServletException { tomcat = new Tomcat(); tomcat.setPort(port); tomcat.setBaseDir("target/tomcat"); tomcat.addWebapp(contextPath, new File("src/main/webapp").getAbsolutePath()); serverThread = new Thread(this); }
Example 14
Source File: TestCompiler.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testBug53257b() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug53257/foo&bar.jsp"); // Check request completed String result = res.toString(); assertEcho(result, "OK"); }
Example 15
Source File: TestApplication.java From zrlog with Apache License 2.0 | 5 votes |
@Before public void before() throws LifecycleException, ServletException { System.setProperty("env", "junit-test"); tomcat = new Tomcat(); //1024~21023中随机未占用的端口(Linux低端口) int port = new Random().nextInt(20000) + 1024; while (!testPortCanBind(port)) { port = new Random().nextInt(20000) + 1024; } tomcat.setPort(port); tomcat.setBaseDir("target/classes"); tomcat.addWebapp("", new File("src/main/webapp/").getAbsolutePath()); tomcat.start(); }
Example 16
Source File: TestStandardContext.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Test public void testBug49922() throws Exception { // Test that filter mapping works. Test that the same filter is // called only once, even if is selected by several mapping // url-patterns or by both a url-pattern and a servlet-name. // Set up a container Tomcat tomcat = getTomcatInstance(); File root = new File("test/webapp-3.0"); tomcat.addWebapp("", root.getAbsolutePath()); tomcat.start(); ByteChunk result = new ByteChunk(); // Check filter and servlet aren't called int rc = getUrl("http://localhost:" + getPort() + "/bug49922/foo", result, null); assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); assertTrue(result.getLength() > 0); // Check extension mapping works result = getUrl("http://localhost:" + getPort() + "/foo.do"); assertEquals("FilterServlet", result.toString()); // Check path mapping works result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet"); assertEquals("FilterServlet", result.toString()); // Check servlet name mapping works result = getUrl("http://localhost:" + getPort() + "/foo.od"); assertEquals("FilterServlet", result.toString()); // Check filter is only called once result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.do"); assertEquals("FilterServlet", result.toString()); result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.od"); assertEquals("FilterServlet", result.toString()); // Check dispatcher mapping result = getUrl("http://localhost:" + getPort() + "/bug49922/target"); assertEquals("Target", result.toString()); result = getUrl("http://localhost:" + getPort() + "/bug49922/forward"); assertEquals("FilterTarget", result.toString()); result = getUrl("http://localhost:" + getPort() + "/bug49922/include"); assertEquals("IncludeFilterTarget", result.toString()); }
Example 17
Source File: AbstractOIDCTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(int port, String servletContextName, String fedizConfigPath) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); Path targetDir = Paths.get("target").toAbsolutePath(); server.setBaseDir(targetDir.toString()); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(port); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("keystorePass", "tompass"); if (null == servletContextName) { // IDP server.getHost().setAppBase("tomcat/idp/webapps"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("clientAuth", "want"); Path stsWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.toString()); Path idpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.toString()); } else { // RP server.getHost().setAppBase("tomcat/rp/webapps"); httpsConnector.setAttribute("clientAuth", "false"); Path rpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve(servletContextName); Context ctx = server.addWebapp(servletContextName, rpWebapp.toString()); // Substitute the IDP port. Necessary if running the test in eclipse where port filtering doesn't seem // to work Path fedizConfig = targetDir.resolve("tomcat").resolve(fedizConfigPath); try (InputStream is = AbstractOIDCTest.class.getResourceAsStream('/' + fedizConfigPath)) { byte[] content = new byte[is.available()]; is.read(content); Files.write(fedizConfig, new String(content).replace("${idp.https.port}", Integer.toString(IDP_HTTPS_PORT)).getBytes()); } if (!fedizConfigPath.contains("spring")) { FederationAuthenticator fa = new FederationAuthenticator(); fa.setConfigFile(fedizConfig.toString()); ctx.getPipeline().addValve(fa); } // callback ctx = server.addContext("", null); final String callbackName = "callback"; Tomcat.addServlet(ctx, callbackName, new CallbackServlet()); ctx.addServletMappingDecoded(CALLBACK_CONTEXT, callbackName); final String logoutName = "logout"; Tomcat.addServlet(ctx, logoutName, new LogoutServlet()); ctx.addServletMappingDecoded(LOGOUT_CONTEXT, logoutName); } server.getService().addConnector(httpsConnector); server.start(); return server; }
Example 18
Source File: TestDefaultServlet.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Test public void testGetWithSubpathmount() throws Exception { Tomcat tomcat = getTomcatInstance(); String contextPath = "/examples"; File appDir = new File(getBuildDirectory(), "webapps" + contextPath); // app dir is relative to server home org.apache.catalina.Context ctx = tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); ctx.addApplicationListener(WsContextListener.class.getName()); // Override the default servlet with our own mappings Tomcat.addServlet(ctx, "default2", new DefaultServlet()); ctx.addServletMappingDecoded("/", "default2"); ctx.addServletMappingDecoded("/servlets/*", "default2"); ctx.addServletMappingDecoded("/static/*", "default2"); tomcat.start(); final ByteChunk res = new ByteChunk(); // Make sure DefaultServlet isn't exposing special directories // by remounting the webapp under a sub-path int rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/web.xml", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/doesntexistanywhere", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/WEB-INF/", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/META-INF/MANIFEST.MF", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/META-INF/doesntexistanywhere", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); // Make sure DefaultServlet is serving resources relative to the // context root regardless of where the it is mapped final ByteChunk rootResource = new ByteChunk(); rc =getUrl("http://localhost:" + getPort() + contextPath + "/index.html", rootResource, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); final ByteChunk subpathResource = new ByteChunk(); rc =getUrl("http://localhost:" + getPort() + contextPath + "/servlets/index.html", subpathResource, null); Assert.assertEquals(HttpServletResponse.SC_OK, rc); Assert.assertFalse(rootResource.toString().equals(subpathResource.toString())); rc =getUrl("http://localhost:" + getPort() + contextPath + "/static/index.html", res, null); Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc); }
Example 19
Source File: TestELInterpreterFactory.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Test public void testBug54239() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ServletContext context = ctx.getServletContext(); ELInterpreter interpreter = ELInterpreterFactory.getELInterpreter(context); Assert.assertNotNull(interpreter); Assert.assertTrue(interpreter instanceof DefaultELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); context.setAttribute(ELInterpreter.class.getName(), SimpleELInterpreter.class.getName()); interpreter = ELInterpreterFactory.getELInterpreter(context); Assert.assertNotNull(interpreter); Assert.assertTrue(interpreter instanceof SimpleELInterpreter); context.removeAttribute(ELInterpreter.class.getName()); SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter(); context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter); interpreter = ELInterpreterFactory.getELInterpreter(context); Assert.assertNotNull(interpreter); Assert.assertTrue(interpreter instanceof SimpleELInterpreter); Assert.assertTrue(interpreter == simpleInterpreter); context.removeAttribute(ELInterpreter.class.getName()); ctx.stop(); ctx.addApplicationListener(Bug54239Listener.class.getName()); ctx.start(); interpreter = ELInterpreterFactory.getELInterpreter(ctx.getServletContext()); Assert.assertNotNull(interpreter); Assert.assertTrue(interpreter instanceof SimpleELInterpreter); }
Example 20
Source File: AbstractRecommenderRestTest.java From TeaStore with Apache License 2.0 | 4 votes |
/** * Sets up a registry, a persistance unit and a store. * * @throws Throwable * Throws uncaught throwables for test to fail. */ @Before public void setup() throws Throwable { persistence = new MockPersistenceProvider(persistenceWireMockRule); otherrecommender = new MockOtherRecommenderProvider(otherRecommenderWireMockRule); setRegistry(new MockRegistry(registryWireMockRule, Arrays.asList(getPersistence().getPort()), Arrays.asList(RECOMMENDER_TEST_PORT, otherrecommender.getPort()))); // debuggging response // Response response1 = ClientBuilder // .newBuilder().build().target("http://localhost:" + otherrecommender.getPort() // + "/" // + Service.RECOMMENDER.getServiceName() + "/rest/train/timestamp") // .request(MediaType.APPLICATION_JSON).get(); // System.out.println(response1.getStatus() + ":" + // response1.readEntity(String.class)); // debuggging response // Response response0 = ClientBuilder.newBuilder().build() // .target("http://localhost:" + MockRegistry.DEFAULT_MOCK_REGISTRY_PORT // + "/tools.descartes.teastore.registry/rest/services/" // + Service.PERSISTENCE.getServiceName() + "/") // .request(MediaType.APPLICATION_JSON).get(); // System.out.println(response0.getStatus() + ":" + // response0.readEntity(String.class)); // // Response response1 = ClientBuilder.newBuilder().build() // .target("http://localhost:" + persistence.getPort() // + "/tools.descartes.teastore.persistence/rest/orderitems") // .request(MediaType.APPLICATION_JSON).get(); // System.out.println(response1.getStatus() + ":" + // response1.readEntity(String.class)); // Setup recommend tomcat testTomcat = new Tomcat(); testTomcat.setPort(RECOMMENDER_TEST_PORT); testTomcat.setBaseDir(testWorkingDir); testTomcat.enableNaming(); Context context = testTomcat.addWebapp("/" + Service.RECOMMENDER.getServiceName(), testWorkingDir); ContextEnvironment registryURL3 = new ContextEnvironment(); registryURL3.setDescription(""); registryURL3.setOverride(false); registryURL3.setType("java.lang.String"); registryURL3.setName("registryURL"); registryURL3.setValue( "http://localhost:" + registry.getPort() + "/tools.descartes.teastore.registry/rest/services/"); context.getNamingResources().addEnvironment(registryURL3); ContextEnvironment servicePort3 = new ContextEnvironment(); servicePort3.setDescription(""); servicePort3.setOverride(false); servicePort3.setType("java.lang.String"); servicePort3.setName("servicePort"); servicePort3.setValue("" + RECOMMENDER_TEST_PORT); context.getNamingResources().addEnvironment(servicePort3); ResourceConfig restServletConfig3 = new ResourceConfig(); restServletConfig3.register(TrainEndpoint.class); restServletConfig3.register(RecommendEndpoint.class); restServletConfig3.register(RecommendSingleEndpoint.class); ServletContainer restServlet3 = new ServletContainer(restServletConfig3); testTomcat.addServlet("/" + Service.RECOMMENDER.getServiceName(), "restServlet", restServlet3); context.addServletMappingDecoded("/rest/*", "restServlet"); context.addApplicationListener(RecommenderStartup.class.getName()); ContextEnvironment recommender = new ContextEnvironment(); recommender.setDescription(""); recommender.setOverride(false); recommender.setType("java.lang.String"); recommender.setName("recommenderAlgorithm"); recommender.setValue("PreprocessedSlopeOne"); context.getNamingResources().addEnvironment(recommender); ContextEnvironment retrainlooptime = new ContextEnvironment(); retrainlooptime.setDescription(""); retrainlooptime.setOverride(false); retrainlooptime.setType("java.lang.Long"); retrainlooptime.setName("recommenderLoopTime"); retrainlooptime.setValue("100"); context.getNamingResources().addEnvironment(retrainlooptime); testTomcat.start(); try { Thread.sleep(5000); } catch (InterruptedException e) { } }