Search in sources :

Example 1 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class CrossProcessTransactionStateImpl method writeResponseHeaders.

@Override
public void writeResponseHeaders() {
    if (tx.isIgnore()) {
        return;
    }
    Dispatcher dispatcher = tx.getDispatcher();
    if (dispatcher == null) {
        return;
    }
    try {
        Response response = dispatcher.getResponse();
        long contentLength = -1;
        if (response instanceof ExtendedResponse) {
            contentLength = ((ExtendedResponse) response).getContentLength();
        } else {
            contentLength = tx.getInboundHeaderState().getRequestContentLength();
        }
        processOutboundResponseHeaders(response, contentLength);
    } catch (Throwable e) {
        Agent.LOG.log(Level.FINEST, e, "Error attempting to write response headers in transaction: {0}", tx);
    }
}
Also used : ExtendedResponse(com.newrelic.api.agent.ExtendedResponse) Response(com.newrelic.api.agent.Response) ExtendedResponse(com.newrelic.api.agent.ExtendedResponse) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 2 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class BrowserTransactionStateImpl method canRenderHeaderForJsp.

private boolean canRenderHeaderForJsp() {
    if (!canRenderHeader()) {
        return false;
    }
    Dispatcher dispatcher = tx.getDispatcher();
    if (dispatcher == null || !dispatcher.isWebTransaction()) {
        Agent.LOG.finer("Unable to get browser timing header: transaction is not a web transaction");
        return false;
    }
    try {
        String contentType = dispatcher.getResponse().getContentType();
        if (!isHtml(contentType)) {
            String msg = MessageFormat.format("Unable to inject browser timing header in a JSP: bad content type: {0}", contentType);
            Agent.LOG.finer(msg);
            return false;
        }
    } catch (Exception e) {
        String msg = MessageFormat.format("Unable to inject browser timing header in a JSP: exception getting content type: {0}", e);
        if (Agent.LOG.isLoggable(Level.FINEST)) {
            Agent.LOG.log(Level.FINEST, msg, e);
        } else if (Agent.LOG.isLoggable(Level.FINER)) {
            Agent.LOG.finer(msg);
        }
        return false;
    }
    return true;
}
Also used : Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 3 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class InvocationPoint method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        if (ignoreApdex) {
            Transaction transaction = Transaction.getTransaction(false);
            if (transaction != null) {
                Dispatcher dispatcher = transaction.getDispatcher();
                if (dispatcher != null) {
                    dispatcher.setIgnoreApdex(true);
                    if (Agent.LOG.isLoggable(Level.FINER)) {
                        String msg = MessageFormat.format("Set Ignore apdex to \"{0}\"", true);
                        Agent.LOG.log(Level.FINER, msg, new Exception());
                    }
                }
            }
        }
        Object t = tracerService.getTracer(tracerFactory, classMethodSignature, args[0], (Object[]) args[1]);
        return t;
    } catch (Throwable t) {
        Agent.LOG.log(Level.FINEST, "Tracer invocation error", t);
    }
    return null;
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 4 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class TransactionInboundHeadersTest method testNullDispatcher.

@Test
public void testNullDispatcher() {
    Transaction tx = Transaction.getTransaction();
    Dispatcher dispatcher = Mockito.mock(Dispatcher.class);
    Mockito.when(dispatcher.getRequest()).thenReturn(null);
    tx.setDispatcher(dispatcher);
    InboundHeaderState inboundHeaderState = tx.getInboundHeaderState();
    Assert.assertTrue(inboundHeaderState != null);
    Assert.assertNull(inboundHeaderState.getClientCrossProcessId());
    Assert.assertNull(inboundHeaderState.getUnparsedSyntheticsHeader());
    Assert.assertNull(inboundHeaderState.getReferrerGuid());
}
Also used : Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) Test(org.junit.Test)

Example 5 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class TransactionInboundHeadersTest method TestEmptyRequestHeaders.

@Test
public void TestEmptyRequestHeaders() {
    Transaction tx = Transaction.getTransaction();
    Dispatcher dispatcher = Mockito.mock(Dispatcher.class);
    Request request = Mockito.mock(Request.class);
    Mockito.when(dispatcher.getRequest()).thenReturn(request);
    tx.setDispatcher(dispatcher);
    InboundHeaders requestHeaders = Transaction.getRequestHeaders(tx);
    // Non-null request headers should be deobfuscated.
    Assert.assertEquals(requestHeaders.getClass(), DeobfuscatedInboundHeaders.class);
}
Also used : Request(com.newrelic.api.agent.Request) InboundHeaders(com.newrelic.api.agent.InboundHeaders) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) Test(org.junit.Test)

Aggregations

Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)20 Transaction (com.newrelic.agent.Transaction)11 Test (org.junit.Test)9 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)4 AgentConfig (com.newrelic.agent.config.AgentConfig)2 Tracer (com.newrelic.agent.tracers.Tracer)2 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)2 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)2 TransactionTimer (com.newrelic.agent.transaction.TransactionTimer)2 InboundHeaders (com.newrelic.api.agent.InboundHeaders)2 NewRelicIgnoreTransaction (test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction)2 CrossProcessTransactionState (com.newrelic.agent.CrossProcessTransactionState)1 TransactionData (com.newrelic.agent.TransactionData)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 TransactionNamingPolicy (com.newrelic.agent.transaction.TransactionNamingPolicy)1