Search in sources :

Example 26 with RequestTraceSpan

use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.

the class RequestTraceTest method testStarting.

@Test
public void testStarting() {
    assertFalse(trace.isStarted());
    RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "StartEvent");
    trace.addEvent(re);
    assertTrue(trace.isStarted());
    assertEquals(1, trace.getTraceSpans().size());
    assertTrue(trace.getTraceSpans().contains(re));
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) Test(org.junit.Test)

Example 27 with RequestTraceSpan

use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.

the class RequestTraceTest method testEnding.

@Test
public void testEnding() throws InterruptedException {
    assertFalse(trace.isStarted());
    RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "StartEvent");
    trace.addEvent(re);
    assertEquals(0, trace.getElapsedTime());
    Thread.sleep(10);
    trace.endTrace();
    // add one after trace end
    re = new RequestTraceSpan("TestEvent");
    trace.addEvent(re);
    assertTrue(trace.getElapsedTime() > 0);
    assertEquals("Trace should not add events after end.", 1, trace.getTraceSpans().size());
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) Test(org.junit.Test)

Example 28 with RequestTraceSpan

use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.

the class RequestTraceTest method testAddEventWithoutStarting.

/**
 * Test of addEvent method, of class RequestTrace.
 */
@Test
public void testAddEventWithoutStarting() {
    trace = new RequestTrace();
    RequestTraceSpan re = new RequestTraceSpan("TestEvent");
    trace.addEvent(re);
    assertFalse(trace.isStarted());
    assertFalse(trace.getTraceSpans().contains(this));
    assertEquals(0, trace.getTraceSpans().size());
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) RequestTrace(fish.payara.notification.requesttracing.RequestTrace) Test(org.junit.Test)

Example 29 with RequestTraceSpan

use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.

the class StandardWrapper method constructServletRequestSpan.

private RequestTraceSpan constructServletRequestSpan(HttpServletRequest httpServletRequest, Servlet serv) {
    RequestTraceSpan span = new RequestTraceSpan("processServletRequest");
    span.addSpanTag("URL", httpServletRequest.getRequestURL().toString());
    Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        span.addSpanTag(headerName, list(httpServletRequest.getHeaders(headerName)).toString());
    }
    span.addSpanTag("Method", httpServletRequest.getMethod());
    span.addSpanTag("QueryString", httpServletRequest.getQueryString());
    span.addSpanTag("Class", serv.getClass().getCanonicalName());
    return span;
}
Also used : RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan)

Example 30 with RequestTraceSpan

use of fish.payara.notification.requesttracing.RequestTraceSpan in project Payara by payara.

the class StandardWrapper method service.

// START IASRI 4665318
/**
 * Wrapper for the service method on the actual servlet
 * @param request The request sent
 * @param response
 * @param servlet The servlet to process
 * @throws IOException
 * @throws ServletException
 * @see Servlet#service(ServletRequest, ServletResponse)
 */
void service(ServletRequest request, ServletResponse response, Servlet servlet) throws IOException, ServletException {
    InstanceSupport supp = getInstanceSupport();
    try {
        supp.fireInstanceEvent(BEFORE_SERVICE_EVENT, servlet, request, response);
        if (!isAsyncSupported()) {
            RequestFacadeHelper reqFacHelper = RequestFacadeHelper.getInstance(request);
            if (reqFacHelper != null) {
                reqFacHelper.disableAsyncSupport();
            }
        }
        if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
            if (SecurityUtil.executeUnderSubjectDoAs()) {
                final ServletRequest req = request;
                final ServletResponse res = response;
                Principal principal = ((HttpServletRequest) req).getUserPrincipal();
                Object[] serviceType = new Object[2];
                serviceType[0] = req;
                serviceType[1] = res;
                SecurityUtil.doAsPrivilege("service", servlet, classTypeUsedInService, serviceType, principal);
            } else {
                RequestTraceSpan span = null;
                if (requestTracing.isRequestTracingEnabled()) {
                    if (servlet instanceof ServletContainer) {
                        span = constructWebServiceRequestSpan((HttpServletRequest) request);
                    } else if (servlet instanceof Servlet) {
                        span = constructServletRequestSpan((HttpServletRequest) request, servlet);
                    }
                }
                try {
                    if (isJspServlet) {
                        isInSuppressFFNFThread.set(true);
                    }
                    servlet.service((HttpServletRequest) request, (HttpServletResponse) response);
                } finally {
                    if (requestTracing.isRequestTracingEnabled() && span != null) {
                        requestTracing.traceSpan(span);
                    }
                    isInSuppressFFNFThread.set(false);
                }
            }
        } else {
            servlet.service(request, response);
        }
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response);
    } catch (IOException e) {
        // Set response status before firing event, see IT 10022
        if (response instanceof HttpServletResponse) {
            ((HttpServletResponse) response).setStatus(SC_INTERNAL_SERVER_ERROR);
        }
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response, e);
        throw e;
    } catch (ServletException e) {
        // Set response status before firing event, see IT 10022
        if (response instanceof HttpServletResponse) {
            ((HttpServletResponse) response).setStatus(SC_INTERNAL_SERVER_ERROR);
        }
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response, e);
        throw e;
    } catch (RuntimeException e) {
        // Set response status before firing event, see IT 10022
        if (response instanceof HttpServletResponse) {
            ((HttpServletResponse) response).setStatus(SC_INTERNAL_SERVER_ERROR);
        }
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response, e);
        throw e;
    } catch (Error e) {
        // Set response status before firing event, see IT 10022
        if (response instanceof HttpServletResponse) {
            ((HttpServletResponse) response).setStatus(SC_INTERNAL_SERVER_ERROR);
        }
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response, e);
        throw e;
    } catch (Throwable e) {
        // Set response status before firing event, see IT 10022
        ((HttpServletResponse) response).setStatus(SC_INTERNAL_SERVER_ERROR);
        supp.fireInstanceEvent(AFTER_SERVICE_EVENT, servlet, request, response, e);
        throw new ServletException(rb.getString(SERVLET_EXECUTION_EXCEPTION), e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestTraceSpan(fish.payara.notification.requesttracing.RequestTraceSpan) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) ContainerServlet(org.apache.catalina.ContainerServlet) InstanceSupport(org.apache.catalina.util.InstanceSupport) Principal(java.security.Principal)

Aggregations

RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)30 Test (org.junit.Test)13 FaultToleranceService (fish.payara.microprofile.faulttolerance.FaultToleranceService)3 RequestTrace (fish.payara.notification.requesttracing.RequestTrace)3 UUID (java.util.UUID)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 Principal (java.security.Principal)2 ServletException (javax.servlet.ServletException)2 Config (org.eclipse.microprofile.config.Config)2 Endpoint (org.glassfish.webservices.monitoring.Endpoint)2 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)1 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 WebPrincipal (com.sun.enterprise.security.web.integration.WebPrincipal)1 ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)1 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ChronoUnit (java.time.temporal.ChronoUnit)1