我正在尝试通过WSO2 API管理器公开WebSocket服务。我要求所有机器之间的通信都必须安全,因此我想使用加密的WebSocket(wss://)。我有一个概念验证的Web服务,它每秒仅发出一条消息。这不是本机实现的wss://,但是我在同一台机器上的前面有一个反向代理(Apache),这是可以的。
问题
这有效:
这不是:
最后一个问题是问题。我认为这是网关中的一些配置,但看不到。 wso2carbon.log显示:
TID: [-1] [] [2019-06-07 11:02:34,051] ERROR {org.apache.synapse.core.axis2.Axis2Sender} - Unexpected error during sending message out {org.apache.synapse.core.axis2.Axis2Sender}
java.lang.NullPointerException
at org.wso2.carbon.websocket.transport.WebsocketConnectionFactory.cacheNewConnection(WebsocketConnectionFactory.java:123)
at org.wso2.carbon.websocket.transport.WebsocketConnectionFactory.getChannelHandler(WebsocketConnectionFactory.java:79)
at org.wso2.carbon.websocket.transport.WebsocketTransportSender.sendMessage(WebsocketTransportSender.java:106)
at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:297)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send(Axis2FlexibleMEPClient.java:592)
at org.apache.synapse.core.axis2.Axis2Sender.sendOn(Axis2Sender.java:83)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:548)
at org.apache.synapse.endpoints.AbstractEndpoint.send(AbstractEndpoint.java:382)
at org.apache.synapse.endpoints.AddressEndpoint.send(AddressEndpoint.java:65)
at org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:121)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:97)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:59)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)
at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:1005)
at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.injectToSequence(InboundWebsocketSourceHandler.java:469)
at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.handleHandshake(InboundWebsocketSourceHandler.java:182)
at org.wso2.carbon.inbound.endpoint.protocol.websocket.InboundWebsocketSourceHandler.channelRead(InboundWebsocketSourceHandler.java:131)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at org.wso2.carbon.apimgt.gateway.handlers.WebsocketInboundHandler.channelRead(WebsocketInboundHandler.java:125)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:147)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:147)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:748)
TID: [-1] [] [2019-06-07 11:02:34,057] WARN {org.apache.synapse.core.axis2.Axis2SynapseEnvironment} - Executing fault handler due to exception encountered {org.apache.synapse.core.axis2.Axis2SynapseEnvironment}
TID: [-1] [] [2019-06-07 11:02:34,058] WARN {org.apache.synapse.endpoints.EndpointContext} - Endpoint : AnonymousEndpoint with address wss://icarcdevapi01.internal.carus.com/notifications/notifications will be marked SUSPENDED as it failed {org.apache.synapse.endpoints.EndpointContext}
TID: [-1] [] [2019-06-07 11:02:34,058] WARN {org.apache.synapse.endpoints.EndpointContext} - Suspending endpoint : AnonymousEndpoint with address wss://icarcdevapi01.internal.carus.com/notifications/notifications - last suspend duration was : 30000ms and current suspend duration is : 30000ms - Next retry after : Fri Jun 07 11:03:04 EEST 2019 {org.apache.synapse.endpoints.EndpointContext}
TID: [-1] [] [2019-06-07 11:02:34,058] INFO {org.apache.synapse.mediators.builtin.LogMediator} - STATUS = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Unexpected error during sending message out {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1] [] [2019-06-07 11:02:34,123] INFO {org.apache.synapse.mediators.builtin.LogMediator} - STATUS = Executing default 'fault' sequence, ERROR_CODE = 303001, ERROR_MESSAGE = Currently , Address endpoint : [ Name : AnonymousEndpoint ] [ State : SUSPENDED ] {org.apache.synapse.mediators.builtin.LogMediator}
其他详细信息
我将以下内容添加到ws的transportSender旁边的repository / conf / axis2 / axis2.xml中:
<transportSender name="wss" class="org.wso2.carbon.websocket.transport.WebsocketTransportSender">
<parameter name="ws.outflow.dispatch.sequence" locked="false">outflowDispatchSeq</parameter>
<parameter name="ws.outflow.dispatch.fault.sequence" locked="false">outflowFaultSeq</parameter>
<parameter name="ws.trust.store" locked="false">
<ws.trust.store.location>repository/resources/security/client-truststore.jks</ws.trust.store.location>
<ws.trust.store.Password>wso2carbon</ws.trust.store.Password>
</parameter>
网关上的反向代理包括:
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /(.*) ws://127.0.0.1:9099/$1 [P,L]
将所有websocket连接映射到端口9099。我假设由于proxy-> wso2通过ws://,所以我不需要其他端口。
如果我在WSO2 Publisher中配置了一个直接指向我的服务(ws://myservice.example.com:8001/foo
)的API,那么它将起作用。我可以通过wss://调用网关,但是可以通过未加密的ws://调用API。我在实际的API服务计算机上也有一个反向代理。如果我在API网关计算机上运行测试客户端并调用wss://myservice.example.com/foo
,则它可以正常工作,因此服务计算机端配置为OK。
但是,如果我在WSO2 Publisher的API定义中将与端点相同的URL(wss://myservice.example.com/foo
)放在终端,则客户端只是挂起,并且上面出现了空指针。
我们仍在使用API Manager 2.1版