use of com.newrelic.api.agent.Request 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));
}
}
}
use of com.newrelic.api.agent.Request 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));
}
use of com.newrelic.api.agent.Request 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);
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class ApiCallingAsyncTest method testNaming1.
@Test(timeout = 10000)
public void testNaming1() throws Exception {
final Request req = new Request() {
@Override
public HeaderType getHeaderType() {
return null;
}
@Override
public String getHeader(String name) {
return null;
}
@Override
public String getRequestURI() {
return null;
}
@Override
public String getRemoteUser() {
return null;
}
@Override
public Enumeration<?> getParameterNames() {
return null;
}
@Override
public String[] getParameterValues(String name) {
return null;
}
@Override
public Object getAttribute(String name) {
return null;
}
@Override
public String getCookieValue(String name) {
return null;
}
};
final Response resp = new Response() {
@Override
public HeaderType getHeaderType() {
return null;
}
@Override
public void setHeader(String name, String value) {
}
@Override
public int getStatus() throws Exception {
return 0;
}
@Override
public String getStatusMessage() throws Exception {
return null;
}
@Override
public String getContentType() {
return null;
}
};
// The two threads call APIs in different orders. The purpose of the test is to ensure
// that the same metrics get reported either way.
Thread t1 = new Thread() {
@Override
@Trace(dispatcher = true)
public void run() {
NewRelic.setTransactionName(null, "MyOtherTransaction");
NewRelic.setRequestAndResponse(req, resp);
}
};
t1.start();
t1.join();
TransactionStats s1 = getStats();
Thread t2 = new Thread() {
@Override
@Trace(dispatcher = true)
public void run() {
NewRelic.setRequestAndResponse(req, resp);
NewRelic.setTransactionName(null, "MyOtherTransaction");
}
};
t2.start();
t2.join();
TransactionStats s2 = getStats();
assertSameKeys(s1, s2, new String[] { "Java/com.newrelic.agent.async.ApiCallingAsyncTest\\$\\d/run" });
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class TransactionTimeTest method doWebWork.
@Trace(dispatcher = true)
public void doWebWork() throws InterruptedException {
Request request = new RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
hello1();
}
Aggregations