org.bdware.doip.audit.AuditIrpMessageFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.audit;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.bdware.doip.audit.writer.AuditRepo;
import org.bdware.doip.auditrepo.AutoAuditDO;
import org.bdware.irp.irplib.core.IrpMessage;
import org.bdware.irp.irplib.core.IrpMessageCode;
import org.bdware.irp.irplib.core.IrpRequest;
import org.bdware.irp.irplib.core.IrpResponse;
import org.bdware.irp.irplib.util.EncoderUtils;
public class AuditIrpMessageFactory {
static final String DOID_DEFAULT = "doid_router";
public static IrpRequest newAuditRepoRequest() {
IrpRequest req = new IrpRequest(IrpMessageCode.OC_QUERY_ROUTER, DOID_DEFAULT);
req.doid = EncoderUtils.encodeString(AutoAuditDO.AUDIT_PROXY);
JsonObject values = new JsonObject();
values.addProperty("queryInfo", AutoAuditDO.AUDIT_PROXY);
req.doidValues = IrpMessage.fromJson2Byte(values);
return req;
}
public static boolean isAuditRepoRequest(IrpMessage msg) {
try {
JsonObject value = ((IrpRequest) msg).getDoidValues();
if (value != null && value.has("queryInfo") && AutoAuditDO.AUDIT_PROXY.equals(value.get("queryInfo").getAsString())) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static IrpMessage newAuditRepoResponse(String auditDoid, String auditUrl) {
IrpResponse res = new IrpResponse(IrpMessageCode.OC_QUERY_ROUTER, IrpMessageCode.RC_SUCCESS);
res.doid = EncoderUtils.encodeString(auditDoid);
res.requestDigestNeeded = false;
JsonObject resp = new JsonObject();
resp.addProperty("auditDoid", auditDoid);
resp.addProperty("auditUrl", auditUrl);
res.doidValues = IrpMessage.fromJson2Byte(resp);
return res;
}
public static AuditRepo getAuditRepo(IrpResponse msg) {
try {
JsonObject ret = IrpMessage.fromByte2Json(msg.doidValues);
Gson gson = new Gson();
if (ret.has("auditDoid") && ret.has("auditUrl")) {
return gson.fromJson(gson.toJson(ret), AuditRepo.class);
}
} catch (Exception e) {
}
return null;
}
}