String repositoryId = null;
if (pathFragments.length > 0) {
repositoryId = pathFragments[0];
}
CallContextImpl context = new CallContextImpl(binding, repositoryId, true);
// call call context handler
if (callContextHandler != null) {
Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
if (callContextMap != null) {
for (Map.Entry<String, String> e : callContextMap.entrySet()) {
context.put(e.getKey(), e.getValue());
}
}
}
// servlet context and HTTP servlet request and response
context.put(CallContext.SERVLET_CONTEXT, servletContext);
context.put(CallContext.HTTP_SERVLET_REQUEST, request);
context.put(CallContext.HTTP_SERVLET_RESPONSE, response);
// temp files
context.put(CallContext.TEMP_DIR, tempDir);
context.put(CallContext.MEMORY_THRESHOLD, memoryThreshold);
// decode range
String rangeHeader = request.getHeader("Range");
if (rangeHeader != null) {
rangeHeader = rangeHeader.trim();
BigInteger offset = null;
BigInteger length = null;
int eq = rangeHeader.indexOf('=');
int ds = rangeHeader.indexOf('-');
if ((eq > 0) && (ds > eq)) {
String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
if (offsetStr.length() > 0) {
offset = new BigInteger(offsetStr);
}
if (ds < rangeHeader.length()) {
String lengthStr = rangeHeader.substring(ds + 1).trim();
if (lengthStr.length() > 0) {
if (offset == null) {
length = new BigInteger(lengthStr);
} else {
length = (new BigInteger(lengthStr)).subtract(offset);
}
}
if (offset != null) {
context.put(CallContext.OFFSET, offset);
}
if (length != null) {
context.put(CallContext.LENGTH, length);
}
}
}
}
// get locale
String acceptLanguage = request.getHeader("Accept-Language");
if (acceptLanguage != null) {
String[] locale = acceptLanguage.split("-");
context.put(CallContext.LOCALE_ISO639_LANGUAGE, locale[0].trim());
if (locale.length > 1) {
int x = locale[1].indexOf(',');
if (x == -1) {
context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].trim());
} else {
context.put(CallContext.LOCALE_ISO3166_COUNTRY, locale[1].substring(0, x).trim());
}
}
}
return context;