Response Interceptor 2
The util.responsecallbackinjector can be used to inject a response callback to an incoming message so that when its callback is invoked, the corresponding response message is emitted from this operator and this message can be sent to the responseinterceptor operator. This examples shows how these two operators can be used with openapi.server and a custom operator to deliver the response to the http request. It is noted that this particular graph is grouped into two groups to demonstrate how the response handling can work across the group boundaries when the cardinality of the source group is 1.
Configure and Run the Graph
- Start the graph. This demo service will be started at path /openapi/service/samples/respintercept2 relative to the vflow instance URL.
- Open the UI from the wiretap operator so that the request messages are displayed on the browser.
- From some REST client, send a POST request to
/openapi/service/samples/respintercept2/echo with some
text content. This service will echo the reversed text. When using curl,
this would correspond to:
curl -i -X POST -d 'some text' http://{host}:{port}/{path}/openapi/service/samples/respintercept2/echo
For example, for a local vflow instance, use http://localhost:8090/ as in$ curl -i -X POST -d 'buenos dias' 'http://localhost:8090/openapi/service/samples/respintercept2/echo' HTTP/1.1 200 OK Access-Control-Allow-Headers: accept, content-type, authorization Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE Access-Control-Allow-Origin: http://localhost:8090 Content-Type: text/plain Date: Wed, 11 Apr 2018 18:16:22 GMT Content-Length: 11 said soneub
- Send another POST request with the wrong path to trigger an error (Note: the
javascript operator returns an error if the request path is not
/samples/respintercept2/echo).
$ curl -i -X POST -d 'buenos dias' 'http://localhost:8090/openapi/service/samples/respintercept2/bad' HTTP/1.1 500 Internal Server Error Access-Control-Allow-Headers: accept, content-type, authorization Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE Access-Control-Allow-Origin: http://localhost:8090 Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Wed, 11 Apr 2018 18:17:19 GMT Content-Length: 81 Invalid path /samples/respintercept/bad; Expect path /samples/respintercept2/echo $