use of org.eclipse.jetty.server.Request in project uavstack by uavorg.
the class JettyPlusIT method onServiceEnd.
/**
* onServiceEnd
*
* @param args
*/
public void onServiceEnd(Object... args) {
final Request request = (Request) args[0];
final Response response = (Response) args[1];
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL, request.getRequestURL().toString());
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_SERVLET, request.getServletPath());
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT, request.getContextPath());
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT_REALPATH, request.getServletContext().getRealPath(""));
} catch (NoSuchMethodError er) {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CONTEXT_REALPATH, request.getRealPath(""));
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSECODE, response.getStatus());
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_FORWARDADDR, request.getHeader("X-Forwarded-For"));
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_LISTENPORT, request.getLocalPort());
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CLIENT_USRAGENT, request.getHeader("User-Agent"));
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_UAVCLIENT_TAG, request.getHeader("UAV-Client-Src"));
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_PROXY_HOST, request.getHeader("Host"));
} catch (Exception e) {
}
try {
params.put(CaptureConstants.INFO_APPSERVER_CONNECTOR_CLIENTADDR, request.getRemoteAddr());
} catch (Exception e) {
}
UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_SERVER_CONNECTOR, Monitor.CapturePhase.DOCAP, params);
}
use of org.eclipse.jetty.server.Request in project apollo by ctripcorp.
the class ConfigIntegrationTest method mockPollNotificationHandler.
private ContextHandler mockPollNotificationHandler(final long pollResultTimeOutInMS, final int statusCode, final List<ApolloConfigNotification> result, final boolean failedAtFirstTime) {
ContextHandler context = new ContextHandler("/notifications/v2");
context.setHandler(new AbstractHandler() {
AtomicInteger counter = new AtomicInteger(0);
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (failedAtFirstTime && counter.incrementAndGet() == 1) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
baseRequest.setHandled(true);
return;
}
try {
TimeUnit.MILLISECONDS.sleep(pollResultTimeOutInMS);
} catch (InterruptedException e) {
}
response.setContentType("application/json;charset=UTF-8");
response.setStatus(statusCode);
response.getWriter().println(gson.toJson(result));
baseRequest.setHandled(true);
}
});
return context;
}
use of org.eclipse.jetty.server.Request in project apollo by ctripcorp.
the class ConfigIntegrationTest method mockConfigServerHandler.
private ContextHandler mockConfigServerHandler(final int statusCode, final ApolloConfig result, final boolean failedAtFirstTime) {
ContextHandler context = new ContextHandler("/configs/*");
context.setHandler(new AbstractHandler() {
AtomicInteger counter = new AtomicInteger(0);
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (failedAtFirstTime && counter.incrementAndGet() == 1) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
baseRequest.setHandled(true);
return;
}
response.setContentType("application/json;charset=UTF-8");
response.setStatus(statusCode);
response.getWriter().println(gson.toJson(result));
baseRequest.setHandled(true);
}
});
return context;
}
use of org.eclipse.jetty.server.Request in project gocd by gocd.
the class BackupFilterTest method shouldGenerateHTMLResponseWhenBackupIsBeingTakenAndMessageJsonIsCalled.
@Test
public void shouldGenerateHTMLResponseWhenBackupIsBeingTakenAndMessageJsonIsCalled() throws Exception {
when(backupService.isBackingUp()).thenReturn(true);
when(backupService.backupRunningSinceISO8601()).thenReturn(BACKUP_STARTED_AT);
when(backupService.backupStartedBy()).thenReturn(BACKUP_STARTED_BY);
String content = IOUtils.toString(inputStream, UTF_8);
content = backupFilter.replaceStringLiterals(content);
Request request = request(HttpMethod.GET, "", "/go/server/messages.json");
backupFilter.doFilter(request, res, chain);
verify(res, times(1)).setContentType("text/html");
verify(writer).print(content);
verify(res).setHeader("Cache-Control", "private, max-age=0, no-cache");
verify(res).setDateHeader("Expires", 0);
}
use of org.eclipse.jetty.server.Request in project gocd by gocd.
the class DeploymentContextWriterTest method shouldSetSecureSiteURLWhenSiteUrlIsConfigured.
@Test
public void shouldSetSecureSiteURLWhenSiteUrlIsConfigured() throws URISyntaxException {
final ServerConfigService serverConfigService = mock(ServerConfigService.class);
when(serverConfigService.hasAnyUrlConfigured()).thenReturn(true);
when(serverConfigService.siteUrlFor("http://url/go/admin?tab=oAuth", true)).thenReturn("https://url/go/admin?tab=oAuth");
Request request = new Request(mock(HttpChannel.class), mock(HttpInput.class));
request.setUri(new HttpURI("/go/admin?tab=oAuth"));
request.setServerName("url");
DeploymentContextWriter writer = new DeploymentContextWriter() {
@Override
protected BaseUrlProvider getBaseUrlProvider(HttpServletRequest req) {
return serverConfigService;
}
};
writer.writeSecureSiteUrl(request);
assertThat(request.getAttribute("secure_site"), is("https://url/go/admin?tab=oAuth"));
assertThat(request.getAttribute("force_ssl"), is("true"));
}
Aggregations