use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class OMTestUtils method walkThrough.
public static void walkThrough(OMElement element) {
Assert.assertFalse("Expected " + element.getQName() + " to be incomplete", element.isComplete());
for (Iterator<OMAttribute> it = element.getAllAttributes(); it.hasNext(); ) {
Assert.assertNotNull(it.next());
}
OMNode child = element.getFirstOMChild();
while (child != null) {
if (child instanceof OMElement) {
walkThrough((OMElement) child);
}
child = child.getNextOMSibling();
}
Assert.assertTrue(element.isComplete());
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestCommentInEpilog method runTest.
@Override
protected void runTest() throws Throwable {
SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(soapFactory.getDefaultEnvelope() + "<!--comment-->")).getSOAPEnvelope();
OMNode sibling = envelope.getNextOMSibling();
assertTrue(sibling instanceof OMComment);
}
use of org.apache.axiom.om.OMNode in project webservices-axiom by apache.
the class TestCommentInProlog method runTest.
@Override
protected void runTest() throws Throwable {
SOAPMessage message = SOAPSampleSet.COMMENT_IN_PROLOG.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getSOAPMessage(metaFactory);
OMNode firstChild = message.getFirstOMChild();
assertTrue(firstChild instanceof OMComment);
}
use of org.apache.axiom.om.OMNode in project carbon-business-process by wso2.
the class SOAPUtils method convertSOAP11toSOAP12.
/**
* Converts the version of the the message context to 1.2.
* <br />
* <b>Message Changes:</b>
* <ol>
* <li>Convert envelope, header elements</li>
* <li>For each header block convert attribute actor to role</li>
* <li>For each header block convert mustUnderstand value type</li>
* <li>For each header block remove 1.1 namespaced other attributes</li>
* </ol>
*
* <b>Fault Changes:</b>
* <ol>
* <li>Convert fault element</li>
* <li>faultcode to Fault/Code</li>
* <li>faultstring to First Fault/Reason/Text with lang=en</li>
* </ol>
*
* @param axisOutMsgCtx message context to be converted
* @throws AxisFault incase conversion process fails
*/
public static void convertSOAP11toSOAP12(org.apache.axis2.context.MessageContext axisOutMsgCtx) throws AxisFault {
if (log.isDebugEnabled()) {
log.debug("convert SOAP11 to SOAP12");
}
SOAPEnvelope oldEnvelope = axisOutMsgCtx.getEnvelope();
SOAPFactory soap12Factory = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope newEnvelope = soap12Factory.getDefaultEnvelope();
if (oldEnvelope.getHeader() != null) {
Iterator itr = oldEnvelope.getHeader().getChildren();
while (itr.hasNext()) {
OMNode omNode = (OMNode) itr.next();
if (omNode instanceof SOAPHeaderBlock) {
SOAPHeaderBlock soapHeader = (SOAPHeaderBlock) omNode;
SOAPHeaderBlock newSOAPHeader = soap12Factory.createSOAPHeaderBlock(soapHeader.getLocalName(), soapHeader.getNamespace());
Iterator allAttributes = soapHeader.getAllAttributes();
while (allAttributes.hasNext()) {
OMAttribute attr = (OMAttribute) allAttributes.next();
if (attr.getNamespace() != null && SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(attr.getNamespace().getNamespaceURI())) {
String attrName = attr.getLocalName();
if (SOAP_ATR_ACTOR.equals(attrName)) {
OMAttribute newAtr = omNode.getOMFactory().createOMAttribute(SOAP_ATR_ROLE, newEnvelope.getNamespace(), attr.getAttributeValue());
newSOAPHeader.addAttribute(newAtr);
} else if (SOAP_ATR_MUST_UNDERSTAND.equals(attrName)) {
boolean isMustUnderstand = soapHeader.getMustUnderstand();
newSOAPHeader.setMustUnderstand(isMustUnderstand);
} else {
log.warn("removed unsupported attribute from SOAP 1.1 " + "namespace when converting to SOAP 1.2:" + attrName);
}
} else {
newSOAPHeader.addAttribute(attr);
}
Iterator itrChildren = soapHeader.getChildren();
while (itrChildren.hasNext()) {
OMNode node = (OMNode) itrChildren.next();
itrChildren.remove();
newSOAPHeader.addChild(node);
}
newEnvelope.getHeader().addChild(newSOAPHeader);
}
// while(allAttributes.hasNext())
} else {
itr.remove();
newEnvelope.getHeader().addChild(omNode);
}
}
// while (itr.hasNext())
}
if (oldEnvelope.getBody() != null) {
Iterator itrBodyChildren = oldEnvelope.getBody().getChildren();
while (itrBodyChildren.hasNext()) {
OMNode omNode = (OMNode) itrBodyChildren.next();
if (omNode != null && omNode instanceof SOAPFault) {
SOAPFault soapFault = (SOAPFault) omNode;
SOAPFault newSOAPFault = soap12Factory.createSOAPFault();
newEnvelope.getBody().addChild(newSOAPFault);
// get the existing envelope
SOAPFaultCode code = soapFault.getCode();
if (code != null) {
SOAPFaultCode newSOAPFaultCode = soap12Factory.createSOAPFaultCode();
newSOAPFault.setCode(newSOAPFaultCode);
QName s11Code = code.getTextAsQName();
if (s11Code != null) {
// get the corresponding SOAP12 fault code
// for the provided SOAP11 fault code
SOAPFaultValue newSOAPFaultValue = soap12Factory.createSOAPFaultValue(newSOAPFaultCode);
newSOAPFaultValue.setText(getMappingSOAP12Code(s11Code));
}
}
SOAPFaultReason reason = soapFault.getReason();
if (reason != null) {
SOAPFaultReason newSOAPFaultReason = soap12Factory.createSOAPFaultReason(newSOAPFault);
String reasonText = reason.getText();
if (reasonText != null) {
SOAPFaultText newSOAPFaultText = soap12Factory.createSOAPFaultText(newSOAPFaultReason);
// hard coded
newSOAPFaultText.setLang("en");
newSOAPFaultText.setText(reasonText);
}
newSOAPFault.setReason(newSOAPFaultReason);
}
SOAPFaultDetail detail = soapFault.getDetail();
if (detail != null) {
SOAPFaultDetail newSOAPFaultDetail = soap12Factory.createSOAPFaultDetail(newSOAPFault);
Iterator<OMElement> iter = detail.getAllDetailEntries();
while (iter.hasNext()) {
OMElement detailEntry = iter.next();
iter.remove();
newSOAPFaultDetail.addDetailEntry(detailEntry);
}
newSOAPFault.setDetail(newSOAPFaultDetail);
}
} else {
itrBodyChildren.remove();
newEnvelope.getBody().addChild(omNode);
}
// if (omNode instanceof SOAPFault)
}
// while (itrBodyChildren.hasNext())
}
// if (clonedOldEnv.getBody() != null)
axisOutMsgCtx.setEnvelope(newEnvelope);
}
use of org.apache.axiom.om.OMNode in project carbon-business-process by wso2.
the class SOAPUtils method parseResponseFromRESTService.
public static org.apache.ode.bpel.iapi.Message parseResponseFromRESTService(BPELMessageContext partnerInvocationContext, PartnerRoleMessageExchange odePartnerMex) {
org.apache.ode.bpel.iapi.Message messageToODE = odePartnerMex.createMessage(odePartnerMex.getOperation().getOutput().getMessage().getQName());
BindingOperation bindingOp = getBindingOperation(partnerInvocationContext, odePartnerMex.getOperationName());
BindingOutput bindingOutPut = getBindingOutPut(bindingOp);
javax.wsdl.extensions.mime.MIMEContent mimeContent = getFirstExtensibilityElement(bindingOutPut, MIMEContent.class);
if (mimeContent != null) {
SOAPEnvelope soapEnv = partnerInvocationContext.getOutMessageContext().getEnvelope();
Iterator childElementsItr = soapEnv.getBody().getChildElements();
while (childElementsItr.hasNext()) {
OMNode child = (OMNode) childElementsItr.next();
if (child.getType() == OMNode.ELEMENT_NODE) {
Document doc = DOMUtils.newDocument();
Element domPart = doc.createElementNS(null, mimeContent.getPart());
domPart.appendChild(doc.importNode(OMUtils.toDOM((OMElement) child), true));
messageToODE.setPart(mimeContent.getPart(), domPart);
return messageToODE;
}
}
}
throw new IllegalArgumentException("WSO2 BPS only support HTTP binding with mime output.");
}
Aggregations