/** * {@inheritDoc} */ @Override public String xmlDocumentToFormattedString(Document document) { Element element = null; String formatted = null; if(document !=null){ if(document.getDocumentElement() !=null){ element = document.getDocumentElement(); if(element !=null){ formatted = XMLHelper.prettyPrintXML(element); formatted = formatted.replace(StringConstants.XML_OMIT_STRING, ""); } } } return formatted; }
/** * {@inheritDoc} */ @Override public String saml2ResponseToFormattedString(Response response) { Element saml2ResponseElement = null; String saml2ResponseString = null; try { if(response !=null){ saml2ResponseElement = responseMarshaller.marshall(response); } if(saml2ResponseElement !=null) { saml2ResponseString = XMLHelper.prettyPrintXML(saml2ResponseElement); } }catch(MarshallingException e){ String message ="saml2ResponseToString(Response), Marshalling failed"; logger.error(message,e); } return saml2ResponseString; }
/** * {@inheritDoc} */ @Override public String saml2AssertionToFormattedString(Assertion assertion) { Element saml2AssertionElement = null; String saml2AssertionString = null; try { if(assertion !=null){ saml2AssertionElement = assertionMarshaller.marshall(assertion); } if(saml2AssertionElement !=null) { saml2AssertionString = XMLHelper.prettyPrintXML(saml2AssertionElement); } }catch(MarshallingException e){ String message ="saml2AssertionToUnFormattedString(Assertion), Marshalling failed"; logger.error(message,e); } return saml2AssertionString; }
/** * {@inheritDoc} */ @Override public String soapMessageToFormattedString(SOAPMessage soapMessage){ Element soapElement = null; String formatted = null; try { if(soapMessage !=null){ soapElement = soapMessage.getSOAPPart().getEnvelope().getOwnerDocument().getDocumentElement(); } if(soapElement !=null){ formatted = XMLHelper.prettyPrintXML(soapElement); formatted = formatted.replace(StringConstants.SOAP_REPLACE_FROM,StringConstants.SOAP_REPLACE_TO); } }catch(SOAPException e){ String message = "Failed to get owning document from SOAPMessage : "; logger.error(message,e); } return formatted; }
/** * Prints the given attribute statement to system output. * * @param attributeStatement attribute statement to print */ private static void printAttributeStatement(SAMLObject attributeStatement) { if (attributeStatement == null) { System.out.println("No attribute statement."); return; } Marshaller statementMarshaller = Configuration.getMarshallerFactory().getMarshaller(attributeStatement); try { Element statement = statementMarshaller.marshall(attributeStatement); System.out.println(XMLHelper.prettyPrintXML(statement)); } catch (MarshallingException e) { errorAndExit("Unable to marshall attribute statement", e); } }
/** * Creates the request entity that makes up the POST message body. * * @param message message to be sent * @param charset character set used for the message * * @return request entity that makes up the POST message body * * @throws SOAPClientException thrown if the message could not be marshalled */ protected RequestEntity createRequestEntity(Envelope message, Charset charset) throws SOAPClientException { try { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); ByteArrayOutputStream arrayOut = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(arrayOut, charset); if (log.isDebugEnabled()) { log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message))); } XMLHelper.writeNode(marshaller.marshall(message), writer); return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml"); } catch (MarshallingException e) { throw new SOAPClientException("Unable to marshall SOAP envelope", e); } }
/** * Unmarshalls the incoming response from a POST request. * * @param responseStream input stream bearing the response * * @return the response * * @throws SOAPClientException thrown if the incoming response can not be unmarshalled into an {@link Envelope} */ protected Envelope unmarshallResponse(InputStream responseStream) throws SOAPClientException { try { Element responseElem = parserPool.parse(responseStream).getDocumentElement(); if (log.isDebugEnabled()) { log.debug("Inbound SOAP message was:\n" + XMLHelper.prettyPrintXML(responseElem)); } Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(responseElem); return (Envelope) unmarshaller.unmarshall(responseElem); } catch (XMLParserException e) { throw new SOAPClientException("Unable to parse the XML within the response", e); } catch (UnmarshallingException e) { throw new SOAPClientException("unable to unmarshall the response DOM", e); } }
/** * Log the encoded message to the protocol message logger. * * @param messageContext the message context to process */ protected void logEncodedMessage(MessageContext messageContext) { if(protocolMessageLog.isDebugEnabled() && messageContext.getOutboundMessage() != null){ if (messageContext.getOutboundMessage().getDOM() == null) { try { marshallMessage(messageContext.getOutboundMessage()); } catch (MessageEncodingException e) { log.error("Unable to marshall message for logging purposes: " + e.getMessage()); return; } } protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getOutboundMessage().getDOM())); } }
/** * Log the decoded message to the protocol message logger. * * @param messageContext the message context to process */ protected void logDecodedMessage(MessageContext messageContext) { if(protocolMessageLog.isDebugEnabled() && messageContext.getInboundMessage() != null){ if (messageContext.getInboundMessage().getDOM() == null) { XMLObject message = messageContext.getInboundMessage(); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(message); if (marshaller != null) { try { marshaller.marshall(message); } catch (MarshallingException e) { log.error("Unable to marshall message for logging purposes: " + e.getMessage()); } } else { log.error("Unable to marshall message for logging purposes, no marshaller registered for message object: " + message.getElementQName()); } if (message.getDOM() == null) { return; } } protocolMessageLog.debug("\n" + XMLHelper.prettyPrintXML(messageContext.getInboundMessage().getDOM())); } }