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