parent
9b10cbe9b7
commit
10ff309803
@ -0,0 +1,8 @@
|
||||
{
|
||||
"subdomainPrefix": "echo",
|
||||
"domain": "vidconnect.cyou",
|
||||
"host": "localhost",
|
||||
"port": 5270,
|
||||
"secretKey": "user-admin_secret",
|
||||
"startEncrypted": false
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.example.sshd.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class XmppComponentConfig {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(XmppComponentConfig.class);
|
||||
|
||||
private String subdomainPrefix;
|
||||
private String domain;
|
||||
private String host;
|
||||
private int port;
|
||||
private String secretKey;
|
||||
private boolean startEncrypted;
|
||||
|
||||
public String getSubdomainPrefix() {
|
||||
return subdomainPrefix;
|
||||
}
|
||||
|
||||
public void setSubdomainPrefix(String subdomainPrefix) {
|
||||
this.subdomainPrefix = subdomainPrefix;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public boolean isStartEncrypted() {
|
||||
return startEncrypted;
|
||||
}
|
||||
|
||||
public void setStartEncrypted(boolean startEncrypted) {
|
||||
this.startEncrypted = startEncrypted;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
try {
|
||||
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error("convert to json error!", e);
|
||||
}
|
||||
return "{}";
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.sshd.service;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jivesoftware.whack.ExternalComponentManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.xmpp.component.AbstractComponent;
|
||||
import org.xmpp.component.ComponentException;
|
||||
import org.xmpp.packet.Message;
|
||||
|
||||
import com.example.sshd.config.XmppComponentConfig;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
public class EchoComponent extends AbstractComponent {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EchoComponent.class);
|
||||
|
||||
@Autowired
|
||||
XmppComponentConfig xmppComponentConfig;
|
||||
|
||||
ExternalComponentManager externalComponentManager = null;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws ComponentException {
|
||||
logger.info("Starting up {} ...", xmppComponentConfig);
|
||||
externalComponentManager = new ExternalComponentManager(xmppComponentConfig.getHost(),
|
||||
xmppComponentConfig.getPort(), xmppComponentConfig.isStartEncrypted());
|
||||
externalComponentManager.setMultipleAllowed(xmppComponentConfig.getSubdomainPrefix(), false);
|
||||
externalComponentManager.setServerName(xmppComponentConfig.getDomain());
|
||||
externalComponentManager.setSecretKey(xmppComponentConfig.getSubdomainPrefix(),
|
||||
xmppComponentConfig.getSecretKey());
|
||||
externalComponentManager.addComponent(xmppComponentConfig.getSubdomainPrefix(), this,
|
||||
xmppComponentConfig.getPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "XMPP component for doing ECHO";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
protected void handleMessage(final Message inMsg) {
|
||||
logger.info("-- RECEIVED -- {}", inMsg);
|
||||
Message outMsg = new Message();
|
||||
outMsg.setType(inMsg.getType());
|
||||
outMsg.setFrom(inMsg.getTo());
|
||||
if (StringUtils.endsWith(inMsg.getSubject(), "@" + xmppComponentConfig.getDomain())) {
|
||||
outMsg.setTo(inMsg.getSubject());
|
||||
} else {
|
||||
outMsg.setTo(inMsg.getFrom());
|
||||
}
|
||||
outMsg.setSubject(inMsg.getSubject());
|
||||
outMsg.setBody(inMsg.getBody());
|
||||
externalComponentManager.sendPacket(this, outMsg);
|
||||
logger.info("-- SENT -- {}", outMsg);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue