use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.
the class TestJettyJspServlet method setUp.
@Before
public void setUp() throws Exception {
JspFactory.setDefaultFactory(new JspFactoryImpl());
_dir = MavenTestingUtils.getTestResourceDir("base");
_tester = new ServletTester("/context");
_tester.getContext().setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
ServletHolder jspHolder = _tester.getContext().addServlet(JettyJspServlet.class, "/*");
jspHolder.setInitParameter("scratchdir", MavenTestingUtils.getTargetTestingDir().getAbsolutePath());
_tester.getContext().setResourceBase(_dir.getAbsolutePath());
_tester.getContext().setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
ServletHolder dfltHolder = new ServletHolder();
dfltHolder.setName("default");
dfltHolder.setHeldClass(DfltServlet.class);
_tester.getContext().addServlet(dfltHolder, "/");
_tester.start();
}
use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.
the class ProxyServer method main.
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8888);
server.addConnector(connector);
// Setup proxy handler to handle CONNECT methods
ConnectHandler proxy = new ConnectHandler();
server.setHandler(proxy);
// Setup proxy servlet
ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
ServletHolder proxyServlet = new ServletHolder(ProxyServlet.class);
proxyServlet.setInitParameter("blackList", "www.eclipse.org");
context.addServlet(proxyServlet, "/*");
server.start();
}
use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.
the class FastCGIProxyServletTest method prepare.
public void prepare(HttpServlet servlet) throws Exception {
QueuedThreadPool serverThreads = new QueuedThreadPool();
serverThreads.setName("server");
server = new Server(serverThreads);
httpConnector = new ServerConnector(server);
server.addConnector(httpConnector);
fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration(), sendStatus200));
server.addConnector(fcgiConnector);
final String contextPath = "/";
context = new ServletContextHandler(server, contextPath);
final String servletPath = "/script";
FastCGIProxyServlet fcgiServlet = new FastCGIProxyServlet() {
@Override
protected String rewriteTarget(HttpServletRequest request) {
return "http://localhost:" + fcgiConnector.getLocalPort() + servletPath + request.getServletPath();
}
};
ServletHolder fcgiServletHolder = new ServletHolder(fcgiServlet);
fcgiServletHolder.setName("fcgi");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_ROOT_INIT_PARAM, "/scriptRoot");
fcgiServletHolder.setInitParameter("proxyTo", "http://localhost");
fcgiServletHolder.setInitParameter(FastCGIProxyServlet.SCRIPT_PATTERN_INIT_PARAM, "(.+?\\.php)");
context.addServlet(fcgiServletHolder, "*.php");
context.addServlet(new ServletHolder(servlet), servletPath + "/*");
QueuedThreadPool clientThreads = new QueuedThreadPool();
clientThreads.setName("client");
client = new HttpClient();
client.setExecutor(clientThreads);
server.addBean(client);
server.start();
}
use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.
the class FastCGIProxyServletTest method testURIRewrite.
@Test
public void testURIRewrite() throws Exception {
String originalPath = "/original/index.php";
String originalQuery = "foo=bar";
String remotePath = "/remote/index.php";
prepare(new HttpServlet() {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Assert.assertThat((String) request.getAttribute(FCGI.Headers.REQUEST_URI), Matchers.startsWith(originalPath));
Assert.assertEquals(originalQuery, request.getAttribute(FCGI.Headers.QUERY_STRING));
Assert.assertThat(request.getRequestURI(), Matchers.endsWith(remotePath));
}
});
context.stop();
String pathAttribute = "_path_attribute";
String queryAttribute = "_query_attribute";
ServletHolder fcgi = context.getServletHandler().getServlet("fcgi");
fcgi.setInitParameter(FastCGIProxyServlet.ORIGINAL_URI_ATTRIBUTE_INIT_PARAM, pathAttribute);
fcgi.setInitParameter(FastCGIProxyServlet.ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM, queryAttribute);
context.insertHandler(new HandlerWrapper() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (target.startsWith("/remote/")) {
request.setAttribute(pathAttribute, originalPath);
request.setAttribute(queryAttribute, originalQuery);
}
super.handle(target, baseRequest, request, response);
}
});
context.start();
ContentResponse response = client.newRequest("localhost", httpConnector.getLocalPort()).path(remotePath).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.servlet.ServletHolder in project jetty.project by eclipse.
the class HttpInputIntegrationTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
__config = new HttpConfiguration();
__server = new Server();
LocalConnector local = new LocalConnector(__server, new HttpConnectionFactory(__config));
local.setIdleTimeout(4000);
__server.addConnector(local);
ServerConnector http = new ServerConnector(__server, new HttpConnectionFactory(__config), new HTTP2CServerConnectionFactory(__config));
http.setIdleTimeout(4000);
__server.addConnector(http);
// SSL Context Factory for HTTPS and HTTP/2
String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
__sslContextFactory = new SslContextFactory();
__sslContextFactory.setKeyStorePath(jetty_distro + "/../../../jetty-server/src/test/config/etc/keystore");
__sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
__sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
// HTTPS Configuration
__sslConfig = new HttpConfiguration(__config);
__sslConfig.addCustomizer(new SecureRequestCustomizer());
// HTTP/1 Connection Factory
HttpConnectionFactory h1 = new HttpConnectionFactory(__sslConfig);
/* TODO
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(__sslConfig);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h1.getProtocol());
*/
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(__sslContextFactory, h1.getProtocol());
// HTTP/2 Connector
ServerConnector http2 = new ServerConnector(__server, ssl, /*TODO alpn,h2,*/
h1);
http2.setIdleTimeout(4000);
__server.addConnector(http2);
ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
ServletHolder holder = new ServletHolder(new TestServlet());
holder.setAsyncSupported(true);
context.addServlet(holder, "/*");
__server.start();
}
Aggregations