diff options
author | Vitaly Takmazov | 2017-02-07 12:49:22 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-02-07 12:49:22 +0300 |
commit | 428c748b25b156a973f508e82a1c53ab6b74bc2b (patch) | |
tree | 7316e60b944ec5a1727cf41872480bc23be26bf7 /juick-xmpp-ft/src/main | |
parent | b8af9d2621a1cd94bfb24ee31e5a92d9f4e56c4e (diff) |
juick-xmpp: merge juick-xmpp-ft
Diffstat (limited to 'juick-xmpp-ft/src/main')
6 files changed, 0 insertions, 235 deletions
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java deleted file mode 100644 index 236c4c0d..00000000 --- a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.juick.components; - -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; -import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.XmppException; -import rocks.xmpp.core.session.Extension; -import rocks.xmpp.core.session.XmppSessionConfiguration; -import rocks.xmpp.core.session.debug.LogbackDebugger; -import rocks.xmpp.core.stanza.model.Message; -import rocks.xmpp.extensions.component.accept.ExternalComponent; -import rocks.xmpp.extensions.filetransfer.FileTransfer; -import rocks.xmpp.extensions.filetransfer.FileTransferManager; -import rocks.xmpp.extensions.oob.model.x.OobX; -import rocks.xmpp.extensions.ping.PingManager; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; - -/** - * Created by vitalyster on 11.11.2016. - */ -public class XMPPFTServer implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(XMPPFTServer.class); - - private ExternalComponent component; - - public XMPPFTServer(Environment env) { - XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() - .debugger(LogbackDebugger.class) - .build(); - component = ExternalComponent.create(env.getProperty("component_name", "files"), - env.getProperty("component_password", "secret"), configuration, env.getProperty("component_host", "localhost"), - NumberUtils.toInt(env.getProperty("component_port", "5347"), 5347)); - String tmpDir = env.getProperty("upload_tmp_dir", "/tmp"); - String juickJid = env.getProperty("xmppbot_jid", "juick@juick.com/Juick"); - PingManager pingManager = component.getManager(PingManager.class); - pingManager.setEnabled(true); - FileTransferManager fileTransferManager = component.getManager(FileTransferManager.class); - fileTransferManager.addFileTransferOfferListener(e -> { - try { - List<String> allowedTypes = new ArrayList<String>() {{ - add("png"); - add("jpg"); - }}; - String attachmentExtension = FilenameUtils.getExtension(e.getName()).toLowerCase(); - String targetFilename = String.format("%s.%s", - DigestUtils.md5Hex(String.format("%s-%s", - e.getInitiator().toString(), e.getSessionId()).getBytes()), attachmentExtension); - if (allowedTypes.contains(attachmentExtension)) { - Path filePath = Paths.get(tmpDir, targetFilename); - FileTransfer ft = e.accept(filePath).get(); - ft.addFileTransferStatusListener(st -> { - logger.debug("{}: received {} of {}", e.getName(), st.getBytesTransferred(), e.getSize()); - if (ft.isDone()) { - logger.info("transfer completed"); - Message msg = new Message(); - msg.setType(Message.Type.CHAT); - msg.setFrom(e.getInitiator()); - msg.setTo(Jid.of(juickJid)); - msg.setBody(e.getDescription()); - try { - String attachmentUrl = String.format("juick://%s", targetFilename); - msg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!")); - component.sendMessage(msg); - } catch (URISyntaxException e1) { - logger.warn("attachment error", e1); - } - } - }); - ft.transfer(); - logger.info("transfer started"); - } else { - e.reject(); - logger.info("transfer rejected"); - } - } catch (IOException | InterruptedException | ExecutionException e1) { - logger.error("ft error", e1); - } - }); - try { - component.connect(); - } catch (XmppException e) { - logger.error("ft initialization error", e); - } - } - - @Override - public void close() throws Exception { - if (component != null) - component.close(); - - logger.info("ExternalComponent on xmpp-ft destroyed"); - } -} diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java deleted file mode 100644 index e52a604a..00000000 --- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferAppConfiguration.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.juick.components.configuration; - -import com.juick.components.XMPPFTServer; -import com.juick.configuration.DataConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; - -import javax.inject.Inject; - -/** - * Created by aalexeev on 11/12/16. - */ -@Configuration -@PropertySource("classpath:juick.conf") -public class FileTransferAppConfiguration { - @Inject - private Environment env; - - @Bean - public XMPPFTServer xmpp() { - return new XMPPFTServer(env); - } -} diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java deleted file mode 100644 index 7fac43d4..00000000 --- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferInitializer.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.juick.components.configuration; - -import com.juick.configuration.DataConfiguration; -import org.apache.commons.lang3.CharEncoding; -import org.springframework.web.filter.CharacterEncodingFilter; -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -import javax.servlet.Filter; - -/** - * Created by vt on 09/02/16. - */ -public class FileTransferInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{FileTransferAppConfiguration.class, DataConfiguration.class}; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return new Class<?>[]{FileTransferMvcConfiguration.class}; - } - - @Override - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - @Override - protected Filter[] getServletFilters() { - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(CharEncoding.UTF_8); - return new Filter[]{characterEncodingFilter}; - } - - @Override - protected String getServletName() { - return "File transfer dispantcher servlet"; - } -} diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java b/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java deleted file mode 100644 index 9500f4e6..00000000 --- a/juick-xmpp-ft/src/main/java/com/juick/components/configuration/FileTransferMvcConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.juick.components.configuration; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -import java.util.List; - -/** - * Created by vitalyster on 28.06.2016. - */ -@Configuration -@ComponentScan(basePackages = {"com.juick.components.controllers"}) -public class FileTransferMvcConfiguration extends WebMvcConfigurationSupport { - - @Override - protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) { - Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder() - .serializationInclusion(JsonInclude.Include.NON_DEFAULT) - .serializationInclusion(JsonInclude.Include.NON_NULL) - .serializationInclusion(JsonInclude.Include.NON_ABSENT) - .serializationInclusion(JsonInclude.Include.NON_EMPTY); - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build()); - converter.getObjectMapper().registerModule(new Jdk8Module()); - converters.add(converter); - super.configureMessageConverters(converters); - } -} diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/controllers/StatusController.java b/juick-xmpp-ft/src/main/java/com/juick/components/controllers/StatusController.java deleted file mode 100644 index eeff36f8..00000000 --- a/juick-xmpp-ft/src/main/java/com/juick/components/controllers/StatusController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.juick.components.controllers; - -import com.juick.components.XMPPFTServer; -import com.juick.Status; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import javax.inject.Inject; - -/** - * Created by vitalyster on 24.10.2016. - */ -@RestController -public class StatusController { - @Inject - XMPPFTServer xmpp; - - @RequestMapping(method = RequestMethod.GET, value = "/", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public Status status() { - return xmpp != null ? Status.OK : Status.ERROR; - } -} diff --git a/juick-xmpp-ft/src/main/webapp/WEB-INF/web.xml b/juick-xmpp-ft/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index a57cceb9..00000000 --- a/juick-xmpp-ft/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<web-app xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" - version="3.0"> - -</web-app>
\ No newline at end of file |