updated API description
This commit is contained in:
@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package de.muehlencord.shared.network.ftp;
|
||||
|
||||
import com.enterprisedt.net.ftp.FTPClient;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class FTPConnection {
|
||||
|
||||
/** the default timeout in ms */
|
||||
public static final int DEFAULTTIMEOUT = 30000;
|
||||
/** the logger object */
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(FTPConnection.class);
|
||||
/** the username to connect with */
|
||||
private String userName;
|
||||
/** the password to connect with */
|
||||
private String password;
|
||||
/** the ftp client to use */
|
||||
private FTPClient client;
|
||||
/** the remote host to connect to */
|
||||
private String remoteHost;
|
||||
/** the locale of the client to use */
|
||||
private Locale clientLocale;
|
||||
|
||||
/**
|
||||
* creates a new ftp connection
|
||||
*
|
||||
* @param remoteHost the host to connect to
|
||||
* @param userName the user to connect with
|
||||
* @param password the password to connect with
|
||||
*/
|
||||
public FTPConnection(String remoteHost, String userName, String password) {
|
||||
this(remoteHost, userName, password, Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new ftp connection
|
||||
*
|
||||
* @param remoteHost the host to connect to
|
||||
* @param userName the user to connect with
|
||||
* @param password the password to connect with
|
||||
* @param clientLocale the locale to use for the client
|
||||
*/
|
||||
public FTPConnection(String remoteHost, String userName, String password, Locale clientLocale) {
|
||||
this.remoteHost = remoteHost;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
this.clientLocale = clientLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* connects the ftp client to the remote host
|
||||
*
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public void connect() throws FTPConnectionException {
|
||||
try {
|
||||
client = new FTPClient();
|
||||
client.setConnectMode(FTPConnectMode.PASV);
|
||||
client.setParserLocale(clientLocale);
|
||||
client.setRemoteHost(remoteHost);
|
||||
client.setTimeout(DEFAULTTIMEOUT);
|
||||
client.connect();
|
||||
client.login(userName, password);
|
||||
} catch (Exception ex) {
|
||||
throw new FTPConnectionException("Error while connecting to ftp client. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** disconnects the ftp client from the remote host */
|
||||
public void disconnect() {
|
||||
try {
|
||||
client.quit();
|
||||
} catch (IOException | FTPException ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of files (as string) found in the given directory
|
||||
*
|
||||
* @param dir the directory to return the list for
|
||||
* @return a list of files (as string) found in the given directory
|
||||
*
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> list(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (FTPFile file : files) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of directories contained in given directory
|
||||
*
|
||||
* @param dir the directory to return the subfolders for
|
||||
* @return a list of subfolders of the given directory
|
||||
*
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listDirsOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (FTPFile file : files) {
|
||||
if (file.isDir()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of files contained in the given folder
|
||||
*
|
||||
* @param dir the directory to list
|
||||
* @return a list of files contained in the given folder
|
||||
*
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listFilesOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (FTPFile file : files) {
|
||||
if (!file.isDir()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of links contained in the given folder
|
||||
*
|
||||
* @param dir the directory to list
|
||||
* @return a list of links contained in the given folder
|
||||
*
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public List<String> listLinksOnly(String dir) throws FTPConnectionException {
|
||||
List<String> returnValue = new LinkedList<>();
|
||||
try {
|
||||
FTPFile[] files = client.dirDetails(dir);
|
||||
for (FTPFile file : files) {
|
||||
if (file.isLink()) {
|
||||
returnValue.add(file.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while getting diretoy listing. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads the given file and stores it under the given remote filename - including path
|
||||
*
|
||||
* @param localFilename the path and filename of the source file
|
||||
* @param remoteFileName the path and filename of the destination file
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public void uploadFile(String localFilename, String remoteFileName) throws FTPConnectionException {
|
||||
|
||||
try {
|
||||
client.setDetectTransferMode(true);
|
||||
if ((remoteFileName != null) && !remoteFileName.equals("")) {
|
||||
client.put(localFilename, remoteFileName, false);
|
||||
} else {
|
||||
File f = new File(localFilename);
|
||||
String remoteName = f.getName();
|
||||
client.put(localFilename, remoteName, false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while uploading file. Reason: " + ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* renames a file on the remote host
|
||||
*
|
||||
* @param remoteOldName the current file name
|
||||
* @param remoteNewName the new file name
|
||||
* @throws FTPConnectionException if the command cannot be executed
|
||||
*/
|
||||
public void rename(String remoteOldName, String remoteNewName) throws FTPConnectionException {
|
||||
try {
|
||||
client.rename(remoteOldName, remoteNewName);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage());
|
||||
LOGGER.debug(StringUtil.getStackTraceString(ex));
|
||||
throw new FTPConnectionException("Error while renaming file. Reason: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package de.muehlencord.shared.network.ftp;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class FTPConnectionException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1001347648193052240L;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an instance of
|
||||
* <code>FTPConnectionException</code> with the specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public FTPConnectionException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of
|
||||
* <code>FTPConnectionException</code> with the specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param th the causing exception
|
||||
*/
|
||||
public FTPConnectionException(String msg, Throwable th) {
|
||||
super(msg, th);
|
||||
}
|
||||
}
|
||||
@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Communication endpoint for posting a messages
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class HttpLayer {
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ package de.muehlencord.shared.network.http;
|
||||
|
||||
/**
|
||||
* This message is thrown if a message cannot be sent
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class MessageNotSendException extends Exception {
|
||||
|
||||
|
||||
@ -25,9 +25,10 @@ import javax.naming.ldap.InitialLdapContext;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
|
||||
/**
|
||||
* Inits and holds a connection to an ldap address directory
|
||||
* @see javax.naming.ldap.LdapContext;
|
||||
* @author dennis.nobel
|
||||
* Initializes and holds a connection to an LDAP address directory
|
||||
* {@link javax.naming.ldap.LdapContext}
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class LDAPConnection {
|
||||
|
||||
@ -91,7 +92,7 @@ public class LDAPConnection {
|
||||
}
|
||||
|
||||
/**
|
||||
* intializes connection to AD
|
||||
* initialize connection to AD
|
||||
* @throws NamingException is thrown if connection to LDAP failed
|
||||
*/
|
||||
protected void init() throws NamingException {
|
||||
@ -106,16 +107,23 @@ public class LDAPConnection {
|
||||
env.put(Context.SECURITY_PROTOCOL, securityProtocol);
|
||||
ldapContext = new InitialLdapContext(env, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see javax.naming.ldap.LdapContext;
|
||||
* {@link javax.naming.ldap.LdapContext}
|
||||
*
|
||||
* @param name the name to search for
|
||||
* @param filter the filter to apply
|
||||
* @param cons the search controls to use
|
||||
* @return the result returned by the LDAP server
|
||||
* @throws NamingException it the search fails
|
||||
*/
|
||||
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException {
|
||||
return ldapContext.search(name, filter, cons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.naming.ldap.LdapContext;
|
||||
* @throws javax.naming.NamingException if the close operation fails
|
||||
* {@link javax.naming.ldap.LdapContext}
|
||||
*/
|
||||
public void close() throws NamingException {
|
||||
if (ldapContext != null) {
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
package de.muehlencord.shared.network.ldap;
|
||||
|
||||
/**
|
||||
* Represents a contact in ldap address directory
|
||||
* Represents a contact in LDAP address directory
|
||||
*
|
||||
* @author Joern Muehlencord
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class LDAPContact {
|
||||
|
||||
@ -45,6 +45,8 @@ public class LDAPContact {
|
||||
private String countryCode = null;
|
||||
private boolean isEnabled = false;
|
||||
private String distinguishedName = null;
|
||||
|
||||
/* *** getter / setter *** */
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
|
||||
@ -29,38 +29,45 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Connection to ldap server to searh by different values
|
||||
* Connection to LDAP server to search by different values
|
||||
*
|
||||
* @author Joern Muehlencord
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class LDAPSearch {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LDAPSearch.class);
|
||||
|
||||
/**
|
||||
* the ldap connection to use
|
||||
* the LDAP connection to use
|
||||
*/
|
||||
private LDAPConnection ldapConnection;
|
||||
/**
|
||||
* the search base for all queries
|
||||
*/
|
||||
private String searchBase;
|
||||
private final String searchBase;
|
||||
|
||||
/**
|
||||
* Creates a new instance of a ldap search.
|
||||
* Creates a new instance of a LDAP search.
|
||||
*
|
||||
* <p>
|
||||
* Important: <br> If you want to use ldaps - usually port 636 make sure you provide a trustkeystore in case your ldap server does not use a certificate which can be trusted by the build in root
|
||||
* certificates. (e.g. self signed certificates) </p>
|
||||
* <div>
|
||||
* Important: <br> If you want to use LDAPs - usually port 636 make sure you
|
||||
* provide a trustkeystore in case your LDAP server does not use a
|
||||
* certificate which can be trusted by the build in root certificates. (e.g.
|
||||
* self signed certificates)
|
||||
* </div>
|
||||
*
|
||||
* <p>
|
||||
* To provide access to a trust center you can specify the following parameter to your application by providing the following parameter
|
||||
* <div>
|
||||
* To provide access to a trust center you can specify the following
|
||||
* parameter to your application by providing the following parameter
|
||||
* <pre>
|
||||
* -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
|
||||
* </pre> </p>
|
||||
* </pre>
|
||||
* </div>
|
||||
*
|
||||
* @param url the url of the ldap server to connect to like <code>ldap://ldapserver.your.domain:389</code>
|
||||
* @param searchBase the search base to use - e.g. <code>DC=domain,DC=tld</code>
|
||||
* @param url the url of the LDAP server to connect to like
|
||||
* <code>ldap://ldapserver.your.domain:389</code>
|
||||
* @param searchBase the search base to use - e.g.
|
||||
* <code>DC=domain,DC=tld</code>
|
||||
* @param username the username to connect with
|
||||
* @param password the password to connect with
|
||||
*/
|
||||
@ -73,22 +80,29 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of a ldap search.
|
||||
* Creates a new instance of a LDAP search.
|
||||
*
|
||||
* <p>
|
||||
* Important: <br> If you want to use ldaps - usually port 636 make sure you provide a trustkeystore in case your ldap server does not use a certificate which can be trusted by the build in root
|
||||
* certificates. (e.g. self signed certificates) </p>
|
||||
* <div>
|
||||
* Important: <br> If you want to use LDAPs - usually port 636 make sure you
|
||||
* provide a trustkeystore in case your LDAP server does not use a
|
||||
* certificate which can be trusted by the build in root certificates. (e.g.
|
||||
* self signed certificates)
|
||||
* </div>
|
||||
*
|
||||
* <p>
|
||||
* To provide access to a trust center you can specify the following parameter to your application by providing the following parameter
|
||||
* <div>
|
||||
* To provide access to a trust center you can specify the following
|
||||
* parameter to your application by providing the following parameter
|
||||
* <pre>
|
||||
* -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
|
||||
* </pre> </p>
|
||||
* </pre>
|
||||
* </div>
|
||||
*
|
||||
* @param authentication the authentification type to use -e.g. "SIMPLE"
|
||||
* @param url the url of the ldap server to connect to like <code>ldap://ldapserver.your.domain:389</code>
|
||||
* @param url the url of the ldap server to connect to like
|
||||
* <code>ldap://ldapserver.your.domain:389</code>
|
||||
* @param securityProtocol the security protocol to use - e.g. SIMPLE
|
||||
* @param searchBase the search base to use - e.g. <code>DC=domain,DC=tld</code>
|
||||
* @param searchBase the search base to use - e.g.
|
||||
* <code>DC=domain,DC=tld</code>
|
||||
* @param username the username to connect with
|
||||
* @param password the password to connect with
|
||||
*/
|
||||
@ -98,7 +112,10 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* execute several init steps, connect to ldap
|
||||
* execute several init steps, connect to LDAP
|
||||
*
|
||||
* @throws de.muehlencord.shared.network.ldap.LDAPException if the
|
||||
* connection cannot be established
|
||||
*/
|
||||
public void init() throws LDAPException {
|
||||
try {
|
||||
@ -109,7 +126,10 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* close the ldap connection
|
||||
* close the LDAP connection
|
||||
*
|
||||
* @throws de.muehlencord.shared.network.ldap.LDAPException if an error
|
||||
* during closing appears.
|
||||
*/
|
||||
public void close() throws LDAPException {
|
||||
if (ldapConnection != null) {
|
||||
@ -123,9 +143,9 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the search base of the ldap connection
|
||||
* Returns the search base of the LDAP connection
|
||||
*
|
||||
* @return the search base of the ldap connection
|
||||
* @return the search base of the LDAP connection
|
||||
*/
|
||||
public String getSearchBase() {
|
||||
return searchBase;
|
||||
@ -135,7 +155,7 @@ public class LDAPSearch {
|
||||
* Searches a contact according to emailaddress in the address directory
|
||||
*
|
||||
* @param email emailaddress to search for
|
||||
* @return ldap contact or null if nothing could be found
|
||||
* @return LDAP contact or null if nothing could be found
|
||||
* @throws LDAPException when search fails
|
||||
*/
|
||||
public LDAPContact searchContactWithEmail(String email) throws LDAPException {
|
||||
@ -182,9 +202,10 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if the given email address can be found in the configured ldap
|
||||
* Returns true, if the given email address can be found in the configured
|
||||
* LDAP.
|
||||
*
|
||||
* @param email the emailaddress to search for
|
||||
* @param email the email address to search for
|
||||
* @return true, if the email address could be found; else false
|
||||
* @throws LDAPException if the search fails
|
||||
*/
|
||||
@ -193,11 +214,16 @@ public class LDAPSearch {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if the given email address is member of the given group, specified by the DN
|
||||
* Returns true, if the given email address is member of the given group,
|
||||
* specified by the DN
|
||||
*
|
||||
* @param email the email to validat
|
||||
* @param groupDn the group search base - all members must be found as "member" in this group
|
||||
* @return
|
||||
* @param email the email to validate
|
||||
* @param groupDn the group search base - all members must be found as
|
||||
* "member" in this group
|
||||
* @return true, if the given contact, specified by the email address is
|
||||
* member of the specified group. Otherwise false is returned.
|
||||
*
|
||||
* @throws de.muehlencord.shared.network.ldap.LDAPException
|
||||
*/
|
||||
public boolean isMemberOfGroup(String email, String groupDn) throws LDAPException {
|
||||
boolean returnValue = false;
|
||||
|
||||
@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* MailReader to connect and work with IMAP mailboxes. Also works with exchange servers.
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public abstract class DefaultMailReader implements MailReader {
|
||||
|
||||
@ -57,7 +57,7 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* onnects to the mailbox
|
||||
* connects to the mailbox
|
||||
*
|
||||
* @throws MailReaderConnectionException if the connection cannot be established
|
||||
*/
|
||||
@ -486,8 +486,8 @@ public abstract class DefaultMailReader implements MailReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* asures the message can be read even if the underlaying IMAP server does not handle the message correctly. see
|
||||
* http://www.oracle.com/technetwork/java/faq-135477.html for details
|
||||
* ensure the message can be read even if the underlaying IMAP server does not handle the message correctly. see
|
||||
* @see <a href="https://www.oracle.com/technetwork/java/faq-135477.html">https://www.oracle.com/technetwork/java/faq-135477.html</a>
|
||||
*
|
||||
* @param msg the message to read
|
||||
* @return the message in a readable format
|
||||
|
||||
@ -25,7 +25,7 @@ import javax.mail.internet.InternetAddress;
|
||||
/**
|
||||
* A mail message
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class MailMessage {
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ package de.muehlencord.shared.network.mail;
|
||||
|
||||
/**
|
||||
* Exception used during mail handling
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class MailMessageException extends Exception {
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Util class to convert between javax.mail.Message and MailMessage objects
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public abstract class MailMessageUtils {
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public interface MailReader {
|
||||
|
||||
@ -85,6 +85,8 @@ public interface MailReader {
|
||||
* retrieves the list of messages stored in the given folder
|
||||
*
|
||||
* @param folder the folder to search return the emails for
|
||||
* @param start the number of the first message
|
||||
* @param end the number of the last message
|
||||
* @return list of messages stored in the given folder
|
||||
*
|
||||
* @throws MailReaderException if the message list cannot be retrieved
|
||||
|
||||
@ -22,11 +22,11 @@ package de.muehlencord.shared.network.mail;
|
||||
public class MailReaderConfiguration {
|
||||
|
||||
/**
|
||||
* server for smtp sessions
|
||||
* server for SMTP sessions
|
||||
*/
|
||||
private String smtpHost = null;
|
||||
/**
|
||||
* server for incoming emails - e.g. the imap or pop3 server
|
||||
* server for incoming emails - e.g. the IMAP or pop3 server
|
||||
*/
|
||||
private String readerHost = null;
|
||||
/**
|
||||
@ -47,11 +47,12 @@ public class MailReaderConfiguration {
|
||||
private MailProtocol protocol = null;
|
||||
|
||||
// TODO add checkConfig to asure the config is valid for the reader it is attached to
|
||||
|
||||
/**
|
||||
* creates a new config
|
||||
*
|
||||
* @param mailHost the smtp host to connect to
|
||||
* @param host the mailreader host (imap, exchange, pop, ...) to connect to
|
||||
* @param host the mailreader host (IMAP, exchange, pop, ...) to connect to
|
||||
* @param user the username to connect with
|
||||
* @param pw the password to connect with
|
||||
*/
|
||||
@ -69,6 +70,7 @@ public class MailReaderConfiguration {
|
||||
* @param host the mailreader host (imap, exchange, pop, ...) to connect to
|
||||
* @param user the username to connect with
|
||||
* @param pw the password to connect with
|
||||
* @param email the email address to use for sending emails
|
||||
*/
|
||||
public MailReaderConfiguration(String mailHost, String host, String user, String pw, String email) {
|
||||
this.smtpHost = mailHost;
|
||||
|
||||
@ -17,7 +17,7 @@ package de.muehlencord.shared.network.mail;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class MailReaderConfigurationException extends Exception {
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public abstract class MailReaderConfigurationFactory {
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Implementation of MailReader to connect to an IMAP server
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class ImapMailReader extends DefaultMailReader {
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class ArinWhoisParser extends AbstractWhoisParser implements WhoisParser {
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ import org.apache.commons.net.whois.WhoisClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class Whois {
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class WhoisInformation {
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public abstract class BaseTest {
|
||||
|
||||
|
||||
@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package de.muehlencord.shared.network.ftp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class FTPConnectionTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(FTPConnectionTest.class.getName());
|
||||
|
||||
/** the properties loaded from the config file */
|
||||
Properties props = null;
|
||||
/** true, if init is complete to execute test */
|
||||
boolean initDone = false;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
System.out.println("\n[FTPConnectionTest]");
|
||||
URL testConfigURL = FTPConnectionTest.class.getResource("/test.properties");
|
||||
FileInputStream fin = null;
|
||||
try {
|
||||
File file = new File(testConfigURL.toURI());
|
||||
props = new Properties();
|
||||
if ((file == null) || (!file.exists())) {
|
||||
initDone = false;
|
||||
|
||||
} else {
|
||||
fin = new FileInputStream(file);
|
||||
props.load(fin);
|
||||
}
|
||||
if ((props.containsKey("ftp.host")) && (props.containsKey("ftp.user")) && (props.containsKey("ftp.password")) && (props.containsKey("ftp.locale"))) {
|
||||
initDone = true;
|
||||
} else {
|
||||
initDone = false;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
initDone = false;
|
||||
} finally {
|
||||
try {
|
||||
if (fin != null) {
|
||||
fin.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error (ex.toString(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** tests connect / disconnect */
|
||||
@Test
|
||||
public void testConnectAndDisconnect() throws FTPConnectionException {
|
||||
System.out.println("testConnectAndDisconnect");
|
||||
if (initDone) {
|
||||
String remoteHost = props.getProperty("ftp.host");
|
||||
String user = props.getProperty("ftp.user");
|
||||
String password = props.getProperty("ftp.password");
|
||||
Locale locale = new Locale(props.getProperty("ftp.locale"));
|
||||
|
||||
FTPConnection con = new FTPConnection(remoteHost, user, password, locale);
|
||||
con.connect();
|
||||
con.disconnect();
|
||||
System.out.println("executed successfully");
|
||||
} else {
|
||||
System.out.println("Skipped because config is not complete");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testList() throws FTPConnectionException {
|
||||
System.out.println("list");
|
||||
String dir = "";
|
||||
FTPConnection instance = null;
|
||||
List expResult = null;
|
||||
List result = instance.list(dir);
|
||||
assertEquals(expResult, result);
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testListDirsOnly() throws FTPConnectionException {
|
||||
System.out.println("listDirsOnly");
|
||||
String dir = "";
|
||||
FTPConnection instance = null;
|
||||
List expResult = null;
|
||||
List result = instance.listDirsOnly(dir);
|
||||
assertEquals(expResult, result);
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testListFilesOnly() throws FTPConnectionException {
|
||||
System.out.println("listFilesOnly");
|
||||
String dir = "";
|
||||
FTPConnection instance = null;
|
||||
List expResult = null;
|
||||
List result = instance.listFilesOnly(dir);
|
||||
assertEquals(expResult, result);
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testListLinksOnly() throws FTPConnectionException {
|
||||
System.out.println("listLinksOnly");
|
||||
String dir = "";
|
||||
FTPConnection instance = null;
|
||||
List expResult = null;
|
||||
List result = instance.listLinksOnly(dir);
|
||||
assertEquals(expResult, result);
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testUploadFile() throws FTPConnectionException {
|
||||
System.out.println("uploadFile");
|
||||
String localFilename = "";
|
||||
String remoteFileName = "";
|
||||
FTPConnection instance = null;
|
||||
instance.uploadFile(localFilename, remoteFileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testRename() throws FTPConnectionException {
|
||||
System.out.println("rename");
|
||||
String remoteOldName = "";
|
||||
String remoteNewName = "";
|
||||
FTPConnection instance = null;
|
||||
instance.rename(remoteOldName, remoteNewName);
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
}
|
||||
@ -38,8 +38,7 @@ public class HttpLayerTest extends BaseTest {
|
||||
String[] value = {"Hello World!", "Hello World again"};
|
||||
map.put("message", value);
|
||||
|
||||
HttpLayer httpLayer = new HttpLayer(
|
||||
"http://localhost:8080/HttpPostListener/HttpPostListener");
|
||||
HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
|
||||
httpLayer.post(map);
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class MailMessageUtilsTest extends BaseTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user