+ if (m_template.empty()) {
+ // Generate redirect.
+ string loc = destination;
+ loc += (strchr(destination,'?') ? '&' : '?');
+ const URLEncoder* escaper = XMLToolingConfig::getConfig().getURLEncoder();
+ loc = loc + "SAMLart=" + escaper->encode(artifact->encode().c_str());
+ if (relayState && *relayState)
+ loc = loc + "&RelayState=" + escaper->encode(relayState);
+ log.debug("message encoded, sending redirect to client");
+ return httpResponse->sendRedirect(loc.c_str());
+ }
+ else {
+ // Push message into template and send result to client.
+ log.debug("message encoded, sending HTML form template to client");
+ TemplateEngine* engine = XMLToolingConfig::getConfig().getTemplateEngine();
+ if (!engine)
+ throw BindingException("Encoding artifact using POST requires a TemplateEngine instance.");
+ ifstream infile(m_template.c_str());
+ if (!infile)
+ throw BindingException("Failed to open HTML template for POST response ($1).", params(1,m_template.c_str()));
+ TemplateEngine::TemplateParameters params;
+ params.m_map["action"] = destination;
+ params.m_map["SAMLart"] = artifact->encode();
+ if (relayState && *relayState)
+ params.m_map["RelayState"] = relayState;
+ stringstream s;
+ engine->run(infile, s, params);
+ httpResponse->setContentType("text/html");
+ httpResponse->setResponseHeader("Expires", "01-Jan-1997 12:00:00 GMT");
+ httpResponse->setResponseHeader("Cache-Control", "no-cache, no-store, must-revalidate, private");
+ httpResponse->setResponseHeader("Pragma", "no-cache");
+ return httpResponse->sendResponse(s);
+ }