}
private void fetchFirstResource(Identity ident) {
TURequest tureq = new TURequest(); //config, ureq);
tureq.setContentType(null); // not used
tureq.setMethod("GET");
tureq.setParameterMap(Collections.EMPTY_MAP);
tureq.setQueryString(query);
if(startUri != null){
if(startUri.startsWith("/")){
tureq.setUri(startUri);
}else{
tureq.setUri("/"+startUri);
}
}
//if (allowedToSendPersonalHeaders) {
String userName = ident.getName();
User u = ident.getUser();
String lastName = u.getProperty(UserConstants.LASTNAME, loc);
String firstName = u.getProperty(UserConstants.FIRSTNAME, loc);
String email = u.getProperty(UserConstants.EMAIL, loc);
tureq.setEmail(email);
tureq.setFirstName(firstName);
tureq.setLastName(lastName);
tureq.setUserName(userName);
//}
HttpMethod meth = fetch(tureq, httpClientInstance);
if (meth == null) {
setFetchError();
}else{
Header responseHeader = meth.getResponseHeader("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 = meth.getResponseBodyAsString();
} catch (IOException e) {
Tracing.logWarn("Problems when tunneling URL::" + tureq.getUri(), e, TunnelComponent.class);
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
}
meth.releaseConnection();
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 + "'.";
}
}
}