Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to spring5 and spring boot2, implement #467 #473

Merged
merged 5 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 47 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import java.time.format.DateTimeFormatter
import java.util.regex.Pattern

buildscript {

dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE'
classpath 'ru.yandex.qatools.embed:postgresql-embedded:+'
}

repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}

Expand All @@ -23,13 +27,16 @@ plugins {
id 'idea'
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.8.2'
id 'com.github.ben-manes.versions' version '0.17.0'
id 'com.github.ben-manes.versions' version '0.20.0'
id 'com.github.hierynomus.license' version '0.14.0'
id 'net.researchgate.release' version '2.6.0'
id 'org.springframework.boot' version '2.0.3.RELEASE'
}

apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


task wrapper(type: Wrapper) {
gradleVersion = '3.5'
Expand Down Expand Up @@ -128,9 +135,12 @@ dependencies {
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
compile "org.springframework.boot:spring-boot-properties-migrator", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.security:spring-security-web:$springSecurityConfigVersion"
compile "org.springframework.security:spring-security-config:$springSecurityConfigVersion"
compile 'org.springframework.session:spring-session:1.3.2.RELEASE'
compile 'org.springframework.session:spring-session:1.3.3.RELEASE'
compile "ch.digitalfondue.npjt-extra:npjt-extra:1.1.4"
compile "com.samskivert:jmustache:1.14"
compile "com.github.sps.mustache:mustache-spring-view:1.4"
Expand All @@ -141,30 +151,30 @@ dependencies {
}
compile 'com.moodysalem:LatLongToTimezoneMaven:1.2'
/**/
compile "com.openhtmltopdf:openhtmltopdf-core:0.0.1-RC12"
compile "com.openhtmltopdf:openhtmltopdf-pdfbox:0.0.1-RC12"
compile "com.openhtmltopdf:openhtmltopdf-jsoup-dom-converter:0.0.1-RC12"
compile "com.openhtmltopdf:openhtmltopdf-core:0.0.1-RC13"
compile "com.openhtmltopdf:openhtmltopdf-pdfbox:0.0.1-RC13"
compile "com.openhtmltopdf:openhtmltopdf-jsoup-dom-converter:0.0.1-RC13"
/**/
compile "com.google.zxing:core:3.3.2"
compile "com.google.zxing:javase:3.3.2"
compile "com.google.zxing:core:3.3.3"
compile "com.google.zxing:javase:3.3.3"
compile "org.flywaydb:flyway-core:4.2.0"
compile "org.postgresql:postgresql:42.1.4"
compile "org.postgresql:postgresql:42.2.2"
compile "com.zaxxer:HikariCP:2.7.7"
compile "org.apache.logging.log4j:log4j-api:$log4jVersion"
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
compile "org.apache.logging.log4j:log4j-jcl:$log4jVersion"
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
compile "com.stripe:stripe-java:5.35.1"
compile "com.stripe:stripe-java:5.42.0"
compile 'com.paypal.sdk:rest-api-sdk:1.14.0'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.squareup.okhttp3:okhttp:3.10.0'
compile "org.apache.commons:commons-lang3:3.7"
compile "org.apache.commons:commons-text:1.2"
compile "com.opencsv:opencsv:4.1"
compile "com.opencsv:opencsv:4.2"
compile 'commons-codec:commons-codec:1.11'
compile 'net.sf.biweekly:biweekly:0.6.1'
compile 'com.atlassian.commonmark:commonmark:0.11.0'
compile 'com.ryantenney.passkit4j:passkit4j:2.0.1'
compile 'com.github.ben-manes.caffeine:caffeine:2.6.1'
compile 'com.github.ben-manes.caffeine:caffeine:2.6.2'
compile 'de.danielbechler:java-object-diff:0.95'
compile 'com.github.scribejava:scribejava-core:5.0.0'
compile 'ch.digitalfondue.vatchecker:vatchecker:1.1'
Expand All @@ -178,22 +188,39 @@ dependencies {

compileOnly "javax.servlet:javax.servlet-api:3.1.0"
testCompile "javax.servlet:javax.servlet-api:3.1.0"
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.springframework.boot:spring-boot-starter-test", {
exclude module : 'spring-boot-starter-logging'
}
testCompile "net.sourceforge.htmlunit:htmlunit:2.29"
runtime "commons-fileupload:commons-fileupload:1.3.3"
providedCompile "org.springframework.boot:spring-boot-starter-web@jar"
providedCompile "org.springframework.boot:spring-boot-starter@jar"
providedCompile "org.springframework.boot:spring-boot@jar"
providedCompile "org.springframework.boot:spring-boot-autoconfigure@jar"
providedCompile "org.springframework.boot:spring-boot-starter-web", {
exclude module : 'spring-boot-starter-logging'
exclude group: "org.springframework.boot", module: 'spring-boot-starter-tomcat'
}
providedCompile "org.springframework.boot:spring-boot-starter", {
exclude module : 'spring-boot-starter-logging'
}
providedCompile "org.springframework.boot:spring-boot@jar", {
exclude module : 'spring-boot-starter-logging'
}
providedCompile "org.springframework.boot:spring-boot-autoconfigure@jar", {
exclude module : 'spring-boot-starter-logging'
}
compile "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
}


providedCompile "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
providedRuntime "org.springframework.boot:spring-boot-starter-jetty", {
exclude group: "org.eclipse.jetty.websocket", module: "websocket-server"
exclude group: "org.eclipse.jetty.websocket", module:"javax-websocket-server-impl"
exclude module : 'spring-boot-starter-logging'
}
}

Expand Down Expand Up @@ -264,8 +291,8 @@ bootRun {
jvmArgs = opts
}

bootRepackage {
mainClass = 'alfio.config.SpringBootLauncher'
bootWar {
mainClassName = 'alfio.config.SpringBootLauncher'
classifier = 'boot'
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version=1.15-SNAPSHOT
sourceCompatibility=1.8
targetCompatibility=1.8

springVersion=4.3.13.RELEASE
springSecurityConfigVersion=4.2.3.RELEASE
log4jVersion=2.10.0
jacksonVersion=2.8.4
springVersion=5.0.7.RELEASE
springSecurityConfigVersion=5.0.6.RELEASE
log4jVersion=2.11.0
jacksonVersion=2.9.6
1 change: 1 addition & 0 deletions src/main/java/alfio/config/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Initializer extends AbstractAnnotationConfigDispatcherServletInitia
public static final String PROFILE_DEMO = "demo";
public static final String PROFILE_DISABLE_JOBS = "disable-jobs";
public static final String PROFILE_JDBC_SESSION = "jdbc-session";
public static final String PROFILE_USE_WORKER_NAME = "use-worker-name";
private Environment environment;

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/config/MvcConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@Configuration
@ComponentScan(basePackages = {"alfio.controller", "alfio.config"})
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter {
public class MvcConfiguration implements WebMvcConfigurer {

private final MessageSource messageSource;
private final JMustacheTemplateLoader templateLoader;
Expand Down
95 changes: 44 additions & 51 deletions src/main/java/alfio/config/SpringBootInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,57 @@

import com.openhtmltopdf.util.XRLog;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.Filter;
import javax.servlet.SessionCookieConfig;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.Objects;
import java.util.logging.Level;

import static org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext;

@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration.class,
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class,
org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.class,
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration.class})
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration.class,
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration.class,
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration.class})
@Configuration
@Profile(Initializer.PROFILE_SPRING_BOOT)
@Log4j2
public class SpringBootInitializer {

private static final ServletContextInitializer SERVLET_CONTEXT_INITIALIZER = servletContext -> {
WebApplicationContext ctx = getRequiredWebApplicationContext(servletContext);
ConfigurableEnvironment environment = ctx.getBean(ConfigurableEnvironment.class);
environment.addActiveProfile("spring-boot");
if(environment.acceptsProfiles(Initializer.PROFILE_DEV)) {
environment.addActiveProfile(Initializer.PROFILE_HTTP);
}
SessionCookieConfig config = servletContext.getSessionCookieConfig();
config.setHttpOnly(true);
config.setSecure(!environment.acceptsProfiles(Initializer.PROFILE_HTTP));
//force log initialization, then disable it
XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
XRLog.setLoggingEnabled(false);
};

@Bean
public ServletContextInitializer servletContextInitializer() {
return servletContext -> {
WebApplicationContext ctx = getRequiredWebApplicationContext(servletContext);
ConfigurableEnvironment environment = ctx.getBean(ConfigurableEnvironment.class);
if(environment.acceptsProfiles(Initializer.PROFILE_DEV)) {
environment.addActiveProfile(Initializer.PROFILE_HTTP);
}
SessionCookieConfig config = servletContext.getSessionCookieConfig();
config.setHttpOnly(true);
config.setSecure(!environment.acceptsProfiles(Initializer.PROFILE_HTTP));
//force log initialization, then disable it
XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING);
XRLog.setLoggingEnabled(false);
};
}

@Bean
public Filter characterEncodingFilter() {
Expand All @@ -78,32 +79,24 @@ public Filter characterEncodingFilter() {
}

@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(Environment environment) {
return (container) -> {
container.addInitializers(SERVLET_CONTEXT_INITIALIZER);
//container.setRegisterJspServlet(false);
Map<String, String> mimeMappings = new HashMap<>();
mimeMappings.put("eot", "application/vnd.ms-fontobject");
mimeMappings.put("otf", "font/opentype");
mimeMappings.put("ttf", "application/x-font-ttf");
mimeMappings.put("woff", "application/x-font-woff");
mimeMappings.put("svg", "image/svg+xml");
container.setSessionTimeout(2, TimeUnit.HOURS);
container.setMimeMappings(new MimeMappings(mimeMappings));
if(!environment.acceptsProfiles("dev")) {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404-not-found"), new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500-internal-server-error"), new ErrorPage("/session-expired"));
}

Optional.ofNullable(System.getProperty("alfio.worker.name")).ifPresent(workerName -> {
((JettyEmbeddedServletContainerFactory)container).addServerCustomizers(server -> {
log.info("Configuring session manager using worker name {}", workerName);
DefaultSessionIdManager sessionIdManager = new DefaultSessionIdManager(server);
sessionIdManager.setWorkerName(workerName);
server.setSessionIdManager(sessionIdManager);
});
});

@Profile(Initializer.PROFILE_USE_WORKER_NAME)
public ConfigurableServletWebServerFactory jettyCustomizer() {
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.addServerCustomizers(server -> {
String workerName = Objects.requireNonNull(StringUtils.trimToNull(System.getProperty("alfio.worker.name")), "Invalid value for 'alfio.worker.name'.");
log.info("Configuring session manager using worker name {}", workerName);
DefaultSessionIdManager sessionIdManager = new DefaultSessionIdManager(server);
sessionIdManager.setWorkerName(workerName);
server.setSessionIdManager(sessionIdManager);
});
return factory;
}

};
@Bean
@Profile("!"+Initializer.PROFILE_DEV)
public ErrorPageRegistrar errorPages() {
return registry -> registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404-not-found"),
new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500-internal-server-error"),
new ErrorPage("/session-expired"));
}
}
10 changes: 3 additions & 7 deletions src/main/java/alfio/controller/TicketController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import alfio.util.LocaleUtil;
import alfio.util.TemplateManager;
import com.google.zxing.WriterException;
import com.openhtmltopdf.pdfboxout.PdfBoxRenderer;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -197,10 +196,7 @@ public void generateTicketPdf(@PathVariable("eventName") String eventName,
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=ticket-" + ticketIdentifier + ".pdf");
try (OutputStream os = response.getOutputStream()) {
PdfBoxRenderer renderer = preparePdfTicket(request, data.getLeft(), data.getMiddle(), ticket).generate(ticket);
if(renderer != null) {
renderer.createPDF(os);
}
preparePdfTicket(request, data.getLeft(), data.getMiddle(), ticket, os).generate(ticket);
}
}

Expand Down Expand Up @@ -234,12 +230,12 @@ public String cancelTicket(@PathVariable("eventName") String eventName,
return "redirect:/event/" + eventName;
}

private PartialTicketPDFGenerator preparePdfTicket(HttpServletRequest request, Event event, TicketReservation ticketReservation, Ticket ticket) throws WriterException, IOException {
private PartialTicketPDFGenerator preparePdfTicket(HttpServletRequest request, Event event, TicketReservation ticketReservation, Ticket ticket, OutputStream os) {
TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId());
Organization organization = organizationRepository.getById(event.getOrganizationId());
String reservationID = ticketReservationManager.getShortReservationID(event, ticketReservation.getId());
return TemplateProcessor.buildPartialPDFTicket(LocaleUtil.getTicketLanguage(ticket, request), event, ticketReservation,
ticketCategory, organization, templateManager, fileUploadManager, reservationID);
ticketCategory, organization, templateManager, fileUploadManager, reservationID, os);
}

private String internalShowTicket(String eventName, String ticketIdentifier, boolean ticketEmailSent, Model model, String backSuffix, Locale locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void previewTemplate(@PathVariable("name") TemplateResource name, @PathVa
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename="+name.name()+".pdf");
try (OutputStream os = response.getOutputStream()) {
TemplateProcessor.prepareItextRenderer(renderedTemplate).createPDF(os);
TemplateProcessor.renderToPdf(renderedTemplate, os);
}
} else {
throw new IllegalStateException("cannot enter here!");
Expand Down