use of com.newrelic.api.agent.Response 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.Response 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.api.agent.Response in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImpl method writeResponseHeaders.
@Override
public void writeResponseHeaders() {
if (tx.isIgnore()) {
return;
}
Dispatcher dispatcher = tx.getDispatcher();
if (dispatcher == null) {
return;
}
try {
Response response = dispatcher.getResponse();
long contentLength = -1;
if (response instanceof ExtendedResponse) {
contentLength = ((ExtendedResponse) response).getContentLength();
} else {
contentLength = tx.getInboundHeaderState().getRequestContentLength();
}
processOutboundResponseHeaders(response, contentLength);
} catch (Throwable e) {
Agent.LOG.log(Level.FINEST, e, "Error attempting to write response headers in transaction: {0}", tx);
}
}
use of com.newrelic.api.agent.Response 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.Response 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