Попытка внедрить SSE с указанными технологиями, но не удается развернуть микро-сервис -
Resource -
@Path("/status-management")
public interface ISocketResource {
@GET
@Path("/v1/statusSocket")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void stockEvents(
@QueryParam("entityProcessContexts") List<String> entityProcessContexts,
@Context Sse sse,
@Context SseEventSink sseEventSink);
}
Регистрация CXF-сервера -
@Bean
public Server cxfServer() {
List<Object> serviceBeans = new ArrayList<Object>(ctx.getBeansWithAnnotation(Path.class).values());
List<Object> providers = new ArrayList<Object>(ctx.getBeansWithAnnotation(Provider.class).values());
providers.add(new FormEncodingProvider<Object>());
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setBus(ctx.getBean(SpringBus.class));
factory.setServiceBeans(serviceBeans);
factory.setProviders(providers);
factory.setFeatures(Arrays.asList(new SseFeature()));// registering SseFeature
Server server = factory.create();
return server;
}
Исключение - ошибка при попытке загрузить джерсиКласс @Provider - OutboundSseEventBodyWriter пакета CXF.
Класс OutboundSseEventBodyWriter имеет защищенный конструктор, который не вызывает проблем.
WARNING: HK2 service reification failed for [org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter] with an exception:
MultiException stack 1 of 2
java.lang.NoSuchMethodException: Could not find a suitable constructor in org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter class.
at org.glassfish.jersey.inject.hk2.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:192)
at org.jvnet.hk2.internal.Utilities.getConstructor(Utilities.java:180)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:129)
at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:180)
at org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:740)
at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:694)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:464)
at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2310)
at org.jvnet.hk2.internal.ServiceLocatorImpl.access$1200(ServiceLocatorImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1395)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1390)
at org.glassfish.hk2.utilities.cache.internal.WeakCARCacheImpl.compute(WeakCARCacheImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetAllServiceHandles(ServiceLocatorImpl.java:1452)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1377)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getAllServiceHandles(ServiceLocatorImpl.java:1366)
....
.
.
.
.
.
MultiException stack 2 of 2
java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor(
implementation=org.apache.cxf.jaxrs.sse.OutboundSseEventBodyWriter
contracts={javax.ws.rs.ext.MessageBodyWriter}
scope=javax.inject.Singleton
qualifiers={org.glassfish.jersey.internal.inject.Custom}
descriptorType=CLASS
descriptorVisibility=NORMAL
metadata=
rank=0
loader=null
proxiable=null
proxyForSameScope=null
analysisName=null
id=189
locatorId=0
identityHashCode=1355595726
reified=false)
at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:705)
at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:464)
at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2310)
at org.jvnet.hk2.internal.ServiceLocatorImpl.access$1200(ServiceLocatorImpl.java:128)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1395)
at org.jvnet.hk2.internal.ServiceLocatorImpl$9.compute(ServiceLocatorImpl.java:1390)
.
.
.
.
<Nov 20, 2018, 11:19:17,989 AM IST> <Error> <HTTP> <BEA-101216> <Servlet: "JAX-RS/Jersey#1" failed to preload on startup in Web application: "/businessstatus-ms".
A MultiException has 2 exceptions. They are:
1. java.lang.InstantiationException
2. java.lang.IllegalStateException: Unable to perform operation: create on org.apache.cxf.jaxrs.provider.AbstractResponseViewProvider
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:392)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83)
at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71)
at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97)
Truncated. see log file for complete stacktrace
Caused By: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1375)
at org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:272)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:366)
Truncated. see log file for complete stacktrace