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());
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations