mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: JsonUtils now in charge of file to JSON
parent
28b33203c9
commit
a8ffe78411
|
@ -443,7 +443,7 @@ public abstract class SessionManager {
|
|||
try {
|
||||
closeSession(sessionId, EndReason.openviduServerStopped);
|
||||
} catch (Exception e) {
|
||||
log.warn("Error closing session '{}'", sessionId, e);
|
||||
log.warn("Error closing session '{}': {}", sessionId, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,21 +19,19 @@ package io.openvidu.server.recording;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.server.utils.JsonUtils;
|
||||
|
||||
public class RecordingInfoUtils {
|
||||
|
||||
private JsonParser parser;
|
||||
private JsonObject json;
|
||||
private JsonObject jsonFormat;
|
||||
private JsonObject videoStream;
|
||||
|
@ -44,10 +42,9 @@ public class RecordingInfoUtils {
|
|||
public RecordingInfoUtils(String infoFilePath) throws FileNotFoundException, IOException, OpenViduException {
|
||||
|
||||
this.infoFilePath = infoFilePath;
|
||||
this.parser = new JsonParser();
|
||||
|
||||
try {
|
||||
this.json = parser.parse(new FileReader(infoFilePath)).getAsJsonObject();
|
||||
this.json = new JsonUtils().fromFileToJson(infoFilePath);
|
||||
} catch (JsonIOException | JsonSyntaxException e) {
|
||||
// Recording metadata from ffprobe is not a JSON: video file is corrupted
|
||||
throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, "The recording file is corrupted");
|
||||
|
|
|
@ -34,7 +34,7 @@ public class RecordingsHttpHandler implements WebMvcConfigurer {
|
|||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
|
||||
String recordingsPath = openviduConfig.getOpenViduRecordingPath();
|
||||
recordingsPath = recordingsPath.endsWith("/") ? recordingsPath : recordingsPath + "/";
|
||||
recordingsPath = recordingsPath.endsWith("/") ? recordingsPath : (recordingsPath + "/");
|
||||
|
||||
openviduConfig.setOpenViduRecordingPath(recordingsPath);
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ public class ComposedRecordingService extends RecordingService {
|
|||
} catch (IOException e) {
|
||||
recording.setStatus(io.openvidu.java.client.Recording.Status.failed);
|
||||
throw new OpenViduException(Code.RECORDING_REPORT_ERROR_CODE,
|
||||
"There was an error generating the metadata report file for the recording");
|
||||
"There was an error generating the metadata report file for the recording: " + e.getMessage());
|
||||
}
|
||||
|
||||
String filesPath = this.openviduConfig.getOpenViduRecordingPath() + recording.getId() + "/";
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package io.openvidu.server.recording.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -48,8 +47,9 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
|
@ -70,6 +70,7 @@ import io.openvidu.server.recording.Recording;
|
|||
import io.openvidu.server.recording.RecordingDownloader;
|
||||
import io.openvidu.server.utils.CustomFileManager;
|
||||
import io.openvidu.server.utils.DockerManager;
|
||||
import io.openvidu.server.utils.JsonUtils;
|
||||
|
||||
public class RecordingManager {
|
||||
|
||||
|
@ -102,6 +103,8 @@ public class RecordingManager {
|
|||
protected Map<String, Recording> sessionsRecordings = new ConcurrentHashMap<>();
|
||||
private final Map<String, ScheduledFuture<?>> automaticRecordingStopThreads = new ConcurrentHashMap<>();
|
||||
|
||||
private JsonUtils jsonUtils = new JsonUtils();
|
||||
|
||||
private ScheduledThreadPoolExecutor automaticRecordingStopExecutor = new ScheduledThreadPoolExecutor(
|
||||
Runtime.getRuntime().availableProcessors());
|
||||
|
||||
|
@ -403,19 +406,12 @@ public class RecordingManager {
|
|||
|
||||
public Recording getRecordingFromEntityFile(File file) {
|
||||
if (file.isFile() && file.getName().startsWith(RecordingManager.RECORDING_ENTITY_FILE)) {
|
||||
JsonObject json = null;
|
||||
FileReader fr = null;
|
||||
JsonObject json;
|
||||
try {
|
||||
fr = new FileReader(file);
|
||||
json = new JsonParser().parse(fr).getAsJsonObject();
|
||||
} catch (IOException e) {
|
||||
json = jsonUtils.fromFileToJson(file.getAbsolutePath());
|
||||
} catch (JsonIOException | JsonSyntaxException | IOException e) {
|
||||
log.error("Error reading recording entity file {}: {}", file.getAbsolutePath(), (e.getMessage()));
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
fr.close();
|
||||
} catch (Exception e) {
|
||||
log.error("Exception while closing FileReader: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
Recording recording = new Recording(json);
|
||||
if (io.openvidu.java.client.Recording.Status.ready.equals(recording.getStatus())
|
||||
|
|
|
@ -18,16 +18,32 @@
|
|||
package io.openvidu.server.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class CommandExecutor {
|
||||
|
||||
public static String execCommand(String... command) throws IOException, InterruptedException {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
return commonExecCommand(processBuilder);
|
||||
}
|
||||
|
||||
public static String execCommandRedirectError(File errorOutputFile, String... command)
|
||||
throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectError(errorOutputFile);
|
||||
return commonExecCommand(processBuilder);
|
||||
}
|
||||
|
||||
public static String execCommandRedirectStandardOutputAndError(File standardOutputFile, File errorOutputFile,
|
||||
String... command) throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
||||
.redirectError(errorOutputFile);
|
||||
return commonExecCommand(processBuilder);
|
||||
}
|
||||
|
||||
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
||||
Process process = processBuilder.start();
|
||||
StringBuilder processOutput = new StringBuilder();
|
||||
|
||||
|
@ -40,7 +56,6 @@ public class CommandExecutor {
|
|||
}
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
return processOutput.toString().trim();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,12 +17,17 @@
|
|||
|
||||
package io.openvidu.server.utils;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kurento.jsonrpc.Props;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
|
@ -38,4 +43,16 @@ public class JsonUtils {
|
|||
return props;
|
||||
}
|
||||
|
||||
public JsonObject fromFileToJson(String filePath) throws JsonIOException, JsonSyntaxException, IOException {
|
||||
JsonObject json;
|
||||
JsonParser parser = new JsonParser();
|
||||
FileReader reader = new FileReader(filePath);
|
||||
try {
|
||||
json = parser.parse(new FileReader(filePath)).getAsJsonObject();
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue