use of javax.xml.soap.SOAPMessage in project jdk8u_jdk by JetBrains.
the class SaajEmptyNamespaceTest method testAddElementToNullNsQName.
/*
* Test that adding element with explicitly empty namespace URI set via QName
* shall put the element into global namespace.
*/
@Test
public void testAddElementToNullNsQName() throws Exception {
// Create empty SOAP message
SOAPMessage msg = createSoapMessage();
SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
// Add elements
SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
childGlobalNS.addNamespaceDeclaration("", "");
SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
// Check namespace URIs
Assert.assertNull(childGlobalNS.getNamespaceURI());
Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
use of javax.xml.soap.SOAPMessage in project wildfly by wildfly.
the class WSHandler method log.
private void log(SOAPMessageContext smc) {
if (!LOGGER.isTraceEnabled()) {
return;
}
boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty) {
LOGGER.trace("Outgoing message:");
} else {
LOGGER.trace("Incoming message:");
}
LOGGER.trace("-----------");
SOAPMessage message = smc.getMessage();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
LOGGER.trace(baos.toString());
LOGGER.trace("");
} catch (Exception e) {
LOGGER.error("Exception in handler: " + e);
}
LOGGER.trace("-----------");
}
use of javax.xml.soap.SOAPMessage 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.SOAPMessage 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.SOAPMessage 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;
}
Aggregations