Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# 1.0.2
* Vaadin
* ``XHRReloadVaadinServiceInitListener``
* Improved performance by not building element every request and cloning it instead
* If an error occurs while the script is added to the document the error is now logged (once at WARN; all subsequent ones at DEBUG)

# 1.0.1
* Vaadin
* Fix ``SecureVaadinRequestCache`` ignoring non-optional url parameters
* Fix ``SecureVaadinRequestCache`` ignoring non-optional url parameters

# 1.0.0
_Initial production ready release_
Expand Down
2 changes: 1 addition & 1 deletion codec-sha256/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion crypto-symmetric/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion oauth2-oidc-remember-me/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion oauth2-oidc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Optional;
import java.util.regex.Pattern;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

import com.vaadin.flow.server.ServiceInitEvent;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.flow.server.communication.IndexHtmlRequestListener;

Expand All @@ -36,7 +39,8 @@ public class XHRReloadVaadinServiceInitListener implements VaadinServiceInitList
{
private static final Logger LOG = LoggerFactory.getLogger(XHRReloadVaadinServiceInitListener.class);

protected final String scriptContents;
protected final Element scriptElement;
protected boolean scriptAttachErrorAlreadyLogged;

public XHRReloadVaadinServiceInitListener(final XHRReloadConfig config)
{
Expand All @@ -48,11 +52,21 @@ public XHRReloadVaadinServiceInitListener(final XHRReloadConfig config)
}

// Remove comments
this.scriptContents = Pattern.compile(
final String scriptContents = Pattern.compile(
"\\/\\*[\\s\\S]*?\\*\\/|(?<=[^:])\\/\\/.*|^\\/\\/.*")
.matcher(new String(is.readAllBytes()))
.replaceAll("")
.trim();

if(scriptContents.isBlank())
{
LOG.error("Script loaded from {} is empty", config.getResourceLocation());
}

this.scriptElement = new Element("script")
.attr("type", "text/javascript")
.html(scriptContents);
LOG.trace("Built scriptElement: {}", this.scriptElement);
}
catch(final IOException e)
{
Expand All @@ -65,11 +79,32 @@ public void serviceInit(final ServiceInitEvent event)
{
event.addIndexHtmlRequestListener((IndexHtmlRequestListener)resp -> {
final Document document = resp.getDocument();

final Element body = document.body();
body.prependElement("script")
.attr("type", "text/javascript")
.html(this.scriptContents);

try
{
body.prependChild(this.scriptElement.clone());
}
catch(final Exception ex)
{
LOG.atLevel(this.scriptAttachErrorAlreadyLogged
? Level.DEBUG
: Level.WARN)
.setMessage(
"Failed to attach XHRReloadScript. {}"
+ "Details: path={} body={}")
.addArgument(!this.scriptAttachErrorAlreadyLogged
? "Subsequent errors will be logged at DEBUG. "
: "")
.addArgument(() ->
Optional.ofNullable(resp.getVaadinRequest())
.map(VaadinRequest::getPathInfo)
.orElse("?"))
.addArgument(body)
.addArgument(ex)
.log();
this.scriptAttachErrorAlreadyLogged = true;
}
});

LOG.debug("Applied serviceInit");
Expand Down
2 changes: 1 addition & 1 deletion web-sidecar-actuator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down