Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/CristianRR94/springCommunity/llms.txt

Use this file to discover all available pages before exploring further.

Spring Community provides two complementary ways to interact with event chat messages. The REST endpoint (GET /api/eventos/{eventoId}/mensajes) lets you fetch the full persisted history of messages for a given event — useful on initial page load or when reconnecting after a network drop. The WebSocket endpoint (/ws-chat, STOMP protocol) delivers messages in real time as participants send them, keeping all connected clients in sync without polling. Both mechanisms use the same HistorialMensajesDTO shape for the message payload, so you can render history and live messages with a single component.

REST — Get Chat History

Fetches all persisted messages for a specific event in chronological order. This endpoint is the recommended way to populate a chat view on load before the WebSocket connection is established.

GET /api/eventos/{eventoId}/mensajes

Authentication: Bearer ACCESS token required in the Authorization header.

Path parameters

eventoId
Long
required
The numeric ID of the event whose chat history you want to retrieve.

Response fields

The endpoint returns an array of HistorialMensajesDTO objects.
id
Long
required
Unique identifier of the persisted message record.
texto
string
required
The text content of the message. Maximum 1 000 characters.
participanteId
Long
required
ID of the participant who sent the message.
nombreParticipante
string
required
Display name of the sender at the time the message was stored.
fechaEnvio
string
required
ISO 8601 datetime string recording when the message was persisted, e.g. 2025-06-01T14:30:00. Derived from the LocalDateTime stored on the Mensaje entity via TimestampEntity.

Response example

[
  {
    "id": 101,
    "texto": "Has anyone confirmed the venue?",
    "participanteId": 1,
    "nombreParticipante": "alice92",
    "fechaEnvio": "2025-06-01T14:22:10"
  },
  {
    "id": 102,
    "texto": "Yes, it's confirmed for Saturday!",
    "participanteId": 2,
    "nombreParticipante": "bobsmith",
    "fechaEnvio": "2025-06-01T14:23:45"
  }
]

Error responses

StatusCondition
401 UnauthorizedToken is missing, expired (ExpiredJwtException), or has an invalid signature (SignatureException / MalformedJwtException).
404 Not FoundNo event exists with the given eventoId (EventoNotFoundException).

curl

curl -X GET http://localhost:8080/api/eventos/1/mensajes \
  -H "Authorization: Bearer <accessToken>"

WebSocket — Send and Receive Messages in Real Time

The real-time chat layer is built on STOMP over WebSocket. Clients connect to the /ws-chat endpoint, subscribe to a per-event topic, and publish messages to an application destination. The server persists each incoming message via MensajeService.guardarMensaje and immediately broadcasts the stored HistorialMensajesDTO to all subscribers of that event’s topic. WebSocket endpoint: ws://localhost:8080/ws-chat (STOMP) Subscribe to receive messages: /topic/evento/{eventoId} Publish to send a message: /app/chat/{eventoId}
WebSocket connections require a valid, non-expired, non-revoked ACCESS token. Pass the token in the STOMP CONNECT frame headers as Authorization: Bearer <accessToken>. Expired or tampered tokens are rejected by JwtChannelInterceptor and the connection will be immediately closed.

Authentication

Send the bearer token as a header in the STOMP CONNECT frame:
Authorization: Bearer <accessToken>
This is handled automatically when you set connectHeaders in the STOMP.js client (see example below).

Sending a message — MensajeDTO fields

Publish a JSON-serialised MensajeDTO to /app/chat/{eventoId}.
texto
string
required
The text content of the message. Must not be blank. Maximum 1 000 characters. Validated server-side with @NotBlank and @Size(max=1000); a violation returns a 400 Bad Request error frame.
nombreParticipante
string
Display name of the sending participant. Used for display purposes within the broadcast payload.
participanteId
Long
ID of the participant sending the message.
eventoId
Long
ID of the event this message belongs to. Should match the {eventoId} in the destination path.

Broadcast payload

After the server persists the message it broadcasts a HistorialMensajesDTO to /topic/evento/{eventoId}. All clients subscribed to that topic receive it immediately. The shape is identical to the REST history response:
FieldTypeDescription
idLongAuto-generated ID of the persisted message.
textostringMessage content.
participanteIdLongID of the sender’s participant record.
nombreParticipantestringDisplay name of the sender.
fechaEnviostringISO 8601 datetime when the message was saved.

JavaScript example (STOMP.js)

The following example uses the @stomp/stompjs library to connect, subscribe to event 1, and publish a message.
import { Client } from '@stomp/stompjs';

const client = new Client({
  brokerURL: 'ws://localhost:8080/ws-chat',
  connectHeaders: {
    Authorization: 'Bearer <accessToken>'
  },
  onConnect: () => {
    // Subscribe to receive all messages for event ID 1
    client.subscribe('/topic/evento/1', (frame) => {
      const msg = JSON.parse(frame.body);
      console.log(msg.nombreParticipante + ': ' + msg.texto);
    });

    // Publish a new message to event ID 1
    client.publish({
      destination: '/app/chat/1',
      body: JSON.stringify({
        texto: 'Hello, event!',
        nombreParticipante: 'alice92',
        participanteId: 42,
        eventoId: 1
      })
    });
  }
});

client.activate();
Replace <accessToken> with the JWT string obtained from the authentication flow. The eventoId in the subscribe path and the destination path must match the event whose chat you want to join. Subscribing to /topic/evento/1 will not deliver messages published to /app/chat/2.

Error handling

ScenarioBehaviour
Expired or invalid token at connect timeJwtChannelInterceptor rejects the CONNECT frame; the WebSocket connection is closed.
texto blank or over 1 000 charactersServer returns a STOMP ERROR frame with a 400 Bad Request message derived from the @NotBlank / @Size constraint annotations on MensajeDTO.
Unknown eventoIdEventoNotFoundException is thrown server-side; the message is not persisted and not broadcast.

Build docs developers (and LLMs) love