TSK-754 Use custom spring boot mvn initializer
This commit is contained in:
parent
3be2a01553
commit
53451cd61b
|
@ -0,0 +1,55 @@
|
||||||
|
package pro.taskana.rest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
|
||||||
|
"classpath:/META-INF/resources/", "classpath:/resources/",
|
||||||
|
"classpath:/static/", "classpath:/public/"};
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations(
|
||||||
|
"classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
|
if (!registry.hasMappingForPattern("/**")) {
|
||||||
|
registry.addResourceHandler("/**").addResourceLocations(
|
||||||
|
CLASSPATH_RESOURCE_LOCATIONS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
for (HttpMessageConverter<?> converter : converters) {
|
||||||
|
if (converter instanceof MappingJackson2HttpMessageConverter) {
|
||||||
|
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
|
||||||
|
jacksonConverter.setPrettyPrint(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void enableObjectIndent() {
|
||||||
|
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@Controller
|
@Controller
|
||||||
public class ViewController {
|
public class ViewController {
|
||||||
|
|
||||||
@RequestMapping({"/administration*/**", "/workplace*/**", "/monitor*/**", "/no-role*/**"})
|
@RequestMapping({"", "/administration*/**", "/workplace*/**", "/monitor*/**", "/no-role*/**"})
|
||||||
public String index() {
|
public String index() {
|
||||||
return "forward:/index.html";
|
return "forward:/index.html";
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
.anyRequest().fullyAuthenticated()
|
.anyRequest().fullyAuthenticated()
|
||||||
.and()
|
.and()
|
||||||
.formLogin().loginPage("/login").failureUrl("/login?error")
|
.formLogin().loginPage("/login").failureUrl("/login?error")
|
||||||
|
.defaultSuccessUrl("/")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
.and()
|
||||||
.logout()
|
.logout()
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 755 B |
|
@ -1,6 +1,9 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
|
<link rel="icon"
|
||||||
|
type="image/x-icon"
|
||||||
|
th:href="@{/img/favicon.png}">
|
||||||
<title>Taskana login</title>
|
<title>Taskana login</title>
|
||||||
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap/4.1.3/bootstrap.min.css}"/>
|
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap/4.1.3/bootstrap.min.css}"/>
|
||||||
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}"/>
|
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}"/>
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import pro.taskana.exceptions.SystemException;
|
import pro.taskana.exceptions.SystemException;
|
||||||
|
@ -299,6 +300,7 @@ public class TaskControllerIntTest {
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
|
con.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
|
||||||
assertEquals(200, con.getResponseCode());
|
assertEquals(200, con.getResponseCode());
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(
|
BufferedReader in = new BufferedReader(
|
||||||
new InputStreamReader(con.getInputStream()));
|
new InputStreamReader(con.getInputStream()));
|
||||||
|
@ -310,11 +312,11 @@ public class TaskControllerIntTest {
|
||||||
in.close();
|
in.close();
|
||||||
con.disconnect();
|
con.disconnect();
|
||||||
String response = content.toString();
|
String response = content.toString();
|
||||||
|
JsonNode jsonNode = objectMapper.readTree(response);
|
||||||
|
String created = jsonNode.get("created").asText();
|
||||||
assertFalse(response.contains("\"attachments\":[]"));
|
assertFalse(response.contains("\"attachments\":[]"));
|
||||||
int start = response.indexOf("created", response.indexOf("created") + 1);
|
|
||||||
String createdString = response.substring(start + 10, start + 30);
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
createdString.matches("\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z)"));
|
created.matches("\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d([+-][0-2]\\d:[0-5]\\d|Z)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@ -12,11 +11,8 @@ import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
import org.springframework.http.converter.json.SpringHandlerInstantiator;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
|
||||||
|
|
||||||
|
@ -35,7 +31,7 @@ import pro.taskana.ldap.LdapClient;
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class RestConfiguration extends WebMvcConfigurationSupport {
|
public class RestConfiguration{
|
||||||
|
|
||||||
@Value("${taskana.schemaName:TASKANA}")
|
@Value("${taskana.schemaName:TASKANA}")
|
||||||
private String schemaName;
|
private String schemaName;
|
||||||
|
@ -83,13 +79,4 @@ public class RestConfiguration extends WebMvcConfigurationSupport {
|
||||||
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
|
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
||||||
for (HttpMessageConverter<?> converter : converters) {
|
|
||||||
if (converter instanceof MappingJackson2HttpMessageConverter) {
|
|
||||||
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
|
|
||||||
jacksonConverter.setPrettyPrint(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue