migrated to Java 8
This commit is contained in:
@ -36,7 +36,7 @@ public abstract class Parameter<T> {
|
|||||||
this.description = name;
|
this.description = name;
|
||||||
this.mandatory = true;
|
this.mandatory = true;
|
||||||
this.stringConverter = converter;
|
this.stringConverter = converter;
|
||||||
this.requiredParameters = new LinkedList<Parameter<?>>();
|
this.requiredParameters = new LinkedList<>();
|
||||||
this.validator = null;
|
this.validator = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package de.muehlencord.shared.configuration.converter;
|
|||||||
|
|
||||||
import de.muehlencord.shared.configuration.ConverterException;
|
import de.muehlencord.shared.configuration.ConverterException;
|
||||||
import de.muehlencord.shared.configuration.StringConverter;
|
import de.muehlencord.shared.configuration.StringConverter;
|
||||||
|
import static java.lang.Boolean.parseBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,6 +17,6 @@ public class BooleanStringConverter implements StringConverter<Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean fromString(String s) throws ConverterException {
|
public Boolean fromString(String s) throws ConverterException {
|
||||||
return Boolean.parseBoolean(s);
|
return parseBoolean(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package de.muehlencord.shared.configuration.converter;
|
|||||||
|
|
||||||
import de.muehlencord.shared.configuration.ConverterException;
|
import de.muehlencord.shared.configuration.ConverterException;
|
||||||
import de.muehlencord.shared.configuration.StringConverter;
|
import de.muehlencord.shared.configuration.StringConverter;
|
||||||
|
import static java.lang.Integer.parseInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -9,12 +10,14 @@ import de.muehlencord.shared.configuration.StringConverter;
|
|||||||
*/
|
*/
|
||||||
public class IntegerStringConverter implements StringConverter<Integer> {
|
public class IntegerStringConverter implements StringConverter<Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString(Integer o) throws ConverterException {
|
public String toString(Integer o) throws ConverterException {
|
||||||
return o.toString();
|
return o.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Integer fromString(String s) throws ConverterException {
|
public Integer fromString(String s) throws ConverterException {
|
||||||
return Integer.parseInt(s);
|
return parseInt(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package de.muehlencord.shared.configuration.converter;
|
|||||||
import de.muehlencord.shared.configuration.ConverterException;
|
import de.muehlencord.shared.configuration.ConverterException;
|
||||||
import de.muehlencord.shared.configuration.StringConverter;
|
import de.muehlencord.shared.configuration.StringConverter;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import static java.net.URI.create;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,7 +18,7 @@ public class URIStringConverter implements StringConverter<URI> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI fromString(String s) throws ConverterException {
|
public URI fromString(String s) throws ConverterException {
|
||||||
return URI.create(s);
|
return create(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package de.muehlencord.shared.configuration.validator;
|
|||||||
import de.muehlencord.shared.configuration.ValidationException;
|
import de.muehlencord.shared.configuration.ValidationException;
|
||||||
import de.muehlencord.shared.configuration.Validator;
|
import de.muehlencord.shared.configuration.Validator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -15,12 +16,12 @@ public class StringValueListValidator implements Validator<String> {
|
|||||||
private List<String> valueList;
|
private List<String> valueList;
|
||||||
|
|
||||||
public StringValueListValidator() {
|
public StringValueListValidator() {
|
||||||
this.valueList = new LinkedList<String>();
|
this.valueList = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringValueListValidator(String... values) {
|
public StringValueListValidator(String... values) {
|
||||||
this();
|
this();
|
||||||
valueList.addAll(Arrays.asList(values));
|
valueList.addAll(asList(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -27,7 +28,7 @@ import org.apache.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public class AuthenticationFilter implements Filter {
|
public class AuthenticationFilter implements Filter {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(AuthenticationFilter.class.getName());
|
private final static Logger logger = getLogger(AuthenticationFilter.class.getName());
|
||||||
private final static String USER = AuthenticationFilter.class.getName() + "_user";
|
private final static String USER = AuthenticationFilter.class.getName() + "_user";
|
||||||
private String loginPage;
|
private String loginPage;
|
||||||
private String errorPage;
|
private String errorPage;
|
||||||
|
|||||||
@ -4,10 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.log4j.Logger;
|
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 {
|
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||||
|
|
||||||
/** logger object */
|
/** logger object */
|
||||||
private final static Logger logger = Logger.getLogger(DefaultWhoisParser.class);
|
private final static Logger logger = getLogger(DefaultWhoisParser.class);
|
||||||
/** information to be returned */
|
/** information to be returned */
|
||||||
private WhoisInformation whoisInformation;
|
private WhoisInformation whoisInformation;
|
||||||
|
|
||||||
@ -30,7 +33,7 @@ public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser
|
|||||||
while (multipleWhoisString.contains("# start")) {
|
while (multipleWhoisString.contains("# start")) {
|
||||||
String whoisPartString;
|
String whoisPartString;
|
||||||
try {
|
try {
|
||||||
whoisPartString = StringUtil.getValueBetweenKeywords(multipleWhoisString, "# start", "# end");
|
whoisPartString = getValueBetweenKeywords(multipleWhoisString, "# start", "# end");
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
throw new WhoisException("Error while reading whois part elements. Reason: " + ex.getMessage(), 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
|
// FIXME add CDIR notation support
|
||||||
String startIpAddress = ipAddresses[0];
|
String startIpAddress = ipAddresses[0];
|
||||||
String endIPAddress = ipAddresses[2];
|
String endIPAddress = ipAddresses[2];
|
||||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||||
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
logger.info("Network:" + whoisInformation.getNetwork().toString());
|
||||||
} else {
|
} else {
|
||||||
throw new WhoisException("Cannot identify netrange value");
|
throw new WhoisException("Cannot identify netrange value");
|
||||||
|
|||||||
@ -4,6 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -30,14 +34,14 @@ public class CidrTool {
|
|||||||
|
|
||||||
maxsize--;
|
maxsize--;
|
||||||
}
|
}
|
||||||
double x = Math.log(end - start + 1) / Math.log(2);
|
double x = log(end - start + 1) / log(2);
|
||||||
byte maxdiff = (byte) (32 - Math.floor(x));
|
byte maxdiff = (byte) (32 - floor(x));
|
||||||
if (maxsize < maxdiff) {
|
if (maxsize < maxdiff) {
|
||||||
maxsize = maxdiff;
|
maxsize = maxdiff;
|
||||||
}
|
}
|
||||||
String ip = longToIP(start);
|
String ip = longToIP(start);
|
||||||
pairs.add(ip + "/" + maxsize);
|
pairs.add(ip + "/" + maxsize);
|
||||||
start += Math.pow(2, (32 - maxsize));
|
start += pow(2, (32 - maxsize));
|
||||||
}
|
}
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
@ -56,7 +60,7 @@ public class CidrTool {
|
|||||||
long[] ip = new long[4];
|
long[] ip = new long[4];
|
||||||
String[] ipSec = strIP.split("\\.");
|
String[] ipSec = strIP.split("\\.");
|
||||||
for (int k = 0; k < 4; k++) {
|
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];
|
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||||
|
|||||||
@ -4,10 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.log4j.Logger;
|
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 {
|
public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||||
|
|
||||||
/** logger object */
|
/** logger object */
|
||||||
private final static Logger logger = Logger.getLogger(DefaultWhoisParser.class);
|
private final static Logger logger = getLogger(DefaultWhoisParser.class);
|
||||||
/** information to be returned */
|
/** information to be returned */
|
||||||
private WhoisInformation whoisInformation;
|
private WhoisInformation whoisInformation;
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ public class DefaultWhoisParser extends AbstractWhoisParser implements WhoisPars
|
|||||||
// FIXME add CDIR notation support
|
// FIXME add CDIR notation support
|
||||||
String startIpAddress = ipAddresses[0];
|
String startIpAddress = ipAddresses[0];
|
||||||
String endIPAddress = ipAddresses[2];
|
String endIPAddress = ipAddresses[2];
|
||||||
whoisInformation.getNetwork().addAll(CidrTool.rangeToCidrList(startIpAddress, endIPAddress));
|
whoisInformation.getNetwork().addAll(rangeToCidrList(startIpAddress, endIPAddress));
|
||||||
} else {
|
} else {
|
||||||
whoisInformation.getNetwork().add(inetnum);
|
whoisInformation.getNetwork().add(inetnum);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package de.muehlencord.shared.network;
|
|||||||
|
|
||||||
import org.apache.commons.net.whois.WhoisClient;
|
import org.apache.commons.net.whois.WhoisClient;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -10,7 +11,7 @@ import org.apache.log4j.Logger;
|
|||||||
public class Whois {
|
public class Whois {
|
||||||
|
|
||||||
/** logger object */
|
/** 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 */
|
/** whois client from commons-net package to execute commands with */
|
||||||
WhoisClient whois;
|
WhoisClient whois;
|
||||||
/** the complete output */
|
/** the complete output */
|
||||||
|
|||||||
@ -5,12 +5,15 @@ import com.enterprisedt.net.ftp.FTPConnectMode;
|
|||||||
import com.enterprisedt.net.ftp.FTPException;
|
import com.enterprisedt.net.ftp.FTPException;
|
||||||
import com.enterprisedt.net.ftp.FTPFile;
|
import com.enterprisedt.net.ftp.FTPFile;
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import static java.util.Locale.getDefault;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -21,7 +24,7 @@ public class FTPConnection {
|
|||||||
/** the default timeout in ms */
|
/** the default timeout in ms */
|
||||||
public static final int DEFAULTTIMEOUT = 30000;
|
public static final int DEFAULTTIMEOUT = 30000;
|
||||||
/** the logger object */
|
/** the logger object */
|
||||||
private final Logger logger = Logger.getLogger(FTPConnection.class);
|
private final Logger logger = getLogger(FTPConnection.class);
|
||||||
/** the username to connect with */
|
/** the username to connect with */
|
||||||
private String userName;
|
private String userName;
|
||||||
/** the password to connect with */
|
/** the password to connect with */
|
||||||
@ -41,7 +44,7 @@ public class FTPConnection {
|
|||||||
* @param password the password to connect with
|
* @param password the password to connect with
|
||||||
*/
|
*/
|
||||||
public FTPConnection(String remoteHost, String userName, String password) {
|
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() {
|
public void disconnect() {
|
||||||
try {
|
try {
|
||||||
client.quit();
|
client.quit();
|
||||||
} catch (IOException ex) {
|
} catch (IOException | FTPException ex) {
|
||||||
logger.error(ex.getMessage());
|
logger.error(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
} catch (FTPException ex) {
|
|
||||||
logger.error(ex.getMessage());
|
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,15 +100,15 @@ public class FTPConnection {
|
|||||||
* @throws FTPConnectionException if the command cannot be executed
|
* @throws FTPConnectionException if the command cannot be executed
|
||||||
*/
|
*/
|
||||||
public List<String> list(String dir) throws FTPConnectionException {
|
public List<String> list(String dir) throws FTPConnectionException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
FTPFile[] files = client.dirDetails(dir);
|
FTPFile[] files = client.dirDetails(dir);
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (FTPFile file : files) {
|
||||||
returnValue.add(files[i].getName());
|
returnValue.add(file.getName());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
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);
|
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
|
* @throws FTPConnectionException if the command cannot be executed
|
||||||
*/
|
*/
|
||||||
public List<String> listDirsOnly(String dir) throws FTPConnectionException {
|
public List<String> listDirsOnly(String dir) throws FTPConnectionException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
FTPFile[] files = client.dirDetails(dir);
|
FTPFile[] files = client.dirDetails(dir);
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (FTPFile file : files) {
|
||||||
if (files[i].isDir()) {
|
if (file.isDir()) {
|
||||||
returnValue.add(files[i].getName());
|
returnValue.add(file.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
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);
|
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
|
* @throws FTPConnectionException if the command cannot be executed
|
||||||
*/
|
*/
|
||||||
public List<String> listFilesOnly(String dir) throws FTPConnectionException {
|
public List<String> listFilesOnly(String dir) throws FTPConnectionException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
FTPFile[] files = client.dirDetails(dir);
|
FTPFile[] files = client.dirDetails(dir);
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (FTPFile file : files) {
|
||||||
if (!files[i].isDir()) {
|
if (!file.isDir()) {
|
||||||
returnValue.add(files[i].getName());
|
returnValue.add(file.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
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);
|
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
|
* @throws FTPConnectionException if the command cannot be executed
|
||||||
*/
|
*/
|
||||||
public List<String> listLinksOnly(String dir) throws FTPConnectionException {
|
public List<String> listLinksOnly(String dir) throws FTPConnectionException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
FTPFile[] files = client.dirDetails(dir);
|
FTPFile[] files = client.dirDetails(dir);
|
||||||
for (int i = 0; i < files.length; i++) {
|
for (FTPFile file : files) {
|
||||||
if (files[i].isLink()) {
|
if (file.isLink()) {
|
||||||
returnValue.add(files[i].getName());
|
returnValue.add(file.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
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);
|
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ public class FTPConnection {
|
|||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
logger.error(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
|
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ public class FTPConnection {
|
|||||||
client.rename(remoteOldName, remoteNewName);
|
client.rename(remoteOldName, remoteNewName);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error(ex.getMessage());
|
logger.error(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), 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.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import static java.net.URLEncoder.encode;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Communication endpoint for posting a messages
|
* Communication endpoint for posting a messages
|
||||||
@ -24,7 +26,7 @@ import org.apache.log4j.Logger;
|
|||||||
*/
|
*/
|
||||||
public class HttpLayer {
|
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 */
|
/** the url to post to */
|
||||||
private String destinationUrlString;
|
private String destinationUrlString;
|
||||||
/** the encoding to use */
|
/** the encoding to use */
|
||||||
@ -53,7 +55,7 @@ public class HttpLayer {
|
|||||||
*/
|
*/
|
||||||
public void post(String parameter, String message)
|
public void post(String parameter, String message)
|
||||||
throws MessageNotSendException {
|
throws MessageNotSendException {
|
||||||
Map<String, String[]> parameterMap = new HashMap<String, String[]>();
|
Map<String, String[]> parameterMap = new HashMap<>();
|
||||||
String[] valueArray = { message };
|
String[] valueArray = { message };
|
||||||
parameterMap.put(parameter, valueArray);
|
parameterMap.put(parameter, valueArray);
|
||||||
post(parameterMap);
|
post(parameterMap);
|
||||||
@ -79,7 +81,7 @@ public class HttpLayer {
|
|||||||
* TODO add https support
|
* TODO add https support
|
||||||
*/
|
*/
|
||||||
public void post(Map<String, String[]> parameterMap) throws MessageNotSendException {
|
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);
|
parameterList.add(parameterMap);
|
||||||
String content = getDataString(parameterList);
|
String content = getDataString(parameterList);
|
||||||
post (content);
|
post (content);
|
||||||
@ -247,7 +249,7 @@ public class HttpLayer {
|
|||||||
data += "&";
|
data += "&";
|
||||||
}
|
}
|
||||||
data += key.toLowerCase() + "="
|
data += key.toLowerCase() + "="
|
||||||
+ URLEncoder.encode(currentValue, encoding);
|
+ encode(currentValue, encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException ex) {
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.network.mail.MailMessageUtils.getInstance;
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import static java.lang.System.getProperties;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -11,12 +14,14 @@ import javax.mail.Folder;
|
|||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
|
import static javax.mail.Session.getInstance;
|
||||||
import javax.mail.Store;
|
import javax.mail.Store;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.search.MessageIDTerm;
|
import javax.mail.search.MessageIDTerm;
|
||||||
import javax.mail.search.SearchTerm;
|
import javax.mail.search.SearchTerm;
|
||||||
import javax.mail.util.SharedByteArrayInputStream;
|
import javax.mail.util.SharedByteArrayInputStream;
|
||||||
import org.apache.log4j.Logger;
|
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.
|
* 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 {
|
public abstract class DefaultMailReader implements MailReader {
|
||||||
|
|
||||||
/** the logging object */
|
/** 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 */
|
/** the store to connect with */
|
||||||
private Store store = null;
|
private Store store = null;
|
||||||
/** the smtp host to work with */
|
/** the smtp host to work with */
|
||||||
@ -57,7 +62,7 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
getStore().close();
|
getStore().close();
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
logger.error("Cannot disconnect from mailbox");
|
logger.error("Cannot disconnect from mailbox");
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
} finally {
|
} finally {
|
||||||
logger.info("Connection closed");
|
logger.info("Connection closed");
|
||||||
setStore(null);
|
setStore(null);
|
||||||
@ -77,7 +82,7 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
try {
|
try {
|
||||||
return getStore().getDefaultFolder().getFullName();
|
return getStore().getDefaultFolder().getFullName();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
throw new MailReaderException("Error while retrieving default folder. Reason: " + ex.getMessage(), 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
|
* @throws MailReaderException if the folder list cannot be retrieved
|
||||||
*/
|
*/
|
||||||
public List<String> getSubFolder(Folder sourceFolder) throws MailReaderException {
|
public List<String> getSubFolder(Folder sourceFolder) throws MailReaderException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
Folder[] folders = sourceFolder.list();
|
Folder[] folders = sourceFolder.list();
|
||||||
for (Folder folder : folders) {
|
for (Folder folder : folders) {
|
||||||
returnValue.add(folder.getFullName());
|
returnValue.add(folder.getFullName());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
throw new MailReaderException("Cannot retrieve folder list. Reason: " + ex.getMessage(), ex);
|
throw new MailReaderException("Cannot retrieve folder list. Reason: " + ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@ -110,11 +115,11 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
* @return the session object to use
|
* @return the session object to use
|
||||||
*/
|
*/
|
||||||
protected Session getDefaultSession() {
|
protected Session getDefaultSession() {
|
||||||
Properties props = (Properties) System.getProperties().clone();
|
Properties props = (Properties) getProperties().clone();
|
||||||
props.put("mail.smtp.host", configuration.getSmtpHost());
|
props.put("mail.smtp.host", configuration.getSmtpHost());
|
||||||
// TODO - add needed properties - only valid for session, do not overwrite properites
|
// TODO - add needed properties - only valid for session, do not overwrite properites
|
||||||
// TODO - add chained properties
|
// 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
|
* @throws MailReaderException if the folder cannot be found
|
||||||
*/
|
*/
|
||||||
private List<Folder> getFolderPath(String folderPath) throws MailReaderException {
|
private List<Folder> getFolderPath(String folderPath) throws MailReaderException {
|
||||||
List<Folder> returnValue = new LinkedList<Folder>();
|
List<Folder> returnValue = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
String[] folderPathParts = folderPath.split("/");
|
String[] folderPathParts = folderPath.split("/");
|
||||||
Folder currentFolder = store.getDefaultFolder();
|
Folder currentFolder = store.getDefaultFolder();
|
||||||
@ -215,7 +220,7 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSubFolder(String sourceFolder) throws MailReaderException {
|
public List<String> getSubFolder(String sourceFolder) throws MailReaderException {
|
||||||
List<String> returnValue = new LinkedList<String>();
|
List<String> returnValue = new LinkedList<>();
|
||||||
Folder folder = getFolderObject(sourceFolder);
|
Folder folder = getFolderObject(sourceFolder);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -231,7 +236,7 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
try {
|
try {
|
||||||
folder.close(false);
|
folder.close(false);
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +267,7 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
try {
|
try {
|
||||||
folder.close(false);
|
folder.close(false);
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,13 +285,13 @@ public abstract class DefaultMailReader implements MailReader {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<MailMessage> getMessages(String sourceFolder) throws MailReaderException {
|
public List<MailMessage> getMessages(String sourceFolder) throws MailReaderException {
|
||||||
List<MailMessage> returnValue = new LinkedList<MailMessage>();
|
List<MailMessage> returnValue = new LinkedList<>();
|
||||||
Folder folder = getFolderObject(sourceFolder);
|
Folder folder = getFolderObject(sourceFolder);
|
||||||
try {
|
try {
|
||||||
folder.open(Folder.READ_ONLY);
|
folder.open(Folder.READ_ONLY);
|
||||||
Message[] messages = folder.getMessages();
|
Message[] messages = folder.getMessages();
|
||||||
for (Message msg : messages) {
|
for (Message msg : messages) {
|
||||||
returnValue.add(MailMessageUtils.getInstance(getValidMessage(msg)));
|
returnValue.add(getInstance(getValidMessage(msg)));
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new MailReaderException("Cannot fetch email from folder " + folder.getFullName() + ". Reason: " + ex.getMessage(), 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 {
|
try {
|
||||||
folder.close(false);
|
folder.close(false);
|
||||||
} catch (MessagingException ex) {
|
} 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) {
|
public MailMessage(String subj, String contentString) {
|
||||||
this.subject = subj;
|
this.subject = subj;
|
||||||
this.content = new LinkedList<String>();
|
this.content = new LinkedList<>();
|
||||||
if (contentString != null) {
|
if (contentString != null) {
|
||||||
content.add(contentString);
|
content.add(contentString);
|
||||||
}
|
}
|
||||||
this.htmlContent = new LinkedList<String>();
|
this.htmlContent = new LinkedList<>();
|
||||||
this.isHtmlMessage = false;
|
this.isHtmlMessage = false;
|
||||||
this.messageId = null;
|
this.messageId = null;
|
||||||
this.sender = null;
|
this.sender = null;
|
||||||
this.receiver = new LinkedList<String>();
|
this.receiver = new LinkedList<>();
|
||||||
this.ccReceiver = new LinkedList<String>();
|
this.ccReceiver = new LinkedList<>();
|
||||||
this.bccReceiver = new LinkedList<String>();
|
this.bccReceiver = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** creates a new instance of MaiLmessage
|
/** creates a new instance of MaiLmessage
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -17,6 +18,7 @@ import javax.mail.Multipart;
|
|||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.internet.MimeMultipart;
|
import javax.mail.internet.MimeMultipart;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Util class to convert between javax.mail.Message and MailMessage objects
|
* Util class to convert between javax.mail.Message and MailMessage objects
|
||||||
@ -26,7 +28,7 @@ import org.apache.log4j.Logger;
|
|||||||
public abstract class MailMessageUtils {
|
public abstract class MailMessageUtils {
|
||||||
|
|
||||||
/** the logging object */
|
/** 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 */
|
/** content type of mutipart messages - e.g. multipart_alternative or _mixed */
|
||||||
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
private static final String CONTENTTYPE_MULTIPART = "multipart/";
|
||||||
@ -299,7 +301,7 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.debug(ex.getMessage());
|
logger.debug(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@ -307,7 +309,7 @@ public abstract class MailMessageUtils {
|
|||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.debug(ex.getMessage());
|
logger.debug(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.apache.log4j.Logger;
|
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 {
|
public abstract class MailReaderConfigurationFactory {
|
||||||
|
|
||||||
/** the logging object */
|
/** 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
|
* reads the config file and creates a configured mailreader configuration
|
||||||
@ -42,7 +44,7 @@ public abstract class MailReaderConfigurationFactory {
|
|||||||
is.close();
|
is.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error("Error while reading input file.");
|
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 de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of MaiLReader to connect to an IMAP server
|
* Implementation of MaiLReader to connect to an IMAP server
|
||||||
@ -14,7 +15,7 @@ import org.apache.log4j.Logger;
|
|||||||
public class ImapMailReader extends DefaultMailReader {
|
public class ImapMailReader extends DefaultMailReader {
|
||||||
|
|
||||||
/** the logger object */
|
/** 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
|
* 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.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
import static org.apache.log4j.PropertyConfigurator.configure;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +20,7 @@ public class BaseTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initLogging() {
|
public static void initLogging() {
|
||||||
URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties");
|
URL defaultConfigUrl = BaseTest.class.getResource("/logging.properties");
|
||||||
PropertyConfigurator.configure(defaultConfigUrl);
|
configure(defaultConfigUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readContentFromFile(String name) throws IOException {
|
public String readContentFromFile(String name) throws IOException {
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ public class CidrToolTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testCidrConversion() {
|
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
|
@Test
|
||||||
@ -27,12 +28,12 @@ public class CidrToolTest {
|
|||||||
// split 213.0.0.0/8 --> belongs to Ripe
|
// split 213.0.0.0/8 --> belongs to Ripe
|
||||||
// but 213.55.64.0 - 213.55.127.255 was transferred to Afrinic
|
// but 213.55.64.0 - 213.55.127.255 was transferred to Afrinic
|
||||||
System.out.println ("First part of Ripe");
|
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 ("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 ("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;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,6 +12,6 @@ public class RangeToCidrTest extends BaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRangeToCidr() {
|
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.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@ -57,7 +58,7 @@ public class FTPConnectionTest {
|
|||||||
fin.close();
|
fin.close();
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} 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
|
@Ignore
|
||||||
public void testPostByMap() throws Exception {
|
public void testPostByMap() throws Exception {
|
||||||
System.out.println("testPostByMap");
|
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"};
|
String[] value = {"Hello World!", "Hello World again"};
|
||||||
map.put("message", value);
|
map.put("message", value);
|
||||||
|
|
||||||
@ -35,12 +35,12 @@ public class HttpLayerTest extends BaseTest {
|
|||||||
@Ignore
|
@Ignore
|
||||||
public void testPostByMapList() throws Exception {
|
public void testPostByMapList() throws Exception {
|
||||||
System.out.println("testPostByMapList");
|
System.out.println("testPostByMapList");
|
||||||
List<Map<String, String[]>> list = new LinkedList<Map<String, String[]>>();
|
List<Map<String, String[]>> list = new LinkedList<>();
|
||||||
Map<String, String[]> map = new HashMap<String, String[]>();
|
Map<String, String[]> map = new HashMap<>();
|
||||||
String[] value = {"Hello World!", "Hello World again"};
|
String[] value = {"Hello World!", "Hello World again"};
|
||||||
map.put("message", value);
|
map.put("message", value);
|
||||||
list.add(map);
|
list.add(map);
|
||||||
map = new HashMap<String, String[]>();
|
map = new HashMap<>();
|
||||||
String[] urlValue = {"http://localhost:8080/testurl"};
|
String[] urlValue = {"http://localhost:8080/testurl"};
|
||||||
map.put("url", urlValue);
|
map.put("url", urlValue);
|
||||||
list.add(map);
|
list.add(map);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
import de.muehlencord.shared.network.BaseTest;
|
import de.muehlencord.shared.network.BaseTest;
|
||||||
|
import static de.muehlencord.shared.network.mail.MailReaderConfigurationFactory.getConfiguration;
|
||||||
import de.muehlencord.shared.network.mail.imap.ImapMailReader;
|
import de.muehlencord.shared.network.mail.imap.ImapMailReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -31,7 +32,7 @@ public class MailMessageUtilsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String testConfigFile = file.toString();
|
String testConfigFile = file.toString();
|
||||||
MailReaderConfiguration config = MailReaderConfigurationFactory.getConfiguration(testConfigFile);
|
MailReaderConfiguration config = getConfiguration(testConfigFile);
|
||||||
MailReader mr = new ImapMailReader(config);
|
MailReader mr = new ImapMailReader(config);
|
||||||
mr.connect();
|
mr.connect();
|
||||||
List<MailMessage> mm = mr.getMessages("INBOX");
|
List<MailMessage> mm = mr.getMessages("INBOX");
|
||||||
|
|||||||
@ -13,6 +13,9 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.security;
|
package de.muehlencord.shared.security;
|
||||||
|
|
||||||
|
import static java.lang.Integer.parseInt;
|
||||||
|
import static java.lang.String.valueOf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
@ -29,7 +32,7 @@ public class Luhn {
|
|||||||
|
|
||||||
// iterate from right digit to left
|
// iterate from right digit to left
|
||||||
for (int currentDigitPos = numberStr.length() - 1; currentDigitPos >= 0; currentDigitPos--) {
|
for (int currentDigitPos = numberStr.length() - 1; currentDigitPos >= 0; currentDigitPos--) {
|
||||||
int currentDigit = Integer.parseInt(String.valueOf(numberStr.charAt(currentDigitPos)));
|
int currentDigit = parseInt(valueOf(numberStr.charAt(currentDigitPos)));
|
||||||
if (doubleNextDigit) {
|
if (doubleNextDigit) {
|
||||||
currentDigit = currentDigit * 2;
|
currentDigit = currentDigit * 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.security;
|
package de.muehlencord.shared.security;
|
||||||
|
|
||||||
import com.lambdaworks.crypto.SCryptUtil;
|
import static com.lambdaworks.crypto.SCryptUtil.check;
|
||||||
|
import static com.lambdaworks.crypto.SCryptUtil.scrypt;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
@ -19,7 +20,7 @@ import org.apache.log4j.Logger;
|
|||||||
public abstract class PasswordUtil {
|
public abstract class PasswordUtil {
|
||||||
|
|
||||||
/** logging object */
|
/** logging object */
|
||||||
private final static Logger logger = Logger.getLogger(PasswordUtil.class);
|
private final static Logger logger = getLogger(PasswordUtil.class);
|
||||||
|
|
||||||
|
|
||||||
/** SCrypt CPU cost parameter */
|
/** SCrypt CPU cost parameter */
|
||||||
@ -229,7 +230,7 @@ public abstract class PasswordUtil {
|
|||||||
* @return the crypted password string
|
* @return the crypted password string
|
||||||
*/
|
*/
|
||||||
public static String getScryptHash(String plainPassword) {
|
public static String getScryptHash(String plainPassword) {
|
||||||
return SCryptUtil.scrypt(plainPassword, scryptCpuCostParameter, scryptMemCostParameter, scryptParallelizationParameter);
|
return scrypt(plainPassword, scryptCpuCostParameter, scryptMemCostParameter, scryptParallelizationParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,6 +241,6 @@ public abstract class PasswordUtil {
|
|||||||
* @return true, if the encrypted string of the given plain password matches the provided crypted password
|
* @return true, if the encrypted string of the given plain password matches the provided crypted password
|
||||||
*/
|
*/
|
||||||
public static boolean validateScryptHash(String plainPassword, String hashedPassword) {
|
public static boolean validateScryptHash(String plainPassword, String hashedPassword) {
|
||||||
return SCryptUtil.check(plainPassword, hashedPassword);
|
return check(plainPassword, hashedPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.security;
|
package de.muehlencord.shared.security;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.security.Luhn.computeCheckDigit;
|
||||||
|
import static de.muehlencord.shared.security.Luhn.validateNumber;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -28,23 +30,23 @@ public class LuhnTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testComputeCheckDigit() {
|
public void testComputeCheckDigit() {
|
||||||
String testString = "7992739871";
|
String testString = "7992739871";
|
||||||
int checkNumber = Luhn.computeCheckDigit(testString, false);
|
int checkNumber = computeCheckDigit(testString, false);
|
||||||
System.out.println(checkNumber);
|
System.out.println(checkNumber);
|
||||||
assertTrue(checkNumber == 3);
|
assertTrue(checkNumber == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateNumber() {
|
public void testValidateNumber() {
|
||||||
assertFalse(Luhn.validateNumber("79927398710"));
|
assertFalse(validateNumber("79927398710"));
|
||||||
assertFalse(Luhn.validateNumber("79927398711"));
|
assertFalse(validateNumber("79927398711"));
|
||||||
assertFalse(Luhn.validateNumber("79927398712"));
|
assertFalse(validateNumber("79927398712"));
|
||||||
assertTrue(Luhn.validateNumber("79927398713"));
|
assertTrue(validateNumber("79927398713"));
|
||||||
assertFalse(Luhn.validateNumber("79927398714"));
|
assertFalse(validateNumber("79927398714"));
|
||||||
assertFalse(Luhn.validateNumber("79927398715"));
|
assertFalse(validateNumber("79927398715"));
|
||||||
assertFalse(Luhn.validateNumber("79927398716"));
|
assertFalse(validateNumber("79927398716"));
|
||||||
assertFalse(Luhn.validateNumber("79927398717"));
|
assertFalse(validateNumber("79927398717"));
|
||||||
assertFalse(Luhn.validateNumber("79927398718"));
|
assertFalse(validateNumber("79927398718"));
|
||||||
assertFalse(Luhn.validateNumber("79927398719"));
|
assertFalse(validateNumber("79927398719"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package de.muehlencord.shared.security;
|
package de.muehlencord.shared.security;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.security.PasswordUtil.getScryptHash;
|
||||||
|
import static de.muehlencord.shared.security.PasswordUtil.validateScryptHash;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -133,8 +135,8 @@ public class PasswordUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetScryptHash() {
|
public void testGetScryptHash() {
|
||||||
String hash1 = PasswordUtil.getScryptHash("secret");
|
String hash1 = getScryptHash("secret");
|
||||||
String hash2 = PasswordUtil.getScryptHash("secret");
|
String hash2 = getScryptHash("secret");
|
||||||
System.out.println (hash1);
|
System.out.println (hash1);
|
||||||
System.out.println (hash2);
|
System.out.println (hash2);
|
||||||
assertNotNull (hash1);
|
assertNotNull (hash1);
|
||||||
@ -151,11 +153,11 @@ public class PasswordUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testValidateScryptHash() {
|
public void testValidateScryptHash() {
|
||||||
String hash1 = PasswordUtil.getScryptHash("secret");
|
String hash1 = getScryptHash("secret");
|
||||||
String hash2 = PasswordUtil.getScryptHash("secret");
|
String hash2 = getScryptHash("secret");
|
||||||
assertTrue ("hash must match if correct password is given",PasswordUtil.validateScryptHash("secret", hash1));
|
assertTrue ("hash must match if correct password is given",validateScryptHash("secret", hash1));
|
||||||
assertTrue ("hash must match if correct password is given", PasswordUtil.validateScryptHash("secret", hash2));
|
assertTrue ("hash must match if correct password is given", validateScryptHash("secret", hash2));
|
||||||
assertFalse ("hash must not match if wrong password is given", PasswordUtil.validateScryptHash("secret2", hash1));
|
assertFalse ("hash must not match if wrong password is given", validateScryptHash("secret2", hash1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
|
import static java.lang.System.getProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern@muehlencord.de
|
* @author joern@muehlencord.de
|
||||||
@ -27,7 +29,7 @@ public abstract class OSUtil {
|
|||||||
* @return an OS_xxxx constants identifiying the operating system the current JVM is running on;
|
* @return an OS_xxxx constants identifiying the operating system the current JVM is running on;
|
||||||
*/
|
*/
|
||||||
public static int getOperationSystem() {
|
public static int getOperationSystem() {
|
||||||
String osName = System.getProperties().getProperty("os.name");
|
String osName = getProperties().getProperty("os.name");
|
||||||
if (osName != null) {
|
if (osName != null) {
|
||||||
osName = osName.toUpperCase();
|
osName = osName.toUpperCase();
|
||||||
if (osName.contains("WINDOWS")) {
|
if (osName.contains("WINDOWS")) {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ package de.muehlencord.shared.util;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -16,7 +17,7 @@ import org.apache.log4j.Logger;
|
|||||||
public abstract class StringUtil {
|
public abstract class StringUtil {
|
||||||
|
|
||||||
/** the logging object */
|
/** the logging object */
|
||||||
private static final Logger logger = Logger.getLogger(StringUtil.class);
|
private static final Logger logger = getLogger(StringUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the given string in ISO-8859-1 encoding
|
* returns the given string in ISO-8859-1 encoding
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
package de.muehlencord.shared.util.file;
|
package de.muehlencord.shared.util.file;
|
||||||
|
|
||||||
import de.muehlencord.shared.util.StringUtil;
|
import de.muehlencord.shared.util.StringUtil;
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -12,9 +13,11 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import static org.apache.log4j.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -23,7 +26,7 @@ import org.apache.log4j.Logger;
|
|||||||
public abstract class FileUtil {
|
public abstract class FileUtil {
|
||||||
|
|
||||||
/** the logging object */
|
/** the logging object */
|
||||||
private static final Logger logger = Logger.getLogger(FileUtil.class);
|
private static final Logger logger = getLogger(FileUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a list of files found by the given regexp in the given folder
|
* returns a list of files found by the given regexp in the given folder
|
||||||
@ -35,7 +38,7 @@ public abstract class FileUtil {
|
|||||||
* @throws FileHandlingException if the given directory cannot be found
|
* @throws FileHandlingException if the given directory cannot be found
|
||||||
*/
|
*/
|
||||||
public static List<File> getFilesFromDirecotry(final String directory, final String regEx) throws FileHandlingException {
|
public static List<File> getFilesFromDirecotry(final String directory, final String regEx) throws FileHandlingException {
|
||||||
List<File> returnValue = new LinkedList<File>();
|
List<File> returnValue = new LinkedList<>();
|
||||||
File dir = new File(directory);
|
File dir = new File(directory);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
throw new FileHandlingException("Directory " + directory + " does not exist");
|
throw new FileHandlingException("Directory " + directory + " does not exist");
|
||||||
@ -44,18 +47,14 @@ public abstract class FileUtil {
|
|||||||
throw new FileHandlingException(directory + " is not a directory");
|
throw new FileHandlingException(directory + " is not a directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileFilter ff = new FileFilter() {
|
FileFilter ff = (File pathname) -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accept(File pathname) {
|
|
||||||
boolean isFile = pathname.isFile();
|
boolean isFile = pathname.isFile();
|
||||||
boolean match = pathname.toString().matches(regEx);
|
boolean match = pathname.toString().matches(regEx);
|
||||||
return isFile && match;
|
return isFile && match;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
File[] files = dir.listFiles(ff);
|
File[] files = dir.listFiles(ff);
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
returnValue.addAll(Arrays.asList(files));
|
returnValue.addAll(asList(files));
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
@ -106,7 +105,7 @@ public abstract class FileUtil {
|
|||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error(ex.getMessage());
|
logger.error(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fos != null) {
|
if (fos != null) {
|
||||||
@ -114,7 +113,7 @@ public abstract class FileUtil {
|
|||||||
fos.close();
|
fos.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error(ex.getMessage());
|
logger.error(ex.getMessage());
|
||||||
logger.debug(StringUtil.getStackTraceString(ex));
|
logger.debug(getStackTraceString(ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.util.OSUtil.getOperationSystem;
|
||||||
|
import static java.lang.System.getProperties;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -19,8 +21,8 @@ public class OSUtilTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetOS() {
|
public void testGetOS() {
|
||||||
String osName = System.getProperties().getProperty("os.name").toUpperCase();
|
String osName = getProperties().getProperty("os.name").toUpperCase();
|
||||||
int os = OSUtil.getOperationSystem();
|
int os = getOperationSystem();
|
||||||
|
|
||||||
switch (osName) {
|
switch (osName) {
|
||||||
case "LINUX":
|
case "LINUX":
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@ -16,7 +17,7 @@ public class StringUtilTest extends DefaultTest {
|
|||||||
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
||||||
String content = readContentFromFile("test.txt");
|
String content = readContentFromFile("test.txt");
|
||||||
|
|
||||||
String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just");
|
String ipAddress = getValueBetweenKeywords(content, "The IP", "has just");
|
||||||
assertEquals("ipAddress", "222.184.230.118", ipAddress);
|
assertEquals("ipAddress", "222.184.230.118", ipAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.util.file;
|
package de.muehlencord.shared.util.file;
|
||||||
|
|
||||||
|
import static de.muehlencord.shared.util.file.FileUtil.getFilesFromDirecotry;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -29,7 +30,7 @@ public class FileUtilTest {
|
|||||||
URL url = getClass().getResource("testfile.txt");
|
URL url = getClass().getResource("testfile.txt");
|
||||||
File testFile = new File(url.getFile());
|
File testFile = new File(url.getFile());
|
||||||
|
|
||||||
List<File> fileList = FileUtil.getFilesFromDirecotry(testFile.getParent(), ".*.java");
|
List<File> fileList = getFilesFromDirecotry(testFile.getParent(), ".*.java");
|
||||||
Iterator<File> it = fileList.iterator();
|
Iterator<File> it = fileList.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
System.out.println(it.next());
|
System.out.println(it.next());
|
||||||
|
|||||||
Reference in New Issue
Block a user