diff --git a/conf/scheduler.xml b/conf/scheduler.xml new file mode 100644 index 0000000..345c31e --- /dev/null +++ b/conf/scheduler.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index d9a0a9e..ce5a4b2 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.example.sshd echo-sshd-server - 2.2.1 + 2.2.2 ECHO SSH SERVER Learning Apache Mina SSHD library diff --git a/src/main/java/com/example/sshd/config/AppConfig.java b/src/main/java/com/example/sshd/config/AppConfig.java index 3adec8e..1ca9345 100644 --- a/src/main/java/com/example/sshd/config/AppConfig.java +++ b/src/main/java/com/example/sshd/config/AppConfig.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Scope; import org.xmpp.packet.Message; @@ -25,6 +26,7 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; @Configuration +@ImportResource("file:conf/scheduler.xml") public class AppConfig { @Value("${xmpp-component.config-json}") diff --git a/src/main/java/com/example/sshd/service/EchoComponent.java b/src/main/java/com/example/sshd/service/EchoComponent.java index 80e54f5..c7ec3d4 100644 --- a/src/main/java/com/example/sshd/service/EchoComponent.java +++ b/src/main/java/com/example/sshd/service/EchoComponent.java @@ -74,6 +74,20 @@ public class EchoComponent extends AbstractComponent { return this.getClass().getName(); } + public void sendMessage(String fromJID, String toJID, String message) { + try { + Message outMsg = new Message(); + outMsg.setType(Message.Type.chat); + outMsg.setFrom(fromJID); + outMsg.setTo(toJID); + outMsg.setBody(replyService.executeShellCommand(message)); + externalComponentManager.sendPacket(this, outMsg); + logger.info("[sendMessage] -- SENT -- {}", outMsg); + } catch (Exception err) { + logger.error("[sendMessage] ", err); + } + } + private void doEcho(final Message inMsg, String body) { try { Message outMsg = new Message(); diff --git a/src/main/java/com/example/sshd/service/MessageSender.java b/src/main/java/com/example/sshd/service/MessageSender.java new file mode 100644 index 0000000..697d7f2 --- /dev/null +++ b/src/main/java/com/example/sshd/service/MessageSender.java @@ -0,0 +1,39 @@ +package com.example.sshd.service; + +import org.springframework.beans.factory.annotation.Autowired; + +public class MessageSender { + + @Autowired + EchoComponent echoComponent; + + private String fromJID, toJID, message; + + public void sendMessage() { + echoComponent.sendMessage(fromJID, toJID, message); + } + + public String getFromJID() { + return fromJID; + } + + public void setFromJID(String fromJID) { + this.fromJID = fromJID; + } + + public String getToJID() { + return toJID; + } + + public void setToJID(String toJID) { + this.toJID = toJID; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +}