-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The webSocket message class cannot generate a document #850
Comments
@PGJiang Can you provide some additional code examples? |
I have the same issue ,my code as follow:
|
In WebSocket programming, it's common to handle URL parameters within the @ServerEndpoint("/documents/did/{did}/bid/{bid}")
@RestController
public class DocumentWebSocketController {
private int documentId;
private String branchBid;
/**
* Handles the opening of a WebSocket connection.
*
* @param session the WebSocket session
* @param documentId the ID of the document
* @param branchBid the ID of the branch
*/
@OnOpen
public void onOpen(Session session, @PathParam("did") int documentId,
@PathParam("bid") String branchBid) {
this.documentId = documentId;
this.branchBid = branchBid;
}
@OnMessage
public void receive(String message, Session session) {
// You can now use documentId and branchBid here
// Example usage:
System.out.println("Received message: " + message + " for Document ID: " + documentId + " and Branch ID: " + branchBid);
}
@OnClose
public void onClose(Session session) {
// Handle close event
}
} By defining the parameters in the You can refer to this example: |
Thank you for your reply! My code is meet the requirement which you discribe, but it can't gen the api document. @Slf4j
@ServerEndpoint("/documents/did/{did}/bid/{bid}/mid/{mid}")
@RestController
public class DocumentWebSocketController {
private static final int HEARTBEAT_TIME = 30;
private static CommandFactory commandFactory;
private static ObjectMapper objectMapper;
@Autowired
public void init(CommandFactory commandFactory, ObjectMapper objectMapper) {
this.commandFactory = commandFactory;
this.objectMapper = objectMapper;
}
@OnMessage
public void receive(String message, Session session, @PathParam("did") int documentId,
@PathParam("bid") String branchBid) {
log.info("[websocket] 收到消息:id={},message={}", session.getId(), message);
}
@OnMessage
public void heartBeat(PongMessage heartBeat, Session session, @PathParam("did") int documentId,
@PathParam("bid") String branchBid) {
}
// 连接打开
@OnOpen
public void onOpen(Session session, @PathParam("did") int documentId, @PathParam("bid") String branchBid) {
log.info("[websocket] 新的连接:id={}, did={}, bid={}", session.getId(), documentId, branchBid);
}
// 连接关闭
@OnClose
public void onClose(Session session, CloseReason closeReason, @PathParam("did") int documentId, @PathParam("bid") String branchBid) {
log.info("[websocket] 连接断开:id={}, did={}, bid={},reason={}", session.getId(), documentId, branchBid, closeReason);
}
// 连接异常
@OnError
public void onError(Session session, Throwable throwable, @PathParam("did") int documentId, @PathParam("bid") String branchBid) throws IOException {
log.info("[websocket] 连接异常:id={},throwable={}, did={}, bid={}", session.getId(), documentId, branchBid, throwable.getMessage());
}
} |
@skydream-xu I used your sample code to run, and the result was that the websocket document could be generated. |
The webSocket message class cannot generate a document
The text was updated successfully, but these errors were encountered: