use of javax.xml.soap.SOAPElement in project wildfly by wildfly.
the class ReliableCheckHandler method handleContext.
private synchronized void handleContext(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage message = smc.getMessage();
if (outboundProperty.booleanValue()) {
log.debug("Outgoing message:");
} else {
log.debug("Incoming message:");
}
log.debug("-----------");
try {
JBossLoggingOutputStream os = new JBossLoggingOutputStream(log, Level.DEBUG);
message.writeTo(os);
os.flush();
log.debug("");
} catch (Exception e) {
log.debug("Exception in handler: " + e);
}
log.debug("-----------");
SOAPElement firstBodyElement;
try {
switch(status % 4) {
case 0:
@SuppressWarnings("unchecked") Iterator<SOAPElement> it = (Iterator<SOAPElement>) message.getSOAPBody().getChildElements();
if (it.hasNext()) {
firstBodyElement = it.next();
final QName createSequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequence");
if (!createSequenceQName.equals(firstBodyElement.getElementQName())) {
throw new WebServiceException("CreateSequence in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
}
status++;
} else {
//we could get multiple acknowledments
verifySequenceAcknowledgement(message);
}
break;
case 1:
firstBodyElement = (SOAPElement) message.getSOAPBody().getChildElements().next();
final QName createSequenceResponseQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequenceResponse");
if (!createSequenceResponseQName.equals(firstBodyElement.getElementQName())) {
throw new WebServiceException("CreateSequenceResponse in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
}
status++;
break;
case 2:
Iterator headerElements = message.getSOAPHeader().getChildElements();
boolean found = false;
final QName sequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "Sequence");
while (headerElements.hasNext()) {
SOAPElement soapElement = (SOAPElement) headerElements.next();
if (sequenceQName.equals(soapElement.getElementQName())) {
found = true;
}
}
if (!found) {
throw new WebServiceException("wsrm:Sequence is not present in soap header");
}
status++;
break;
case 3:
if (verifySequenceAcknowledgement(message)) {
status++;
}
break;
}
} catch (SOAPException ex) {
throw new WebServiceException(ex.getMessage(), ex);
}
}
use of javax.xml.soap.SOAPElement in project wildfly by wildfly.
the class TestHandler method ensureInjectionsAndInitialization.
private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
if (!this.correctState) {
throw new WebServiceException("Unfunctional injections");
}
try {
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
soapElement = (SOAPElement) soapElement.getChildElements().next();
String oldValue = soapElement.getValue();
String newValue = oldValue + ":" + direction + ":TestHandler";
soapElement.setValue(newValue);
log.debug("oldValue: " + oldValue);
log.debug("newValue: " + newValue);
return true;
} catch (SOAPException ex) {
throw new WebServiceException(ex);
}
}
use of javax.xml.soap.SOAPElement in project nhin-d by DirectProject.
the class RepositorySOAPHandler method handleMessage.
/**
* This method handles the incoming and outgoing SOAP-Message. It's an
* excellent point to manipulate the SOAP.
*
* @param SOAPMessageContext
* The SOAPMessageContext object.
*
* @return true if successful handling, false otherwise.
*/
@Override
public boolean handleMessage(SOAPMessageContext context) {
//Inquire incoming or outgoing message.
boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
try {
if (outbound) {
getHeaderData();
SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
// dumpSOAPMessage(msg);
SOAPPart sp = msg.getSOAPPart();
// edit Envelope
SOAPEnvelope env = sp.getEnvelope();
SOAPHeader sh = env.addHeader();
@SuppressWarnings("unused") SOAPBody sb = env.getBody();
if (action != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "Action");
SOAPHeaderElement saction = sh.addHeaderElement(qname);
boolean must = true;
saction.setMustUnderstand(must);
saction.setValue(action);
}
if (relatesTo != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "RelatesTo");
SOAPHeaderElement relates = sh.addHeaderElement(qname);
relates.setValue(relatesTo);
}
if (from != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "From");
QName child = new QName("http://www.w3.org/2005/08/addressing", "Address");
SOAPHeaderElement efrom = sh.addHeaderElement(qname);
SOAPElement address = efrom.addChildElement(child);
address.setValue(from);
}
if (messageId != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "MessageID");
SOAPHeaderElement message = sh.addHeaderElement(qname);
message.setValue(messageId);
}
if (to != null) {
QName qname = new QName("http://www.w3.org/2005/08/addressing", "To");
SOAPHeaderElement sto = sh.addHeaderElement(qname);
sto.setValue(to);
}
} else {
//should not be any inbound
}
} catch (Exception e) {
LOGGER.error("Error handling SOAP message", e);
return false;
}
return true;
}
use of javax.xml.soap.SOAPElement in project webservices-axiom by apache.
the class TestAddChildElementReification method runTest.
@Override
protected void runTest() throws Throwable {
MessageFactory mf = spec.getAdapter(FactorySelector.class).newMessageFactory(saajImplementation, false);
SOAPBody body = mf.createMessage().getSOAPBody();
SOAPElement child = body.addChildElement((SOAPElement) body.getOwnerDocument().createElementNS("urn:test", "p:test"));
assertThat(child).isInstanceOf(SOAPBodyElement.class);
}
use of javax.xml.soap.SOAPElement in project ddf by codice.
the class IdpEndpoint method determineAuthMethod.
private AuthObj determineAuthMethod(String bodyStr, AuthnRequest authnRequest) {
XMLStreamReader xmlStreamReader = null;
try {
xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(bodyStr));
} catch (XMLStreamException e) {
LOGGER.debug("Unable to parse SOAP message from client.", e);
}
SoapMessage soapMessage = new SoapMessage(Soap11.getInstance());
SAAJInInterceptor.SAAJPreInInterceptor preInInterceptor = new SAAJInInterceptor.SAAJPreInInterceptor();
soapMessage.setContent(XMLStreamReader.class, xmlStreamReader);
preInInterceptor.handleMessage(soapMessage);
SAAJInInterceptor inInterceptor = new SAAJInInterceptor();
inInterceptor.handleMessage(soapMessage);
SOAPPart soapMessageContent = (SOAPPart) soapMessage.getContent(Node.class);
AuthObj authObj = new AuthObj();
try {
Iterator soapHeaderElements = soapMessageContent.getEnvelope().getHeader().examineAllHeaderElements();
while (soapHeaderElements.hasNext()) {
SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) soapHeaderElements.next();
if (soapHeaderElement.getLocalName().equals("Security")) {
Iterator childElements = soapHeaderElement.getChildElements();
while (childElements.hasNext()) {
Object nextElement = childElements.next();
if (nextElement instanceof SOAPElement) {
SOAPElement element = (SOAPElement) nextElement;
if (element.getLocalName().equals("UsernameToken")) {
Iterator usernameTokenElements = element.getChildElements();
Object next;
while (usernameTokenElements.hasNext()) {
if ((next = usernameTokenElements.next()) instanceof Element) {
Element nextEl = (Element) next;
if (nextEl.getLocalName().equals("Username")) {
authObj.username = nextEl.getTextContent();
} else if (nextEl.getLocalName().equals("Password")) {
authObj.password = nextEl.getTextContent();
}
}
}
if (authObj.username != null && authObj.password != null) {
authObj.method = USER_PASS;
break;
}
} else if (element.getLocalName().equals("Assertion") && element.getNamespaceURI().equals("urn:oasis:names:tc:SAML:2.0:assertion")) {
authObj.assertion = new SecurityToken(element.getAttribute("ID"), element, null, null);
authObj.method = SAML;
break;
}
}
}
}
}
} catch (SOAPException e) {
LOGGER.debug("Unable to parse SOAP message.", e);
}
RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
boolean requestingPki = false;
boolean requestingUp = false;
if (requestedAuthnContext != null) {
List<AuthnContextClassRef> authnContextClassRefs = requestedAuthnContext.getAuthnContextClassRefs();
for (AuthnContextClassRef authnContextClassRef : authnContextClassRefs) {
String authnContextClassRefStr = authnContextClassRef.getAuthnContextClassRef();
if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SPKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_TLS_CLIENT.equals(authnContextClassRefStr)) {
requestingPki = true;
} else if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT.equals(authnContextClassRefStr)) {
requestingUp = true;
}
}
} else {
//The requested auth context isn't required so we don't know what they want... just set both to true
requestingPki = true;
requestingUp = true;
}
if (requestingUp && authObj.method != null && authObj.method.equals(USER_PASS)) {
LOGGER.trace("Found UsernameToken and correct AuthnContextClassRef");
return authObj;
} else if (requestingPki && authObj.method == null) {
LOGGER.trace("Found no token, but client requested PKI AuthnContextClassRef");
authObj.method = PKI;
return authObj;
} else if (authObj.method == null) {
LOGGER.debug("No authentication tokens found for the current request and the client did not request PKI authentication");
}
return authObj;
}
Aggregations