use of org.apache.cxf.jaxrs.sse.SseContextProvider in project tomee by apache.
the class CxfRsHttpListener method deployApplication.
@Override
public void deployApplication(final Application application, final String prefix, final String webContext, final Collection<Object> additionalProviders, final Map<String, EJBRestServiceInfo> restEjbs, final ClassLoader classLoader, final Collection<Injection> injections, final Context context, final WebBeansContext owbCtx, final ServiceConfiguration serviceConfiguration) {
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
try {
final ApplicationData applicationData = getApplicationData(application, prefix, additionalProviders);
logApplication(applicationData);
if (applicationData.getResources().size() == 0) {
throw new NoResourcesFoundException(applicationData);
}
final JAXRSServerFactoryBean factory = newFactory(prefix, createServiceJmxName(classLoader), createEndpointName(application));
configureFactory(additionalProviders, serviceConfiguration, factory, owbCtx, application);
factory.setApplication(application);
final List<Class<?>> classes = new ArrayList<>();
for (final Class<?> clazz : application.getClasses()) {
if (!additionalProviders.contains(clazz) && !clazz.isInterface()) {
classes.add(clazz);
final EJBRestServiceInfo restServiceInfo = getEjbRestServiceInfo(restEjbs, clazz);
if (restServiceInfo != null) {
final Object proxy = ProxyEJB.subclassProxy(restServiceInfo.context);
factory.setResourceProvider(clazz, new NoopResourceProvider(restServiceInfo.context.getBeanClass(), proxy));
} else {
if (owbCtx != null) {
final BeanManagerImpl bm = owbCtx.getBeanManagerImpl();
Bean<?> bean = null;
if (bm != null && bm.isInUse()) {
try {
final Set<Bean<?>> beans = bm.getBeans(clazz);
bean = bm.resolve(beans);
} catch (final InjectionException ie) {
final String msg = "Resource class " + clazz.getName() + " can not be instantiated";
LOGGER.warning(msg, ie);
throw new WebApplicationException(Response.serverError().entity(msg).build());
}
if (bean != null && isConsideredSingleton(bean.getScope())) {
final Object reference = bm.getReference(bean, bean.getBeanClass(), bm.createCreationalContext(bean));
factory.setResourceProvider(clazz, new CdiSingletonResourceProvider(classLoader, clazz, reference, injections, context, owbCtx));
continue;
}
}
}
factory.setResourceProvider(clazz, new OpenEJBPerRequestPojoResourceProvider(classLoader, clazz, injections, context, owbCtx));
}
}
}
for (final Object o : application.getSingletons()) {
if (!additionalProviders.contains(o)) {
final Class<?> clazz = realClass(o.getClass());
classes.add(clazz);
final EJBRestServiceInfo restServiceInfo = getEjbRestServiceInfo(restEjbs, clazz);
if (restServiceInfo != null) {
final Object proxy = ProxyEJB.subclassProxy(restServiceInfo.context);
factory.setResourceProvider(clazz, new NoopResourceProvider(restServiceInfo.context.getBeanClass(), proxy));
} else {
if (owbCtx != null && owbCtx.getBeanManagerImpl().isInUse()) {
final CdiSingletonResourceProvider provider = new CdiSingletonResourceProvider(classLoader, clazz, o, injections, context, owbCtx);
singletons.add(provider);
factory.setResourceProvider(clazz, provider);
} else {
factory.setResourceProvider(clazz, new SingletonResourceProvider(o));
}
}
}
}
factory.setResourceClasses(classes);
factory.setInvoker(new AutoJAXRSInvoker(restEjbs));
injectApplication(application, factory);
/*
* During setApplication CXF will inspect the binding annotations
* on the Application subclass and apply them to every Resource class
* definition. This is how global bindings are supported. Thus, if
* setApplication is called before we've called setResourceClasses()
* binding annotations on the Application subclass will not work.
*
* Global binding annotations are tested in:
* com/sun/ts/tests/jaxrs/spec/filter/globalbinding/JAXRSClient#globalBoundResourceTest_from_standalone
*/
factory.setApplication(application);
this.context = webContext;
if (!webContext.startsWith("/")) {
this.context = "/" + webContext;
}
// /webcontext/servlet for event firing
final Level level = SERVER_IMPL_LOGGER.getLevel();
try {
SERVER_IMPL_LOGGER.setLevel(Level.OFF);
} catch (final UnsupportedOperationException e) {
// ignore
}
try {
factory.setProvider(new SseContextProvider());
factory.setProvider(new TomEESseEventSinkContextProvider());
server = factory.create();
fixProviders(serviceConfiguration);
fireServerCreated(oldLoader);
final ServerProviderFactory spf = ServerProviderFactory.class.cast(server.getEndpoint().get(ServerProviderFactory.class.getName()));
LOGGER.info("Using readers:");
for (final Object provider : List.class.cast(Reflections.get(spf, "messageReaders"))) {
LOGGER.info(" " + ProviderInfo.class.cast(provider).getProvider());
}
LOGGER.info("Using writers:");
for (final Object provider : List.class.cast(Reflections.get(spf, "messageWriters"))) {
LOGGER.info(" " + ProviderInfo.class.cast(provider).getProvider());
}
LOGGER.info("Using exception mappers:");
for (final Object provider : List.class.cast(Reflections.get(spf, "exceptionMappers"))) {
LOGGER.info(" " + ProviderInfo.class.cast(provider).getProvider());
}
} finally {
try {
SERVER_IMPL_LOGGER.setLevel(level);
} catch (final UnsupportedOperationException e) {
// ignore
}
}
final int servletIdx = 1 + this.context.substring(1).indexOf('/');
if (servletIdx > 0) {
this.servlet = this.context.substring(servletIdx);
this.context = this.context.substring(0, servletIdx);
}
destination = (HttpDestination) server.getDestination();
final String base;
if (prefix.endsWith("/")) {
base = prefix.substring(0, prefix.length() - 1);
} else if (prefix.endsWith(wildcard)) {
base = prefix.substring(0, prefix.length() - wildcard.length());
} else {
base = prefix;
}
// stack info to log to get nice logs
logEndpoints(application, prefix, restEjbs, factory, base);
} finally {
if (oldLoader != null) {
CxfUtil.clearBusLoader(oldLoader);
}
}
}
use of org.apache.cxf.jaxrs.sse.SseContextProvider in project cxf by apache.
the class SseTransportCustomizationExtension method customize.
@Override
public void customize(final JAXRSServerFactoryBean bean) {
bean.setTransportId(SseHttpTransportFactory.TRANSPORT_ID);
bean.setProvider(new SseContextProvider());
bean.setProvider(new SseAtmosphereEventSinkContextProvider());
final Bus bus = bean.getBus();
if (bus != null) {
bus.setProperty(AbstractTransportFactory.PREFERRED_TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID);
}
}
Aggregations