diff options
38 files changed, 224 insertions, 523 deletions
diff --git a/build.gradle b/build.gradle index f4128c78..89ffeb42 100644 --- a/build.gradle +++ b/build.gradle @@ -21,8 +21,7 @@ allprojects { } project.ext { - springFrameworkVersion = '5.0.4.RELEASE' - springSecurityVersion = '5.0.3.RELEASE' + springBootVersion = '2.0.0.RELEASE' jacksonVersion = '2.9.4' slf4jVersion = '1.7.25' logbackVersion = '1.2.3' @@ -37,20 +36,13 @@ buildscript { jcenter() } dependencies { - classpath 'org.akhikhl.gretty:gretty:+' + classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE" classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0' } } apply plugin: 'java' -apply plugin: 'org.akhikhl.gretty' - -farm { - webapp ':juick-www' - webapp ':juick-server' - - - servletContainer = 'tomcat8' -} +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' repositories { jcenter() @@ -62,9 +54,9 @@ dependencies { testCompile "org.json:json:20180130" testCompile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}" testCompile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" - testCompile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${rootProject.jacksonVersion}" - testCompile "org.springframework:spring-jdbc:${springFrameworkVersion}" - testCompile "org.springframework:spring-test:${springFrameworkVersion}" + testCompile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}" + compile("org.springframework.boot:spring-boot-starter-jdbc") + compile("org.springframework.boot:spring-boot-starter-test") testCompile "org.slf4j:slf4j-api:${slf4jVersion}" testCompile "junit:junit:${junitVersion}" testCompile "org.hamcrest:hamcrest-all:${hamcrestVersion}" diff --git a/juick-notifications/build.gradle b/juick-notifications/build.gradle index 8cf770a6..099e5e29 100644 --- a/juick-notifications/build.gradle +++ b/juick-notifications/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'java' apply plugin: 'war' -apply plugin: 'org.akhikhl.gretty' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' dependencies { compile project(':juick-server-web') @@ -14,12 +15,6 @@ dependencies { compileJava.options.encoding = 'UTF-8' -gretty { - httpPort = 8080 - contextPath = '' - servletContainer = 'tomcat8' -} - configurations { all*.exclude module: 'commons-logging' } diff --git a/juick-notifications/src/main/java/com/juick/components/MPNSClient.java b/juick-notifications/src/main/java/com/juick/components/MPNSClient.java index 21286258..efa47bb1 100644 --- a/juick-notifications/src/main/java/com/juick/components/MPNSClient.java +++ b/juick-notifications/src/main/java/com/juick/components/MPNSClient.java @@ -34,9 +34,9 @@ public class MPNSClient { @Inject private ObjectMapper jsonMapper; - @Value("${wns_application_sip}") + @Value("${wns_application_sip:}") private String applicationSip; - @Value("${wns_client_secret}") + @Value("${wns_client_secret:}") private String applicationSecret; private RestTemplate wnsService; diff --git a/juick-notifications/src/main/java/com/juick/components/PushServer.java b/juick-notifications/src/main/java/com/juick/components/PushServer.java new file mode 100644 index 00000000..c22f48dc --- /dev/null +++ b/juick-notifications/src/main/java/com/juick/components/PushServer.java @@ -0,0 +1,12 @@ +package com.juick.components; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PushServer { + + public static void main(String[] args) { + SpringApplication.run(PushServer.class, args); + } +} diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/GCMConfiguration.java b/juick-notifications/src/main/java/com/juick/components/configuration/GCMConfiguration.java index 96c7716f..27e1af0f 100644 --- a/juick-notifications/src/main/java/com/juick/components/configuration/GCMConfiguration.java +++ b/juick-notifications/src/main/java/com/juick/components/configuration/GCMConfiguration.java @@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class GCMConfiguration { - @Value("${gcm_key}") + @Value("${gcm_key:}") private String gcmKey; @Bean diff --git a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java b/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java deleted file mode 100644 index d4068d26..00000000 --- a/juick-notifications/src/main/java/com/juick/components/configuration/NotificationsInitializer.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.juick.components.configuration; - -import org.apache.commons.codec.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 NotificationsInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[] {}; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return new Class<?>[]{ NotificationsAppConfiguration.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 "Notifications dispatcher servlet"; - } -} diff --git a/juick-server-core/src/main/resources/schema.sql b/juick-server-core/src/main/resources/juick.sql index 518c89ab..518c89ab 100644 --- a/juick-server-core/src/main/resources/schema.sql +++ b/juick-server-core/src/main/resources/juick.sql diff --git a/juick-server-jdbc/build.gradle b/juick-server-jdbc/build.gradle index 76a37e4b..f17398b6 100644 --- a/juick-server-jdbc/build.gradle +++ b/juick-server-jdbc/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'java' -apply plugin: 'war' +apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 @@ -12,42 +12,43 @@ dependencies { compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${rootProject.jacksonVersion}" - providedCompile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" - providedCompile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" + compile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.apache.commons:commons-lang3:3.7" - providedCompile "org.apache.commons:commons-collections4:4.1" + compile "org.apache.commons:commons-lang3:3.7" + compile "org.apache.commons:commons-collections4:4.1" - compile "org.springframework:spring-context:${rootProject.springFrameworkVersion}" - compile "org.springframework:spring-jdbc:${rootProject.springFrameworkVersion}" + compile("org.springframework.boot:spring-boot-starter-jdbc") - providedCompile "org.apache.commons:commons-dbcp2:2.2.0" + compile "org.apache.commons:commons-dbcp2:2.2.0" compile "com.googlecode.log4jdbc:log4jdbc:1.2" compile "javax.inject:javax.inject:1" compile 'org.imgscalr:imgscalr-lib:4.2' - providedCompile 'com.h2database:h2:1.4.196' - providedCompile "javax.servlet:javax.servlet-api:3.1.0" - providedRuntime 'mysql:mysql-connector-java:5.1.40' + compile 'com.h2database:h2:1.4.196' + runtime 'mysql:mysql-connector-java:5.1.40' - providedRuntime "commons-fileupload:commons-fileupload:1.3.3" + runtime "commons-fileupload:commons-fileupload:1.3.3" testCompile project(path: ':juick-core', configuration: 'testArtifacts') testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}" - testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" + testCompile("org.springframework.boot:spring-boot-starter-test") testRuntime "mysql:mysql-connector-java:5.1.40" testRuntime "org.postgresql:postgresql:42.2.1" } +dependencyManagement { + imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${rootProject.springBootVersion}") } +} compileJava.options.encoding = 'UTF-8' diff --git a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java index 2073c3c0..ee9d0baa 100644 --- a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java +++ b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java @@ -23,8 +23,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; @@ -40,7 +40,6 @@ import java.util.List; */ @Configuration @EnableTransactionManagement -@PropertySource(value = {"classpath:juick.conf"}, ignoreResourceNotFound = true) @ComponentScan(basePackages = {"com.juick.service"}) public class DataConfiguration implements TransactionManagementConfigurer { @Value("${datasource_driver:org.h2.Driver}") @@ -246,18 +245,18 @@ public class DataConfiguration implements TransactionManagementConfigurer { " `cnt` smallint(5) unsigned NOT NULL DEFAULT '0'," + " PRIMARY KEY (`user_id`)" + ")"); - jdbcTemplate.execute("CREATE TABLE `auth` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `auth` (" + " `user_id` int(10) unsigned NOT NULL," + " `protocol` enum('xmpp','email','sms') NOT NULL," + " `account` char(64) NOT NULL," + " `authcode` char(8) NOT NULL" + ")"); - jdbcTemplate.execute("CREATE TABLE `mail` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `mail` (" + " `user_id` int(10) unsigned NOT NULL," + " `hash` char(16) NOT NULL," + " PRIMARY KEY (`user_id`)" + ")"); - jdbcTemplate.execute("CREATE TABLE `usersinfo` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `usersinfo` (" + " `user_id` int(10) unsigned NOT NULL," + " `jid` char(32) DEFAULT NULL," + " `fullname` char(32) DEFAULT NULL," + diff --git a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java index eac98354..4541da94 100644 --- a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java +++ b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java @@ -19,23 +19,13 @@ package com.juick.configuration; import com.juick.service.ImagesService; import com.juick.service.MockImagesService; -import com.juick.service.search.SearchService; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; - -import javax.sql.DataSource; -import java.util.Collections; -import java.util.List; /** * Created by aalexeev on 11/25/16. */ @Configuration -@ComponentScan(basePackages = "com.juick.service") public class RepositoryConfiguration { @Bean public ImagesService imagesService() { diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index d9f095ac..b082bfd1 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -26,18 +26,17 @@ import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.TagStats; import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import javax.inject.Inject; import java.sql.Timestamp; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -50,7 +49,7 @@ import static org.junit.Assert.assertEquals; /** * Created by aalexeev on 11/25/16. */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration(classes = { DataConfiguration.class, RepositoryConfiguration.class }) public class MessageServiceTest extends AbstractJUnit4SpringContextTests { @Inject diff --git a/juick-server-web/build.gradle b/juick-server-web/build.gradle index 9a5e97a9..0cf63313 100644 --- a/juick-server-web/build.gradle +++ b/juick-server-web/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'java' -apply plugin: 'war' +apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 @@ -11,38 +11,41 @@ dependencies { compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${rootProject.jacksonVersion}" - providedCompile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" - providedCompile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" + compile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" compile 'com.github.ben-manes.caffeine:caffeine:2.6.2' - - compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}" - compile "org.springframework:spring-context-support:${rootProject.springFrameworkVersion}" - compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}" - - compile "org.springframework.security:spring-security-web:${rootProject.springSecurityVersion}" - compile "org.springframework.security:spring-security-config:${rootProject.springSecurityVersion}" + compile("org.springframework.boot:spring-boot-starter-cache") + compile("org.springframework.boot:spring-boot-starter-web") + compile("org.springframework.boot:spring-boot-starter-websocket") + compile("org.springframework.boot:spring-boot-starter-security") compile "javax.inject:javax.inject:1" compile 'org.imgscalr:imgscalr-lib:4.2' compile "org.apache.commons:commons-imaging:1.0-SNAPSHOT" - providedCompile "javax.servlet:javax.servlet-api:3.1.0" + runtime "commons-fileupload:commons-fileupload:1.3.3" - providedRuntime "commons-fileupload:commons-fileupload:1.3.3" + compile ('com.github.juick:com.juick.xmpp:658f8cf751') { + exclude group: 'xmlpull' + } + compile 'xpp3:xpp3:1.1.4c' testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}" - testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" - testCompile "org.springframework.security:spring-security-test:${rootProject.springSecurityVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test" + testCompile "org.springframework.security:spring-security-test" +} +dependencyManagement { + imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${rootProject.springBootVersion}") } } compileJava.options.encoding = 'UTF-8' diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index 3ceee3eb..d9b842af 100644 --- a/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/juick-server-web/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -21,8 +21,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.juick.server.xmpp.JidConverter; +import com.juick.server.xmpp.s2s.BasicXmppSession; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.ConversionService; +import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.scheduling.annotation.SchedulingConfigurer; @@ -31,9 +36,13 @@ import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import rocks.xmpp.core.session.Extension; +import rocks.xmpp.core.session.XmppSessionConfiguration; +import rocks.xmpp.core.session.debug.LogbackDebugger; import java.util.List; import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** @@ -81,4 +90,25 @@ public class BaseWebConfiguration implements WebMvcConfigurer, SchedulingConfigu public Executor taskExecutor() { return Executors.newScheduledThreadPool(100); } + @Value("${hostname:localhost}") + private String hostname; + + @Bean + public ExecutorService service() { + return Executors.newCachedThreadPool(); + } + @Bean + public BasicXmppSession session() { + XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() + .extensions(Extension.of(com.juick.Message.class)) + .debugger(LogbackDebugger.class) + .build(); + return BasicXmppSession.create(hostname, configuration); + } + @Bean + public static ConversionService conversionService() { + DefaultFormattingConversionService cs = new DefaultFormattingConversionService(); + cs.addConverter(new JidConverter()); + return cs; + } } diff --git a/juick-server/src/main/java/com/juick/server/xmpp/helpers/JidConverter.java b/juick-server-web/src/main/java/com/juick/server/xmpp/JidConverter.java index ca25c4b8..e9a9707e 100644 --- a/juick-server/src/main/java/com/juick/server/xmpp/helpers/JidConverter.java +++ b/juick-server-web/src/main/java/com/juick/server/xmpp/JidConverter.java @@ -1,4 +1,4 @@ -package com.juick.server.xmpp.helpers; +package com.juick.server.xmpp; import org.springframework.core.convert.converter.Converter; import org.springframework.lang.Nullable; diff --git a/juick-server/src/main/java/com/juick/server/xmpp/extensions/JuickMessage.java b/juick-server-web/src/main/java/com/juick/server/xmpp/extensions/JuickMessage.java index 6956a99a..6956a99a 100644 --- a/juick-server/src/main/java/com/juick/server/xmpp/extensions/JuickMessage.java +++ b/juick-server-web/src/main/java/com/juick/server/xmpp/extensions/JuickMessage.java diff --git a/juick-server/src/main/java/com/juick/server/xmpp/extensions/JuickUser.java b/juick-server-web/src/main/java/com/juick/server/xmpp/extensions/JuickUser.java index 534efcc9..534efcc9 100644 --- a/juick-server/src/main/java/com/juick/server/xmpp/extensions/JuickUser.java +++ b/juick-server-web/src/main/java/com/juick/server/xmpp/extensions/JuickUser.java diff --git a/juick-server/src/main/java/com/juick/server/xmpp/s2s/BasicXmppSession.java b/juick-server-web/src/main/java/com/juick/server/xmpp/s2s/BasicXmppSession.java index 647f2717..647f2717 100644 --- a/juick-server/src/main/java/com/juick/server/xmpp/s2s/BasicXmppSession.java +++ b/juick-server-web/src/main/java/com/juick/server/xmpp/s2s/BasicXmppSession.java diff --git a/juick-server-web/src/main/java/com/juick/service/security/NotAuthorizedAuthenticationEntryPoint.java b/juick-server-web/src/main/java/com/juick/service/security/NotAuthorizedAuthenticationEntryPoint.java index 133ec3e5..b9bdcaa9 100644 --- a/juick-server-web/src/main/java/com/juick/service/security/NotAuthorizedAuthenticationEntryPoint.java +++ b/juick-server-web/src/main/java/com/juick/service/security/NotAuthorizedAuthenticationEntryPoint.java @@ -30,8 +30,7 @@ import java.io.IOException; */ public class NotAuthorizedAuthenticationEntryPoint implements AuthenticationEntryPoint { @Override - public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) - throws IOException, ServletException { + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } } diff --git a/juick-server/build.gradle b/juick-server/build.gradle index 06d28474..bcad2f41 100644 --- a/juick-server/build.gradle +++ b/juick-server/build.gradle @@ -6,11 +6,13 @@ buildscript { apply plugin: 'java' apply plugin: 'war' -apply plugin: 'org.akhikhl.gretty' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' dependencies { compile project(':juick-server-jdbc') compile project(':juick-server-web') + providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") compile 'io.springfox:springfox-swagger2:2.8.0' compile 'io.springfox:springfox-swagger-ui:2.8.0' @@ -20,10 +22,7 @@ dependencies { compile 'org.springframework.social:spring-social-twitter:1.1.2.RELEASE' compile 'org.apache.commons:commons-email:1.5' compile 'org.imgscalr:imgscalr-lib:4.2' - compile ('com.github.juick:com.juick.xmpp:658f8cf751') { - exclude group: 'xmlpull' - } - providedCompile 'xpp3:xpp3:1.1.4c' + compile 'com.rometools:rome:1.9.0' compile 'com.rometools:rome-modules:1.9.0' @@ -31,16 +30,13 @@ dependencies { testCompile project(path: ':juick-server-web', configuration: 'testArtifacts') testCompile project(path: ':juick-server-jdbc', configuration: 'testArtifacts') - testRuntime 'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.5' testRuntime 'com.jayway.jsonpath:json-path:2.4.0' } compileJava.options.encoding = 'UTF-8' -gretty { - httpPort = 8080 - contextPath = '/' - servletContainer = 'tomcat8' +bootJar { + launchScript() } configurations { diff --git a/juick-server/src/main/java/com/juick/server/ApiServer.java b/juick-server/src/main/java/com/juick/server/ApiServer.java new file mode 100644 index 00000000..b2caff40 --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/ApiServer.java @@ -0,0 +1,12 @@ +package com.juick.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ApiServer { + + public static void main(String[] args) { + SpringApplication.run(ApiServer.class, args); + } +} diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index ef0291c0..50c84bd6 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -89,6 +89,8 @@ public class XMPPConnection implements AutoCloseable { private int componentPort; @Value("${xmpp_password:secret}") private String password; + @Value("${xmpp_disabled:false}") + private boolean isXmppDisabled; @Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}") private String tmpDir; @@ -241,14 +243,16 @@ public class XMPPConnection implements AutoCloseable { logger.info("component connected"); } }); - service.submit(() -> { - try { - Thread.sleep(3000); - router.connect(); - } catch (InterruptedException | XmppException e) { - logger.warn("xmpp exception", e); - } - }); + if (!isXmppDisabled) { + service.submit(() -> { + try { + Thread.sleep(3000); + router.connect(); + } catch (InterruptedException | XmppException e) { + logger.warn("xmpp exception", e); + } + }); + } } String stanzaToString(Stanza stanza) throws XMLStreamException, JAXBException { diff --git a/juick-server/src/main/java/com/juick/server/api/Notifications.java b/juick-server/src/main/java/com/juick/server/api/Notifications.java index 5f849080..16601b7f 100644 --- a/juick-server/src/main/java/com/juick/server/api/Notifications.java +++ b/juick-server/src/main/java/com/juick/server/api/Notifications.java @@ -101,7 +101,7 @@ public class Notifications { @ApiIgnore @RequestMapping(value = "/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public Status doDelete( - @RequestBody List<ExternalToken> list) throws IOException { + @RequestBody List<ExternalToken> list) { User visitor = UserUtils.getCurrentUser(); // FIXME: it is possible to delete other user's tokens if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) { diff --git a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java index 146e277c..65a9d410 100644 --- a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java +++ b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java @@ -17,18 +17,15 @@ package com.juick.server.configuration; +import com.juick.configuration.DataConfiguration; import com.juick.server.WebsocketManager; import com.juick.server.api.rss.MessagesView; import com.juick.server.api.rss.RepliesView; import com.juick.server.component.JuickServerComponent; import com.juick.server.component.JuickServerReconnectManager; import com.juick.service.UserService; -import com.juick.server.xmpp.helpers.JidConverter; -import com.juick.server.xmpp.s2s.BasicXmppSession; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.*; -import org.springframework.core.convert.ConversionService; -import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; @@ -43,9 +40,6 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer; import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean; import org.springframework.web.util.UriComponentsBuilder; -import rocks.xmpp.core.session.Extension; -import rocks.xmpp.core.session.XmppSessionConfiguration; -import rocks.xmpp.core.session.debug.LogbackDebugger; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; @@ -56,19 +50,16 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; import javax.annotation.Nonnull; import javax.inject.Inject; import java.util.Collections; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; /** * Created by aalexeev on 11/12/16. */ @Configuration @EnableAsync -@EnableWebMvc @EnableSwagger2 @EnableScheduling @EnableWebSocket -@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true) +@Import({ApiSecurityConfig.class, DataConfiguration.class, StorageConfiguration.class}) @ComponentScan(basePackages = "com.juick.server") public class ApiAppConfiguration extends BaseWebConfiguration implements WebSocketConfigurer { @Inject @@ -132,27 +123,6 @@ public class ApiAppConfiguration extends BaseWebConfiguration implements WebSock container.setMaxBinaryMessageBufferSize(8192); return container; } - @Value("${hostname:localhost}") - private String hostname; - - @Bean - public ExecutorService service() { - return Executors.newCachedThreadPool(); - } - @Bean - public BasicXmppSession session() { - XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() - .extensions(Extension.of(com.juick.Message.class)) - .debugger(LogbackDebugger.class) - .build(); - return BasicXmppSession.create(hostname, configuration); - } - @Bean - public static ConversionService conversionService() { - DefaultFormattingConversionService cs = new DefaultFormattingConversionService(); - cs.addConverter(new JidConverter()); - return cs; - } @Bean public BeanNameViewResolver beanNameViewResolver() { return new BeanNameViewResolver(); diff --git a/juick-server/src/main/java/com/juick/server/configuration/ApiInitializer.java b/juick-server/src/main/java/com/juick/server/configuration/ApiInitializer.java deleted file mode 100644 index b789fc50..00000000 --- a/juick-server/src/main/java/com/juick/server/configuration/ApiInitializer.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.server.configuration; - -import com.juick.configuration.DataConfiguration; -import org.apache.commons.codec.CharEncoding; -import org.springframework.web.filter.CharacterEncodingFilter; -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -import javax.annotation.Nonnull; -import javax.servlet.Filter; - -/** - * Created by vt on 09/02/16. - */ -public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ - ApiAppConfiguration.class, - ApiSecurityConfig.class, - DataConfiguration.class, - StorageConfiguration.class - }; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return null; - } - - @Override - @Nonnull - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - @Override - protected Filter[] getServletFilters() { - return new Filter[]{new CharacterEncodingFilter(CharEncoding.UTF_8)}; - } - - @Override - @Nonnull - protected String getServletName() { - return "API dispatcher servlet"; - } -} diff --git a/juick-server/src/main/java/com/juick/server/configuration/ApiSecurityInitializer.java b/juick-server/src/main/java/com/juick/server/configuration/ApiSecurityInitializer.java deleted file mode 100644 index ece023fc..00000000 --- a/juick-server/src/main/java/com/juick/server/configuration/ApiSecurityInitializer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.server.configuration; - -/** - * - * Created by vitalyster on 25.11.2016. - * - - */ - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; - -import javax.servlet.ServletContext; - -public class ApiSecurityInitializer extends AbstractSecurityWebApplicationInitializer { - private final Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - protected void afterSpringSecurityFilterChain(ServletContext servletContext) { - logger.info("SpringSecurityFilterChain initialized"); - } -}
\ No newline at end of file diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index ecb06d45..cd1af5a4 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -24,8 +24,6 @@ import com.juick.ExternalToken; import com.juick.Message; import com.juick.Tag; import com.juick.User; -import com.juick.configuration.DataConfiguration; -import com.juick.configuration.RepositoryConfiguration; import com.juick.server.EmailManager; import com.juick.server.XMPPBot; import com.juick.server.XMPPServer; @@ -33,18 +31,21 @@ import com.juick.server.configuration.ApiAppConfiguration; import com.juick.server.configuration.ApiSecurityConfig; import com.juick.server.helpers.TagStats; import com.juick.service.*; +import com.juick.service.security.NotAuthorizedAuthenticationEntryPoint; import com.juick.util.DateFormattersHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -75,16 +76,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * Created by vitalyster on 25.11.2016. */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, DataConfiguration.class, RepositoryConfiguration.class}) -@TestPropertySource(properties = {"broken_ssl_hosts=localhost,serverstorageisfull.tld"}) -@WebAppConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@TestPropertySource(properties = {"broken_ssl_hosts=localhost,serverstorageisfull.tld", "xmpp_disabled=true"}) +@AutoConfigureMockMvc public class ServerTests extends AbstractJUnit4SpringContextTests { - private MockMvc mockMvc; @Inject - private WebApplicationContext webApplicationContext; - + private MockMvc mockMvc; @Inject private MessagesService messagesService; @Inject @@ -118,13 +117,9 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { @Before public void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) - .apply(SecurityMockMvcConfigurers.springSecurity()) - .dispatchOptions(true) - .build(); if (!isSetUp) { ugnichName = "ugnich"; - ugnichPassword = "MyPassw0rd!"; + ugnichPassword = "secret"; freefdName = "freefd"; freefdPassword = "MyPassw0rd!"; juickName = "juick"; @@ -148,21 +143,20 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { @Test public void testAllUnAuthorized() throws Exception { - mockMvc.perform(get("/")) .andExpect(status().isMovedPermanently()); mockMvc.perform(get("/auth")) - .andExpect(status().is4xxClientError()); + .andExpect(status().isUnauthorized()); mockMvc.perform(get("/home")) - .andExpect(status().is4xxClientError()); + .andExpect(status().isUnauthorized()); mockMvc.perform(get("/messages/recommended")) - .andExpect(status().is4xxClientError()); + .andExpect(status().isUnauthorized()); mockMvc.perform(get("/messages/set_privacy")) - .andExpect(status().is4xxClientError()); + .andExpect(status().isUnauthorized()); } @Test @@ -356,7 +350,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { } @Test public void statusPageIsUp() throws Exception { - mockMvc.perform(get("http://localhost:8080/status").with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().isOk()); + mockMvc.perform(get("/api/status").with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().isOk()); assertThat(server.getJid(), equalTo(jid)); } @Test diff --git a/juick-www/build.gradle b/juick-www/build.gradle index e7a9dfca..defc6558 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -20,7 +20,8 @@ task compileFrontend(type: YarnTask) { apply plugin: 'java' apply plugin: 'war' -apply plugin: 'org.akhikhl.gretty' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' dependencies { compile project(':juick-server-web') @@ -42,10 +43,8 @@ compileFrontend.dependsOn 'yarn' processResources.dependsOn 'compileFrontend' compileJava.options.encoding = 'UTF-8' -gretty { - httpPort = 8080 - contextPath = '/' - servletContainer = 'tomcat8' +bootJar { + launchScript() } configurations { diff --git a/juick-www/src/main/java/com/juick/www/Application.java b/juick-www/src/main/java/com/juick/www/Application.java new file mode 100644 index 00000000..0e60e1d8 --- /dev/null +++ b/juick-www/src/main/java/com/juick/www/Application.java @@ -0,0 +1,12 @@ +package com.juick.www; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java index e04538e8..250197f7 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java @@ -17,6 +17,10 @@ package com.juick.www.configuration; +import com.juick.configuration.DataConfiguration; +import com.juick.configuration.SearchConfiguration; +import com.juick.server.configuration.BaseWebConfiguration; +import com.juick.server.configuration.StorageConfiguration; import com.juick.service.CloudflareCache; import com.juick.service.TagService; import com.juick.service.UserService; @@ -29,7 +33,7 @@ import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.Import; import javax.inject.Inject; import java.util.Collections; @@ -38,9 +42,10 @@ import java.util.Collections; * Created by aalexeev on 11/22/16. */ @Configuration -@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true) @EnableCaching -public class WwwAppConfiguration { +@Import({WwwServletConfiguration.class, WebSecurityConfig.class, SapeConfiguration.class, SearchConfiguration.class, + DataConfiguration.class, StorageConfiguration.class}) +public class WwwAppConfiguration extends BaseWebConfiguration { @Inject private UserService userService; @Inject diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java deleted file mode 100644 index 26beaee4..00000000 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.www.configuration; - -import com.juick.configuration.DataConfiguration; -import com.juick.configuration.SearchConfiguration; -import com.juick.server.configuration.StorageConfiguration; -import org.apache.commons.codec.CharEncoding; -import org.springframework.web.filter.CharacterEncodingFilter; -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -import javax.servlet.FilterRegistration; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -/** - * Created by aalexeev on 11/20/16. - */ -public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ - WwwServletConfiguration.class, - WwwAppConfiguration.class, - SearchConfiguration.class, - SapeConfiguration.class, - WebSecurityConfig.class, - DataConfiguration.class, - StorageConfiguration.class - }; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return null; - } - - @Override - protected String[] getServletMappings() { - return new String[]{"/"}; - } - - @Override - protected String getServletName() { - return "WWW-spring dispatcher servlet"; - } - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - super.onStartup(servletContext); - - FilterRegistration.Dynamic registration = servletContext.addFilter( - "encodingFilter", new CharacterEncodingFilter(CharEncoding.UTF_8, true)); - - registration.addMappingForUrlPatterns(null, true, "/*"); - } -} - diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java deleted file mode 100644 index a977268f..00000000 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwSecurityInitializer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.www.configuration; - -/** - * Created by vitalyster on 25.11.2016. - */ - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; - -import javax.servlet.ServletContext; - -public class WwwSecurityInitializer extends AbstractSecurityWebApplicationInitializer { - private final Logger logger = LoggerFactory.getLogger(getClass()); - - @Override - protected void afterSpringSecurityFilterChain(ServletContext servletContext) { - logger.info("SpringSecurityFilterChain initialized"); - } -} diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 1654f2ac..a8dbad8b 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -22,14 +22,12 @@ import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.extension.FormatterExtension; import com.mitchellbosecke.pebble.loader.ClasspathLoader; import com.mitchellbosecke.pebble.loader.Loader; -import com.mitchellbosecke.pebble.loader.ServletLoader; import com.mitchellbosecke.pebble.spring4.PebbleViewResolver; import com.mitchellbosecke.pebble.spring4.extension.SpringExtension; import org.apache.commons.codec.CharEncoding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.core.Ordered; import org.springframework.http.CacheControl; import org.springframework.web.servlet.ViewResolver; diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 726a4612..73cec17a 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -44,14 +44,18 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -77,16 +81,17 @@ import java.util.stream.StreamSupport; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** * Created by vitalyster on 12.01.2017. */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@TestPropertySource(properties = {"xmpp_disabled=true"}) + @ContextConfiguration(classes = { DataConfiguration.class, WwwServletConfiguration.class, WwwAppConfiguration.class, SapeConfiguration.class, @@ -94,7 +99,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. }) public class WebAppTests { @Configuration - @ComponentScan(basePackages = "com.juick.www.controllers") static class Config { @Bean public ImagesService imagesService() { @@ -103,12 +107,12 @@ public class WebAppTests { } @Inject - private WebApplicationContext wac; - @Inject private WebApp webApp; - private static MockMvc mockMvc; - private static WebClient webClient; + @Inject + private MockMvc mockMvc; + @Inject + private WebClient webClient; @Inject private UserService userService; @@ -134,21 +138,17 @@ public class WebAppTests { @Before public void setup() throws IOException { if (!isSetUp) { - mockMvc = MockMvcBuilders.webAppContextSetup(wac) - .apply(springSecurity()) - .build(); - webClient = MockMvcWebClientBuilder.mockMvcSetup(mockMvc).build(); webClient.getOptions().setJavaScriptEnabled(false); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); ugnichName = "ugnich"; - ugnichPassword = "MyPassw0rd!"; + ugnichPassword = "secret"; freefdName = "freefd"; freefdPassword = "MyPassw0rd!"; - int ugnichId = userService.createUser(ugnichName, ugnichPassword); - ugnich = userService.getUserByUID(ugnichId).orElseThrow(IllegalStateException::new); + userService.createUser(ugnichName, ugnichPassword); + ugnich = userService.getUserByName(ugnichName); int freefdId = userService.createUser(freefdName, freefdPassword); freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); diff --git a/juick-xmpp-wip/build.gradle b/juick-xmpp-wip/build.gradle index cc69ed34..ad49cf16 100644 --- a/juick-xmpp-wip/build.gradle +++ b/juick-xmpp-wip/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'java' apply plugin: 'war' -apply plugin: 'org.akhikhl.gretty' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' dependencies { compile project(':juick-server-jdbc') compile project(':juick-server-web') - compile project(':juick-server') testCompile project(path: ':juick-core', configuration: 'testArtifacts') testCompile project(path: ':juick-server', configuration: 'testArtifacts') @@ -15,12 +15,6 @@ dependencies { compileJava.options.encoding = 'UTF-8' -gretty { - httpPort = 8080 - contextPath = '/router' - servletContainer = 'tomcat8' -} - configurations { all*.exclude module: 'commons-logging' } diff --git a/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java b/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java index 2e051d32..27206a32 100644 --- a/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java +++ b/juick-xmpp-wip/src/main/java/com/juick/components/XMPPBot.java @@ -25,6 +25,8 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.env.Environment; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; @@ -41,6 +43,7 @@ import java.net.URL; /** * Created by vt on 12/11/2016. */ +@SpringBootApplication public class XMPPBot implements AutoCloseable { private static final Logger logger = LoggerFactory.getLogger(XMPPBot.class); @Inject @@ -104,4 +107,7 @@ public class XMPPBot implements AutoCloseable { logger.info("ExternalComponent on xmpp-bot destroyed"); } + public static void main(String[] args) { + SpringApplication.run(XMPPBot.class, args); + } } diff --git a/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotAppConfiguration.java b/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotAppConfiguration.java index 9825751b..7806347d 100644 --- a/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotAppConfiguration.java +++ b/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotAppConfiguration.java @@ -20,23 +20,16 @@ package com.juick.components.configuration; import com.juick.components.XMPPBot; import com.juick.server.configuration.BaseWebConfiguration; import com.juick.server.protocol.JuickProtocol; -import org.springframework.context.annotation.*; -import org.springframework.core.env.Environment; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; - -import javax.inject.Inject; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; /** * Created by aalexeev on 11/12/16. */ @Configuration @ComponentScan(basePackages = {"com.juick.components"}) -@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true) -@Import(BaseWebConfiguration.class) -public class BotAppConfiguration extends WebMvcConfigurationSupport { - @Inject - private Environment env; - +public class BotAppConfiguration extends BaseWebConfiguration { @Bean public XMPPBot xmpp() { return new XMPPBot(); diff --git a/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotInitializer.java b/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotInitializer.java deleted file mode 100644 index 8b8c3623..00000000 --- a/juick-xmpp-wip/src/main/java/com/juick/components/configuration/BotInitializer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.components.configuration; - -import org.apache.commons.codec.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 BotInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - - @Override - protected Class<?>[] getRootConfigClasses() { - return new Class<?>[]{ }; - } - - @Override - protected Class<?>[] getServletConfigClasses() { - return new Class<?>[]{ BotAppConfiguration.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 "Bot dispatcher servlet"; - } -} diff --git a/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java b/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java index 1193f3a2..2cad5fb4 100644 --- a/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java +++ b/juick-xmpp-wip/src/test/java/com/juick/xmpp/XMPPTests.java @@ -21,8 +21,6 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.juick.components.XMPPRouter; import com.juick.components.configuration.BotAppConfiguration; import com.juick.configuration.MockDataConfiguration; -import com.juick.server.XMPPConnection; -import com.juick.server.configuration.ApiAppConfiguration; import com.juick.service.MessengerService; import com.juick.service.PrivacyQueriesService; import com.juick.service.ShowQueriesService; @@ -60,7 +58,7 @@ import static org.hamcrest.Matchers.equalTo; public class XMPPTests { @Configuration @Import(value = { - BotAppConfiguration.class, ApiAppConfiguration.class, MockDataConfiguration.class + BotAppConfiguration.class, MockDataConfiguration.class }) static class Config { @Bean @@ -91,11 +89,9 @@ public class XMPPTests { @Inject XMPPRouter router; @Inject - XMPPConnection component; - @Inject ExecutorService service; @Test - public void routerHandshake() throws XmppException, InterruptedException { + public void routerHandshake() throws InterruptedException { XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() .extensions(Extension.of(com.juick.Message.class)) .debugger(LogbackDebugger.class) @@ -108,23 +104,33 @@ public class XMPPTests { lock.countDown(); } }); + ExternalComponent routerClient2 = ExternalComponent.create("bot.localhost", + "secret", configuration, "localhost", 5347); + CountDownLatch lock2 = new CountDownLatch(1); + routerClient2.addConnectionListener(connectionEvent -> { + if (connectionEvent.equals(ConnectionEvent.Type.RECONNECTION_SUCCEEDED)) { + lock2.countDown(); + } + }); service.submit(() -> { try { Thread.sleep(3000); routerClient.connect(); + routerClient2.connect(); } catch (XmppException | InterruptedException e) { e.printStackTrace(); } lock.countDown(); + lock2.countDown(); }); lock.await(); - CountDownLatch lock2 = new CountDownLatch(2); - component.sendStanza(new Message(Jid.of("yoyo@test.localhost"), Message.Type.CHAT, "test" )); - component.sendStanza(new Message(Jid.of("yoyo@test.localhost"), Message.Type.CHAT, "test" )); + CountDownLatch lock3 = new CountDownLatch(2); + routerClient2.sendMessage(new Message(Jid.of("yoyo@test.localhost"), Message.Type.CHAT, "test" )); + routerClient2.sendMessage(new Message(Jid.of("yoyo@test.localhost"), Message.Type.CHAT, "test" )); routerClient.addInboundMessageListener(messageEvent -> { assertThat(messageEvent.getMessage().getBody(), equalTo("test")); - lock2.countDown(); + lock3.countDown(); }); - lock2.await(); + lock3.await(); } } |