- Envelope* env = dynamic_cast<Envelope*>(xmlObject);
- if (env) {
- SignableObject* msg =
- (env->getBody() && env->getBody()->hasChildren()) ?
- dynamic_cast<SignableObject*>(env->getBody()->getUnknownXMLObjects().front()) : NULL;
- if (msg && credential) {
- if (msg->getSignature()) {
- log.debug("message already signed, skipping signature operation");
- rootElement = env->marshall();
- }
- else {
- log.debug("signing the message and marshalling the envelope");
-
- // Build a Signature.
- Signature* sig = SignatureBuilder::buildSignature();
- msg->setSignature(sig);
- if (signatureAlg)
- sig->setSignatureAlgorithm(signatureAlg);
- if (digestAlg) {
- opensaml::ContentReference* cr = dynamic_cast<opensaml::ContentReference*>(sig->getContentReference());
- if (cr)
- cr->setDigestAlgorithm(digestAlg);
- }
-
- // Sign message while marshalling.
- vector<Signature*> sigs(1,sig);
- rootElement = env->marshall((DOMDocument*)NULL,&sigs,credential);
- }
- }
- else {
- log.debug("marshalling the envelope");
- rootElement = env->marshall();
- }
-
- string xmlbuf;
- XMLHelper::serialize(rootElement, xmlbuf);
- istringstream s(xmlbuf);
- log.debug("sending serialized envelope");
- bool error =
- (env->getBody() &&
- env->getBody()->hasChildren() &&
- dynamic_cast<Fault*>(env->getBody()->getUnknownXMLObjects().front()));
- long ret = error ? genericResponse.sendError(s) : genericResponse.sendResponse(s);
-
- // Cleanup by destroying XML.
- delete env;
- return ret;
- }
-