首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSE实现(WebLogic12.2.1.2.0+ Jax-RS 2.1 (用于注册资源)+ CXF 3.2.5+ + Springboot + jersey 2.25.1)

SSE实现(WebLogic12.2.1.2.0+ Jax-RS 2.1 (用于注册资源)+ CXF 3.2.5+ + Springboot + jersey 2.25.1)
EN

Stack Overflow用户
提问于 2018-11-26 19:30:10
回答 1查看 1.3K关注 0票数 3

尝试使用上述技术实现SSE,但微服务部署失败-

代码语言:javascript
复制
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服务器注册-

代码语言:javascript
复制
@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;
}

异常-当jersey试图加载CXF包的ext @Provider类- OutboundSseEventBodyWriter时失败。

OutboundSseEventBodyWriter类有一个不会引起问题的受保护的构造函数。

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2018-11-28 23:44:45

在这里查看关于如何在WebLogic上使用Apache CXF的建议:http://cxf.apache.org/docs/jax-rs-deployment.html查看WebLogic部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53480167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档