Fix MissingPropertyException in EnhancedMcpServlet on session lookup failure
Showing
1 changed file
with
15 additions
and
3 deletions
| ... | @@ -562,8 +562,13 @@ try { | ... | @@ -562,8 +562,13 @@ try { |
| 562 | // Initialize web facade for proper session management (like SSE connections) | 562 | // Initialize web facade for proper session management (like SSE connections) |
| 563 | // This prevents the null user loop by ensuring HTTP session is properly linked | 563 | // This prevents the null user loop by ensuring HTTP session is properly linked |
| 564 | try { | 564 | try { |
| 565 | // If we have a visit, make sure it's in the request/session before initWebFacade | ||
| 566 | if (visit) { | ||
| 567 | request.setAttribute("moqui.visitId", visit.visitId) | ||
| 568 | request.getSession().setAttribute("moqui.visitId", visit.visitId) | ||
| 569 | } | ||
| 565 | ec.initWebFacade(webappName, request, response) | 570 | ec.initWebFacade(webappName, request, response) |
| 566 | logger.debug("JSON-RPC web facade initialized for user: ${ec.user?.username}") | 571 | logger.debug("JSON-RPC web facade initialized for user: ${ec.user?.username} with visit: ${ec.user.visitId}") |
| 567 | } catch (Exception e) { | 572 | } catch (Exception e) { |
| 568 | logger.warn("JSON-RPC web facade initialization failed: ${e.message}") | 573 | logger.warn("JSON-RPC web facade initialization failed: ${e.message}") |
| 569 | // Continue anyway - we may still have basic user context from auth | 574 | // Continue anyway - we may still have basic user context from auth |
| ... | @@ -708,9 +713,9 @@ try { | ... | @@ -708,9 +713,9 @@ try { |
| 708 | // This ensures Moqui picks up the existing Visit when initWebFacade() is called | 713 | // This ensures Moqui picks up the existing Visit when initWebFacade() is called |
| 709 | if (sessionId && rpcRequest.method != "initialize") { | 714 | if (sessionId && rpcRequest.method != "initialize") { |
| 710 | try { | 715 | try { |
| 716 | ec.artifactExecution.disableAuthz() | ||
| 711 | def existingVisit = ec.entity.find("moqui.server.Visit") | 717 | def existingVisit = ec.entity.find("moqui.server.Visit") |
| 712 | .condition("visitId", sessionId) | 718 | .condition("visitId", sessionId) |
| 713 | .disableAuthz() | ||
| 714 | .one() | 719 | .one() |
| 715 | 720 | ||
| 716 | if (!existingVisit) { | 721 | if (!existingVisit) { |
| ... | @@ -750,6 +755,8 @@ try { | ... | @@ -750,6 +755,8 @@ try { |
| 750 | id: rpcRequest.id | 755 | id: rpcRequest.id |
| 751 | ])) | 756 | ])) |
| 752 | return | 757 | return |
| 758 | } finally { | ||
| 759 | ec.artifactExecution.enableAuthz() | ||
| 753 | } | 760 | } |
| 754 | } | 761 | } |
| 755 | 762 | ||
| ... | @@ -1063,6 +1070,7 @@ try { | ... | @@ -1063,6 +1070,7 @@ try { |
| 1063 | logger.debug("Enhanced Calling MCP service: ${serviceName} with params: ${params}") | 1070 | logger.debug("Enhanced Calling MCP service: ${serviceName} with params: ${params}") |
| 1064 | 1071 | ||
| 1065 | try { | 1072 | try { |
| 1073 | ec.artifactExecution.disableAuthz() | ||
| 1066 | def result = ec.service.sync().name("McpServices.${serviceName}") | 1074 | def result = ec.service.sync().name("McpServices.${serviceName}") |
| 1067 | .parameters(params ?: [:]) | 1075 | .parameters(params ?: [:]) |
| 1068 | .call() | 1076 | .call() |
| ... | @@ -1084,6 +1092,8 @@ try { | ... | @@ -1084,6 +1092,8 @@ try { |
| 1084 | } catch (Exception e) { | 1092 | } catch (Exception e) { |
| 1085 | logger.error("Error calling Enhanced MCP service ${serviceName}", e) | 1093 | logger.error("Error calling Enhanced MCP service ${serviceName}", e) |
| 1086 | return [error: e.message] | 1094 | return [error: e.message] |
| 1095 | } finally { | ||
| 1096 | ec.artifactExecution.enableAuthz() | ||
| 1087 | } | 1097 | } |
| 1088 | } | 1098 | } |
| 1089 | 1099 | ||
| ... | @@ -1248,10 +1258,10 @@ try { | ... | @@ -1248,10 +1258,10 @@ try { |
| 1248 | */ | 1258 | */ |
| 1249 | void broadcastToAllSessions(JsonRpcMessage message) { | 1259 | void broadcastToAllSessions(JsonRpcMessage message) { |
| 1250 | try { | 1260 | try { |
| 1261 | ec.artifactExecution.disableAuthz() | ||
| 1251 | // Look up all MCP Visits (persistent) | 1262 | // Look up all MCP Visits (persistent) |
| 1252 | def mcpVisits = ec.entity.find("moqui.server.Visit") | 1263 | def mcpVisits = ec.entity.find("moqui.server.Visit") |
| 1253 | .condition("initialRequest", "like", "%mcpSession%") | 1264 | .condition("initialRequest", "like", "%mcpSession%") |
| 1254 | .disableAuthz() | ||
| 1255 | .list() | 1265 | .list() |
| 1256 | 1266 | ||
| 1257 | logger.info("Broadcasting to ${mcpVisits.size()} MCP visits, ${activeConnections.size()} active connections") | 1267 | logger.info("Broadcasting to ${mcpVisits.size()} MCP visits, ${activeConnections.size()} active connections") |
| ... | @@ -1282,6 +1292,8 @@ try { | ... | @@ -1282,6 +1292,8 @@ try { |
| 1282 | 1292 | ||
| 1283 | } catch (Exception e) { | 1293 | } catch (Exception e) { |
| 1284 | logger.error("Error broadcasting to all sessions: ${e.message}", e) | 1294 | logger.error("Error broadcasting to all sessions: ${e.message}", e) |
| 1295 | } finally { | ||
| 1296 | ec.artifactExecution.enableAuthz() | ||
| 1285 | } | 1297 | } |
| 1286 | } | 1298 | } |
| 1287 | 1299 | ... | ... |
-
Please register or sign in to post a comment