|
@@ -1,103 +1,115 @@
|
|
|
package com.its.rota.server.xnet.server.process.response;
|
|
package com.its.rota.server.xnet.server.process.response;
|
|
|
|
|
|
|
|
-import com.beanit.its.C2CAuthenticatedMessage;
|
|
|
|
|
-import com.beanit.its.PDUs;
|
|
|
|
|
-import com.its.app.common.utils.NettyUtils;
|
|
|
|
|
|
|
+import com.beanit.asn1bean.ber.types.BerEnum;
|
|
|
|
|
+import com.beanit.enums.eObjectId;
|
|
|
|
|
+import com.beanit.enums.eRejectSubscription;
|
|
|
|
|
+import com.beanit.its.*;
|
|
|
|
|
+import com.beanit.utils.ItsAsnUtils;
|
|
|
import com.its.rota.server.dto.CenterDto;
|
|
import com.its.rota.server.dto.CenterDto;
|
|
|
|
|
+import com.its.rota.server.xnet.server.process.request.AiAccept;
|
|
|
|
|
+import com.its.rota.server.xnet.server.process.request.AiReject;
|
|
|
import com.its.rota.server.xnet.server.process.service.SubscriptionService;
|
|
import com.its.rota.server.xnet.server.process.service.SubscriptionService;
|
|
|
-import io.netty.channel.ChannelFuture;
|
|
|
|
|
-import io.netty.channel.ChannelHandlerContext;
|
|
|
|
|
|
|
+import com.its.rota.server.xnet.server.process.service.impl.SubscriptionRegisterService;
|
|
|
|
|
+import com.its.rota.server.xnet.server.process.service.impl.SubscriptionSingleService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.slf4j.MDC;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class SubscriptionResponse implements ItsAsnResponse {
|
|
public class SubscriptionResponse implements ItsAsnResponse {
|
|
|
- private CenterDto obj;
|
|
|
|
|
- private ChannelHandlerContext ctx;
|
|
|
|
|
- private C2CAuthenticatedMessage c2c;
|
|
|
|
|
|
|
+ private final CenterDto center;
|
|
|
|
|
+ private final C2CAuthenticatedMessage c2c;
|
|
|
|
|
|
|
|
- public SubscriptionResponse(CenterDto obj, ChannelHandlerContext ctx, C2CAuthenticatedMessage c2c) {
|
|
|
|
|
- this.obj = obj;
|
|
|
|
|
- this.ctx = ctx;
|
|
|
|
|
|
|
+ public SubscriptionResponse(CenterDto center, C2CAuthenticatedMessage c2c) {
|
|
|
|
|
+ this.center = center;
|
|
|
this.c2c = c2c;
|
|
this.c2c = c2c;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean response() {
|
|
public boolean response() {
|
|
|
- String ipAddress = NettyUtils.getRemoteIpAddress(this.ctx.channel());
|
|
|
|
|
- log.debug("SubscriptionResponse.response: {}", ipAddress);
|
|
|
|
|
|
|
+ // AI_Accept or AI_Reject 로 응답
|
|
|
|
|
+ boolean result = true;
|
|
|
|
|
+ boolean accepted = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ MDC.put("id", this.center.getLogKey());
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}].", this.center.getLogKey(), this.center.getIpAddress());
|
|
|
|
|
|
|
|
- int dataPacketNmbr = this.c2c.getDatexDataPacketNumber().intValue();
|
|
|
|
|
- int objectId = 0;
|
|
|
|
|
- SubscriptionService subscriptionService = null;
|
|
|
|
|
- C2CAuthenticatedMessage resC2c = null;
|
|
|
|
|
- PDUs pdus = this.c2c.getPdu();
|
|
|
|
|
-// Subscription subscription = pdus.getSubscription();
|
|
|
|
|
-// if (subscription != null) {
|
|
|
|
|
-// int subscribeSerialNbr = subscription.getDatexSubscribeSerialNbr().intValue();
|
|
|
|
|
-// SubscriptionType subscriptionType = subscription.getDatexSubscribeType();
|
|
|
|
|
-// BerEnum cancelReasonCd = subscriptionType.getDatexSubscribeCancelReasonCd();
|
|
|
|
|
-// if (subscriptionType != null) {
|
|
|
|
|
-// SubscriptionData subscriptionData = subscriptionType.getSubscription();
|
|
|
|
|
-// if (subscriptionData != null) {
|
|
|
|
|
-// boolean persistentBool = subscriptionData.getDatexSubscribePersistentBool().value;
|
|
|
|
|
-// int statusCd = subscriptionData.getDatexSubscribeStatusCd().value.intValue(); // new, update
|
|
|
|
|
-// int publishFormatCd = subscriptionData.getDatexSubscribePublishFormatCd().value.intValue();
|
|
|
|
|
-// int priorityNbr = subscriptionData.getDatexSubscriptionPriorityNbr().value.intValue();
|
|
|
|
|
-// boolean guaranteeBool = subscriptionData.getDatexSubscribeGuaranteeBool().value;
|
|
|
|
|
-//
|
|
|
|
|
-// objectId = DsrcAsn1Utils.getObjectId(subscriptionData.getDatexSubscribePdu().getEndApplicationMessageId().value);
|
|
|
|
|
-// //log.info("SubscriptionResponse.response: objectId: {}", objectId);
|
|
|
|
|
-//
|
|
|
|
|
-// if (objectId != eObjectId.OBJ_ProbeVehicleDetectionRoadSide.getValue() &&
|
|
|
|
|
-// objectId > eObjectId.OBJ_DSRCRecentOBUTransactionInfo.getValue()) {
|
|
|
|
|
-// // Reject
|
|
|
|
|
-// resC2c = DsrcAsn1Reject.makeC2CAuthenticatedMessage(this.obj, this.ctx.channel(), this.c2c,
|
|
|
|
|
-// eRejectSubscription.Reject_Subscription_cd_invalidSubscriptionMsgId.getValue());
|
|
|
|
|
-// log.info("SubscriptionResponse.response: {}, Reject, objectId: {}", ipAddress, objectId);
|
|
|
|
|
-// }
|
|
|
|
|
-// else {
|
|
|
|
|
-// SubscriptionMode subscriptionMode = subscriptionData.getDatexSubscribeMode();
|
|
|
|
|
-// if (subscriptionMode != null) {
|
|
|
|
|
-// // subscriptionMode = single, event-driven, periodic
|
|
|
|
|
-// if (subscriptionMode.getSingle() != null) {
|
|
|
|
|
-// //log.info("SubscriptionResponse.response: {}, SubscriptionSingleService", ipAddress);
|
|
|
|
|
-// subscriptionService = SubscriptionSingleService.getInstance();
|
|
|
|
|
-// } else if (subscriptionMode.getEventDriven() != null) {
|
|
|
|
|
-// //log.info("SubscriptionResponse.response: {}, SubscriptionRegisterService[EventDriven]", ipAddress);
|
|
|
|
|
-// subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
|
|
-// } else if (subscriptionMode.getPeriodic() != null) {
|
|
|
|
|
-// //log.info("SubscriptionResponse.response: {}, SubscriptionRegisterService[Periodic]", ipAddress);
|
|
|
|
|
-// subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
|
|
-// }
|
|
|
|
|
-// if (guaranteeBool) {
|
|
|
|
|
-// resC2c = DsrcAsn1Accept.makeC2CAuthenticatedMessage(this.obj, this.ctx.channel(), this.c2c);
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// log.warn("SubscriptionResponse.response: {}, SubscriptionMode null", ipAddress);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// } else if (cancelReasonCd != null) {
|
|
|
|
|
-// // Cancel
|
|
|
|
|
-// int cancelReasonId = cancelReasonCd.value.intValue();
|
|
|
|
|
-// resC2c = DsrcAsn1Accept.makeC2CAuthenticatedMessage(this.obj, this.ctx.channel(), this.c2c);
|
|
|
|
|
-// log.info("SubscriptionResponse.response: {}, Accept, cancelReasonCd: {}", ipAddress, cancelReasonId);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ int dataPacketNmbr = this.c2c.getDatexDataPacketNumber().intValue();
|
|
|
|
|
+ int objectId = 0;
|
|
|
|
|
+ SubscriptionService subscriptionService = null;
|
|
|
|
|
+ C2CAuthenticatedMessage c2c = null;
|
|
|
|
|
+ PDUs pdUs = this.c2c.getPdu();
|
|
|
|
|
+ Subscription subscription = pdUs.getSubscription();
|
|
|
|
|
+ if (subscription != null) {
|
|
|
|
|
+ int subscribeSerialNbr = subscription.getDatexSubscribeSerialNbr().intValue();
|
|
|
|
|
+ SubscriptionType subscriptionType = subscription.getDatexSubscribeType();
|
|
|
|
|
+ BerEnum cancelReasonCd = subscriptionType.getDatexSubscribeCancelReasonCd();
|
|
|
|
|
+ if (subscriptionType != null) {
|
|
|
|
|
+ SubscriptionData subscriptionData = subscriptionType.getSubscription();
|
|
|
|
|
+ if (subscriptionData != null) {
|
|
|
|
|
+// boolean persistentBool = subscriptionData.getDatexSubscribePersistentBool().value;
|
|
|
|
|
+// int statusCd = subscriptionData.getDatexSubscribeStatusCd().value.intValue(); // new, update
|
|
|
|
|
+// int publishFormatCd = subscriptionData.getDatexSubscribePublishFormatCd().value.intValue();
|
|
|
|
|
+// int priorityNbr = subscriptionData.getDatexSubscriptionPriorityNbr().value.intValue();
|
|
|
|
|
+ boolean guaranteeBool = subscriptionData.getDatexSubscribeGuaranteeBool().value;
|
|
|
|
|
|
|
|
-// if (subscriptionService != null) {
|
|
|
|
|
-// subscriptionService.response(this.obj, this.ctx.channel(), objectId, subscription);
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ objectId = ItsAsnUtils.getObjectId(subscriptionData.getDatexSubscribePdu().getEndApplicationMessageId().value);
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. objectId: {}", this.center.getLogKey(), this.center.getIpAddress(), objectId);
|
|
|
|
|
|
|
|
- if (resC2c != null) {
|
|
|
|
|
- // send accept or reject
|
|
|
|
|
- ChannelFuture f = this.ctx.channel().writeAndFlush(resC2c);
|
|
|
|
|
- f.awaitUninterruptibly();
|
|
|
|
|
- if (!f.isDone() && !f.isSuccess()) {
|
|
|
|
|
- log.error("SubscriptionResponse.response: {}. packet send Failed.", ipAddress);
|
|
|
|
|
|
|
+ if (objectId < eObjectId.OBJ_CurrentLinkState.getValue() && objectId > eObjectId.OBJ_DetectorCollection.getValue()) {
|
|
|
|
|
+ // Reject
|
|
|
|
|
+ accepted = false;
|
|
|
|
|
+ c2c = AiReject.makeMessage(this.center, this.c2c, eRejectSubscription.Reject_Subscription_cd_invalidSubscriptionMsgId.getValue());
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. objectId: {}, Reject.", this.center.getLogKey(), this.center.getIpAddress(), objectId);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ SubscriptionMode subscriptionMode = subscriptionData.getDatexSubscribeMode();
|
|
|
|
|
+ if (subscriptionMode != null) {
|
|
|
|
|
+ // subscriptionMode = single, event-driven, periodic
|
|
|
|
|
+ if (subscriptionMode.getSingle() != null) {
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. subscriptionMode-Single.", this.center.getLogKey(), this.center.getIpAddress());
|
|
|
|
|
+ subscriptionService = SubscriptionSingleService.getInstance();
|
|
|
|
|
+ } else if (subscriptionMode.getEventDriven() != null) {
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. subscriptionMode-EventDriven.", this.center.getLogKey(), this.center.getIpAddress());
|
|
|
|
|
+ subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
|
|
+ } else if (subscriptionMode.getPeriodic() != null) {
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. subscriptionMode-Periodic.", this.center.getLogKey(), this.center.getIpAddress());
|
|
|
|
|
+ subscriptionService = SubscriptionRegisterService.getInstance();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (guaranteeBool) {
|
|
|
|
|
+ c2c = AiAccept.makeMessage(this.center, this.c2c);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ log.warn("SubscriptionResponse.response: [{}, {}]. subscriptionMode is null.", this.center.getLogKey(), this.center.getIpAddress());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (cancelReasonCd != null) {
|
|
|
|
|
+ // Cancel
|
|
|
|
|
+ int cancelReasonId = cancelReasonCd.value.intValue();
|
|
|
|
|
+ c2c = AiAccept.makeMessage(this.center, this.c2c);
|
|
|
|
|
+ log.info("SubscriptionResponse.response: [{}, {}]. Accept, cancelReasonCd: {}.", this.center.getLogKey(), this.center.getIpAddress(), cancelReasonId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (subscriptionService != null) {
|
|
|
|
|
+// subscriptionService.response(this.obj, this.ctx.channel(), objectId, subscription);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (c2c != null) {
|
|
|
|
|
+ String sendMsg = accepted ? "AI_Subscription-AI_Accept" : "AI_Subscription-AI_Reject";
|
|
|
|
|
+ result = this.center.sendData(c2c, sendMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e) {
|
|
|
|
|
+ log.error("SubscriptionResponse.response: [{}, {}]. Packet send Exception. will be closed. {}", this.center.getLogKey(), this.center.getIpAddress(), e.getMessage());
|
|
|
|
|
+ result = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ finally {
|
|
|
|
|
+ MDC.clear();
|
|
|
}
|
|
}
|
|
|
- return true;
|
|
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|