Can I do a service callout in the proxy preflow if the calling client is using a websocket connection?

Not applicable

I am trying to call a new version API we created which utilizes websocket connections but am getting an error. Our current /v1/ setup calls an endpoint similar to "wss://{host}/v1/{Websocket URI}" and is authenticated by passing in a username and password which is base64 encoded. This works successfully and we can see the duplex communication.

I am in the process of building a new version (/v2/) and I had to make some changes to the workflow of this API. In doing so, it requires a service callout in the proxy preflow which is a HTTPS callout. This is where I am seeing the error which I have detailed below. When I call this new version over HTTPS, it is successful. When I call using WSS, Apigee MP throws an exception on the service callout policy.

The error I receive on the flow is:

error Execution of ServiceCallout serviceCallout-Authentication failed. Reason: null 
type ErrorPoint 
state PROXY_REQ_FLOW 
error.class com.apigee.kernel.exceptions.spi.UncheckedException 
error.cause -NA- 
Identifier fault 

Logs from the message processor as the traffic was being sent. Exception was:

2016-06-15 18:12:17,366 10.205.4.58 message-processor Scheduler#5 ERROR ADAPTORS.NETTY.WEBSOCKET - NettyHttpAdaptor.buildErrorResponse() : Building error message for exception: 
com.apigee.kernel.exceptions.spi.UncheckedException: Execution of ServiceCallout serviceCallout-Authentication failed. Reason: null 
at com.apigee.steps.servicecallout.ServiceCalloutExecution$1$1.run(ServiceCalloutExecution.java:160) ~[service-callout-1.0.0.jar:na] 
at com.apigee.transport.adaptor.netty.scheduler.HashScheduler$SchedulerThread.run(HashScheduler.java:98) [netty-adaptor-common-1.0.0.jar:na] 
Caused by: java.lang.NullPointerException: null 
at com.apigee.protocol.http.HTTPClient$Context.<init>(HTTPClient.java:404) ~[http-1.0.0.jar:na] 
at com.apigee.protocol.http.HTTPClient.createContext(HTTPClient.java:363) ~[http-1.0.0.jar:na] 
at com.apigee.messaging.adaptors.LegacyTransportAdaptor.buildRequestContext(LegacyTransportAdaptor.java:360) ~[http-adaptor-1.0.0.jar:na] 
at com.apigee.transport.adaptor.flow.data.TargetRequestSender.sendRequest(TargetRequestSender.java:146) ~[transport-adaptor-1.0.0.jar:na] 
at com.apigee.transport.adaptor.flow.data.InlineTargetRequestSender.sendRequest(InlineTargetRequestSender.java:62) ~[transport-adaptor-1.0.0.jar:na] 
at com.apigee.steps.servicecallout.ServiceCalloutExecution$1$1.run(ServiceCalloutExecution.java:154) ~[service-callout-1.0.0.jar:na] 
... 1 common frames omitted 
2016-06-15 18:12:17,517 10.205.4.58 message-processor MessageProcessorWS-2IOThread-7 ERROR CONNECTION - NettyChannel$DefaultContext.onException() : Connection closed cause: 
java.io.IOException: Connection reset by peer 
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.7.0_75] 
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:1.7.0_75] 
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.7.0_75] 
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.7.0_75] 
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379) ~[na:1.7.0_75] 
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:259) ~[netty-all-4.0.0.CR1.jar:na] 
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:885) ~[netty-all-4.0.0.CR1.jar:na] 
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:226) ~[netty-all-4.0.0.CR1.jar:na] 
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:72) ~[netty-all-4.0.0.CR1.jar:na] 
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:434) [netty-all-4.0.0.CR1.jar:na] 
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:397) [netty-all-4.0.0.CR1.jar:na] 
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:327) [netty-all-4.0.0.CR1.jar:na] 
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:109) [netty-all-4.0.0.CR1.jar:na] 
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_75] 
2016-06-15 18:12:17,518 10.205.4.58 message-processor MessageProcessorWS-2IOThread-7 ERROR CONNECTION - NettyChannel$DefaultContext.onDisconnect() : Connection closed

Is it possible to have a http service callout in the preflow of a websocket connection? I should note we are using edge on-prem and currently at an older version 15.01 (upgrade happening near future)

Thanks.

0 2 692
2 REPLIES 2

adas
Participant V

I don't think Apigee service callouts support websockets at the moment. We only did some basic support (tunnelling) for websockets for target endpoints, which means you could make Edge proxy work as a passthrough to a websocket target. Of course, you could enforce policies like quota, apikey, oauth etc. before the actual handshake request to the target is made, and the http connection is upgraded to websocket. I hope this answers your question.

Hi Arghya, Thanks for the response. It does answer my question, but I now have another after reading your response. Do you know of any documentation available that outlines what policies are supported in a websocket connection? I will have to change my design and will likely need to use caching now.

Thanks