Search in sources :

Example 1 with WebRequestDispatcher

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

the class Transaction method setWebRequest.

/**
 * Sets the request for the current transaction.
 * Setting the request will convert the current transaction into a web transaction.
 * Successive calls will have no effect (first wins).
 *
 * @param req The current transaction's request.
 */
public void setWebRequest(Request req) {
    final Request request = req == null ? DUMMY_REQUEST : req;
    synchronized (lock) {
        // Set web request at most once.
        if (dispatcher instanceof WebRequestDispatcher) {
            if (DUMMY_REQUEST.equals(dispatcher.getRequest())) {
                dispatcher.setRequest(request);
                Agent.LOG.log(Level.FINEST, "Set web request for transaction {0} to {1}", this, request);
                getInboundHeaderState();
            } else {
                Agent.LOG.log(Level.FINEST, "Not setting web request for transaction {0}. Web request is already set.", this);
            }
        } else {
            Agent.LOG.log(Level.FINEST, "Set web request for transaction {0}", this);
            setDispatcher(new WebRequestDispatcher(request, DUMMY_RESPONSE, this));
        }
    }
}
Also used : Request(com.newrelic.api.agent.Request) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher)

Example 2 with WebRequestDispatcher

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

the class Transaction method setRequestAndResponse.

public void setRequestAndResponse(Request request, Response response) {
    Request req = request == null ? DUMMY_REQUEST : request;
    Response res = response == null ? DUMMY_RESPONSE : response;
    setDispatcher(new WebRequestDispatcher(req, res, this));
}
Also used : Response(com.newrelic.api.agent.Response) WebResponse(com.newrelic.agent.bridge.WebResponse) Request(com.newrelic.api.agent.Request) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher)

Example 3 with WebRequestDispatcher

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

the class Transaction method setWebResponse.

/**
 * Sets the response for the current transaction.
 * Setting the response will convert the current transaction into a web transaction.
 * Successive calls will have no effect (first wins).
 *
 * @param resp The current transaction's response.
 */
public void setWebResponse(Response resp) {
    final Response response = resp == null ? DUMMY_RESPONSE : resp;
    synchronized (lock) {
        // Set web response at most once.
        if (dispatcher instanceof WebRequestDispatcher) {
            if (DUMMY_RESPONSE.equals(dispatcher.getResponse())) {
                dispatcher.setResponse(response);
                Agent.LOG.log(Level.FINEST, "Set web response for transaction {0} to {1}", this, response);
            } else {
                Agent.LOG.log(Level.FINEST, "Not setting web response for transaction {0}. Web response is already set.", this);
            }
        } else {
            Agent.LOG.log(Level.FINEST, "Set web response for transaction {0}. Transaction does not have a corresponding request", this);
            setDispatcher(new WebRequestDispatcher(DUMMY_REQUEST, response, this));
        }
    }
}
Also used : Response(com.newrelic.api.agent.Response) WebResponse(com.newrelic.agent.bridge.WebResponse) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher)

Example 4 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method testHttpHeaders.

@Test
public void testHttpHeaders() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader("Referer", "Referer value");
    httpRequest.setHeader("Accept", "Accept value");
    httpRequest.setHeader("Host", "Host value");
    httpRequest.setHeader("User-Agent", "User-Agent value");
    httpRequest.setHeader("Content-Length", "Content-Length value");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    dispatcher.getTransaction().getTransactionActivity().markAsResponseSender();
    dispatcher.getTransaction().getRootTracer().finish(0, null);
    Map<String, Object> agentAttributes = dispatcher.getTransaction().getAgentAttributes();
    assertEquals("Referer value", agentAttributes.get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME));
    assertEquals("Accept value", agentAttributes.get(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME));
    assertEquals("Host value", agentAttributes.get(AttributeNames.REQUEST_HOST_PARAMETER_NAME));
    assertEquals("User-Agent value", agentAttributes.get(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME));
    assertEquals("Content-Length value", agentAttributes.get(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME));
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 5 with WebRequestDispatcher

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

the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderNoValue.

@Test
public void requestXQueueStartHeaderNoValue() throws Exception {
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "");
    WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
    dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
    Assert.assertEquals(0, dispatcher.getQueueTime());
}
Also used : WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Aggregations

WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)55 Test (org.junit.Test)49 TransactionStats (com.newrelic.agent.stats.TransactionStats)11 Transaction (com.newrelic.agent.Transaction)10 ApdexStats (com.newrelic.agent.stats.ApdexStats)4 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)3 Response (com.newrelic.api.agent.Response)3 HashMap (java.util.HashMap)3 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)3 ConnectionConfigListener (com.newrelic.agent.ConnectionConfigListener)2 MockRPMService (com.newrelic.agent.MockRPMService)2 WebResponse (com.newrelic.agent.bridge.WebResponse)2 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 Request (com.newrelic.api.agent.Request)2 Trace (com.newrelic.api.agent.Trace)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 GenericServlet (javax.servlet.GenericServlet)2