use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class HttpClientTest method testRequestAfterFailedRequest.
@Test
public void testRequestAfterFailedRequest() throws Exception {
int length = FlowControlStrategy.DEFAULT_WINDOW_SIZE;
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
baseRequest.setHandled(true);
response.getOutputStream().write(new byte[length]);
} catch (IOException e) {
}
}
});
// Make a request with a large enough response buffer.
org.eclipse.jetty.client.api.Request request = client.newRequest(newURI());
FutureResponseListener listener = new FutureResponseListener(request, length);
request.send(listener);
ContentResponse response = listener.get(5, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), 200);
// Make a request with a small response buffer, should fail.
try {
request = client.newRequest(newURI());
listener = new FutureResponseListener(request, length / 10);
request.send(listener);
listener.get(5, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException x) {
Assert.assertThat(x.getMessage(), Matchers.containsString("Buffering capacity exceeded"));
}
// Verify that we can make another request.
request = client.newRequest(newURI());
listener = new FutureResponseListener(request, length);
request.send(listener);
response = listener.get(5, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), 200);
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class HttpClientTest method testOPTIONS.
@Test
public void testOPTIONS() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
Assert.assertTrue(HttpMethod.OPTIONS.is(request.getMethod()));
Assert.assertEquals("*", target);
Assert.assertEquals("*", request.getPathInfo());
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(getScheme()).method(HttpMethod.OPTIONS).path("*").timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.server.Request in project jetty.project by eclipse.
the class HttpClientTest method testOPTIONSWithRelativeRedirect.
@Test
public void testOPTIONSWithRelativeRedirect() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
if ("*".equals(target)) {
// Be nasty and send a relative redirect.
// Code 303 will change the method to GET.
response.setStatus(HttpStatus.SEE_OTHER_303);
response.setHeader("Location", "/");
}
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(getScheme()).method(HttpMethod.OPTIONS).path("*").timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
}
use of org.eclipse.jetty.server.Request in project buck by facebook.
the class PublicAnnouncementManagerIntegrationTest method testAnnouncementsWork.
@Test
public void testAnnouncementsWork() throws Exception {
final AtomicReference<byte[]> requestBody = new AtomicReference<>();
try (HttpdForTests httpd = new HttpdForTests()) {
httpd.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
httpServletResponse.setStatus(200);
request.setHandled(true);
if (request.getUri().getPath().equals("/status.php")) {
return;
}
requestBody.set(ByteStreams.toByteArray(httpServletRequest.getInputStream()));
FrontendRequest thriftRequest = new FrontendRequest();
ThriftUtil.deserialize(ThriftProtocol.BINARY, requestBody.get(), thriftRequest);
assertTrue("Request should contain the repository.", thriftRequest.getAnnouncementRequest().getRepository().equals(REPOSITORY));
try (DataOutputStream out = new DataOutputStream(httpServletResponse.getOutputStream())) {
Announcement announcement = new Announcement();
announcement.setErrorMessage(ERROR_MSG);
announcement.setSolutionMessage(SOLUTION_MSG);
AnnouncementResponse announcementResponse = new AnnouncementResponse();
announcementResponse.setAnnouncements(ImmutableList.of(announcement));
FrontendResponse frontendResponse = new FrontendResponse();
frontendResponse.setType(FrontendRequestType.ANNOUNCEMENT);
frontendResponse.setAnnouncementResponse(announcementResponse);
out.write(ThriftUtil.serialize(ThriftProtocol.BINARY, frontendResponse));
}
}
});
httpd.start();
Clock clock = new DefaultClock();
BuckEventBus eventBus = BuckEventBusFactory.newInstance(clock);
ExecutionEnvironment executionEnvironment = new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties());
BuckConfig buckConfig = new FakeBuckConfig.Builder().setSections(ImmutableMap.of("log", ImmutableMap.of("slb_server_pool", "http://localhost:" + httpd.getRootUri().getPort()))).build();
TestConsole console = new TestConsole();
SuperConsoleEventBusListener listener = new SuperConsoleEventBusListener(new SuperConsoleConfig(FakeBuckConfig.builder().build()), console, clock, /* verbosity */
TestResultSummaryVerbosity.of(false, false), executionEnvironment, Optional.empty(), Locale.US, logPath, TimeZone.getTimeZone("UTC"));
eventBus.register(listener);
PublicAnnouncementManager manager = new PublicAnnouncementManager(clock, eventBus, listener, REPOSITORY, new RemoteLogBuckConfig(buckConfig), MoreExecutors.newDirectExecutorService());
manager.getAndPostAnnouncements();
Optional<String> announcements = listener.getPublicAnnouncements();
assertEquals("The header and the message", announcements.get(), "**-------------------------------**\n" + "**- Sticky Public Announcements -**\n" + "**-------------------------------**\n" + "** This is the error message. This is the solution message.");
}
}
use of org.eclipse.jetty.server.Request in project buck by facebook.
the class IndexHandlerDelegateTest method testIndexHandlerReturnsCorrectTemplateAndData.
@Test
public void testIndexHandlerReturnsCorrectTemplateAndData() throws IOException {
Request baseRequest = EasyMock.createMock(Request.class);
EasyMock.replay(baseRequest);
IndexHandlerDelegate indexHandlerDelegate = new IndexHandlerDelegate();
assertEquals("buck.index", indexHandlerDelegate.getTemplateForRequest(baseRequest));
SoyMapData templateData = indexHandlerDelegate.getDataForRequest(baseRequest);
assertTrue(templateData.getKeys().isEmpty());
EasyMock.verify(baseRequest);
}
Aggregations