use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthenticationFilterTest method testNoAuthorizationAttributeInHeader.
@Test(expected = WebApplicationException.class)
public void testNoAuthorizationAttributeInHeader() throws IOException {
// Given
FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
when(mockRequest.getHeaderString("Authorization")).thenReturn(null);
when(mockRequest.getMethod()).thenReturn("GET");
UriInfo mockUriInfo = mock(UriInfo.class);
when(mockUriInfo.getPath()).thenReturn("someURL");
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
faf.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project jaeger-client-java by jaegertracing.
the class FilterIntegrationTest method testExtractorReturnsNullWhenTracerStateHeaderIsMissing.
/*
* This test exists because opentracing's convention around missing tracer
* state headers may change to stop supporting the automatic creation of
* building a span.
*/
@Test
public void testExtractorReturnsNullWhenTracerStateHeaderIsMissing() {
ContainerRequestContext reqContext = mock(ContainerRequestContext.class);
given(reqContext.getHeaders()).willReturn(new MultivaluedHashMap<String, String>());
ServerRequestCarrier carrier = new ServerRequestCarrier(reqContext);
SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, carrier);
assertNull(spanCtx);
}
use of javax.ws.rs.container.ContainerRequestContext in project cxf by apache.
the class WadlGeneratorJsonTest method testWadlInJsonFormat.
@Test
public void testWadlInJsonFormat() throws Exception {
ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(BookChapters.class, BookChapters.class, true, true);
final Message m = mockMessage("http://localhost:8080/baz", "/bookstore/1", WadlGenerator.WADL_QUERY, cri);
Map<String, List<String>> headers = new HashMap<>();
headers.put("Accept", Collections.singletonList("application/json"));
m.put(Message.PROTOCOL_HEADERS, headers);
WadlGenerator wg = new WadlGenerator() {
@Override
public void filter(ContainerRequestContext context) {
super.doFilter(context, m);
}
};
wg.setUseJaxbContextForQnames(false);
wg.setIgnoreMessageWriters(false);
wg.setExternalLinks(Collections.singletonList("json.schema"));
Response r = handleRequest(wg, m);
assertEquals("application/json", r.getMetadata().getFirst("Content-Type").toString());
ByteArrayOutputStream os = new ByteArrayOutputStream();
new JSONProvider<Document>().writeTo((Document) r.getEntity(), Document.class, Document.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
String s = os.toString();
String expected1 = "{\"application\":{\"grammars\":{\"include\":{\"@href\":\"http://localhost:8080/baz" + "/json.schema\"}},\"resources\":{\"@base\":\"http://localhost:8080/baz\"," + "\"resource\":{\"@path\":\"/bookstore/{id}\"";
assertTrue(s.startsWith(expected1));
String expected2 = "\"response\":{\"representation\":[{\"@mediaType\":\"application/xml\"}," + "{\"@element\":\"Chapter\",\"@mediaType\":\"application/json\"}]}";
assertTrue(s.contains(expected2));
}
use of javax.ws.rs.container.ContainerRequestContext in project cxf by apache.
the class JAXRSUtils method runContainerResponseFilters.
public static void runContainerResponseFilters(ServerProviderFactory pf, ResponseImpl r, Message m, OperationResourceInfo ori, Method invoked) throws IOException, Throwable {
List<ProviderInfo<ContainerResponseFilter>> containerFilters = pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
if (!containerFilters.isEmpty()) {
ContainerRequestContext requestContext = new ContainerRequestContextImpl(m.getExchange().getInMessage(), false, true);
ContainerResponseContext responseContext = new ContainerResponseContextImpl(r, m, ori == null ? null : ori.getClassResourceInfo().getServiceClass(), invoked);
for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
InjectionUtils.injectContexts(filter.getProvider(), filter, m);
filter.getProvider().filter(requestContext, responseContext);
}
}
}
use of javax.ws.rs.container.ContainerRequestContext in project wildfly by wildfly.
the class OpenTelemetryContainerFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) {
if (tracer != null) {
final boolean remoteContext = requestContext.getHeaders().keySet().stream().anyMatch(k -> W3CTraceContextPropagator.getInstance().fields().contains(k));
final UriInfo uriInfo = requestContext.getUriInfo();
final URI requestUri = uriInfo.getRequestUri();
final String method = requestContext.getMethod();
final String uri = uriInfo.getPath();
SpanBuilder spanBuilder = tracer.spanBuilder(method + " " + uri).setSpanKind(SpanKind.SERVER);
if (remoteContext) {
spanBuilder.setParent(openTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), requestContext, new TextMapGetter<ContainerRequestContext>() {
@Override
public String get(ContainerRequestContext requestContext, String key) {
if (requestContext.getHeaders().containsKey(key)) {
return requestContext.getHeaders().get(key).get(0);
}
return null;
}
@Override
public Iterable<String> keys(ContainerRequestContext requestContext) {
return requestContext.getHeaders().keySet();
}
}));
} else {
spanBuilder.setNoParent();
}
Span serverSpan = spanBuilder.startSpan();
serverSpan.makeCurrent();
serverSpan.setAttribute(SemanticAttributes.HTTP_METHOD, method);
serverSpan.setAttribute(SemanticAttributes.HTTP_SCHEME, requestUri.getScheme());
serverSpan.setAttribute(SemanticAttributes.HTTP_HOST, requestUri.getHost() + ":" + requestUri.getPort());
serverSpan.setAttribute(SemanticAttributes.HTTP_TARGET, uri);
requestContext.setProperty(SERVER_SPAN, serverSpan);
}
}
Aggregations