migrated to Java 8
This commit is contained in:
@ -4,10 +4,13 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,7 +19,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 = getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@ -30,7 +33,7 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
||||
while (multipleWhoisString.contains("# start")) {
|
||||
String whoisPartString;
|
||||
try {
|
||||
whoisPartString = StringUtil.getValueBetweenKeywords(multipleWhoisString, "# start", "# end");
|
||||
whoisPartString = getValueBetweenKeywords(multipleWhoisString, "# start", "# end");
|
||||
} catch (ParseException ex) {
|
||||
throw new WhoisException("Error while reading whois part elements. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
@ -88,7 +91,7 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
||||
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||
} else {
|
||||
throw new WhoisException("Cannot identify netrange value");
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static java.lang.Long.valueOf;
|
||||
import static java.lang.Math.floor;
|
||||
import static java.lang.Math.log;
|
||||
import static java.lang.Math.pow;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -30,14 +34,14 @@ public class CidrTool {
|
||||
|
||||
maxsize--;
|
||||
}
|
||||
double x = Math.log(end - start + 1) / Math.log(2);
|
||||
byte maxdiff = (byte) (32 - Math.floor(x));
|
||||
double x = log(end - start + 1) / log(2);
|
||||
byte maxdiff = (byte) (32 - floor(x));
|
||||
if (maxsize < maxdiff) {
|
||||
maxsize = maxdiff;
|
||||
}
|
||||
String ip = longToIP(start);
|
||||
pairs.add(ip + "/" + maxsize);
|
||||
start += Math.pow(2, (32 - maxsize));
|
||||
start += pow(2, (32 - maxsize));
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
@ -56,7 +60,7 @@ public class CidrTool {
|
||||
long[] ip = new long[4];
|
||||
String[] ipSec = strIP.split("\\.");
|
||||
for (int k = 0; k < 4; k++) {
|
||||
ip[k] = Long.valueOf(ipSec[k]);
|
||||
ip[k] = valueOf(ipSec[k]);
|
||||
}
|
||||
|
||||
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||
|
||||
@ -4,10 +4,12 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,7 +18,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 = getLogger(DefaultWhoisParser.class);
|
||||
/** information to be returned */
|
||||
private WhoisInformation whoisInformation;
|
||||
|
||||
@ -74,7 +76,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
||||
// FIXME add CDIR notation support
|
||||
String startIpAddress = ipAddresses[0];
|
||||
String endIPAddress = ipAddresses[2];
|
||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
||||
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||
} else {
|
||||
whoisInformation.getNetwork().add(inetnum);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package de.muehlencord.shared.network;
|
||||
|
||||
import org.apache.commons.net.whois.WhoisClient;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -10,7 +11,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 = getLogger(Whois.class);
|
||||
/** whois client from commons-net package to execute commands with */
|
||||
WhoisClient whois;
|
||||
/** the complete output */
|
||||
|
||||
@ -5,12 +5,15 @@ import com.enterprisedt.net.ftp.FTPConnectMode;
|
||||
import com.enterprisedt.net.ftp.FTPException;
|
||||
import com.enterprisedt.net.ftp.FTPFile;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import static java.util.Locale.getDefault;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,7 +24,7 @@ public class FTPConnection {
|
||||
/** the default timeout in ms */
|
||||
public static final int DEFAULTTIMEOUT = 30000;
|
||||
/** the logger object */
|
||||
private final Logger logger = Logger.getLogger(FTPConnection.class);
|
||||
private final Logger logger = getLogger(FTPConnection.class);
|
||||
/** the username to connect with */
|
||||
private String userName;
|
||||
/** the password to connect with */
|
||||
@ -41,7 +44,7 @@ public class FTPConnection {
|
||||
* @param password the password to connect with
|
||||
*/
|
||||
public FTPConnection(String remoteHost, String userName, String password) {
|
||||
this(remoteHost, userName, password, Locale.getDefault());
|
||||
this(remoteHost, userName, password, getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,12 +85,9 @@ public class FTPConnection {
|
||||
public void disconnect() {
|
||||
try {
|
||||
client.quit();
|
||||
} catch (IOException ex) {
|
||||
} catch (IOException | FTPException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
} catch (FTPException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,15 +100,15 @@ public class FTPConnection {
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> list(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
returnValue.add(files[i].getName());
|
||||
for (FTPFile file : files) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
@ -124,17 +124,17 @@ public class FTPConnection {
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listDirsOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isDir()) {
|
||||
returnValue.add(files[i].getName());
|
||||
for (FTPFile file : files) {
|
||||
if (file.isDir()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -151,17 +151,17 @@ public class FTPConnection {
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listFilesOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (!files[i].isDir()) {
|
||||
returnValue.add(files[i].getName());
|
||||
for (FTPFile file : files) {
|
||||
if (!file.isDir()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -178,17 +178,17 @@ public class FTPConnection {
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listLinksOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].isLink()) {
|
||||
returnValue.add(files[i].getName());
|
||||
for (FTPFile file : files) {
|
||||
if (file.isLink()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -216,7 +216,7 @@ public class FTPConnection {
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
@ -234,7 +234,7 @@ public class FTPConnection {
|
||||
client.rename(remoteOldName, remoteNewName);
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,12 +10,14 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import static java.net.URLEncoder.encode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* Communication endpoint for posting a messages
|
||||
@ -24,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 = getLogger(HttpLayer.class);
|
||||
/** the url to post to */
|
||||
private String destinationUrlString;
|
||||
/** the encoding to use */
|
||||
@ -53,7 +55,7 @@ public class HttpLayer {
|
||||
*/
|
||||
public void post(String parameter, String message)
|
||||
throws MessageNotSendException {
|
||||
Map<String, String[]> parameterMap = new HashMap<String, String[]>();
|
||||
Map<String, String[]> parameterMap = new HashMap<>();
|
||||
String[] valueArray = { message };
|
||||
parameterMap.put(parameter, valueArray);
|
||||
post(parameterMap);
|
||||
@ -79,7 +81,7 @@ public class HttpLayer {
|
||||
* TODO add https support
|
||||
*/
|
||||
public void post(Map<String, String[]> parameterMap) throws MessageNotSendException {
|
||||
List<Map<String,String[]>> parameterList = new LinkedList<Map<String,String[]>>();
|
||||
List<Map<String,String[]>> parameterList = new LinkedList<>();
|
||||
parameterList.add(parameterMap);
|
||||
String content = getDataString(parameterList);
|
||||
post (content);
|
||||
@ -247,7 +249,7 @@ public class HttpLayer {
|
||||
data += "&";
|
||||
}
|
||||
data += key.toLowerCase() + "="
|
||||
+ URLEncoder.encode(currentValue, encoding);
|
||||
+ encode(currentValue, encoding);
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import static de.muehlencord.shared.network.mail.MailMessageUtils.getInstance;
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import static java.lang.System.getProperties;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@ -11,12 +14,14 @@ import javax.mail.Folder;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import static javax.mail.Session.getInstance;
|
||||
import javax.mail.Store;
|
||||
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 static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* MailReader to connect and work with IMAP mailboxes. Also works with exchange servers.
|
||||
@ -26,7 +31,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 = getLogger(DefaultMailReader.class);
|
||||
/** the store to connect with */
|
||||
private Store store = null;
|
||||
/** the smtp host to work with */
|
||||
@ -57,7 +62,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
getStore().close();
|
||||
} catch (MessagingException ex) {
|
||||
logger.error("Cannot disconnect from mailbox");
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
} finally {
|
||||
logger.info("Connection closed");
|
||||
setStore(null);
|
||||
@ -77,7 +82,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
try {
|
||||
return getStore().getDefaultFolder().getFullName();
|
||||
} catch (Exception ex) {
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new MailReaderException("Error while retrieving default folder. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
@ -91,14 +96,14 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
* @throws MailReaderException if the folder list cannot be retrieved
|
||||
*/
|
||||
public List<String> getSubFolder(Folder sourceFolder) throws MailReaderException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
Folder[] folders = sourceFolder.list();
|
||||
for (Folder folder : folders) {
|
||||
returnValue.add(folder.getFullName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
throw new MailReaderException("Cannot retrieve folder list. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
return returnValue;
|
||||
@ -110,11 +115,11 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
* @return the session object to use
|
||||
*/
|
||||
protected Session getDefaultSession() {
|
||||
Properties props = (Properties) System.getProperties().clone();
|
||||
Properties props = (Properties) getProperties().clone();
|
||||
props.put("mail.smtp.host", configuration.getSmtpHost());
|
||||
// TODO - add needed properties - only valid for session, do not overwrite properites
|
||||
// TODO - add chained properties
|
||||
return Session.getInstance(props, null);
|
||||
return getInstance(props, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +154,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
* @throws MailReaderException if the folder cannot be found
|
||||
*/
|
||||
private List<Folder> getFolderPath(String folderPath) throws MailReaderException {
|
||||
List<Folder> returnValue = new LinkedList<Folder>();
|
||||
List<Folder> returnValue = new LinkedList<>();
|
||||
try {
|
||||
String[] folderPathParts = folderPath.split("/");
|
||||
Folder currentFolder = store.getDefaultFolder();
|
||||
@ -215,7 +220,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubFolder(String sourceFolder) throws MailReaderException {
|
||||
List<String> returnValue = new LinkedList<String>();
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
Folder folder = getFolderObject(sourceFolder);
|
||||
|
||||
try {
|
||||
@ -231,7 +236,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
try {
|
||||
folder.close(false);
|
||||
} catch (MessagingException ex) {
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,7 +267,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
try {
|
||||
folder.close(false);
|
||||
} catch (MessagingException ex) {
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -280,13 +285,13 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
*/
|
||||
@Override
|
||||
public List<MailMessage> getMessages(String sourceFolder) throws MailReaderException {
|
||||
List<MailMessage> returnValue = new LinkedList<MailMessage>();
|
||||
List<MailMessage> returnValue = new LinkedList<>();
|
||||
Folder folder = getFolderObject(sourceFolder);
|
||||
try {
|
||||
folder.open(Folder.READ_ONLY);
|
||||
Message[] messages = folder.getMessages();
|
||||
for (Message msg : messages) {
|
||||
returnValue.add(MailMessageUtils.getInstance(getValidMessage(msg)));
|
||||
returnValue.add(getInstance(getValidMessage(msg)));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new MailReaderException("Cannot fetch email from folder " + folder.getFullName() + ". Reason: " + ex.getMessage(), ex);
|
||||
@ -296,7 +301,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
try {
|
||||
folder.close(false);
|
||||
} catch (MessagingException ex) {
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,17 +48,17 @@ public class MailMessage {
|
||||
*/
|
||||
public MailMessage(String subj, String contentString) {
|
||||
this.subject = subj;
|
||||
this.content = new LinkedList<String>();
|
||||
this.content = new LinkedList<>();
|
||||
if (contentString != null) {
|
||||
content.add(contentString);
|
||||
}
|
||||
this.htmlContent = new LinkedList<String>();
|
||||
this.htmlContent = new LinkedList<>();
|
||||
this.isHtmlMessage = false;
|
||||
this.messageId = null;
|
||||
this.sender = null;
|
||||
this.receiver = new LinkedList<String>();
|
||||
this.ccReceiver = new LinkedList<String>();
|
||||
this.bccReceiver = new LinkedList<String>();
|
||||
this.receiver = new LinkedList<>();
|
||||
this.ccReceiver = new LinkedList<>();
|
||||
this.bccReceiver = new LinkedList<>();
|
||||
}
|
||||
|
||||
/** creates a new instance of MaiLmessage
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@ -17,6 +18,7 @@ import javax.mail.Multipart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* Util class to convert between javax.mail.Message and MailMessage objects
|
||||
@ -26,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 = getLogger(MailMessageUtils.class.getName());
|
||||
|
||||
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
|
||||
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
||||
@ -299,7 +301,7 @@ public abstract class MailMessageUtils {
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.debug(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
try {
|
||||
if (input != null) {
|
||||
@ -307,7 +309,7 @@ public abstract class MailMessageUtils {
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.debug(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -14,7 +16,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class MailReaderConfigurationFactory {
|
||||
|
||||
/** the logging object */
|
||||
private final static Logger logger = Logger.getLogger(MailReaderConfigurationFactory.class.getName());
|
||||
private final static Logger logger = getLogger(MailReaderConfigurationFactory.class.getName());
|
||||
|
||||
/**
|
||||
* reads the config file and creates a configured mailreader configuration
|
||||
@ -42,7 +44,7 @@ public abstract class MailReaderConfigurationFactory {
|
||||
is.close();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error while reading input file.");
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||
import javax.mail.Session;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
* 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 = getLogger(ImapMailReader.class);
|
||||
|
||||
/**
|
||||
* creates a new instance to connect to an IMAP (or MS Exchange) server
|
||||
|
||||
@ -5,6 +5,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ public class BaseTest {
|
||||
@BeforeClass
|
||||
public static void initLogging() {
|
||||
URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties");
|
||||
PropertyConfigurator.configure(defaultConfigUrl);
|
||||
configure(defaultConfigUrl);
|
||||
}
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -19,7 +20,7 @@ public class CidrToolTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testCidrConversion() {
|
||||
System.out.println (CidrTool.rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||
System.out.println (rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -27,12 +28,12 @@ public class CidrToolTest {
|
||||
// split 213.0.0.0/8 --> belongs to Ripe
|
||||
// but 213.55.64.0 - 213.55.127.255 was transferred to Afrinic
|
||||
System.out.println ("First part of Ripe");
|
||||
System.out.println (CidrTool.rangeToCidrList("213.0.0.1", "213.55.63.255"));
|
||||
System.out.println (rangeToCidrList("213.0.0.1", "213.55.63.255"));
|
||||
|
||||
System.out.println ("Transferred part of Afrinic");
|
||||
System.out.println (CidrTool.rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||
System.out.println (rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||
|
||||
System.out.println ("Second part of Ripe");
|
||||
System.out.println (CidrTool.rangeToCidrList("213.55.128.0", "213.255.255.255"));
|
||||
System.out.println (rangeToCidrList("213.55.128.0", "213.255.255.255"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -11,6 +12,6 @@ public class RangeToCidrTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testRangeToCidr() {
|
||||
System.out.println (CidrTool.rangeToCidrList("212.204.60.0", "212.204.60.255"));
|
||||
System.out.println (rangeToCidrList("212.204.60.0", "212.204.60.255"));
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,7 @@ import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
@ -57,7 +58,7 @@ public class FTPConnectionTest {
|
||||
fin.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(FTPConnectionTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
getLogger(FTPConnectionTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ public class HttpLayerTest extends BaseTest {
|
||||
@Ignore
|
||||
public void testPostByMap() throws Exception {
|
||||
System.out.println("testPostByMap");
|
||||
Map<String, String[]> map = new HashMap<String, String[]>();
|
||||
Map<String, String[]> map = new HashMap<>();
|
||||
String[] value = {"Hello World!", "Hello World again"};
|
||||
map.put("message", value);
|
||||
|
||||
@ -35,12 +35,12 @@ public class HttpLayerTest extends BaseTest {
|
||||
@Ignore
|
||||
public void testPostByMapList() throws Exception {
|
||||
System.out.println("testPostByMapList");
|
||||
List<Map<String, String[]>> list = new LinkedList<Map<String, String[]>>();
|
||||
Map<String, String[]> map = new HashMap<String, String[]>();
|
||||
List<Map<String, String[]>> list = new LinkedList<>();
|
||||
Map<String, String[]> map = new HashMap<>();
|
||||
String[] value = {"Hello World!", "Hello World again"};
|
||||
map.put("message", value);
|
||||
list.add(map);
|
||||
map = new HashMap<String, String[]>();
|
||||
map = new HashMap<>();
|
||||
String[] urlValue = {"http://localhost:8080/testurl"};
|
||||
map.put("url", urlValue);
|
||||
list.add(map);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package de.muehlencord.shared.network.mail;
|
||||
|
||||
import de.muehlencord.shared.network.BaseTest;
|
||||
import static de.muehlencord.shared.network.mail.MailReaderConfigurationFactory.getConfiguration;
|
||||
import de.muehlencord.shared.network.mail.imap.ImapMailReader;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
@ -31,7 +32,7 @@ public class MailMessageUtilsTest extends BaseTest {
|
||||
}
|
||||
|
||||
String testConfigFile = file.toString();
|
||||
MailReaderConfiguration config = MailReaderConfigurationFactory.getConfiguration(testConfigFile);
|
||||
MailReaderConfiguration config = getConfiguration(testConfigFile);
|
||||
MailReader mr = new ImapMailReader(config);
|
||||
mr.connect();
|
||||
List<MailMessage> mm = mr.getMessages("INBOX");
|
||||
|
||||
Reference in New Issue
Block a user