Search in sources :

Example 86 with Request

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);
}
Also used : Response(org.eclipse.jetty.server.Response) HashMap(java.util.HashMap) Request(org.eclipse.jetty.server.Request) ServletException(javax.servlet.ServletException)

Example 87 with Request

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;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler)

Example 88 with Request

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;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler)

Example 89 with Request

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);
}
Also used : Request(org.eclipse.jetty.server.Request) Test(org.junit.Test)

Example 90 with Request

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Aggregations

Request (org.eclipse.jetty.server.Request)297 HttpServletRequest (javax.servlet.http.HttpServletRequest)250 HttpServletResponse (javax.servlet.http.HttpServletResponse)225 Test (org.junit.Test)177 IOException (java.io.IOException)169 ServletException (javax.servlet.ServletException)150 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)147 CountDownLatch (java.util.concurrent.CountDownLatch)66 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)64 InterruptedIOException (java.io.InterruptedIOException)45 Server (org.eclipse.jetty.server.Server)41 InputStream (java.io.InputStream)37 AtomicReference (java.util.concurrent.atomic.AtomicReference)35 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Response (org.eclipse.jetty.client.api.Response)27 Result (org.eclipse.jetty.client.api.Result)27 ServletInputStream (javax.servlet.ServletInputStream)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 ServletOutputStream (javax.servlet.ServletOutputStream)23 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)23