use of org.mockserver.proxyservlet.ProxyServlet in project mockserver by mock-server.
the class ServletProxyIntegrationTest method startServer.
@BeforeClass
@SuppressWarnings("deprecation")
public static void startServer() throws Exception {
servletContext = "";
// start server
echoServer = new EchoServer(false);
// wait for server to start up
TimeUnit.MILLISECONDS.sleep(500);
// start proxy (in tomcat)
tomcat = new Tomcat();
tomcat.setBaseDir(new File(".").getCanonicalPath() + File.separatorChar + "tomcat" + (servletContext.length() > 0 ? "_" + servletContext : ""));
// add http port
tomcat.setPort(PROXY_PORT);
Connector defaultConnector = tomcat.getConnector();
defaultConnector.setRedirectPort(PROXY_HTTPS_PORT);
// add https connector
KeyStoreFactory keyStoreFactory = new KeyStoreFactory(configuration(), new MockServerLogger());
keyStoreFactory.loadOrCreateKeyStore();
Connector httpsConnector = new Connector();
httpsConnector.setPort(PROXY_HTTPS_PORT);
httpsConnector.setSecure(true);
httpsConnector.setAttribute("keyAlias", KeyStoreFactory.KEY_STORE_CERT_ALIAS);
httpsConnector.setAttribute("keystorePass", KeyStoreFactory.KEY_STORE_PASSWORD);
httpsConnector.setAttribute("keystoreFile", new File(keyStoreFactory.keyStoreFileName).getAbsoluteFile());
httpsConnector.setAttribute("sslProtocol", "TLS");
httpsConnector.setAttribute("clientAuth", false);
httpsConnector.setAttribute("SSLEnabled", true);
Service service = tomcat.getService();
service.addConnector(httpsConnector);
// add servlet
Context ctx = tomcat.addContext("/" + servletContext, new File(".").getAbsolutePath());
tomcat.addServlet("/" + servletContext, "mockServerServlet", new ProxyServlet());
ctx.addServletMappingDecoded("/*", "mockServerServlet");
ctx.addApplicationListener(ProxyServlet.class.getName());
// start server
tomcat.start();
// start client
mockServerClient = new MockServerClient("localhost", PROXY_PORT, servletContext);
}
use of org.mockserver.proxyservlet.ProxyServlet in project mockserver by mock-server.
the class ServletProxyWithContextPathIntegrationTest method startServer.
@BeforeClass
@SuppressWarnings("deprecation")
public static void startServer() throws Exception {
servletContext = "proxy";
// start server
echoServer = new EchoServer(false);
// wait for server to start up
TimeUnit.MILLISECONDS.sleep(500);
// start proxy (in tomcat)
tomcat = new Tomcat();
tomcat.setBaseDir(new File(".").getCanonicalPath() + File.separatorChar + "tomcat" + (servletContext.length() > 0 ? "_" + servletContext : ""));
// add http port
tomcat.setPort(PROXY_PORT);
Connector defaultConnector = tomcat.getConnector();
defaultConnector.setRedirectPort(PROXY_HTTPS_PORT);
// add https connector
KeyStoreFactory keyStoreFactory = new KeyStoreFactory(configuration(), new MockServerLogger());
keyStoreFactory.loadOrCreateKeyStore();
Connector httpsConnector = new Connector();
httpsConnector.setPort(PROXY_HTTPS_PORT);
httpsConnector.setSecure(true);
httpsConnector.setAttribute("keyAlias", KeyStoreFactory.KEY_STORE_CERT_ALIAS);
httpsConnector.setAttribute("keystorePass", KeyStoreFactory.KEY_STORE_PASSWORD);
httpsConnector.setAttribute("keystoreFile", new File(keyStoreFactory.keyStoreFileName).getAbsoluteFile());
httpsConnector.setAttribute("sslProtocol", "TLS");
httpsConnector.setAttribute("clientAuth", false);
httpsConnector.setAttribute("SSLEnabled", true);
Service service = tomcat.getService();
service.addConnector(httpsConnector);
// add servlet
Context ctx = tomcat.addContext("/" + servletContext, new File(".").getAbsolutePath());
tomcat.addServlet("/" + servletContext, "mockServerServlet", new ProxyServlet());
ctx.addServletMappingDecoded("/*", "mockServerServlet");
ctx.addApplicationListener(ProxyServlet.class.getName());
// start server
tomcat.start();
// start client
mockServerClient = new MockServerClient("localhost", PROXY_PORT, servletContext);
}
Aggregations