use of com.developmentontheedge.be5.api.Session in project jetty.project by eclipse.
the class TrailersTest method testTrailersSentByClient.
@Test
public void testTrailersSentByClient() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
start(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Request request = (MetaData.Request) frame.getMetaData();
Assert.assertFalse(frame.isEndStream());
Assert.assertTrue(request.getFields().containsKey("X-Request"));
return new Stream.Listener.Adapter() {
@Override
public void onHeaders(Stream stream, HeadersFrame frame) {
MetaData trailer = frame.getMetaData();
Assert.assertTrue(frame.isEndStream());
Assert.assertTrue(trailer.getFields().containsKey("X-Trailer"));
latch.countDown();
}
};
}
});
Session session = newClient(new Session.Listener.Adapter());
HttpFields requestFields = new HttpFields();
requestFields.put("X-Request", "true");
MetaData.Request request = newRequest("GET", requestFields);
HeadersFrame requestFrame = new HeadersFrame(request, null, false);
FuturePromise<Stream> streamPromise = new FuturePromise<>();
session.newStream(requestFrame, streamPromise, new Stream.Listener.Adapter());
Stream stream = streamPromise.get(5, TimeUnit.SECONDS);
// Send the trailers.
HttpFields trailerFields = new HttpFields();
trailerFields.put("X-Trailer", "true");
MetaData trailers = new MetaData(HttpVersion.HTTP_2, trailerFields);
HeadersFrame trailerFrame = new HeadersFrame(stream.getId(), trailers, null, true);
stream.headers(trailerFrame, Callback.NOOP);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of com.developmentontheedge.be5.api.Session in project be5 by DevelopmentOnTheEdge.
the class AuthenticationPropagationListener method requestInitialized.
@Override
public void requestInitialized(ServletRequestEvent event) {
HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
HttpSession session = request.getSession(false);
if (session == null) {
return;
}
UserInfo user = (UserInfo) session.getAttribute(SessionConstants.USER_INFO);
UserInfoHolder.setUserInfo(user);
}
use of com.developmentontheedge.be5.api.Session in project be5 by DevelopmentOnTheEdge.
the class UserHelper method initGuest.
public void initGuest(Request req) {
Locale locale = Locale.US;
String remoteAddr = "";
Session session;
if (req != null) {
locale = req.getLocale();
remoteAddr = req.getRemoteAddr();
session = req.getSession();
} else {
session = new TestSession();
}
if (ModuleLoader2.getDevRoles().size() > 0) {
saveUser("dev", ModuleLoader2.getDevRoles(), ModuleLoader2.getDevRoles(), locale, remoteAddr, session);
} else {
List<String> roles = Collections.singletonList(RoleType.ROLE_GUEST);
saveUser(RoleType.ROLE_GUEST, roles, roles, locale, remoteAddr, session);
}
}
use of com.developmentontheedge.be5.api.Session in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testLastStreamId.
@Test
public void testLastStreamId() throws Exception {
prepareServer(new RawHTTP2ServerConnectionFactory(new HttpConfiguration(), new ServerSessionListener.Adapter() {
@Override
public Map<Integer, Integer> onPreface(Session session) {
Map<Integer, Integer> settings = new HashMap<>();
settings.put(SettingsFrame.MAX_CONCURRENT_STREAMS, 1);
return settings;
}
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
MetaData.Request request = (MetaData.Request) frame.getMetaData();
if (HttpMethod.HEAD.is(request.getMethod())) {
stream.getSession().close(ErrorCode.REFUSED_STREAM_ERROR.code, null, Callback.NOOP);
} else {
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, HttpStatus.OK_200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
}
return null;
}
}));
server.start();
CountDownLatch latch = new CountDownLatch(2);
AtomicInteger lastStream = new AtomicInteger();
AtomicReference<Stream> streamRef = new AtomicReference<>();
CountDownLatch streamLatch = new CountDownLatch(1);
client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()) {
@Override
protected HttpConnectionOverHTTP2 newHttpConnection(HttpDestination destination, Session session) {
return new HttpConnectionOverHTTP2(destination, session) {
@Override
protected HttpChannelOverHTTP2 newHttpChannel(boolean push) {
return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession(), push) {
@Override
public void setStream(Stream stream) {
super.setStream(stream);
streamRef.set(stream);
streamLatch.countDown();
}
};
}
};
}
@Override
protected void onClose(HttpConnectionOverHTTP2 connection, GoAwayFrame frame) {
super.onClose(connection, frame);
lastStream.set(frame.getLastStreamId());
latch.countDown();
}
}, null);
QueuedThreadPool clientExecutor = new QueuedThreadPool();
clientExecutor.setName("client");
client.setExecutor(clientExecutor);
client.start();
// Prime the connection to allow client and server prefaces to be exchanged.
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).path("/zero").timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
org.eclipse.jetty.client.api.Request request = client.newRequest("localhost", connector.getLocalPort()).method(HttpMethod.HEAD).path("/one");
request.send(result -> {
if (result.isFailed())
latch.countDown();
});
Assert.assertTrue(streamLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Stream stream = streamRef.get();
Assert.assertNotNull(stream);
Assert.assertEquals(lastStream.get(), stream.getId());
}
use of com.developmentontheedge.be5.api.Session in project jetty.project by eclipse.
the class CloseTest method testServerSendsGoAwayClientDoesNotCloseServerIdleTimeout.
@Test
public void testServerSendsGoAwayClientDoesNotCloseServerIdleTimeout() throws Exception {
final long idleTimeout = 1000;
final AtomicReference<Session> sessionRef = new AtomicReference<>();
startServer(new ServerSessionListener.Adapter() {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) {
stream.setIdleTimeout(10 * idleTimeout);
sessionRef.set(stream.getSession());
MetaData.Response response = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
stream.headers(new HeadersFrame(stream.getId(), response, null, true), Callback.NOOP);
stream.getSession().close(ErrorCode.NO_ERROR.code, "OK", Callback.NOOP);
return null;
}
});
connector.setIdleTimeout(idleTimeout);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.control(lease, new PrefaceFrame());
generator.control(lease, new SettingsFrame(new HashMap<>(), false));
MetaData.Request metaData = newRequest("GET", new HttpFields());
generator.control(lease, new HeadersFrame(1, metaData, null, true));
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
OutputStream output = client.getOutputStream();
for (ByteBuffer buffer : lease.getByteBuffers()) {
output.write(BufferUtil.toArray(buffer));
}
final CountDownLatch responseLatch = new CountDownLatch(1);
final CountDownLatch closeLatch = new CountDownLatch(1);
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {
@Override
public void onHeaders(HeadersFrame frame) {
responseLatch.countDown();
}
@Override
public void onGoAway(GoAwayFrame frame) {
closeLatch.countDown();
}
}, 4096, 8192);
parseResponse(client, parser);
Assert.assertTrue(responseLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(closeLatch.await(5, TimeUnit.SECONDS));
// Don't close the connection.
// Wait for the server to idle timeout.
Thread.sleep(2 * idleTimeout);
// Client received the TCP FIN from server.
Assert.assertEquals(-1, client.getInputStream().read());
// Server is closed.
Session session = sessionRef.get();
Assert.assertTrue(session.isClosed());
Assert.assertTrue(((HTTP2Session) session).isDisconnected());
}
}
Aggregations