"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "flow-server/src/main/java/com/vaadin/flow/server/communication/IndexHtmlRequestHandler.java" between
vaadin-flow-4.0.7.tar.gz and vaadin-flow-4.0.8.tar.gz

About: Vaadin flow is a Java framework binding Vaadin 17 web components to Java.

IndexHtmlRequestHandler.java  (vaadin-flow-4.0.7):IndexHtmlRequestHandler.java  (vaadin-flow-4.0.8)
skipping to change at line 18 skipping to change at line 18
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package com.vaadin.flow.server.communication; package com.vaadin.flow.server.communication;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.io.UncheckedIOException;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.DataNode; import org.jsoup.nodes.DataNode;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.vaadin.flow.component.UI; import com.vaadin.flow.component.UI;
skipping to change at line 59 skipping to change at line 62
import static com.vaadin.flow.shared.ApplicationConstants.CSRF_TOKEN; import static com.vaadin.flow.shared.ApplicationConstants.CSRF_TOKEN;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* This class is responsible for serving the <code>index.html</code> according * This class is responsible for serving the <code>index.html</code> according
* to the template provided in the frontend folder. The handler will calculate a nd * to the template provided in the frontend folder. The handler will calculate a nd
* inject baseHref as well as the bundle scripts into the template. * inject baseHref as well as the bundle scripts into the template.
*/ */
public class IndexHtmlRequestHandler extends JavaScriptBootstrapHandler { public class IndexHtmlRequestHandler extends JavaScriptBootstrapHandler {
private transient IndexHtmlResponse indexHtmlResponse;
@Override @Override
public boolean synchronizedHandleRequest(VaadinSession session, public boolean synchronizedHandleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException { VaadinRequest request, VaadinResponse response) throws IOException {
Document indexDocument = getIndexHtmlDocument(request); DeploymentConfiguration config = session.getConfiguration();
IndexHtmlResponse indexHtmlResponse;
Document indexDocument = config.isProductionMode()
? getCachedIndexHtmlDocument(request.getService())
: getIndexHtmlDocument(request.getService());
prependBaseHref(request, indexDocument); prependBaseHref(request, indexDocument);
JsonObject initialJson = Json.createObject(); JsonObject initialJson = Json.createObject();
if (request.getService().getBootstrapInitialPredicate() if (request.getService().getBootstrapInitialPredicate()
.includeInitialUidl(request)) { .includeInitialUidl(request)) {
includeInitialUidl(initialJson, session, request, response); includeInitialUidl(initialJson, session, request, response);
indexHtmlResponse = new IndexHtmlResponse(request, response, indexDo cument, UI.getCurrent()); indexHtmlResponse = new IndexHtmlResponse(request, response, indexDo cument, UI.getCurrent());
skipping to change at line 94 skipping to change at line 100
configureErrorDialogStyles(indexDocument); configureErrorDialogStyles(indexDocument);
showWebpackErrors(indexDocument); showWebpackErrors(indexDocument);
response.setContentType(CONTENT_TYPE_TEXT_HTML_UTF_8); response.setContentType(CONTENT_TYPE_TEXT_HTML_UTF_8);
VaadinContext context = session.getService().getContext(); VaadinContext context = session.getService().getContext();
AppShellRegistry registry = AppShellRegistry.getInstance(context); AppShellRegistry registry = AppShellRegistry.getInstance(context);
DeploymentConfiguration config = session.getConfiguration();
if (!config.isProductionMode()) { if (!config.isProductionMode()) {
UsageStatisticsExporter.exportUsageStatisticsToDocument(indexDocumen t); UsageStatisticsExporter.exportUsageStatisticsToDocument(indexDocumen t);
} }
// modify the page based on the @PWA annotation // modify the page based on the @PWA annotation
setupPwa(indexDocument, session.getService()); setupPwa(indexDocument, session.getService());
// modify the page based on the @Meta, @ViewPort, @BodySize and @Inline annotations // modify the page based on the @Meta, @ViewPort, @BodySize and @Inline annotations
// and on the AppShellConfigurator // and on the AppShellConfigurator
registry.modifyIndexHtml(indexDocument, request); registry.modifyIndexHtml(indexDocument, request);
skipping to change at line 212 skipping to change at line 217
Document indexDocument) { Document indexDocument) {
Elements base = indexDocument.head().getElementsByTag("base"); Elements base = indexDocument.head().getElementsByTag("base");
String baseHref = getServiceUrl(request); String baseHref = getServiceUrl(request);
if (base.isEmpty()) { if (base.isEmpty()) {
indexDocument.head().prependElement("base").attr("href", baseHref); indexDocument.head().prependElement("base").attr("href", baseHref);
} else { } else {
base.first().attr("href", baseHref); base.first().attr("href", baseHref);
} }
} }
private static Document getIndexHtmlDocument(VaadinRequest request) private static Document getCachedIndexHtmlDocument(VaadinService service) {
return service.getContext()
.getAttribute(IndexHtmlHolder.class, () -> new IndexHtmlHolder(s
ervice))
.getDocument();
}
private static Document getIndexHtmlDocument(VaadinService service)
throws IOException { throws IOException {
String index = FrontendUtils.getIndexHtmlContent(request.getService()); String index = FrontendUtils.getIndexHtmlContent(service);
if (index != null) { if (index != null) {
return Jsoup.parse(index); return Jsoup.parse(index);
} }
String frontendDir = FrontendUtils.getProjectFrontendDir( String frontendDir = FrontendUtils.getProjectFrontendDir(
request.getService().getDeploymentConfiguration()); service.getDeploymentConfiguration());
String indexHtmlFilePath;
if(frontendDir.endsWith(File.separator)) {
indexHtmlFilePath = frontendDir + "index.html";
} else {
indexHtmlFilePath = frontendDir + File.separatorChar + "index.html";
}
String message = String String message = String
.format("Failed to load content of '%1$sindex.html'." .format("Failed to load content of '%1$s'. "
+ "It is required to have '%1$sindex.html' file when " + "It is required to have '%1$s' file when "
+ "using client side bootstrapping.", frontendDir); + "using client side bootstrapping.", indexHtmlFilePath)
;
throw new IOException(message); throw new IOException(message);
} }
// Holds parsed index.html to avoid re-parsing on every request in productio
n mode
//
// This holder is supposed to be stored as a VaadinContext attribute
//
// Note: IndexHtmlHolder is not really serializable, but I can't come up wit
h
// circumstances under which it'll break. It seems unlikely that VaadinConte
xt
// will be serialized/deserialized.
private static final class IndexHtmlHolder implements Serializable {
private final transient Document indexHtmlDocument;
private IndexHtmlHolder(VaadinService service) {
try {
this.indexHtmlDocument = getIndexHtmlDocument(service);
this.indexHtmlDocument.outputSettings().prettyPrint(false);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private Document getDocument() {
return this.indexHtmlDocument.clone();
}
}
private static Logger getLogger() { private static Logger getLogger() {
return LoggerFactory.getLogger(IndexHtmlRequestHandler.class); return LoggerFactory.getLogger(IndexHtmlRequestHandler.class);
} }
protected IndexHtmlResponse getIndexHtmlResponse() {
return this.indexHtmlResponse;
}
} }
 End of changes. 11 change blocks. 
13 lines changed or deleted 56 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)