Search in sources :

Example 11 with Response

use of com.newrelic.api.agent.Response in project newrelic-java-agent by newrelic.

the class ApiTest method testSetRequestAndResponse.

@Test
public void testSetRequestAndResponse() {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(request, response);
    tracer.finish(0, null);
    Assert.assertEquals(1, txList.size());
    Assert.assertEquals("/mytest", txList.get(0).getRequestUri(AgentConfigImpl.ATTRIBUTES));
    TransactionStats stats = apiTestHelper.tranStats;
    ResponseTimeStats dispatcherStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("HttpDispatcher");
    Assert.assertEquals(1, dispatcherStats.getCallCount());
    Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats("WebTransaction/Uri/mytest").getCallCount());
    Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex/Uri/mytest").getApdexSatisfying());
    Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex").getApdexSatisfying());
    Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.WEB_TRANSACTION).getCallCount());
    Assert.assertEquals(0, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.OTHER_TRANSACTION_ALL).getCallCount());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionStats(com.newrelic.agent.stats.TransactionStats) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 12 with Response

use of com.newrelic.api.agent.Response in project newrelic-java-agent by newrelic.

the class ApiTest method testSetRequestAndResponseThenSetTxName.

@Test
public void testSetRequestAndResponseThenSetTxName() {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(request, response);
    NewRelic.setTransactionName("Test", "Foo");
    tracer.finish(0, null);
    Assert.assertEquals("WebTransaction/Test/Foo", tx.getPriorityTransactionName().getName());
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 13 with Response

use of com.newrelic.api.agent.Response in project newrelic-java-agent by newrelic.

the class ApiTest method nameTransactionThenSetRequestAndResponse.

@Test
public void nameTransactionThenSetRequestAndResponse() {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    tracer.nameTransaction(TransactionNamePriority.CUSTOM_HIGH);
    Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
    Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(request, response);
    tracer.finish(0, null);
    Assert.assertEquals("WebTransaction/Custom/test.newrelic.test.agent.api.ApiTest/", tx.getPriorityTransactionName().getName());
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 14 with Response

use of com.newrelic.api.agent.Response in project newrelic-java-agent by newrelic.

the class OtherTransactionErrorsTest method testException.

@Test
public void testException() throws Exception {
    MockHttpRequest mockHttpRequest = new MockHttpRequest();
    mockHttpRequest.setMethod("GET");
    mockHttpRequest.setRequestURI("requesturi");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME, "accept");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_HOST_PARAMETER_NAME, "host");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME, "useragent");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME, "content-length");
    NewRelic.setRequestAndResponse(mockHttpRequest, new Response() {

        @Override
        public int getStatus() throws Exception {
            return 200;
        }

        @Override
        public String getStatusMessage() throws Exception {
            return "Status Message";
        }

        @Override
        public String getContentType() {
            return "text/content-type";
        }

        @Override
        public HeaderType getHeaderType() {
            return HeaderType.HTTP;
        }

        @Override
        public void setHeader(String name, String value) {
        // 
        }
    });
    try {
        new Runnable() {

            @Trace(dispatcher = true)
            @Override
            public void run() {
                throw new RuntimeException();
            }
        }.run();
    } catch (RuntimeException ex) {
    }
    Assert.assertEquals(1, transactions.size());
    Assert.assertNotNull(transactions.get(0).getThrowable());
}
Also used : Response(com.newrelic.api.agent.Response) Trace(com.newrelic.api.agent.Trace) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) HeaderType(com.newrelic.api.agent.HeaderType) Test(org.junit.Test)

Example 15 with Response

use of com.newrelic.api.agent.Response in project newrelic-java-agent by newrelic.

the class NRServletRequestListener method requestInitialized.

@Override
@CatchAndLog
public void requestInitialized(ServletRequestEvent sre) {
    HttpServletRequest httpServletRequest = getHttpServletRequest(sre);
    if (httpServletRequest != null) {
        if (httpServletRequest.getDispatcherType() == DispatcherType.ASYNC) {
            AsyncContext asyncContext = httpServletRequest.getAsyncContext();
            if (asyncContext != null) {
                AgentBridge.asyncApi.resumeAsync(asyncContext);
                return;
            }
        }
        Response response = getResponse(httpServletRequest);
        AgentBridge.getAgent().getTransaction(true).requestInitialized(getRequest(httpServletRequest), response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IResponse(com.ibm.websphere.servlet.response.IResponse) Response(com.newrelic.api.agent.Response) IExtendedResponse(com.ibm.wsspi.webcontainer.servlet.IExtendedResponse) AsyncContext(javax.servlet.AsyncContext) CatchAndLog(com.newrelic.api.agent.weaver.CatchAndLog)

Aggregations

Response (com.newrelic.api.agent.Response)18 Request (com.newrelic.api.agent.Request)12 Transaction (com.newrelic.agent.Transaction)10 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)10 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)10 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)10 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)10 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)10 Test (org.junit.Test)10 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)8 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 TransactionDataList (com.newrelic.agent.TransactionDataList)5 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)3 WebResponse (com.newrelic.agent.bridge.WebResponse)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2