Support server sent event with custom Java proxy servlet - servlets

I have a custom implementation of reverse proxy server in Java Servlet. I want to support server sent events in my web application. To do that I need to modify my servlet code to support the SSE connection. I searched enough for examples of how to do that, but did not find anything. Can anyone provide me a direction about how to implement the SSE support in my Java Servlet?
Thanks.

Related

Grpc-Web Client in Java

I'm trying to connect to a grpc-service from a Java client. The problem is that this service is currently supporting only grpc-web over http1.1, this is because of a limitation of supporting http2 in Azure App service where the service is deployed.
The grpc-java client liberary from io.grpc only supports grpc over http2 protocol, which maskes sense, and unfortenatly is not working for me.
I managed to consume a service using HTTP client from apache and okhttp3 but this works for unary calls and it didn't work for a server-side streaming service.
Is any one aware of a grpc-web java client liberary that I could use or a work arround using convenienal Http for reading grpc-web server-side streaming service.
If I understand your question correctly, you want a Java client for gRPC-Web so that your client can talk HTTP/1.1 through a gRPC-Web proxy (e.g. Envoy gRPC-Web) because you're unable to talk HTTP/2 directly to your service because of the Azure networking limitation?
In theory this should be possible. The JavaScript implementation is because, in-browser, there's no alternative except JSON transcoding. The JavaScript implementation does implement server-side streaming, which is another requirement and confirms that this should be possible over HTTP/1.1.
However, in a quick search I found no other (i.e non-JavaScript) client implementations of gRPC-Web.

How to collect and pass b3 propagation headers in grpc client request using opentracing api?

I was using https://github.com/opentracing-contrib/java-grpc with jaegar tracer for enabling tracing in my grpc client program. Now I would like to use istio service mesh to handle tracing in server side. https://istio.io/latest/docs/tasks/observability/distributed-tracing/overview/ .
So the grpc client now needs to send the appropriate tracing HTTP headers along with each grpc client request so that istio can send those metrics to Jaegar. Does anyone have a working example of fetching the trace span information in grpc client and include the corresponding b3 propagation headers in a grpc client request?
Following http headers need to be passed in a java/C# grpc client request :
x-request-id
x-b3-traceid
x-b3-spanid
x-b3-parentspanid
x-b3-sampled
x-b3-flags
x-ot-span-context
Thanks.
Have a look at the OpenTelemetry-Java-Instrumentation project. It can provide automated tracing of your application without needing to write custom code. It uses an instrumentation agent that runs in the JVM beside your application.
java -javaagent:path/to/opentelemetry-javaagent-all.jar \
-jar myapp.jar
It supports exporting metrics to Jaeger
It also supports propagating headers to downstream requests.
They have just added support for b3-multi headers so a new release should be available in the coming days

grpc - is TLS necessary if https enabled?

I'm newbie of grpc and have played with simple grpc clients of java, go, and python. I know basic http and https but not familiar with protocal details. So this question may be rediculous to you but I didn't find any explaination online.
I know grpc has insecure(go: grpc.WithInsecure(), python: grpc.insecure_channel, java: usePlaintext()) and secure mode(TLS). and grpc is based on httpv2, and http has security mode(https).
So what if use insecure grpc with https? Is the overall data transfer safe?
And what if use TLS grpc with https? Is there performance overhead(becuase I think the messages are encrypted twice)?
Thank you for any answer, any exsiting webpages explaining such topic that will be best!
Insecure implies http. And TLS implies https. So there's no way "to use insecure grpc with https", as at that point it is then http.
There is no double-encryption. The gRPC security mode is the same as the HTTP security mode.
Using gRPC over TLS is highly recommended if you gRPC server is serving requests coming from outside(external network). For example you're creating front end app in javascript serving user requests. Your javascript app make call to your gRPC server for APIs your server provide. Your javascript communicate to your gRPC server through stub created in javascript end. At the end of your gRPC server, you need to set tls mechanism to secure communication between your javascript app and your gRPC server(because requests coming from outside).
gRPC somehow mostly used for internal services communication inside internal network in microservice architecture. You don't need to set tls for internal network usage since requests coming from your own environment from within your watch.
If you want to apply something like "gRPC over HTTPS", then you need something like gateway to map your http call to your gRPC server. Check this out.
You need to compile your proto file as gateway service definitions as well using provided tools. Now you can create your normal http server with tls enabled through something like http.ListenAndServeTLS(...). Dont forget to register your grpc server to the http server using the service definitions compiled from the proto file. With this all your requests to are encrypted with tls to your http server like normal rest apis do, but get proxied to gRPC server you defined. There's no need to enable tls at your gRPC server since it has been enabled in your http server.

How to enable amf sampler type

I want to record script using amf proxy server but in http sampler setting amf type is missing. How should i enable amf type in amf proxy server.
Try first existent solutions:
1. AMF Plugin for JMeter
This will add the following new components:
AMF Request
AMF Request Defaults
AMF Proxy Server
that will allow you to test your app using the AMF3 protocol:
Record AMF and HTTP traffic with the AMF Proxy Server
Translate AMF to XML for easy manipulation
Use variables to provide each virtual user with unique Client and Session IDs
Store response XML in a variable for assertion and value extraction
Review AMF responses as XML
NOTE: not supported in JMeter 2.6, works with JMeter 2.5.1.
...And these two as possible addition:
2. jmeter-amf-visualizer
JMeter visualizer AMF response.
3. jmeter-amfsampler
JMeter sampler for testing Flex/BlazeDS applications using Adobe's AMF protocol over HTTP.
4. UbikLoadPack Flex/AMF plugin
Commercial plugin from UBIK Load Pack.
Apache JMeter does not propose AMF Sampler due to License incompatibility of BlazeDS with Apache licence.
Regarding your login issue you should check that you add a CookieManager to your test plan.
Then check you add the Java beans used by your Flex Application to send objects to Flex layer.
You can have a look at:
https://www.ubik-ingenierie.com/blog/load-testing-flex-with-jmeter-made-easy/
https://www.ubik-ingenierie.com/blog/ubikloadpack-flex-amf-plugin-4-0-for-apache-jmeter-released/
Performance testing Flex applications

Do Java web-server apps have any way to PUSH?

Web-servers work in response to incoming HTTP requests... process the request and return an HTTP response. Are there any common ways that a server can PUSH data to clients in this architecture... e.g a request comes in from client1 and the server wants to notify client2? It can obviously be done by a non-web server, using sockets, but what about a web-server app which has to support page requests AND allow PUSHing data..?
what about a web-server app which has to support page requests AND allow PUSHing data..?
Servlet 3.0 introduces Async support allowing to write Comet style applications (i.e. applications using Long-lived HTTP connections and either long polling or streaming).
If you can't wait for Servlet 3.0 Async support and don't want to use proprietary Comet or WebSocket support from containers (like GlassFish, Jetty), then have a look at Atmosphere.
See also
JavaOne 2008: Comet (AJAX, Grizzly and Cometd)
Asynchronous processing support in Servlet 3.0
Servlet 3.0 Async API or Atmosphere? A Simple Comparison
You can use web app containers like Jetty which support Web Sockets if you don't mind waiting for the web world to catch up to this up-and-coming standard. Then you'll have real bi-directional communications instead of HTTP + Polling or special plug-ins or the like.
No, not without some client side tech (Flash, Silverlight, Applets, etc.)
You could have the page poll the server with AJAX though.
Another possibility would be to abuse HTTP Keep Alive to achieve this. See http://en.wikipedia.org/wiki/HTTP_persistent_connection for some background. In your scenario you would have client2 initiate a connection to the server that then would stay open listening for notifications.
This is not a great solution, first off you need to keep lots of long lived TCP connections around, and if a connection is lost there is no way for the server to reconnect. It must wait for the client to come back.

Resources