String sAccept = request.getHeader(Tags.HEADER_ACCEPT);
// initialize the following input parameters to proxy server in addition to
// addition flags refs, trust & sep
MimeType resolutionMediaType = null;
String serviceResMediaType = null;
String serviceType = null; // this always comes from http get query
/*
* We expect Accept header of format and would contain only expected variables and values
* The general format of aceept header is: <mediatype>[;name=value]*[,<mediatype>[;named=value]*]
* 1. If multiple mediatypes appears the proxy server shoud pick the first one.
* 2. If mediatype is one of the application/xrd(s)+xml or text/uri-list then ResolutionMediaType=mediatype
* and ServiceMediaType becomes null
* 3. If mediatype doesn't match with applciation/xrd(s) or text/uri-list ResolutionMediaType=null
* and ServiceMediaType = mediatype
* if accept header is null then ResolutionMediaType and ServiceMediaType = null (used loose constraint)
* 4. In any case the proxy query parameters _xrd_r and _xrd_m takes higher precendence over accept header
*/
if (sAccept != null ){
StringTokenizer tokenizer = new StringTokenizer(sAccept, ",");
while (tokenizer.hasMoreTokens() ){
String token = (String)tokenizer.nextToken();
MimeType mType = MimeType.parse(token);
if (mType == null || mType.getType() == null || mType.getType().length() == 0)
continue; // ignore
if (mType.isValidXriResMediaType()) {
resolutionMediaType = mType;
serviceResMediaType = null;
isDumbBrowser = false;
}
else {
resolutionMediaType = null;
serviceResMediaType = mType.toString();
}
break;
}
}
QueryParams qp = parseQuery(request);
if (qp.xrdR != null) {
if (qp.xrdR.trim().length() == 0) {
// parameter exists, but is empty
resolutionMediaType = null;
}
else {
MimeType mType = MimeType.parse(qp.xrdR);
if (mType != null && mType.getType() != null && mType.getType().length() > 0) {
// this overrides earlier value (that might be in Accept: header)
resolutionMediaType = mType;
}
}
}