Commits

György Kohut committed 29b6fc4

shadowserver_geoip: ignore empty response after a retry

  • Participants
  • Parent commits 35597f3

Comments (0)

Files changed (1)

File src/main/java/org/honeynet/hbbackend/shadowserver_geoip/ShadowserverGeoip.java

 import java.util.regex.Pattern;
 
 import javax.annotation.Resource;
+import javax.ejb.ApplicationException;
 import javax.ejb.EJBException;
 import javax.ejb.Schedule;
+import javax.ejb.SessionContext;
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.ejb.TransactionAttribute;
 	@Resource(mappedName="jms/new_ip")
 	private Topic jms_new_ip;
 	
+	@Resource
+	SessionContext ctx;
 	
 	private String emsg;
 	
+
+	@ApplicationException(rollback=true)
+	public static class EmptyResponseException extends Exception { }
+	
 	
 	@Schedule(second="*/1", minute="*", hour="*", persistent=false)
 	@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
-	public void work() {
+	public void work() throws EmptyResponseException {
 		log.trace("work()");
 		
 		javax.jms.Connection mq = null;
 			if (msg == null) return;
 			
 			String ip = msg.getStringProperty("ip");
-			log.debug("received new msg | ip = {}", ip);
-			
-			store(ip, retrieve(ip));
+			log.debug("received new msg | ip={}", ip);
+			try {
+				store(ip, retrieve(ip));
+			}
+			catch (EmptyResponseException e) {
+				if (msg.getJMSRedelivered()) {
+					log.warn("ignoring due to empty response | ip={}", ip);
+					return;
+				} else {
+					throw e;
+				}
+			}
 		}
 		catch (JMSException e) {
 			log.error("got JMSException", e);
 	}
 	
 	
-	private Result retrieve(String ip) {
+	private Result retrieve(String ip) throws EmptyResponseException {
 		log.trace("retrieve()");
 		
 		try {
 			socket.close();
 			
 			if (response == null) {
-				emsg = "no response";
-				log.error(emsg);
-				throw new EJBException(emsg);
+				log.warn("empty response | ip={}", ip);
+				throw new EmptyResponseException();
 			}
 			
 			// format: (0) ip | (1) country code | (2) (empty) | (3) (ignored) | (4) city | (5) latitude | (6) longitude