Servlet provides server-side engine with open API for creating and deploying web chats. It is not a chat itself but a complete engine lets you create chat rooms and users, post and request messages etc. Current version supports REST API and outputs data in JSON, so your actual chat could be programmed with any language including JavaScript. And you can even deploy chats on mobile web with this engine. How to use it: 1) download chatengine.jar and save it in WEB-INF/lib 2) describe ChatEngine servlet in web.xml file.
3) define a mapping:
engine accepts some parameters as a part of request URI, so your requests look so for example:
or (if you are deploying Chat engine as a part of some web application):
app_name here is a name for your web application.
The model. Chat engine supports rooms (separate spaces). Each room
has got an unique ID and name. One room (ID is 0) exists always by default.
Chat's user can join to any room. Names and ID's within the room should be unique.
Published message is a plain text. You can publish private messages (addressed to
some user only) - just start the message (text) from @user_name pattern.
JSON API returns an object with two fields:
code - a status code for the request. 1 - success
Here is a full list of accepted commands:
version Returns a version info.
URL: /engine/version
Formats: JSON
HTTP Method: GET
Requires Authentication false
Parameters: none
--------------------------------------- restart Restarts the engine.
URL: /engine/restart
Formats: JSON
HTTP Method: GET
Requires Authentication false
Parameters: none
--------------------------------------- create room create a new chat room.
URL: /rooms/create
Formats: JSON
HTTP Method: GET
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- delete room delete a room.
URL: /rooms/delete
Formats: JSON
HTTP Method: GET
Requires Authentication false
Parameters:
--------------------------------------- clear room clear a room (delete all messages).
URL: /rooms/clear
HTTP Method: GET
Requires Authentication false
Parameters:
--------------------------------------- list rooms get a list of rooms
URL: /rooms/list
HTTP Method: GET
Requires Authentication false
Parameters: none
Fields in the response:
code - a status code
--------------------------------------- room info get room info
URL: /rooms/info
HTTP Method: GET
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- join to chat add user to room
URL: /users/login
HTTP Method: GET
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- leave the chat disconnect user from chat
URL: /users/logout
HTTP Method: GET
Requires Authentication false
Parameters:
--------------------------------------- list of users get list of users
URL: /users/list
HTTP Method: GET
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- user info get user info
URL: /users/info
HTTP Method: GET
Requires Authentication false
Parameters:
also you can optionally pass additional attributes from this user. Just set a
pair in your request: attribute_name and attribute_value
Fields in the response:
code - a status code
--------------------------------------- add message post a new message
URL: /messages/create
HTTP Method: GET, POST
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- get messages get last messages
URL: /messages/get
HTTP Method: GET
Requires Authentication false
Parameters:
Fields in the response:
code - a status code
--------------------------------------- and here you can download a JavaScript based chat you can use as a basic
example for Chat engine - simplechat.jsp
For downloading:
servlet: chatengine.jar
See also JSOS - the largest collection of servlets and filters.
|
Also in JSOS:
|