Web based collaborative editing using AJAX - java

I am looking to create a web based collaborative editor (like Google docs but very basic. 2 or more users editing a page). I am using the Spring MVC framework and wanted to know the best way to start this.
Should I use AJAX, if so can you point me in the right direction?
Otherwise, how should I go about doing this?

You need spring's websocket support. Go through the spring docs here
You may need to create a handler which will be mapped with websocket in spring like this.
<websocket:handlers>
<websocket:mapping path="/myHandler" handler="myHandler"/>
<websocket:handshake-interceptors>
<bean class="org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor"/>
</websocket:handshake-interceptors>
</websocket:handlers>
Or you can create a web-scoket configuration with annotation like below.
#Configuration
#EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

Related

Spring-Boot without STOMP (raw websocket)

Edit: Please do not downvote without leaving at least a comment.
I'd like to implement websocket in a SpringBoot application without Message Broker and STOMP. However, I need to access Spring Beans (repositories and services).
The Java API is so simple that I can't understand why Spring made it so complex.
Here's what I need:
I need to implement a websocket endpoint with dynamic URI so I can use #PathParam like this:
#ServerEndpoint(value = "/chat/{username}")
public class wsEndpoint
Using #EnableWebSocket with WebSocketConfigurer and TextWebSocketHandler only allows me to implement static endpoints.
The alternative recommended by Spring documentation is to implement Message Brokers and STOMP, which makes usage (IMHO) unnecessarily complex for most cases.
I really would like to use #EnableWebSocket with WebSocketConfigurer, TextWebSocketHandler and dynamic URIs. Is there a way to do so?

Ways to register custom interceptors in some spring boot projects

I have a nmj-api-framework project which is a spring boot backend web project.
In the project, I've defined some interceptors extended HandlerInterceptorAdapter and registered them by extending WebMvcConfigurerAdapter.
I think it's the common way to use interceptors.
Using Spring MVC HandlerInterceptor with Spring Boot - Hello World example showed the details.
Then I have some other projects which depends on nmj-api-framework, e.g. nmj-api-project1 and nmj-api-project2.
I'd like to register other custom interceptors in these projects and not modify the base project nmj-api-framework.
Are there some ways to achieve this?
The solution is dependent on how the Spring Context between your nmj-api-framework, nmj-api-project1 and nmj-api-project2 is shared.
If there is single component scan, you can just register interceptor in nmj-api-project1 and nmj-api-project2 (as described in blog post you pointed out) and component scanning should find and use it.

Checking whether a user is logged in using stormpath and spring-boot

I have a simple web application which I am writing using spring-boot and storm path for user authentication. (I'm actually using spring-boot-starter-stormpath-thymeleaf)
I have a have the following request mapping in my controller
#RequestMapping(value = "/secure", method = RequestMethod.GET)
public String secure(Model mode, HttpServletRequest request) {
Account account = AccountResolver.INSTANCE.getAccount(request);
if (account != null)
return "secure";
else
return "redirect:/login?next=secure";
}
which forces a user to login to view the secure page. It works, but it doesn't feel like it is the most elegant of solutions. Is there a better way? I think a solution with filters should be possible but I cannot figure it out.
The current Stormpath Spring Boot starter does not (yet) have an authentication filter, but it will on future releases for those that want an out-of-the-box experience without having to use Spring Security or Apache Shiro.
That said, we're currently working on natively supporting Spring Security and Apache Shiro as Spring Boot starters that 'just work' with the Stormpath Spring Boot starter. Until we can release those, creating a custom servlet filter as you indicate is the best approach.
Are you also using the Stormpath Servlet as well?
If so, you could do what you need following this piece of documentation. This way you will only need to declare which are the resources of your application that you want to secure and Stormpath's authc filter will prompt for authentication when required.
If you're using Spring MVC, you should use Spring Security and have Stormpath acting as an authentication provider. Then use the standard Spring Security tools to declare access rules and inject the current user where needed.

Naming Spring Services when accessed by different client types

I am quite new to Spring and have a question related to Spring Service naming convention.
I have written a service, and used an annotation to define and name it.
#Service(value="CustomerService")
This service is implemented within a library that is used by a web app. Everything works fine and I can autowire my service into my client components.
Now I would also like to expose this service using http invoker. This works ok. I have define a /CustomerService http service which accesses CustomerService bean.
The issue I have is that one of my components, a client side component, that I used in my web app (CustomerDetailsValidator) can also be used in this new application.
In my CustomerDetailsValidator I have something like this:
#Autowired
#Qualifier(name="CustomerService").
But if I want to reuse my CustomerDetailsValidator and use it in my new app, this time I need to wire it to the httpservice instead.
Which means that the #Autowired and #Qualifier code is useless.
My question is what is the best practice in this case?
Should I still use #Service?
I guess I cannot use Qualifier anymore.
My feeling is that I should define everything in xml in each application context.
The web app using the library directly would just use the CustomerService bean as a singleton.
While my new client app would link the customer service id to the http service.
Is that a good approach? Do we have patterns for this?
Thanks and regards
Gilles

How to make authorization in Java EE to be externally recofigurable (out of war-file) and to be hot-recofigurable?

Some Java Web-framework put roles on controllers, look to example:
#Controller
#RequestMapping("/company")
#RolesAllowed("ROLE_ADMIN")
public class CompanyController { ... }
This requires recompilation of code in order to remap roles and URLs...
Is there are any standard framework or library which allow mapping of roles and URLs out of war file and allow hot-reconfiguration (without stopping application)?
Seems that for the EE stack this requires including a custom interceptor.
Your given example seams the Spring security example. Please look at following tutorial. It is much helpful.
http://krams915.blogspot.com/2010/12/spring-security-3-mvc-using-simple-user.html

Categories

Resources