* @param uri
* @param pageContext - MarinerPageContext
* @throws PAPIException
*/
private void setHostAndPort(Request request, URI uri, MarinerPageContext pageContext) throws PAPIException {
MutableParameters params = (MutableParameters) request.getInputParams();
if (!params.containsName(ParameterNames.SOURCE_HOST)) {
try {
// generate an absolute URL to the asset. This allows us to
// hijack the host and port.
URL fakeUrl = pageContext.getAbsoluteURL(
new MarinerURL(uri.toString()), true);
params.setParameterValue(ParameterNames.SOURCE_HOST, fakeUrl.getHost());
int port = fakeUrl.getPort();
port = port < 0 ? fakeUrl.getDefaultPort(): port;
if (port >= 0) {
params.setParameterValue(
ParameterNames.SOURCE_PORT, Integer.toString(port));
}
String protocol = fakeUrl.getProtocol();
if (protocol != null && !"".equals(protocol)) {
params.setParameterValue(ParameterNames.SOURCE_HOST, protocol);
}
} catch (MalformedURLException e) {
throw new PAPIException(e);
}
}