Embedding Vaadin in JSP - fetchRootConfig issue

Hi,
I’m trying to embedd vaadin 8.0.6 application (the demo app generated by vaadin plugin) into our company jsp web app which is running at
http://localhost:8080/platform
.
I have updated web.xml with vaadin servlet and mapping. The url-pattern is “/vaadinapp/*” and the vaadin app itself is working fine at
http://localhost:8080/platform/vaadinapp

Then I took the content from vaadin app html, modify it a bit according the documentation and put it into the simple test.jsp.
When I open
http://localhost:8080/platform/test.jsp
the folllowing code from
vaadinBootstrap.js
is executed and it fails.

var fetchRootConfig = function(callback) {
log('Fetching root config');
var url = getConfig('browserDetailsUrl');
if (!url) {
// No special url defined, use the same URL that loaded this page (without the fragment)
url = window.location.href.replace(/#.*/,'');
}
// Timestamp to avoid caching
url += ((/\?/).test(url) ? "&" : "?") + "v-" + (new Date()).getTime();
var params = "v-browserDetails=1";
var rootId = getConfig("v-rootId");
if (rootId !== undefined) {
params += "&v-rootId=" + rootId;
}
// Tell the UI what theme it is configured to use
var theme = getConfig('theme');
if (theme !== undefined) {
params += '&theme=' + encodeURIComponent(theme);
}
params += "&v-appId=" + appId;
var extraParams = getConfig('extraParams')
if (extraParams !== undefined) {
params += extraParams;
}
params += '&' + vaadin.getBrowserDetailsParameters(appId, getConfig('sendUrlsAsParameters')); 
var r;
try {
r = new XMLHttpRequest();
} catch (e) {
r = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
r.open('POST', url, true);
r.onreadystatechange = function (aEvt) {  
if (r.readyState == 4) {
// Save responseStatus so as Offline Applications know what happened
// when loading root configuration from server, and depending on the
// error status display an error message or the offline UI.
config.rootResponseStatus = r.status;
config.rootResponseText = r.responseText;
var text = r.responseText;
if (r.status == 200){
log("Got root config response", text);
var updatedConfig = JSON.parse(text);

So if
browserDetailsUrl
is not defined as config parameter you take the same URL which loaded the page. And that is the problem because you are trying to parse json string from the response which is not json string at all. It’s the html code of jsp page and parsing is failing on syntax error.

Ok, so I thought, let’s add
browserDetailsUrl
and point it to the vaadin app and see what happens. :slight_smile:
Almost working but I ended up with
server connection lost
message and I see in console repeating this error (with increasing v-uId):
localhost:8080/platform/test.jsp/UIDL/?v-uId=1 403 Forbidden

Can you please advice?

I got it. I forgot the
serviceUrl
which is the same as
browserDetailsUrl
. :slight_smile:
I leave this topic here, maybe it will help somebody.

Hi Martin, I am struggling with same error. Where exactly did ju put
serviceUrl
and
browserDetailsUrl
?

If I recall I think when you build your application you should have a vaadinBootstrap.js file. There you can find the settings mentioned above.
I was following this example: https://vaadin.com/docs/v8/framework/advanced/advanced-embedding.html