use of javax.xml.soap.SOAPHeader in project scout.rt by eclipse.
the class WsseUsernameTokenMethod method readWsseCredentials.
/**
* Method invoked to extract the WSSE-credentials from the {@link SOAPHeader}.
*
* @return {@link Entry} with username as key and password as value, or <code>null</code> if not found.
*/
protected Entry<String, String> readWsseCredentials(final SOAPMessageContext messageContext) {
SOAPHeader header;
try {
header = messageContext.getMessage().getSOAPPart().getEnvelope().getHeader();
} catch (final SOAPException e) {
throw new WebServiceException("Failed to read SOAP envelope", e);
}
if (header == null) {
throw new WebServiceException("Missing WSSE-security header");
}
final Iterator iterator = header.getChildElements(new QName(NAME_SPACE_URI, WS_SEC, WSSE));
while (iterator.hasNext()) {
final SOAPElement security = (SOAPElement) iterator.next();
final Iterator iteratorUserToken = security.getChildElements(new QName(NAME_SPACE_URI, USERNAME_TOKEN, WSSE));
while (iteratorUserToken.hasNext()) {
final SOAPElement userTokenElement = (SOAPElement) iteratorUserToken.next();
final Iterator iteratorUsername = userTokenElement.getChildElements(new QName(NAME_SPACE_URI, USERNAME, WSSE));
final Iterator iteratorPassword = userTokenElement.getChildElements(new QName(NAME_SPACE_URI, PASSWORD, WSSE));
if (iteratorUsername.hasNext() && iteratorPassword.hasNext()) {
final SOAPElement usernameElement = (SOAPElement) iteratorUsername.next();
final SOAPElement passwordElement = (SOAPElement) iteratorPassword.next();
if (usernameElement != null && passwordElement != null) {
return new SimpleEntry<>(usernameElement.getValue(), passwordElement.getValue());
}
}
}
}
return null;
}
use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.
the class ProviderMessageTestCase method testProviderDispatch.
@Test
@RunAsClient
public void testProviderDispatch() throws Exception {
Dispatch<SOAPMessage> dispatch = createDispatch("ProviderEndpoint");
SOAPMessage reqMsg = getRequestMessage();
SOAPMessage resMsg = dispatch.invoke(reqMsg);
SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = resEnv.getHeader();
if (soapHeader != null)
soapHeader.detachNode();
assertEquals(DOMUtils.parse(msgString), resEnv);
}
use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.
the class ProviderPayloadTestCase method testProviderMessage.
@Test
@RunAsClient
public void testProviderMessage() throws Exception {
String reqEnvStr = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + " <env:Body>" + reqString + "</env:Body>" + "</env:Envelope>";
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
URL epURL = baseURL;
SOAPMessage resMsg = con.call(reqMsg, epURL);
SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = resEnv.getHeader();
if (soapHeader != null)
soapHeader.detachNode();
Node responseBody = DOMUtils.getFirstChildElement(resEnv.getBody());
assertEquals("wrong namespace: " + responseBody.getNamespaceURI(), "http://org.jboss.ws/provider", responseBody.getNamespaceURI());
assertEquals("wrong localPart: " + responseBody.getLocalName(), "somePayload", responseBody.getLocalName());
String responseString = DOMUtils.getTextContent(responseBody);
assertEquals("wrong content: " + responseString, "Hello:Inbound:LogicalSourceHandler:Outbound:LogicalSourceHandler", responseString);
}
use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.
the class LogHandler method handleInbound.
@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
log.info("handleInbound");
try {
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("LogHandlerInbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|LogIn");
} catch (SOAPException e) {
throw new WebServiceException(e);
}
return true;
}
use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.
the class LogHandler method handleOutbound.
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
log.info("handleOutbound");
try {
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("LogHandlerOutbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|LogOut");
} catch (SOAPException e) {
throw new WebServiceException(e);
}
return true;
}
Aggregations