fix: 调整 env api path 路径

This commit is contained in:
zhangshuai
2024-09-04 14:28:00 +08:00
parent 64f5a46928
commit a9251f238c
4 changed files with 11 additions and 11 deletions

View File

@@ -81,7 +81,7 @@ public class EnvironmentWebSocketHandler extends TextWebSocketHandler {
return; return;
} }
String urlStr = String.format("%s%s", paramJSONObject.getStr("url"), Constants.DEVICE_API_WEBSOCKET_PATH); String urlStr = String.format("%s%s", paramJSONObject.getStr("url"), Constants.ENV_API_PREFIX);
urlStr = urlStr.replace("http", "ws"); urlStr = urlStr.replace("http", "ws");
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();

View File

@@ -56,9 +56,9 @@ public class Constants {
/** /**
* device api path prefix * env api path prefix
*/ */
public static final String DEVICE_API_PREFIX = "/api/v1/device"; public static final String ENV_API_PREFIX = "/api/v1/env";
public static final String AUTH_TOKEN_CODE = "Authorization"; public static final String AUTH_TOKEN_CODE = "Authorization";
@@ -70,7 +70,7 @@ public class Constants {
/** /**
* device api websocket path * env api websocket path
*/ */
public static final String DEVICE_API_WEBSOCKET_PATH = "/api/v1/device/websocket"; public static final String ENV_API_WEBSOCKET_PATH = "/api/v1/env/websocket";
} }

View File

@@ -78,7 +78,7 @@ public class EnvironmentController {
} }
try { try {
HttpRequest request = T.HttpUtil.createGet(String.format("%s/api/v1/device/status", url)); HttpRequest request = T.HttpUtil.createGet(String.format("%s/api/v1/env/status", url));
request.header("Authorization", token); request.header("Authorization", token);
HttpResponse response = request.execute(); HttpResponse response = request.execute();
log.info("[testConnect] [status: {}]", response.getStatus()); log.info("[testConnect] [status: {}]", response.getStatus());

View File

@@ -40,11 +40,11 @@ public class EnvironmentUtil {
public static void getForObject(EnvironmentEntity device, HttpServletRequest request, HttpServletResponse response, String sessionId) throws IOException, ServletException { public static void getForObject(EnvironmentEntity device, HttpServletRequest request, HttpServletResponse response, String sessionId) throws IOException, ServletException {
// path // path
String pathProfix = T.StrUtil.concat(true, Constants.DEVICE_API_PREFIX, "/", device.getId()); String pathProfix = T.StrUtil.concat(true, Constants.ENV_API_PREFIX, "/", device.getId());
String[] paths = request.getServletPath().split(sessionId); String[] paths = request.getServletPath().split(sessionId);
String path = Arrays.asList(paths).getLast(); String path = Arrays.asList(paths).getLast();
path = path.startsWith("/") ? (String.format("%s%s", Constants.DEVICE_API_PREFIX, path)) path = path.startsWith("/") ? (String.format("%s%s", Constants.ENV_API_PREFIX, path))
: (String.format("%s/%s", Constants.DEVICE_API_PREFIX, path)); : (String.format("%s/%s", Constants.ENV_API_PREFIX, path));
// host port token // host port token
JSONObject jsonObject = device.getParamJSONObject(); JSONObject jsonObject = device.getParamJSONObject();
@@ -106,7 +106,7 @@ public class EnvironmentUtil {
try { try {
responseEntity = restTemplate.exchange(new URI(urlStr), HttpMethod.valueOf(request.getMethod()), httpEntity, byte[].class); responseEntity = restTemplate.exchange(new URI(urlStr), HttpMethod.valueOf(request.getMethod()), httpEntity, byte[].class);
} catch (Exception e) { } catch (Exception e) {
log.error(e, "device request error. url:{}", urlStr); log.error(e, "env request error. url:{}", urlStr);
String message = e.getMessage(); String message = e.getMessage();
if (ObjectUtil.isNotNull(e.getCause())) { if (ObjectUtil.isNotNull(e.getCause())) {
message = e.getCause().getMessage(); message = e.getCause().getMessage();
@@ -116,7 +116,7 @@ public class EnvironmentUtil {
HttpHeaders httpHeaders = responseEntity.getHeaders(); HttpHeaders httpHeaders = responseEntity.getHeaders();
int statusCode = responseEntity.getStatusCodeValue(); int statusCode = responseEntity.getStatusCodeValue();
log.info("device request url:{}, responseStatus:{}", urlStr, statusCode); log.info("env request url:{}, responseStatus:{}", urlStr, statusCode);
byte[] responseBody = responseEntity.getBody(); byte[] responseBody = responseEntity.getBody();
response.reset(); response.reset();