String serverName = extractServerNameFromUri(uri);
uri = uri.replace(serverName, "localhost");
HttpPost httpPost = new HttpPost(uri);
if (!serverName.equals("localhost")) {
httpPost.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(serverName, 8080));
}
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair(name, value));
UrlEncodedFormEntity entity;
try {
entity = new UrlEncodedFormEntity(formparams, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
httpPost.setEntity(entity);
request = httpPost;
} else if (responseType == ResponseType.SAML_MESSAGE_REDIRECT_BOUND) {
String location = response.getFirstHeader("Location").getValue();
log.info("Received redirect to " + location);
String serverName = extractServerNameFromUri(location);
HttpGet httpGet = new HttpGet(location.replace(serverName, "localhost"));
httpGet.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(serverName, 8080));
request = httpGet;
} else if (responseType == ResponseType.ERROR) {
Assert.fail("Error response received by test client (status code " + response.getStatusLine().getStatusCode() + "): " + responseBody);
} else {
throw new RuntimeException("Cannot relay the non-SAML response type " + responseType + " (message: " + responseBody + ")");