Skip to content

Commit 49efce2

Browse files
tsuoanttilahesara
authored andcommitted
Use Vaadin 8, fix static resource fetching (#166)
* Switch version to 2.0-SNAPSHOT, use vaadin 8.0-SNAPSHOT * Fix for new static resource handling in Vaadin 8 * Upgrade all spring dependencies to latest versions; Web tests for static resources handling. * Update Travis configuration Fixes vaadin/framework8-issues#445 Addresses vaadin/framework8-issues#454
1 parent 47e2ac2 commit 49efce2

File tree

10 files changed

+360
-27
lines changed

10 files changed

+360
-27
lines changed

.travis.before_install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
# Disable all Travis default repositories
4+
sed -i "s/activeByDefault>true</activeByDefault>false</g" ~/.m2/settings.xml

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: java
2-
jdk: oraclejdk7
2+
jdk: oraclejdk8
33
sudo: required
44
dist: trusty
5+
before_install: "./.travis.before_install.sh"
56
branches:
67
only:
78
- master

checkstyle/vaadin-checkstyle.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
• LineLenght (the default value is 80 which is also used in formatter, but
2828
i.e. member declarations are not wrapped onto next line)
2929
• RedundantModifier (i.e. using public in interface method declarations)
30-
• RedundantThrows (causes unnecessary fails when can't get class information)
3130
• MethodLength (default maxLength is 150)
3231
• ParameterNumber (default maxLength is 7)
3332
• EmptyBlock (if-else statements have some blocks if x -> no action)
@@ -216,9 +215,6 @@
216215
<property name="severity" value="ignore" />
217216
</module>
218217
<module name="MissingSwitchDefault" />
219-
<module name="RedundantThrows">
220-
<property name="severity" value="warning" />
221-
</module>
222218
<module name="SimplifyBooleanExpression" />
223219
<module name="SimplifyBooleanReturn" />
224220

pom.xml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

66
<parent>
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.vaadin</groupId>
1313
<artifactId>vaadin-spring-parent</artifactId>
14-
<version>1.1-SNAPSHOT</version>
14+
<version>2.0-SNAPSHOT</version>
1515
<packaging>pom</packaging>
1616

1717
<name>vaadin-spring-parent</name>
@@ -78,14 +78,14 @@
7878
<email>[email protected]</email>
7979
</developer>
8080
</developers>
81-
81+
8282
<properties>
83-
<project.build.encoding>UTF-8</project.build.encoding>
84-
<project.build.target>1.6</project.build.target>
85-
<project.build.source>1.6</project.build.source>
86-
83+
<encoding>UTF-8</encoding>
84+
<maven.compiler.source>1.8</maven.compiler.source>
85+
<maven.compiler.target>1.8</maven.compiler.target>
86+
8787
<!-- These are typically overridden with BOMs -->
88-
<vaadin.version>7.7.3</vaadin.version>
88+
<vaadin.version>8.0-SNAPSHOT</vaadin.version>
8989
<spring.version>4.3.3.RELEASE</spring.version>
9090
<spring.boot.version>1.4.1.RELEASE</spring.boot.version>
9191

@@ -99,20 +99,10 @@
9999

100100
<build>
101101
<plugins>
102-
<plugin>
103-
<groupId>org.apache.maven.plugins</groupId>
104-
<artifactId>maven-compiler-plugin</artifactId>
105-
<version>3.1</version>
106-
<configuration>
107-
<encoding>${project.build.encoding}</encoding>
108-
<target>${project.build.target}</target>
109-
<source>${project.build.source}</source>
110-
</configuration>
111-
</plugin>
112102
<plugin>
113103
<groupId>org.apache.maven.plugins</groupId>
114104
<artifactId>maven-checkstyle-plugin</artifactId>
115-
<version>2.14</version>
105+
<version>2.17</version>
116106
<configuration>
117107
<enableRulesSummary>false</enableRulesSummary>
118108
<includeTestSourceDirectory>true</includeTestSourceDirectory>
@@ -202,4 +192,16 @@
202192
<module>vaadin-spring-boot</module>
203193
<module>vaadin-spring-boot-starter</module>
204194
</modules>
195+
<repositories>
196+
<repository>
197+
<id>vaadin-snapshots</id>
198+
<url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
199+
<releases>
200+
<enabled>false</enabled>
201+
</releases>
202+
<snapshots>
203+
<enabled>true</enabled>
204+
</snapshots>
205+
</repository>
206+
</repositories>
205207
</project>

vaadin-spring-boot-starter/pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.vaadin</groupId>
88
<artifactId>vaadin-spring-parent</artifactId>
9-
<version>1.1-SNAPSHOT</version>
9+
<version>2.0-SNAPSHOT</version>
1010
</parent>
1111

1212
<name>vaadin-spring-boot-starter</name>
@@ -38,6 +38,25 @@
3838
<artifactId>vaadin-client-compiled</artifactId>
3939
<version>${vaadin.version}</version>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-test</artifactId>
44+
<version>${spring.boot.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>net.sourceforge.htmlunit</groupId>
49+
<artifactId>htmlunit</artifactId>
50+
<version>2.23</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.vaadin</groupId>
55+
<artifactId>vaadin-server</artifactId>
56+
<version>8.0-SNAPSHOT</version>
57+
<scope>test</scope>
58+
</dependency>
59+
4160
</dependencies>
4261

4362
</project>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2015-2016 The original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vaadin.spring.web;
17+
18+
import com.gargoylesoftware.htmlunit.WebClient;
19+
import com.vaadin.server.VaadinRequest;
20+
import com.vaadin.spring.annotation.SpringUI;
21+
import com.vaadin.ui.Button;
22+
import com.vaadin.ui.Notification;
23+
import com.vaadin.ui.UI;
24+
import com.vaadin.ui.VerticalLayout;
25+
import org.junit.Assert;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.autoconfigure.SpringBootApplication;
30+
import org.springframework.boot.context.embedded.LocalServerPort;
31+
import org.springframework.boot.test.context.SpringBootTest;
32+
import org.springframework.context.annotation.Bean;
33+
import org.springframework.test.context.junit4.SpringRunner;
34+
35+
/**
36+
* Web based test {@link com.vaadin.spring.server.SpringVaadinServlet} static resource handling
37+
*
38+
* @author Vaadin Ltd
39+
*/
40+
@RunWith(SpringRunner.class)
41+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
42+
public class TestStaticHttp {
43+
private static final String MANDATORY_BOOTSTRAP_PART = "log('Vaadin bootstrap loaded');";
44+
@Autowired
45+
private WebClient webClient;
46+
47+
@LocalServerPort
48+
private int port;
49+
50+
@Test
51+
public void testExample() throws Exception {
52+
String javaScriptUrl = "http://localhost:" + port + "/VAADIN/vaadinBootstrap.js?v=8.0-SNAPSHOT";
53+
String content = this.webClient.getPage(javaScriptUrl).getWebResponse().getContentAsString();
54+
Assert.assertTrue("Mandatory part of bootstrap is not found",
55+
content.contains(MANDATORY_BOOTSTRAP_PART));
56+
}
57+
58+
@SpringUI
59+
public static class MyUI extends UI {
60+
@Override
61+
protected void init(VaadinRequest vaadinRequest) {
62+
setContent(
63+
new VerticalLayout(
64+
new Button("Click me", event -> Notification.show("Thanks"))));
65+
}
66+
}
67+
68+
@SpringBootApplication
69+
public static class MyConfig {
70+
@Bean
71+
public MyUI createUI() {
72+
return new MyUI();
73+
}
74+
75+
@Bean
76+
public WebClient createWebClient() {
77+
return new WebClient();
78+
}
79+
}
80+
}

vaadin-spring-boot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.vaadin</groupId>
99
<artifactId>vaadin-spring-parent</artifactId>
10-
<version>1.1-SNAPSHOT</version>
10+
<version>2.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<name>vaadin-spring-boot</name>

vaadin-spring/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.vaadin</groupId>
99
<artifactId>vaadin-spring-parent</artifactId>
10-
<version>1.1-SNAPSHOT</version>
10+
<version>2.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<name>vaadin-spring</name>

vaadin-spring/src/main/java/com/vaadin/spring/server/SpringVaadinServlet.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.vaadin.spring.server;
1717

18+
import java.io.UnsupportedEncodingException;
19+
import java.net.URLDecoder;
20+
import java.nio.charset.StandardCharsets;
1821
import java.util.ArrayList;
1922
import java.util.List;
2023

@@ -145,4 +148,45 @@ protected VaadinServletRequest createVaadinRequest(
145148
}
146149
}
147150

151+
/**
152+
* Check if this is a request for a static resource and, if it is, return the
153+
* resource path.
154+
*
155+
* @param request http client request
156+
* @return static file path or null if the request is not for a static resource.
157+
*
158+
*/
159+
@Override
160+
protected String getStaticFilePath(HttpServletRequest request) {
161+
/*
162+
Under spring environment, all requests are intercepted with DispatcherServlet, and then mapped to
163+
SpringVaadinServlet with VaadinServletConfiguration, and a static resource prefix (/VAADIN) is not present nor in
164+
getPathInfo(), nor in getServletPath() after that. Here request URL is manually decoded to detect the prefix and
165+
handle static resources properly.
166+
167+
This method is a copy of a hack from VaadinServlet.java of version 7 to support static resource handling in any case.
168+
TODO fix static resource request mapping for spring application
169+
*/
170+
String staticFilePath = super.getStaticFilePath(request);
171+
if (staticFilePath == null) {
172+
173+
try {
174+
String decodedRequestURI = URLDecoder.decode(
175+
request.getRequestURI(), StandardCharsets.UTF_8.name());
176+
if (decodedRequestURI.startsWith("/VAADIN/")) {
177+
return decodedRequestURI;
178+
}
179+
180+
String decodedContextPath = URLDecoder.decode(
181+
request.getContextPath(), StandardCharsets.UTF_8.name());
182+
if (decodedRequestURI.startsWith(decodedContextPath + "/VAADIN/")) {
183+
return decodedRequestURI.substring(decodedContextPath.length());
184+
}
185+
} catch (UnsupportedEncodingException exception) {
186+
// cannot happen since UTF8 is always supported
187+
throw new RuntimeException(exception);
188+
}
189+
}
190+
return staticFilePath;
191+
}
148192
}

0 commit comments

Comments
 (0)