eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
690 stars 351 forks source link

One Servlet as Web Servlet, REST Servlet and WebSocket Servlet #3869

Open Tibor17 opened 6 years ago

Tibor17 commented 6 years ago

Is there any servlet in JEE which understands all three APIs? The problem is that there is no servlet which handles requests from all these three under one Security Context. At the same time the Model (in MVC) should appear on client side and server should become stateless. This means the web (xhtml), rest API and websocket API in one servlet and understands same Security Context if the request is coming from the page or REST or Websocket. The servlet should understand the CDI context as well. I do not want to use Angular and I think it is the time when JEE discontinues JSF and creates something like Java Client Faces and the backend will be a servlet which understands HTML5 + REST + WebSocket. The Web Servlet should resolve static expressions, then the same servlet should understand AJAX and REST requests under the same Security Context. Same with Websockets. The REST calls on server side must understand the JSESSIONID, roles, etc. The xhtml page should use expressions. Servlet should resolve them to static strings which prevents from producing too many async calls to the server.

jansupol commented 6 years ago

I am not sure I understand this request correctly. There is MVC JSR 371 that you might want to consider to use from JEE. Servlet that understands both REST and Websocket....there is a different protocol for both, one is HTTP, one is WS...what is your use case? There is SSE alternative to Websocket for instance...

Tibor17 commented 6 years ago

@jansupol I have one problem with MVC 1.0. It all looks nice in code but the client's page in browser does not really use JavaScript e.g. XMLHttpRequest in order to get the data from the server's model. Correct me if I am wrong but I think this might be the reason why JSR 371 was postponed.

chkal commented 6 years ago

Correct me if I am wrong but I think this might be the reason why JSR 371 was postponed.

MVC 1.0 spec lead here. You are wrong. :wink: JSR 371 is delayed because we took over the spec from Oracle which was very time-consuming.

With MVC 1.0 you render the HTML on the server side. Of course you can also use JavaScript and XMLHttpRequest on such pages, but you in this case you will typically fetch data from a standard JAX-RS resource. But of course MVC 1.0 isn't really useful if you are building an SPA.

Feel free to post on the JSR 371 mailing list if you have any questions.

arjantijms commented 6 years ago

@Tibor17

I think it is the time when JEE discontinues JSF

Why do you think that?

Tibor17 commented 6 years ago

@chkal I am looking for a substitute of Angular in Java standard. The MVC was a candidate. I said candidate because it is not since the server loads data for itself renderer embedded in the same server. The MVC 1.0 looks like a technology which serves model's data from Rest server for Rendered and that Renderer serves View to the browser. I think this is wrong and the web page should Get/Post data from/to the REST servlet directly instead of this web servlet; does not mater if both web and rest servlets are in one server instance or in two. I am just trying to explain that the behavior of Angular is right and that MVC 1.0 is not anyhow similar competitor; even if they somehow use REST Resource class.

Tibor17 commented 6 years ago

@arjantijms In my experiences JSF is useful in simple enterprise apps which redirect pages and then the server becomes more less stateless. The end-user expect fast user experience and then the developer is forced to use long scope of the Model. The user expects immediate response when he clicks on Back button. Nowadays the tendency is single-page webapp with the model in the client which can be developed only with JavaScript. Even if you try to use JavaScript in JSF, it's a pain.

Tibor17 commented 6 years ago

Last two weeks I spoke with a company and they told me that the concurrency with JSF is horrible. The system consumes a lots of Java Heap due to holding JSF Model in memory and the system is able to serve for max of only 50 concurrent users. I think this is important and it is good that MVC 1.0 was not given a chance yet, because the world around us have practicle problems. The people voted for MVC 1.0 but I think it happened because technologies are juicy but I am not convinced they are applicable.

chkal commented 6 years ago

@Tibor17 I think you have to understand that there are different technical approaches for creating web applications with different strength and weaknesses. MVC 1.0 provides a very simple and lightweight framework for creating action-based server-rendered applications. So you cannot compare MVC with Angular, which is a client-side JavaScript framework. Which type of web framework you need, depends on your specific requirements. There is no single best approach.

BTW: The Jersey issue tracker isn't the best place to discuss these things. You could post your questions on the jakarta.ee-community mailing list.

Tibor17 commented 6 years ago

@chkal ok, I will continue on the mailing list. Last thing I want to tell you is the fact that EE will not have good reputation if we try to have more and more APIs of web frameworks. One is JSF which is server-based, and now is the time to have client-based framework. So please let the people chooose upon client and server based approaches in EE and not two server-based frameworks. Therefore my expectations from MVC 1.0 was different. It was actually that the Servlet would compile my page with Expression Language #{http::post[/path/to/resource]} to JavaScript REST call, and that Expression #{myBean.property} or ${myBean.property} to model's value as it is in JSF/JSP. I do not say MVC 1.0 is completely wrong, I only say the world needs to extend MVC Servlet with a compiler to the JavaScript. In Java EE is no way to aggregate two Servlets in one (keeping bundary of security context).

chkal commented 6 years ago

@Tibor17 Well, there are more than just two categories of web frameworks. So even on the server side there are multiple approaches with strength and weaknesses. Please have a look at this fantastic blog post by @edburns about different kinds of server-side web frameworks on the server-side.

I'm not sure I fully understand your expectations you had for MVC. But I guess this should be discussed on the JSR 371 mailing list.

Tibor17 commented 6 years ago

@chkal Thx for the article. I'll have a look.

Tibor17 commented 6 years ago

@chkal How you call the mechanism which compiles JSP to a pure HTML? I call it compiler. My tendency was to extend this mechanism with asynchronous JavaScript for e.g. http/html Forms and there the REST call from the page would be fantastic. There is only one unknown thing, and a task for Language Architect, to express that this Form would be sent to MVC Servlet via async JS. This is the main purpose of this PR.

chkal commented 6 years ago

@Tibor17 I'm still not sure if I understand what you are trying to achieve. In MVC there is the concept of "view engines" which are used to compile a template to the HTML sent to the client. You can provide your own view engine to customize how HTML is generated. In most cases this is used to add support for different template technologies.

jansupol commented 2 years ago

In WebSocket, there is a new upgradeHttpToWebSocket API that redirects HTTP request to WebSocket Endpoints