updated to log4j2
This commit is contained in:
@ -21,6 +21,17 @@ public class IpInformation {
|
||||
public List<PortInformation> getPortInformation() {
|
||||
return portInformation;
|
||||
}
|
||||
|
||||
public List<PortInformation> getOpenPorts() {
|
||||
List<PortInformation> openPorts = new ArrayList<>();
|
||||
|
||||
for (PortInformation currentPort : getPortInformation()) {
|
||||
if (currentPort.isOpen()) {
|
||||
openPorts.add (currentPort);
|
||||
}
|
||||
}
|
||||
return openPorts;
|
||||
}
|
||||
|
||||
public void setPortInformation(List<PortInformation> portInformation) {
|
||||
this.portInformation = portInformation;
|
||||
@ -29,5 +40,10 @@ public class IpInformation {
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getIpAddress()+": "+getPortInformation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,8 @@ import de.muehlencord.shared.network.whois.NetworkInformation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -12,7 +13,7 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public class NetworkScanner {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(NetworkScanner.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(NetworkScanner.class);
|
||||
|
||||
private String networkString;
|
||||
private NetworkInformation networkInformation = null; // TODO add scan for information
|
||||
|
||||
@ -5,7 +5,8 @@ import java.net.Socket;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -13,7 +14,7 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public final class PortScan {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(PortScan.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(PortScan.class);
|
||||
|
||||
private PortScan() {
|
||||
// hide constructor
|
||||
@ -30,7 +31,7 @@ public final class PortScan {
|
||||
socket.close();
|
||||
return new PortInformation(port, true);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.debug(ex.toString(), ex);
|
||||
LOGGER.trace(ex.toString(), ex);
|
||||
return new PortInformation(port, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,8 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -15,7 +16,7 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public class PortScanner {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(PortScanner.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(PortScanner.class);
|
||||
|
||||
private final int startPort;
|
||||
private final int endPort;
|
||||
@ -46,7 +47,7 @@ public class PortScanner {
|
||||
resultList.add(f.get());
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
LOGGER.error(ex.toString(), ex);
|
||||
LOGGER.trace(ex.toString(), ex);
|
||||
}
|
||||
|
||||
return resultList;
|
||||
|
||||
@ -10,7 +10,8 @@ import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,7 +22,7 @@ public class FTPConnection {
|
||||
/** the default timeout in ms */
|
||||
public static final int DEFAULTTIMEOUT = 30000;
|
||||
/** the logger object */
|
||||
private final static Logger LOGGER = Logger.getLogger(FTPConnection.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(FTPConnection.class);
|
||||
/** the username to connect with */
|
||||
private String userName;
|
||||
/** the password to connect with */
|
||||
|
||||
@ -16,7 +16,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Communication endpoint for posting a messages
|
||||
@ -25,7 +26,7 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public class HttpLayer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(HttpLayer.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(HttpLayer.class);
|
||||
/** the url to post to */
|
||||
private final String destinationUrlString;
|
||||
/** the encoding to use */
|
||||
|
||||
@ -15,7 +15,8 @@ import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.search.MessageIDTerm;
|
||||
import javax.mail.search.SearchTerm;
|
||||
import javax.mail.util.SharedByteArrayInputStream;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* MailReader to connect and work with IMAP mailboxes. Also works with exchange servers.
|
||||
@ -25,7 +26,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class DefaultMailReader implements MailReader {
|
||||
|
||||
/** the logging object */
|
||||
private final static Logger LOGGER = Logger.getLogger(DefaultMailReader.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(DefaultMailReader.class);
|
||||
/** the store to connect with */
|
||||
private Store store = null;
|
||||
/** the smtp host to work with */
|
||||
|
||||
@ -17,7 +17,8 @@ import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Util class to convert between javax.mail.Message and MailMessage objects
|
||||
@ -27,7 +28,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class MailMessageUtils {
|
||||
|
||||
/** the logging object */
|
||||
private static final Logger LOGGER = Logger.getLogger(MailMessageUtils.class.getName());
|
||||
private static final Logger LOGGER = LogManager.getLogger(MailMessageUtils.class.getName());
|
||||
|
||||
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
|
||||
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
||||
|
||||
@ -5,7 +5,8 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -14,7 +15,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class MailReaderConfigurationFactory {
|
||||
|
||||
/** the logging object */
|
||||
private final static Logger LOGGER = Logger.getLogger(MailReaderConfigurationFactory.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(MailReaderConfigurationFactory.class);
|
||||
|
||||
/**
|
||||
* reads the config file and creates a configured mailreader configuration
|
||||
|
||||
@ -4,7 +4,8 @@ import de.muehlencord.shared.network.mail.DefaultMailReader;
|
||||
import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||
import javax.mail.Session;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Implementation of MaiLReader to connect to an IMAP server
|
||||
@ -14,7 +15,7 @@ import org.apache.log4j.Logger;
|
||||
public class ImapMailReader extends DefaultMailReader {
|
||||
|
||||
/** the logger object */
|
||||
private final static Logger LOGGER = Logger.getLogger(ImapMailReader.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(ImapMailReader.class);
|
||||
|
||||
/**
|
||||
* creates a new instance to connect to an IMAP (or MS Exchange) server
|
||||
|
||||
@ -4,7 +4,8 @@ import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
/**
|
||||
@ -14,7 +15,7 @@ import org.apache.log4j.Logger;
|
||||
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger LOGGER = Logger.getLogger(DefaultWhoisParser.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
|
||||
@ -2,7 +2,8 @@ package de.muehlencord.shared.network.whois;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -11,7 +12,7 @@ import org.apache.log4j.Logger;
|
||||
public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger LOGGER = Logger.getLogger(DefaultWhoisParser.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
|
||||
@ -2,7 +2,8 @@ package de.muehlencord.shared.network.whois;
|
||||
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.net.whois.WhoisClient;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -11,7 +12,7 @@ import org.apache.log4j.Logger;
|
||||
public class Whois {
|
||||
|
||||
/** logger object */
|
||||
private final static Logger LOGGER = Logger.getLogger(Whois.class);
|
||||
private final static Logger LOGGER = LogManager.getLogger(Whois.class);
|
||||
/** whoisClient client from commons-net package to execute commands with */
|
||||
WhoisClient whoisClient;
|
||||
/** the complete output */
|
||||
|
||||
2
network/src/main/resources/buildInfo.properties
Normal file
2
network/src/main/resources/buildInfo.properties
Normal file
@ -0,0 +1,2 @@
|
||||
build.version=${project.version}
|
||||
build.timestamp=${timestamp}
|
||||
14
network/src/main/resources/log4j2.xml
Normal file
14
network/src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
<Appenders>
|
||||
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="org.apache.log4j.xml" level="info"/>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@ -3,10 +3,6 @@ package de.muehlencord.shared.network;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import static org.apache.log4j.PropertyConfigurator.configure;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -14,15 +10,6 @@ import org.junit.BeforeClass;
|
||||
*/
|
||||
public class BaseTest {
|
||||
|
||||
/**
|
||||
* inits logging according to default setup in package
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void initLogging() {
|
||||
URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties");
|
||||
configure(defaultConfigUrl);
|
||||
}
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -4,6 +4,7 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -16,6 +17,7 @@ public class NetworkScannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // takes very long
|
||||
public void testScan() throws UnknownHostException {
|
||||
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
SubnetUtils utils = new SubnetUtils(ipAddress, "255.255.255.0");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -13,6 +14,7 @@ public class PortScannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // takes very long
|
||||
public void testMain() {
|
||||
PortScanner portScanner = new PortScanner();
|
||||
List<PortInformation> resultList = portScanner.scan("127.0.0.1");
|
||||
|
||||
@ -6,8 +6,10 @@ import de.muehlencord.shared.network.mail.imap.ImapMailReader;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -22,12 +24,13 @@ public class MailMessageUtilsTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // depends on environment
|
||||
public void testGetInstance() throws Exception {
|
||||
System.out.println("testGetInstance");
|
||||
URL testConfigURL = MailMessageUtilsTest.class.getResource("/test.properties");
|
||||
File file = new File(testConfigURL.toURI());
|
||||
|
||||
if ((file == null) || (!file.exists())) {
|
||||
if (!file.exists()) {
|
||||
return; // Skip test if config file is not available
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,9 @@ import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||
import de.muehlencord.shared.network.mail.MailReaderException;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -26,6 +28,7 @@ public class ImapMailReaderTest extends BaseTest {
|
||||
* @throws Exception if the tests fails
|
||||
*/
|
||||
@Test
|
||||
@Ignore // depends on environment
|
||||
public void testConnect() throws Exception {
|
||||
System.out.println("connect");
|
||||
String meta = "meta.muehlencord.intra";
|
||||
@ -37,6 +40,7 @@ public class ImapMailReaderTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // depends on environment
|
||||
public void testGetFolder() throws Exception {
|
||||
System.out.println("getFolder");
|
||||
String meta = "meta.muehlencord.intra";
|
||||
@ -50,6 +54,7 @@ public class ImapMailReaderTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // depends on environment
|
||||
public void testGetMessageCount() throws MailReaderConnectionException, MailReaderException {
|
||||
System.out.println("testGetMessageCount");
|
||||
String meta = "meta.muehlencord.intra";
|
||||
@ -62,6 +67,7 @@ public class ImapMailReaderTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // depends on environment
|
||||
public void testGetSubFolder() throws MailReaderConnectionException, MailReaderException {
|
||||
System.out.println("getSubFolder");
|
||||
String meta = "meta.muehlencord.intra";
|
||||
|
||||
@ -1,16 +1,11 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import de.muehlencord.shared.network.BaseTest;
|
||||
import de.muehlencord.shared.network.whois.Whois;
|
||||
import de.muehlencord.shared.network.whois.WhoisInformation;
|
||||
import de.muehlencord.shared.network.whois.WhoisException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -66,6 +61,7 @@ public class WhoisTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testUnkown() throws WhoisException {
|
||||
Whois whoIsClient = new Whois();
|
||||
// whoIsClient.execute("whois.arin.net", "174.139.180.10");
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
log4j.rootLogger=ALL, ConsoleLogger
|
||||
log4j.debug=false
|
||||
|
||||
# ConsoleAppender
|
||||
log4j.appender.ConsoleLogger=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.ConsoleLogger.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.ConsoleLogger.layout.ConversionPattern= %d - %m (%c)%n
|
||||
log4j.appender.ConsoleLogger.threshold=DEBUG
|
||||
Reference in New Issue
Block a user