use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class ServletInputStreamEarlyCloseTestCase method testServletInputStreamEarlyClose.
@Test
public void testServletInputStreamEarlyClose() throws Exception {
DeploymentUtils.setupServlet(new ServletInfo(SERVLET, EarlyCloseServlet.class).addMapping("/" + SERVLET));
TestHttpClient client = new TestHttpClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + SERVLET;
HttpPost post = new HttpPost(uri);
post.setEntity(new StringEntity("A non-empty request body"));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class ServletRegistrationImpl method addMapping.
@Override
public Set<String> addMapping(final String... urlPatterns) {
DeploymentInfo deploymentInfo = deployment.getDeploymentInfo();
final Set<String> ret = new HashSet<>();
final Set<String> existing = new HashSet<>();
for (ServletInfo s : deploymentInfo.getServlets().values()) {
if (!s.getName().equals(servletInfo.getName())) {
existing.addAll(s.getMappings());
}
}
for (String pattern : urlPatterns) {
if (existing.contains(pattern)) {
ret.add(pattern);
}
}
//only update if no changes have been made
if (ret.isEmpty()) {
for (String pattern : urlPatterns) {
if (!servletInfo.getMappings().contains(pattern)) {
servletInfo.addMapping(pattern);
}
}
}
deployment.getServletPaths().invalidate();
return ret;
}
use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class DefaultServletCachingTestCase method setup.
@BeforeClass
public static void setup() throws ServletException, IOException {
tmpDir = Files.createTempDirectory(DIR_NAME);
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760), METADATA_MAX_AGE));
builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default")).addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT ")).addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class DefaultServletTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(DefaultServletTestCase.class));
builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default"));
builder.addServlet(new ServletInfo("default", DefaultServlet.class).addInitParam("directory-listing", "true").addMapping("/*"));
//see UNDERTOW-458
builder.addFilter(new FilterInfo("date-header", GetDateFilter.class));
builder.addFilterUrlMapping("date-header", "/*", DispatcherType.REQUEST);
builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
use of io.undertow.servlet.api.ServletInfo in project undertow by undertow-io.
the class ServletAndResourceWelcomeFileTestCase method setup.
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(ServletAndResourceWelcomeFileTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default");
builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("*.html"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
Aggregations