четвер, 5 квітня 2018 р.

Books and Multimedia data structure

I'm developing web application, diary for travelers. And I have 'Books' and 'Multimedia' pages. The functionality of these pages pretty similar but work with different types of data. These pages provide simple CRUD functionality for the list of books (Books page) and for the list of multimedia content (Multimedia page).



But this part of business logic has quite unusable data structure, simple Books and Multimedia entities.
For avoiding performance issues and difficulties in extending this part of application in the future, I decided to expand database structure.



So each author has an authors_type, for example:
  • writer
  • composer
  • singer
  • band

Movies and music have a genre. Also movies have a type:
  • film
  • cartoon
  • anime

Also we should keep in mind next situations:
  •  movie has multiple genres
  •  author has multiple types (writer and producer)
  •  book has multiple authors

Now we can develop business layer for Books and Multimedia pages regarding to this database schema.

пʼятниця, 16 березня 2018 р.

Instant messenger implementation

Database structure

There are many answers on Stack Overflow and many articles on Internet about possible database structure for instant messenger application.
Database structure for different types of chat
Some advices regarding to database structure for chat: here and here with nice scheme on the pic

Instant messenger or chat can be divided into 3 categories:
  • private messenger 
  • group chat
  • public chat

Here is most typical and simple database structure:


This database schema works fine for private messenger, I use it in Diary messenger.

Can Message Queue Service be used to create a chat?

The answers:
  • Message/Queue service provides a way to post a message on queue and then receive that message on other end. If you are planning to have private chat between your users, this will not be a wise solution to implement because you will end up using multiple queue inside your application. Since we have restriction in creating queue (50 per app) this might be bottle neck for your app. Also, this is an offline messaging and not suited for real time chat application. [more]



How to implement WebSocket protocol in Java?

  • WebSocket implementation with Java 

Java API for WebSocket (JSR 356) provides support for creating WebSocket applications.
There are good tutorials:
Oracle documentation, Java API for WebSocket
Java EE 7: Building Web Applications with WebSocket, JavaScript and HTML5
  • WebSocket implementation with Spring (including STOMP)

How to work with STOMP and spring-messaging module
STOMP is just derived on top of WebSockets.
I have chosen STOMP protocol, because this protocol easy to implement for simple messaging system. Also, Java API for WebSocket (JSR 356) requires to use Java CDI rather than Spring. When you try to inject bean into server endpoint, there is an NPE.
"A class annotated by @Component is registered to a spring bean and its instance is managed by spring as a singleton by default. However, a class annotated by @ServerEndpoint is registered to a server-side WebSocket endpoint and every time the corresponding endpoint's WebSocket is connected to the server, its instance is created and managed by JWA implementation. Therefore, you can't use both annotations together.Maybe the simplest workaround is to use CDI instead of Spring. Of course, your server should support CDI." 
https://stackoverflow.com/questions/29306854/serverendpoint-and-autowired

I develop my project with Spring framework, so STOMP was better chose.
About the difference between CDI and Spring:
"CDI stands for "context and dependency injection", while Spring is a complete ecosystem around a dependency injection container. To compare both, you have to differentiate the comparison."  
https://stackoverflow.com/questions/5973364/is-cdi-a-good-replacement-of-spring

You need to deploy your project on TomEE or GlassFish server for working with CDI. Simple Tomcat  server is plain servlet container, which supports servlet and JSP technology, but not an CDI technology.



пʼятниця, 19 січня 2018 р.

Working with THC-Hydra


Recently I have solved one easy challenge on one of the virtual penetration labs.
It was web application security challenge. There is a login form, and you have to guess a password. The login is shown as a title of login page :)
I decided to use THC-Hydra, famous login cracker.

Books and Multimedia data structure

I'm developing web application, diary for travelers. And I have 'Books' and 'Multimedia' pages. The functionality of the...