use of com.amazonaws.xray.strategy.FixedSegmentNamingStrategy in project aws-xray-sdk-java by aws.
the class AWSXRayServletFilterTest method testServletUsesPassedInRecorder.
@Test
public void testServletUsesPassedInRecorder() throws IOException, ServletException {
AWSXRayRecorder customRecorder = Mockito.spy(getMockRecorder());
AWSXRayServletFilter servletFilter = new AWSXRayServletFilter(new FixedSegmentNamingStrategy("test"), customRecorder);
AsyncContext asyncContext = mock(AsyncContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
when(request.getMethod()).thenReturn("TEST_METHOD");
when(request.isAsyncStarted()).thenReturn(true);
when(request.getAsyncContext()).thenReturn(asyncContext);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mockChain(request, response);
AsyncEvent event = mock(AsyncEvent.class);
when(event.getSuppliedRequest()).thenReturn(request);
when(event.getSuppliedResponse()).thenReturn(response);
servletFilter.doFilter(request, response, chain);
Assert.assertNull(AWSXRay.getTraceEntity());
AWSXRayServletAsyncListener listener = (AWSXRayServletAsyncListener) Whitebox.getInternalState(servletFilter, "listener");
listener.onComplete(event);
verify(customRecorder.getEmitter(), Mockito.times(1)).sendSegment(Mockito.any());
}
use of com.amazonaws.xray.strategy.FixedSegmentNamingStrategy in project aws-xray-sdk-java by aws.
the class AWSXRayServletAsyncListener method init.
/**
* @param config
* the filter configuration. There are various init-params which may be passed on initialization. The values in init-params will create segment naming strategies which override those passed in constructors.
*
* <ul>
*
* <li>
* <b>fixedName</b> A String value used as the fixedName parameter for a created {@link com.amazonaws.xray.strategy.FixedSegmentNamingStrategy}. Used only if the {@code dynamicNamingFallbackName} init-param is not set.
* </li>
*
* <li>
* <b>dynamicNamingFallbackName</b> A String value used as the fallbackName parameter for a created {@link com.amazonaws.xray.strategy.DynamicSegmentNamingStrategy}.
* </li>
*
* <li>
* <b>dynamicNamingRecognizedHosts</b> A String value used as the recognizedHosts parameter for a created {@link com.amazonaws.xray.strategy.DynamicSegmentNamingStrategy}.
* </li>
*
* </ul>
*
* @throws ServletException
* when a segment naming strategy is not provided in constructor arguments nor in init-params.
*/
@Override
public void init(FilterConfig config) throws ServletException {
String fixedName = config.getInitParameter("fixedName");
String dynamicNamingFallbackName = config.getInitParameter("dynamicNamingFallbackName");
String dynamicNamingRecognizedHosts = config.getInitParameter("dynamicNamingRecognizedHosts");
if (StringValidator.isNotNullOrBlank(dynamicNamingFallbackName)) {
if (StringValidator.isNotNullOrBlank(dynamicNamingRecognizedHosts)) {
segmentNamingStrategy = new DynamicSegmentNamingStrategy(dynamicNamingFallbackName, dynamicNamingRecognizedHosts);
} else {
segmentNamingStrategy = new DynamicSegmentNamingStrategy(dynamicNamingFallbackName);
}
} else if (StringValidator.isNotNullOrBlank(fixedName)) {
segmentNamingStrategy = new FixedSegmentNamingStrategy(fixedName);
} else if (null == segmentNamingStrategy) {
throw new ServletException("The AWSXRayServletFilter requires either a fixedName init-param or an instance of SegmentNamingStrategy. Add an init-param tag to the AWSXRayServletFilter's declaration in web.xml, using param-name: 'fixedName'. Alternatively, pass an instance of SegmentNamingStrategy to the AWSXRayServletFilter constructor.");
}
}
use of com.amazonaws.xray.strategy.FixedSegmentNamingStrategy in project aws-xray-sdk-java by aws.
the class AWSXRayServletFilter method init.
/**
* @param config
* the filter configuration. There are various init-params which may be passed on initialization. The values in init-params
* will create segment naming strategies which override those passed in constructors.
*
* <ul>
*
* <li>
* <b>fixedName</b> A String value used as the fixedName parameter for a created
* {@link com.amazonaws.xray.strategy.FixedSegmentNamingStrategy}. Used only if the {@code dynamicNamingFallbackName}
* init-param is not set.
* </li>
*
* <li>
* <b>dynamicNamingFallbackName</b> A String value used as the fallbackName parameter for a created
* {@link com.amazonaws.xray.strategy.DynamicSegmentNamingStrategy}.
* </li>
*
* <li>
* <b>dynamicNamingRecognizedHosts</b> A String value used as the recognizedHosts parameter for a created
* {@link com.amazonaws.xray.strategy.DynamicSegmentNamingStrategy}.
* </li>
*
* </ul>
*
* @throws ServletException
* when a segment naming strategy is not provided in constructor arguments nor in init-params.
*/
@Override
public void init(FilterConfig config) throws ServletException {
String fixedName = config.getInitParameter("fixedName");
String dynamicNamingFallbackName = config.getInitParameter("dynamicNamingFallbackName");
String dynamicNamingRecognizedHosts = config.getInitParameter("dynamicNamingRecognizedHosts");
if (StringValidator.isNotNullOrBlank(dynamicNamingFallbackName)) {
if (StringValidator.isNotNullOrBlank(dynamicNamingRecognizedHosts)) {
segmentNamingStrategy = new DynamicSegmentNamingStrategy(dynamicNamingFallbackName, dynamicNamingRecognizedHosts);
} else {
segmentNamingStrategy = new DynamicSegmentNamingStrategy(dynamicNamingFallbackName);
}
} else if (StringValidator.isNotNullOrBlank(fixedName)) {
segmentNamingStrategy = new FixedSegmentNamingStrategy(fixedName);
} else if (null == segmentNamingStrategy) {
throw new ServletException("The AWSXRayServletFilter requires either a fixedName init-param or an instance of SegmentNamingStrategy. " + "Add an init-param tag to the AWSXRayServletFilter's declaration in web.xml, using param-name: 'fixedName'. " + "Alternatively, pass an instance of SegmentNamingStrategy to the AWSXRayServletFilter constructor.");
}
}
Aggregations