9100端口无法连接问题(重启wda),打印无法获取设备token的日志
parent
40ba86aff5
commit
d5f77b7295
|
@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -163,18 +164,20 @@ public class IosScreenResponseThread extends ImageScreenResponse {
|
|||
|
||||
//有后端会话则给后端推送屏幕图片
|
||||
if (!CollectionUtils.isEmpty(webSessions)) {
|
||||
for (Session webSession : webSessions) {
|
||||
Iterator<Session> iterator = webSessions.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Session webSession = iterator.next();
|
||||
if (webSession.isOpen()) {
|
||||
if (sendDeviceStatus) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.CONNECTED);
|
||||
SessionUtils.sendMessageInitiative(webSession, ResponseCmd.DEVICE_STATUS, phone.getUdid(), result, "设备连接失败");
|
||||
SessionUtils.sendMessageInitiative(webSession, ResponseCmd.DEVICE_STATUS, deviceId, result, "设备连接失败");
|
||||
sendDeviceStatus = false;
|
||||
}
|
||||
SessionUtils.sendBinary(webSession, rawImageFileByteArray);
|
||||
} else {
|
||||
logger.warn("推送到web端的session已经断开,sessionId:{}",webSession.getId());
|
||||
//todo:操作一下,去掉webSessions里面的无效session
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
|
@ -67,11 +66,6 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
|
|||
if (xctestPath == null) {
|
||||
throw new IllegalStateException("未准备好iOS " + productMainVersion + "的xctest");
|
||||
}
|
||||
File logDir = new File(UpperComputerManager.getInstance().getApplicationPath() + "/wdaLog");
|
||||
if (!logDir.exists()) {
|
||||
logDir.mkdirs();
|
||||
}
|
||||
logFileName = logDir.getAbsolutePath() + "/" + "WDA-" + appleDevice.getConnectionDetail().serialNumber + "-" + getLogFileNameDateTime() + ".log";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,25 +83,32 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
|
|||
"id=" + appleDevice.getConnectionDetail().serialNumber
|
||||
);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
try {
|
||||
process = processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
logger.error("启动WDA时发生IO异常", e);
|
||||
return;
|
||||
}
|
||||
FileOutputStream logOutput = null;
|
||||
try {
|
||||
logOutput = new FileOutputStream(logFileName);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("尝试创建独立日志文件时发生异常", e);
|
||||
}
|
||||
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
do {
|
||||
while (!isInterrupted()) {
|
||||
try {
|
||||
String line = bufferReader.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
} else {
|
||||
process = processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
logger.error("启动WDA时发生IO异常", e);
|
||||
return;
|
||||
}
|
||||
FileOutputStream logOutput = null;
|
||||
File logDir = new File(UpperComputerManager.getInstance().getApplicationPath() + "/wdaLog");
|
||||
if (!logDir.exists()) {
|
||||
logDir.mkdirs();
|
||||
}
|
||||
logFileName = logDir.getAbsolutePath() + "/" + "WDA-" + appleDevice.getConnectionDetail().serialNumber + "-" + getLogFileNameDateTime() + ".log";
|
||||
try {
|
||||
logOutput = new FileOutputStream(logFileName);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("尝试创建独立日志文件时发生异常", e);
|
||||
return;
|
||||
}
|
||||
InputStreamReader inputStreamReader = null;
|
||||
BufferedReader bufferReader = null;
|
||||
String line = null;
|
||||
try {
|
||||
inputStreamReader = new InputStreamReader(process.getInputStream());
|
||||
bufferReader = new BufferedReader(inputStreamReader);
|
||||
while ((line = bufferReader.readLine()) != null) {
|
||||
if (wdaConfig.isPrintWdaOutput()) {
|
||||
logger.debug("WDA-" + appleDevice.getConnectionDetail().serialNumber + "->" + line);
|
||||
}
|
||||
|
@ -133,23 +134,38 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("读取WDA输出时发生IO异常,设备" + appleDevice.getConnectionDetail().serialNumber, e);
|
||||
}finally {
|
||||
if (null != inputStreamReader) {
|
||||
try {
|
||||
inputStreamReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != bufferReader) {
|
||||
try {
|
||||
bufferReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
exitCode = process.waitFor();
|
||||
} catch (InterruptedException ignored) {
|
||||
break;
|
||||
}
|
||||
} while (!isInterrupted());
|
||||
|
||||
try {
|
||||
exitCode = process.waitFor();
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
|
||||
if (logOutput != null) {
|
||||
try {
|
||||
logOutput.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("关闭WDA独立日志流时发生IO异常,路径:{}", logFileName, e);
|
||||
if (logOutput != null) {
|
||||
try {
|
||||
logOutput.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("关闭WDA独立日志流时发生IO异常,路径:{}", logFileName, e);
|
||||
}
|
||||
}
|
||||
logger.debug("设备【{}】的wda退出了,重启一次......................", appleDevice.getConnectionDetail().serialNumber);
|
||||
isFBServerReady = false;
|
||||
}
|
||||
logger.debug("设备【{}】的wda退出了,不在重启了......................", appleDevice.getConnectionDetail().serialNumber);
|
||||
}
|
||||
|
||||
|
||||
|
@ -232,10 +248,10 @@ public class MacIosDeviceInitThread extends IosDeviceInitThread {
|
|||
deviceInfo.put("wdaUrl", "http://" + UpperComputerManager.getInstance().getHost() + ":" + phone.getPort8100());
|
||||
int rotation = screenInfoData.getOrientation() - 1;
|
||||
if (rotation < 0) {
|
||||
logger.debug("无法获取设备【{}】的屏幕方向,默认为0",phone.getUdid());
|
||||
logger.debug("无法获取设备【{}】的屏幕方向,默认为0", phone.getUdid());
|
||||
rotation = 0;
|
||||
}
|
||||
deviceInfo.put("rotation",rotation );
|
||||
deviceInfo.put("rotation", rotation);
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ public class MobileSessionManager {
|
|||
session.setMaxBinaryMessageBufferSize(50 * 1024 * 1024);
|
||||
String deviceId = SpringUtils.getBean(MobileConnectService.class).getDeviceIdByToken(deviceToken);
|
||||
if (StringUtils.isBlank(deviceId)) {
|
||||
logger.debug("未获取到设备id对应的设备token:{}", deviceToken);
|
||||
UpperWSResponse response = buildErrorMessage(null, "根据设备token获取设备id为空");
|
||||
sendErrorMessageToWeb(session,JSON.toJSONString(response));
|
||||
// closeSession(session, CloseReason.CloseCodes.CANNOT_ACCEPT,"根据设备token获取设备id为空!");
|
||||
|
|
Loading…
Reference in New Issue