use of org.olat.course.nodes.tu.TURequest in project openolat by klemens.
the class TunnelComponent method getAsyncMediaResource.
/**
* @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
*/
public MediaResource getAsyncMediaResource(UserRequest ureq) {
String moduleURI = ureq.getModuleURI();
// ../index.php instead everything works as expected
if (moduleURI == null) {
// after a click on some other component e.g.
if (!firstCall)
return null;
// reset first call
firstCall = false;
}
TURequest tureq = new TURequest(config, ureq);
fillTURequestWithUserInfo(tureq, ureq);
HttpResponse response = fetch(tureq, httpClientInstance);
if (response == null) {
setFetchError();
return null;
}
Header responseHeader = response.getFirstHeader("Content-Type");
if (responseHeader == null) {
setFetchError();
return null;
}
String mimeType = responseHeader.getValue();
if (mimeType != null && mimeType.startsWith("text/html")) {
// we have html content, let doDispatch handle it for
// inline rendering, update hreq for next content request
String body;
try {
body = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
log.warn("Problems when tunneling URL::" + tureq.getUri(), e);
return null;
}
SimpleHtmlParser parser = new SimpleHtmlParser(body);
if (!parser.isValidHtml()) {
// asynchronuous
return new HttpRequestMediaResource(response);
}
htmlHead = parser.getHtmlHead();
jsOnLoad = parser.getJsOnLoad();
htmlContent = parser.getHtmlContent();
setDirty(true);
} else {
// this is a async browser
return new HttpRequestMediaResource(response);
}
// refetch
return null;
}
use of org.olat.course.nodes.tu.TURequest in project OpenOLAT by OpenOLAT.
the class TunnelComponent method getAsyncMediaResource.
/**
* @see org.olat.core.gui.media.AsyncMediaResponsible#getAsyncMediaResource(org.olat.core.gui.UserRequest)
*/
public MediaResource getAsyncMediaResource(UserRequest ureq) {
String moduleURI = ureq.getModuleURI();
// ../index.php instead everything works as expected
if (moduleURI == null) {
// after a click on some other component e.g.
if (!firstCall)
return null;
// reset first call
firstCall = false;
}
TURequest tureq = new TURequest(config, ureq);
fillTURequestWithUserInfo(tureq, ureq);
HttpResponse response = fetch(tureq, httpClientInstance);
if (response == null) {
setFetchError();
return null;
}
Header responseHeader = response.getFirstHeader("Content-Type");
if (responseHeader == null) {
setFetchError();
return null;
}
String mimeType = responseHeader.getValue();
if (mimeType != null && mimeType.startsWith("text/html")) {
// we have html content, let doDispatch handle it for
// inline rendering, update hreq for next content request
String body;
try {
body = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
log.warn("Problems when tunneling URL::" + tureq.getUri(), e);
return null;
}
SimpleHtmlParser parser = new SimpleHtmlParser(body);
if (!parser.isValidHtml()) {
// asynchronuous
return new HttpRequestMediaResource(response);
}
htmlHead = parser.getHtmlHead();
jsOnLoad = parser.getJsOnLoad();
htmlContent = parser.getHtmlContent();
setDirty(true);
} else {
// this is a async browser
return new HttpRequestMediaResource(response);
}
// refetch
return null;
}
use of org.olat.course.nodes.tu.TURequest in project OpenOLAT by OpenOLAT.
the class TunnelComponent method fetchFirstResource.
private void fetchFirstResource(UserRequest ureq) {
// config, ureq);
TURequest tureq = new TURequest();
// not used
tureq.setContentType(null);
tureq.setMethod("GET");
tureq.setParameterMap(Collections.<String, String[]>emptyMap());
tureq.setQueryString(query);
if (startUri != null) {
if (startUri.startsWith("/")) {
tureq.setUri(startUri);
} else {
tureq.setUri("/" + startUri);
}
}
fillTURequestWithUserInfo(tureq, ureq);
HttpResponse response = fetch(tureq, httpClientInstance);
if (response == null) {
setFetchError();
} else {
Header responseHeader = response.getFirstHeader("Content-Type");
String mimeType;
if (responseHeader == null) {
setFetchError();
mimeType = null;
} else {
mimeType = responseHeader.getValue();
}
if (mimeType != null && mimeType.startsWith("text/html")) {
// we have html content, let doDispatch handle it for
// inline rendering, update hreq for next content request
String body;
try {
body = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
log.warn("Problems when tunneling URL::" + tureq.getUri(), e);
htmlContent = "Error: cannot display inline :" + tureq.getUri() + ": Unknown transfer problem '";
return;
}
SimpleHtmlParser parser = new SimpleHtmlParser(body);
if (!parser.isValidHtml()) {
// this is not valid HTML, deliver
// asynchronuous
}
htmlHead = parser.getHtmlHead();
jsOnLoad = parser.getJsOnLoad();
htmlContent = parser.getHtmlContent();
} else {
htmlContent = "Error: cannot display inline :" + tureq.getUri() + ": mime type was '" + mimeType + "' but expected 'text/html'. Response header was '" + responseHeader + "'.";
}
}
}
use of org.olat.course.nodes.tu.TURequest in project openolat by klemens.
the class TunnelComponent method fetchFirstResource.
private void fetchFirstResource(UserRequest ureq) {
// config, ureq);
TURequest tureq = new TURequest();
// not used
tureq.setContentType(null);
tureq.setMethod("GET");
tureq.setParameterMap(Collections.<String, String[]>emptyMap());
tureq.setQueryString(query);
if (startUri != null) {
if (startUri.startsWith("/")) {
tureq.setUri(startUri);
} else {
tureq.setUri("/" + startUri);
}
}
fillTURequestWithUserInfo(tureq, ureq);
HttpResponse response = fetch(tureq, httpClientInstance);
if (response == null) {
setFetchError();
} else {
Header responseHeader = response.getFirstHeader("Content-Type");
String mimeType;
if (responseHeader == null) {
setFetchError();
mimeType = null;
} else {
mimeType = responseHeader.getValue();
}
if (mimeType != null && mimeType.startsWith("text/html")) {
// we have html content, let doDispatch handle it for
// inline rendering, update hreq for next content request
String body;
try {
body = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
log.warn("Problems when tunneling URL::" + tureq.getUri(), e);
htmlContent = "Error: cannot display inline :" + tureq.getUri() + ": Unknown transfer problem '";
return;
}
SimpleHtmlParser parser = new SimpleHtmlParser(body);
if (!parser.isValidHtml()) {
// this is not valid HTML, deliver
// asynchronuous
}
htmlHead = parser.getHtmlHead();
jsOnLoad = parser.getJsOnLoad();
htmlContent = parser.getHtmlContent();
} else {
htmlContent = "Error: cannot display inline :" + tureq.getUri() + ": mime type was '" + mimeType + "' but expected 'text/html'. Response header was '" + responseHeader + "'.";
}
}
}
Aggregations