Skip to content

Commit

Permalink
NPE fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceko committed Oct 19, 2016
1 parent c552dff commit f17dcf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.lang.String.format;

import uk.gov.justice.metrics.agent.artemis.agent.common.EmptyTimerContext;
import uk.gov.justice.metrics.agent.artemis.agent.common.TimerContext;
import uk.gov.justice.metrics.agent.artemis.agent.common.BaseTimeContextFactory;

Expand All @@ -14,11 +15,12 @@ public class WildflyRestMetricsTimerContextFactory {
private static final BaseTimeContextFactory BASE_TIME_CONTEXT_FACTORY = new BaseTimeContextFactory("wildfly.rest.total");
private static final String URL_PARTS_TO_REMOVE = "/query|/command|/api|/view|/controller|/rest|/$|^/";
private static final String ID_PATTERN = "/[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}|/[0-9][A-Za-z0-9]*";
private static final EmptyTimerContext EMPTY_TIMER_CONTEXT = new EmptyTimerContext();


public static TimerContext timerContextOf(final String requestURL) {
LOGGER.trace("Fetching timer context for rest request: {}", requestURL);
return BASE_TIME_CONTEXT_FACTORY.timerContextOf(timerContextNameFrom(requestURL));
return requestURL != null ? BASE_TIME_CONTEXT_FACTORY.timerContextOf(timerContextNameFrom(requestURL)) : EMPTY_TIMER_CONTEXT;
}

static String timerContextNameFrom(final String requestURL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ public void shouldLogErrorIfExpectedMethodNotFoundInPassedObjectOnExit() {
assertThat(logEntry.getLevel(), is(Level.ERROR));
assertThat((String) logEntry.getMessage(), containsString("Introspection error"));
}


@Test
public void shouldDoNothingWhenRequestUrlNull() {
HttpServerExchange exchange = new HttpServerExchange(null);
agentHelper.onEntry(exchange);
agentHelper.onExit(exchange);

}
}

0 comments on commit f17dcf0

Please sign in to comment.