use of org.apache.cxf.jaxrs.provider.ServerProviderFactory in project cxf by apache.
the class InjectionUtils method getParamConverter.
public static <T> Optional<ParamConverter<T>> getParamConverter(Class<T> pClass, Type genericType, Annotation[] anns, Message message) {
if (message != null) {
ServerProviderFactory pf = ServerProviderFactory.getInstance(message);
ParamConverter<T> pm = pf.createParameterHandler(pClass, genericType, anns, message);
return Optional.ofNullable(pm);
}
return Optional.empty();
}
use of org.apache.cxf.jaxrs.provider.ServerProviderFactory in project cxf by apache.
the class AbstractSearchConditionParser method paramConverterAvailable.
private boolean paramConverterAvailable(final Class<?> pClass) {
Message m = JAXRSUtils.getCurrentMessage();
ServerProviderFactory pf = m == null ? null : ServerProviderFactory.getInstance(m);
return pf != null && pf.createParameterHandler(pClass, pClass, EMPTY_ANNOTTAIONS, m) != null;
}
use of org.apache.cxf.jaxrs.provider.ServerProviderFactory in project cxf by apache.
the class ServerProviderFactoryTest method testCustomWadlHandler.
@Test
public void testCustomWadlHandler() {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
assertEquals(1, pf.getPreMatchContainerRequestFilters().size());
assertTrue(pf.getPreMatchContainerRequestFilters().get(0).getProvider() instanceof WadlGenerator);
WadlGenerator wg = new WadlGenerator();
pf.setUserProviders(Collections.singletonList(wg));
assertEquals(1, pf.getPreMatchContainerRequestFilters().size());
assertTrue(pf.getPreMatchContainerRequestFilters().get(0).getProvider() instanceof WadlGenerator);
assertSame(wg, pf.getPreMatchContainerRequestFilters().get(0).getProvider());
}
use of org.apache.cxf.jaxrs.provider.ServerProviderFactory in project cxf by apache.
the class SseInterceptor method handleMessage.
public void handleMessage(Message message) {
// Not an SSE invocation, skipping it in favor of normal processing
if (message.get(SseEventSink.class) == null) {
return;
}
if (!isRequestor(message) && message.get(SseInterceptor.class) == null) {
message.put(SseInterceptor.class, this);
final Exchange exchange = message.getExchange();
OperationResourceInfo ori = (OperationResourceInfo) exchange.get(OperationResourceInfo.class.getName());
if (ori != null) {
Response.ResponseBuilder builder = Response.ok();
HttpServletResponse servletResponse = null;
final ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(message);
final Object response = message.get(AbstractHTTPDestination.HTTP_RESPONSE);
if (response instanceof HttpServletResponse) {
servletResponse = (HttpServletResponse) response;
builder = Response.status(servletResponse.getStatus());
for (final String header : servletResponse.getHeaderNames()) {
final Collection<String> headers = servletResponse.getHeaders(header);
addHeader(builder, header, headers);
}
}
// Run the filters
try {
final ResponseImpl responseImpl = (ResponseImpl) builder.build();
final Message outMessage = getOutMessage(message);
JAXRSUtils.runContainerResponseFilters(providerFactory, responseImpl, outMessage, ori, ori.getAnnotatedMethod());
if (servletResponse != null) {
servletResponse.setStatus(responseImpl.getStatus());
final Map<String, List<String>> userHeaders = CastUtils.cast((Map<?, ?>) outMessage.get(Message.PROTOCOL_HEADERS));
if (userHeaders != null) {
for (Map.Entry<String, List<String>> entry : userHeaders.entrySet()) {
setHeader(servletResponse, entry);
}
}
final MultivaluedMap<String, String> headers = responseImpl.getStringHeaders();
if (headers != null) {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
setHeader(servletResponse, entry);
}
}
}
} catch (Throwable ex) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, ex.getMessage(), ex);
}
}
}
}
}
use of org.apache.cxf.jaxrs.provider.ServerProviderFactory in project cxf by apache.
the class OpenApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
final ServerProviderFactory factory = (ServerProviderFactory) server.getEndpoint().get(ServerProviderFactory.class.getName());
final Set<String> packages = new HashSet<>();
if (resourcePackages != null) {
packages.addAll(resourcePackages);
}
Properties swaggerProps = null;
GenericOpenApiContextBuilder<?> openApiConfiguration;
final Application application = getApplicationOrDefault(server, factory, sfb, bus);
if (StringUtils.isEmpty(getConfigLocation())) {
swaggerProps = getSwaggerProperties(propertiesLocation, bus);
if (isScan()) {
packages.addAll(scanResourcePackages(sfb));
}
final OpenAPI oas = new OpenAPI().info(getInfo(swaggerProps));
registerComponents(securityDefinitions).ifPresent(oas::setComponents);
final SwaggerConfiguration config = new SwaggerConfiguration().openAPI(oas).prettyPrint(getOrFallback(isPrettyPrint(), swaggerProps, PRETTY_PRINT_PROPERTY)).readAllResources(isReadAllResources()).ignoredRoutes(getIgnoredRoutes()).filterClass(getOrFallback(getFilterClass(), swaggerProps, FILTER_CLASS_PROPERTY)).resourceClasses(getResourceClasses()).resourcePackages(getOrFallback(packages, swaggerProps, RESOURCE_PACKAGE_PROPERTY));
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).openApiConfiguration(config);
} else {
openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).configLocation(getConfigLocation());
}
try {
final OpenApiContext context = openApiConfiguration.buildContext(true);
final Properties userProperties = getUserProperties(context.getOpenApiConfiguration().getUserDefinedOptions());
registerOpenApiResources(sfb, packages, context.getOpenApiConfiguration());
registerSwaggerUiResources(sfb, combine(swaggerProps, userProperties), factory, bus);
if (customizer != null) {
customizer.setApplicationInfo(factory.getApplicationProvider());
}
} catch (OpenApiConfigurationException ex) {
throw new RuntimeException("Unable to initialize OpenAPI context", ex);
}
}
Aggregations