use of javax.servlet.http.HttpServlet in project tomcat by apache.
the class TestExpiresFilter method testUseMajorTypeExpiresConfiguration.
@Test
public void testUseMajorTypeExpiresConfiguration() throws Exception {
HttpServlet servlet = new HttpServlet() {
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/json; charset=iso-8859-1");
response.getWriter().print("Hello world");
}
};
validate(servlet, Integer.valueOf(7 * 60));
}
use of javax.servlet.http.HttpServlet in project hive by apache.
the class HttpServer method initializeWebServer.
void initializeWebServer(Builder b) {
// Create the thread pool for the web server to handle HTTP requests
QueuedThreadPool threadPool = new QueuedThreadPool();
if (b.maxThreads > 0) {
threadPool.setMaxThreads(b.maxThreads);
}
threadPool.setDaemon(true);
threadPool.setName(b.name + "-web");
webServer.setThreadPool(threadPool);
// Create the channel connector for the web server
Connector connector = createChannelConnector(threadPool.getMaxThreads(), b);
connector.setHost(b.host);
connector.setPort(b.port);
webServer.addConnector(connector);
RewriteHandler rwHandler = new RewriteHandler();
rwHandler.setRewriteRequestURI(true);
rwHandler.setRewritePathInfo(false);
RewriteRegexRule rootRule = new RewriteRegexRule();
rootRule.setRegex("^/$");
rootRule.setReplacement(b.contextRootRewriteTarget);
rootRule.setTerminating(true);
rwHandler.addRule(rootRule);
rwHandler.setHandler(webAppContext);
// Configure web application contexts for the web server
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.addHandler(rwHandler);
webServer.setHandler(contexts);
addServlet("jmx", "/jmx", JMXJsonServlet.class);
addServlet("conf", "/conf", ConfServlet.class);
addServlet("stacks", "/stacks", StackServlet.class);
for (Pair<String, Class<? extends HttpServlet>> p : b.servlets) {
addServlet(p.getFirst(), "/" + p.getFirst(), p.getSecond());
}
ServletContextHandler staticCtx = new ServletContextHandler(contexts, "/static");
staticCtx.setResourceBase(appDir + "/static");
staticCtx.addServlet(DefaultServlet.class, "/*");
staticCtx.setDisplayName("static");
String logDir = getLogDir(b.conf);
if (logDir != null) {
ServletContextHandler logCtx = new ServletContextHandler(contexts, "/logs");
setContextAttributes(logCtx.getServletContext(), b.contextAttrs);
logCtx.addServlet(AdminAuthorizedServlet.class, "/*");
logCtx.setResourceBase(logDir);
logCtx.setDisplayName("logs");
}
}
use of javax.servlet.http.HttpServlet in project Openfire by igniterealtime.
the class PluginServlet method handleDevJSP.
/**
* Handles a request for a JSP page in development mode. If development mode is
* not enabled, this method returns false so that normal JSP handling can be performed.
* If development mode is enabled, this method tries to locate the JSP, compile
* it using JSPC, and then return the output.
*
* @param pathInfo the extra path info.
* @param request the request object.
* @param response the response object.
* @return true if this page request was handled; false if the request was not handled.
*/
private boolean handleDevJSP(String pathInfo, HttpServletRequest request, HttpServletResponse response) {
String jspURL = pathInfo.substring(1);
// Handle pre-existing pages and fail over to pre-compiled pages.
int fileSeperator = jspURL.indexOf("/");
if (fileSeperator != -1) {
String pluginName = jspURL.substring(0, fileSeperator);
Plugin plugin = pluginManager.getPlugin(pluginName);
PluginDevEnvironment environment = pluginManager.getDevEnvironment(plugin);
// If development mode not turned on for plugin, return false.
if (environment == null) {
return false;
}
File webDir = environment.getWebRoot();
if (webDir == null || !webDir.exists()) {
return false;
}
File pluginDirectory = pluginManager.getPluginDirectory(plugin);
File compilationDir = new File(pluginDirectory, "classes");
compilationDir.mkdirs();
String jsp = jspURL.substring(fileSeperator + 1);
int indexOfLastSlash = jsp.lastIndexOf("/");
String relativeDir = "";
if (indexOfLastSlash != -1) {
relativeDir = jsp.substring(0, indexOfLastSlash);
relativeDir = relativeDir.replaceAll("//", ".") + '.';
}
File jspFile = new File(webDir, jsp);
String filename = jspFile.getName();
int indexOfPeriod = filename.indexOf(".");
if (indexOfPeriod != -1) {
filename = "dev" + StringUtils.randomString(4);
}
JspC jspc = new JspC();
if (!jspFile.exists()) {
return false;
}
try {
jspc.setJspFiles(jspFile.getCanonicalPath());
} catch (IOException e) {
Log.error(e.getMessage(), e);
}
jspc.setOutputDir(compilationDir.getAbsolutePath());
jspc.setClassName(filename);
jspc.setCompile(true);
jspc.setClassPath(getClasspathForPlugin(plugin));
jspc.execute();
try {
Object servletInstance = pluginManager.loadClass(plugin, "org.apache.jsp." + relativeDir + filename).newInstance();
HttpServlet servlet = (HttpServlet) servletInstance;
servlet.init(servletConfig);
servlet.service(request, response);
return true;
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
return false;
}
use of javax.servlet.http.HttpServlet in project druid by druid-io.
the class AsyncQueryForwardingServletTest method makeTestDeleteServer.
private static Server makeTestDeleteServer(int port, final CountDownLatch latch) {
Server server = new Server(port);
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(new HttpServlet() {
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
latch.countDown();
resp.setStatus(200);
}
}), "/default/*");
server.setHandler(handler);
return server;
}
use of javax.servlet.http.HttpServlet in project OpenAM by OpenRock.
the class RestEndpointServletTest method shouldHandleRequestWithRestletServlet.
@Test(dataProvider = "restletPaths", enabled = false)
public void shouldHandleRequestWithRestletServlet(String path, HttpServlet servlet) throws Exception {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
given(request.getHeaderNames()).willReturn(Collections.enumeration(Collections.<String>emptySet()));
given(request.getAttributeNames()).willReturn(Collections.enumeration(Collections.<String>emptySet()));
given(request.getServletPath()).willReturn(path);
restEndpointServlet.init();
//When
restEndpointServlet.service(request, response);
//Then
verify(servlet).service(Matchers.<HttpServletRequest>anyObject(), eq(response));
for (HttpServlet s : Arrays.asList(restletXACMLHttpServlet, restletOAuth2ServiceServlet, restletUMAServiceServlet)) {
if (s != servlet) {
verifyZeroInteractions(s);
}
}
}
Aggregations