}
private void processDynamicContent(final Properties tokens,
final String relativeURIString,
final Request gReq, final Response gResp) throws IOException, URISyntaxException {
final DynamicContent dc = dynamicContent.get(relativeURIString);
if (dc == null) {
respondNotFound(gResp);
logger.log(Level.FINE, "{0} Could not find dynamic content requested using {1}",
new Object[]{logPrefix(), relativeURIString});
return;
}
final URI requestURI = requestURI(gReq);
if ( ! dc.isAvailable(requestURI)) {
finishErrorResponse(gResp, contentStateToResponseStatus(dc, requestURI));
logger.log(Level.FINE, "{0} Found dynamic content ({1} but is is not marked as available",
new Object[]{logPrefix(), relativeURIString});
return;
}
/*
* Assign values for all the properties which we must compute
* at request time, such as the scheme, host, port, and
* items from the query string. This merges the request-time
* tokens with those that were known when this adapter was created.
*/
Properties allTokens = null;
try {
allTokens = prepareRequestPlaceholders(tokens, gReq);
} catch (Exception e) {
logger.log(Level.SEVERE, "prepareRequestPlaceholder", e);
finishErrorResponse(gResp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
/*
* Create an instance of the dynamic content using the dynamic
* content's template and the just-prepared properties.
*/
final DynamicContent.Instance instance = dc.getOrCreateInstance(allTokens);
final Date instanceTimestamp = instance.getTimestamp();
if (returnIfClientCacheIsCurrent(relativeURIString, gReq,
instanceTimestamp.getTime())) {
return;
}
gResp.setDateHeader(LAST_MODIFIED_HEADER_NAME, instanceTimestamp.getTime());
gResp.setDateHeader(DATE_HEADER_NAME, System.currentTimeMillis());
gResp.setContentType(dc.getMimeType());
gResp.setStatus(HttpServletResponse.SC_OK);
String text = instance.getText();
if (dc.isMain()) {
saveJNLPWithSession(gReq, text, requestURI);
}
/*
* Only for GET should the response actually contain the content.