use of org.apache.axiom.soap.SOAPHeader in project carbon-apimgt by wso2.
the class Utils method setSOAPFault.
public static void setSOAPFault(MessageContext messageContext, String code, String reason, String detail) {
SOAPFactory factory = (messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory());
OMDocument soapFaultDocument = factory.createOMDocument();
SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
soapFaultDocument.addChild(faultEnvelope);
SOAPFault fault = faultEnvelope.getBody().getFault();
if (fault == null) {
fault = factory.createSOAPFault();
}
SOAPFaultCode faultCode = factory.createSOAPFaultCode();
if (messageContext.isSOAP11()) {
faultCode.setText(new QName(fault.getNamespace().getNamespaceURI(), code));
} else {
SOAPFaultValue value = factory.createSOAPFaultValue(faultCode);
value.setText(new QName(fault.getNamespace().getNamespaceURI(), code));
}
fault.setCode(faultCode);
SOAPFaultReason faultReason = factory.createSOAPFaultReason();
if (messageContext.isSOAP11()) {
faultReason.setText(reason);
} else {
SOAPFaultText text = factory.createSOAPFaultText();
text.setText(reason);
text.setLang("en");
faultReason.addSOAPText(text);
}
fault.setReason(faultReason);
SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
soapFaultDetail.setText(detail);
fault.setDetail(soapFaultDetail);
// set the all headers of original SOAP Envelope to the Fault Envelope
if (messageContext.getEnvelope() != null) {
SOAPHeader soapHeader = messageContext.getEnvelope().getHeader();
if (soapHeader != null) {
for (Iterator iterator = soapHeader.examineAllHeaderBlocks(); iterator.hasNext(); ) {
Object o = iterator.next();
if (o instanceof SOAPHeaderBlock) {
SOAPHeaderBlock header = (SOAPHeaderBlock) o;
faultEnvelope.getHeader().addChild(header);
} else if (o instanceof OMElement) {
faultEnvelope.getHeader().addChild((OMElement) o);
}
}
}
}
try {
messageContext.setEnvelope(faultEnvelope);
} catch (AxisFault af) {
log.error("Error while setting SOAP fault as payload", af);
return;
}
if (messageContext.getFaultTo() != null) {
messageContext.setTo(messageContext.getFaultTo());
} else if (messageContext.getReplyTo() != null) {
messageContext.setTo(messageContext.getReplyTo());
} else {
messageContext.setTo(null);
}
// set original messageID as relatesTo
if (messageContext.getMessageID() != null) {
RelatesTo relatesTo = new RelatesTo(messageContext.getMessageID());
messageContext.setRelatesTo(new RelatesTo[] { relatesTo });
}
}
use of org.apache.axiom.soap.SOAPHeader in project webservices-axiom by apache.
the class TestWrongParent3 method runTest.
@Override
protected void runTest() throws Throwable {
SOAPHeader parent = soapFactory.createSOAPHeader();
OMElement child1 = soapFactory.createSOAPHeaderBlock("child1", soapFactory.createOMNamespace("urn:test", "p"), parent);
SOAPFault fault = soapFactory.createSOAPFault();
try {
child1.insertSiblingBefore(fault);
fail("Expected SOAPProcessingException");
} catch (SOAPProcessingException ex) {
// Expected
}
}
use of org.apache.axiom.soap.SOAPHeader in project webservices-axiom by apache.
the class TestCloneWithSourcedElement2 method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
SOAPBody body = sourceEnv.getBody();
SOAPHeader header = sourceEnv.getHeader();
// Create a header OMSE
OMDataSource dsHdr = new StringOMDataSource("<hdr:myheader xmlns:hdr=\"urn://test\">Hello World</hdr:myheader>");
OMNamespace hdrNS = header.getOMFactory().createOMNamespace("urn://test", "hdr");
SOAPFactory sf = (SOAPFactory) header.getOMFactory();
SOAPHeaderBlock shb = sf.createSOAPHeaderBlock("myheader", hdrNS, dsHdr);
// test setting processing flag
shb.setProcessed();
header.addChild(shb);
// Create a payload
OMDataSource ds = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
OMSourcedElement omse = body.getOMFactory().createOMElement(ds, "payload", ns);
body.addChild(omse);
copyAndCheck(sourceEnv);
// The source SOAPHeaderBlock should not be expanded in the process
assertFalse(shb.isExpanded());
}
use of org.apache.axiom.soap.SOAPHeader in project webservices-axiom by apache.
the class TestGetHeader method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
SOAPHeader header = envelope.getHeader();
assertEquals("Header Test : - Header local name mismatch", SOAPConstants.HEADER_LOCAL_NAME, header.getLocalName());
assertEquals("Header Test : - Header namespace mismatch", spec.getEnvelopeNamespaceURI(), header.getNamespace().getNamespaceURI());
}
use of org.apache.axiom.soap.SOAPHeader in project webservices-axiom by apache.
the class TestGetOrCreateHeaderWithParserNoHeader method runTest.
@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
SOAPHeader header = envelope.getOrCreateHeader();
assertNotNull(header);
assertSame(envelope.getFirstElement(), header);
assertFalse(envelope.getBody().isComplete());
}
Aggregations