From 0f46865151403dbc6cf40e1d0216cfcefdd689ae Mon Sep 17 00:00:00 2001 From: waner Date: Tue, 20 May 2025 17:12:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B5=8B=E8=AF=95demo=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sunyard/snmp/SnmpTrapSender.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sunyard/snmp/SnmpTrapSender.java b/src/main/java/com/sunyard/snmp/SnmpTrapSender.java index b9e17ea..57439a6 100644 --- a/src/main/java/com/sunyard/snmp/SnmpTrapSender.java +++ b/src/main/java/com/sunyard/snmp/SnmpTrapSender.java @@ -23,7 +23,7 @@ public class SnmpTrapSender implements AutoCloseable{ private String community; private int version; - public SnmpTrapSender(Map map) throws IOException { + public SnmpTrapSender(Map map) throws Exception { loadConfig(map); initializeSNMP(); } @@ -36,13 +36,13 @@ public class SnmpTrapSender implements AutoCloseable{ version = Integer.parseInt(map.getOrDefault("snmp.version", "1")); } - private void initializeSNMP() throws IOException { + private void initializeSNMP() throws Exception { TransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); snmp.listen(); } - public ResponseEvent sendTrap(String message, int severity) throws IOException { + public ResponseEvent sendTrap(String message, int severity) throws Exception { ResponseEvent event = null; switch (version) { case SnmpConstants.version1: @@ -57,7 +57,7 @@ public class SnmpTrapSender implements AutoCloseable{ return event; } - private ResponseEvent sendV1Trap(String message, int severity) throws IOException { + private ResponseEvent sendV1Trap(String message, int severity) throws Exception { CommunityTarget target = createCommunityTarget(SnmpConstants.version1); PDUv1 pdu = new PDUv1(); configureCommonTrap(pdu, message, severity); @@ -65,7 +65,7 @@ public class SnmpTrapSender implements AutoCloseable{ return snmp.send(pdu, target); } - private ResponseEvent sendV2Trap(String message, int severity) throws IOException { + private ResponseEvent sendV2Trap(String message, int severity) throws Exception { CommunityTarget target = createCommunityTarget(SnmpConstants.version2c); PDU pdu = new PDU(); configureCommonTrap(pdu, message, severity); @@ -96,7 +96,7 @@ public class SnmpTrapSender implements AutoCloseable{ } @Override - public void close() throws IOException { + public void close() throws Exception { if (snmp != null) { snmp.close(); snmp = null;