use of javax.servlet.Servlet in project undertow by undertow-io.
the class WebSocketServletTest method testText.
@Test
public void testText() throws Exception {
final AtomicBoolean connected = new AtomicBoolean(false);
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentUtils.setupServlet(new ServletInfo("websocket", WebSocketServlet.class, new ImmediateInstanceFactory<Servlet>(new WebSocketServlet(new WebSocketConnectionCallback() {
@Override
public void onConnect(final WebSocketHttpExchange exchange, final WebSocketChannel channel) {
connected.set(true);
channel.getReceiveSetter().set(new AbstractReceiveListener() {
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) throws IOException {
final String string = message.getData();
if (string.equals("hello")) {
WebSockets.sendText("world", channel, null);
} else {
WebSockets.sendText(string, channel, null);
}
}
});
channel.resumeReceives();
}
}))).addMapping("/*"));
final FutureResult latch = new FutureResult();
WebSocketTestClient client = new WebSocketTestClient(io.netty.handler.codec.http.websocketx.WebSocketVersion.V13, new URI("ws://" + NetworkUtils.formatPossibleIpv6Address(DefaultServer.getHostAddress("default")) + ":" + DefaultServer.getHostPort("default") + "/servletContext/"));
client.connect();
client.send(new TextWebSocketFrame(Unpooled.copiedBuffer("hello", US_ASCII)), new FrameChecker(TextWebSocketFrame.class, "world".getBytes(US_ASCII), latch));
latch.getIoFuture().get();
client.destroy();
}
use of javax.servlet.Servlet in project wildfly by wildfly.
the class WebHostService method addWebDeployment.
@Override
public WebDeploymentController addWebDeployment(final WebDeploymentBuilder webDeploymentBuilder) throws Exception {
DeploymentInfo d = new DeploymentInfo();
d.setDeploymentName(webDeploymentBuilder.getContextRoot());
d.setContextPath(webDeploymentBuilder.getContextRoot());
d.setClassLoader(webDeploymentBuilder.getClassLoader());
d.setResourceManager(new FileResourceManager(webDeploymentBuilder.getDocumentRoot().getCanonicalFile(), 1024 * 1024));
d.setIgnoreFlush(false);
for (ServletBuilder servlet : webDeploymentBuilder.getServlets()) {
ServletInfo s;
if (servlet.getServlet() == null) {
s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass());
} else {
s = new ServletInfo(servlet.getServletName(), (Class<? extends Servlet>) servlet.getServletClass(), new ImmediateInstanceFactory<>(servlet.getServlet()));
}
if (servlet.isForceInit()) {
s.setLoadOnStartup(1);
}
s.addMappings(servlet.getUrlMappings());
for (Map.Entry<String, String> param : servlet.getInitParams().entrySet()) {
s.addInitParam(param.getKey(), param.getValue());
}
d.addServlet(s);
}
if (controlPoint != null) {
d.addOuterHandlerChainWrapper(GlobalRequestControllerHandler.wrapper(controlPoint, webDeploymentBuilder.getAllowRequestPredicates()));
}
return new WebDeploymentControllerImpl(d);
}
use of javax.servlet.Servlet in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method testCompletionAwareForSyncButStartAsync.
@Test
public void testCompletionAwareForSyncButStartAsync() throws IOException, ServletException {
Servlet s = mock(Servlet.class);
framework.addInitParameter(ApplicationConfig.RESPONSE_COMPLETION_AWARE, "true");
ReflectorServletProcessor handler = new ReflectorServletProcessor(s);
handler.init(framework.getAtmosphereConfig());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
AtmosphereResponseImpl response = mock(AtmosphereResponseImpl.class);
AtmosphereResourceImpl res = new AtmosphereResourceImpl();
res.initialize(framework.getAtmosphereConfig(), framework.getBroadcasterFactory().get(), request, response, null, null);
res.transport(AtmosphereResource.TRANSPORT.WEBSOCKET);
request.setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, res);
request.setAttribute(FrameworkConfig.INJECTED_ATMOSPHERE_RESOURCE, res);
AsyncContext ac = request.startAsync();
handler.onRequest(res);
verify(response, times(0)).onComplete();
ac.complete();
verify(response, times(1)).onComplete();
}
use of javax.servlet.Servlet in project gitiles by GerritCodeReview.
the class DevServer method createRootedDocServlet.
private Servlet createRootedDocServlet(DebugRenderer renderer, String docRoot) {
File docRepo = new File(docRoot);
FileKey repoKey = FileKey.exact(docRepo, FS.DETECTED);
RepositoryResolver<HttpServletRequest> resolver = (req, name) -> {
try {
return RepositoryCache.open(repoKey, true);
} catch (IOException e) {
throw new RepositoryNotFoundException(repoKey.getFile(), e);
}
};
return new RootedDocServlet(resolver, new RootedDocAccess(docRepo), renderer);
}
use of javax.servlet.Servlet in project gitiles by GerritCodeReview.
the class DevServer method appHandler.
private Handler appHandler() {
DebugRenderer renderer = new DebugRenderer(STATIC_PREFIX, Arrays.asList(cfg.getStringList("gitiles", null, "customTemplates")), sourceRoot.resolve("gitiles-servlet/src/main/resources/com/google/gitiles/templates").toString(), firstNonNull(cfg.getString("gitiles", null, "siteTitle"), "Gitiles"));
String docRoot = cfg.getString("gitiles", null, "docroot");
Servlet servlet;
if (!Strings.isNullOrEmpty(docRoot)) {
servlet = createRootedDocServlet(renderer, docRoot);
} else {
servlet = new GitilesServlet(cfg, renderer, null, null, null, null, null, null, null);
}
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("");
handler.addServlet(new ServletHolder(servlet), "/*");
return handler;
}
Aggregations