Copilot commented on code in PR #6228:
URL: https://github.com/apache/shenyu/pull/6228#discussion_r2532865081
##########
shenyu-client/shenyu-client-mcp/shenyu-client-mcp-register/src/main/java/org/apache/shenyu/client/mcp/McpServiceEventListener.java:
##########
@@ -65,14 +66,19 @@ public class McpServiceEventListener extends
AbstractContextRefreshedEventListen
private static final Logger log =
LoggerFactory.getLogger(McpServiceEventListener.class);
+ private final Environment env;
+
/**
* Instantiates a new context refreshed event listener.
*
* @param clientConfig the shenyu client config
* @param shenyuClientRegisterRepository the shenyuClientRegisterRepository
Review Comment:
The JavaDoc for the constructor is missing the `@param env` documentation.
Please add:
```java
/**
* Instantiates a new context refreshed event listener.
*
* @param clientConfig the shenyu client config
* @param shenyuClientRegisterRepository the shenyuClientRegisterRepository
* @param env the spring environment
*/
```
```suggestion
* @param shenyuClientRegisterRepository the
shenyuClientRegisterRepository
* @param env the spring environment
```
##########
shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java:
##########
@@ -583,9 +584,14 @@ private void configureShenyuContext(final
ServerWebExchange decoratedExchange,
} catch (URISyntaxException ignore) {
shenyuContext.setPath(decoratedPath);
}
-
- shenyuContext.setRealUrl(decoratedPath);
-
+ Map<String, Object> attributes = decoratedExchange.getAttributes();
+ String contextPath = (String)
attributes.get(Constants.CONTEXT_PATH);
+ if (Objects.isNull(contextPath) || decoratedPath.length() <
contextPath.length()) {
+ shenyuContext.setRealUrl(decoratedPath);
+ } else {
+ String realURI = decoratedPath.substring(contextPath.length());
+ shenyuContext.setRealUrl(realURI);
+ }
Review Comment:
The substring operation should verify that `decoratedPath` actually starts
with `contextPath` before performing the substring. Without this check, if
`decoratedPath` is longer than `contextPath` but doesn't start with it, the
substring operation could produce an incorrect result.
Consider adding a check:
```java
if (Objects.isNull(contextPath) || decoratedPath.length() <
contextPath.length() || !decoratedPath.startsWith(contextPath)) {
shenyuContext.setRealUrl(decoratedPath);
} else {
String realURI = decoratedPath.substring(contextPath.length());
shenyuContext.setRealUrl(realURI);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]