simplify the doip afterExec packing logic

This commit is contained in:
haoeliu@foxmail.com 2023-03-09 21:16:37 +08:00
parent fb8305031e
commit d040028463

View File

@ -6,6 +6,7 @@ import com.google.gson.JsonParser;
import org.bdware.doip.codec.doipMessage.DoipMessage; import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory; import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.doipMessage.DoipResponseCode; import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.codec.doipMessage.MessageHeader;
import org.bdware.doip.codec.operations.BasicOperations; import org.bdware.doip.codec.operations.BasicOperations;
import org.bdware.sc.JSEngine; import org.bdware.sc.JSEngine;
import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.bean.ContractRequest;
@ -72,17 +73,9 @@ public class DOOPAfterExecHandler implements AnnotationHook {
JsonObject header = jsonObjectRes.get("header") != null ? jsonObjectRes.get("header").getAsJsonObject() : null; JsonObject header = jsonObjectRes.get("header") != null ? jsonObjectRes.get("header").getAsJsonObject() : null;
String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null; String body = jsonObjectRes.get("body") != null ? jsonObjectRes.get("body").getAsString() : null;
originDoipMsg.header.setIsRequest(false); // 和HTTP一样所有需要的字段自己封装校验规则也比较简单这里只做简单的包装返回即可
if(header != null) { if(header != null) {
String headerRespCode = header.get("response") != null ? header.get("response").getAsString() : null; originDoipMsg.header = JsonUtil.fromJson(header, MessageHeader.class);
if(headerRespCode != null) {
originDoipMsg.header.parameters.response = DoipResponseCode.valueOf(headerRespCode);
}
// todo 其他的规则的添加
if(header.get("parameters") != null && header.get("parameters").getAsJsonObject().get("attributes") != null) {
originDoipMsg.header.parameters.attributes = header.get("parameters").getAsJsonObject().get("attributes").getAsJsonObject();
}
} }
if(body != null) { if(body != null) {