diff options
author | Simon Rettberg | 2015-09-04 15:50:33 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-04 15:50:33 +0200 |
commit | cf5c2c886f65e61870b951546258949e3a4030f8 (patch) | |
tree | 7ac4dfeb26c60a3213e9e4fa4c69f515a42e2e16 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java | |
parent | [*] OS now has mem and cpu info (diff) | |
download | tutor-module-cf5c2c886f65e61870b951546258949e3a4030f8.tar.gz tutor-module-cf5c2c886f65e61870b951546258949e3a4030f8.tar.xz tutor-module-cf5c2c886f65e61870b951546258949e3a4030f8.zip |
[server] mailtest RPC methods, bugfixes to nanohttpd
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java index 6fdd57b6..1cc71e45 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebRpc.java @@ -1,7 +1,10 @@ package org.openslx.bwlp.sat.web; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.PrintStream; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; @@ -10,20 +13,18 @@ import java.util.Map; import javax.security.auth.login.LoginException; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.log4j.Logger; import org.openslx.bwlp.sat.mail.SmtpMailer; import org.openslx.bwlp.sat.mail.SmtpMailer.EncryptionMode; import org.openslx.util.Util; +import fi.iki.elonen.NanoHTTPD; import fi.iki.elonen.NanoHTTPD.Response; public class WebRpc { - private static final Logger LOGGER = Logger.getLogger(WebRpc.class); - public static Response handle(String uri, Map<String, String> params) { if (uri.equals("mailtest")) { - mailTest(params); + return mailTest(params); } return WebServer.notFound(); } @@ -42,7 +43,7 @@ public class WebRpc { try { ssl = EncryptionMode.valueOf(params.get("ssl")); } catch (Exception e) { - return WebServer.badRequest("Invalid SSL mode"); + return WebServer.badRequest("Invalid SSL mode '" + params.get("ssl") + "'"); } // Validate if (port < 1 || port > 65535) @@ -59,9 +60,24 @@ public class WebRpc { new PrintStream(baos)); } catch (InvalidKeyException | LoginException | NoSuchAlgorithmException | InvalidKeySpecException | IOException e) { - LOGGER.error("Could not initialize connection to SMTP server. Mails will not be sent", e); + try { + baos.write("Could not connect to mail server".getBytes(StandardCharsets.UTF_8)); + e.printStackTrace(new PrintWriter(baos)); + } catch (IOException e1) { + } + smtpc = null; + } + boolean ret = false; + if (smtpc != null) { + ret = smtpc.send(recipient, "bwLehrpool Mail Test", "Test der Mailkonfiguration.\n\nHost: " + + host + ":" + port + "\nSSL: " + ssl.toString() + "\nLogin: " + username); } - return WebServer.internalServerError(); + try { + baos.write(("\n\n-----------------------------------------\nTestergebnis: " + + (ret ? "" : "nicht ") + "erfolgreich").getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + } + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/plain; charset=utf-8", + new ByteArrayInputStream(baos.toByteArray())); } - } |