use of org.w3.x2003.x05.soapEnvelope.Body in project arctic-sea by 52North.
the class Soap12Decoder method getBodyContent.
private OwsServiceRequest getBodyContent(EnvelopeDocument doc) throws DecodingException {
Body body = doc.getEnvelope().getBody();
try {
Node domNode = body.getDomNode();
if (domNode.hasChildNodes()) {
NodeList childNodes = domNode.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
XmlObject content = XmlObject.Factory.parse(node);
// fix problem with invalid prefix in xsi:type value for
// om:result, e.g. OM_SWEArrayObservation or
// gml:ReferenceType
Map<?, ?> namespaces = XmlHelper.getNamespaces(doc.getEnvelope());
fixNamespaceForXsiType(content, namespaces);
XmlHelper.fixNamespaceForXsiType(content, SweConstants.QN_DATA_ARRAY_PROPERTY_TYPE_SWE_200);
return decodeXmlElement(content);
}
}
}
return decodeXmlElement(body);
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing SOAP body element!", xmle);
}
}
use of org.w3.x2003.x05.soapEnvelope.Body in project camel by apache.
the class Soap12DataFormatAdapter method doMarshal.
@Override
public Object doMarshal(Exchange exchange, Object inputObject, OutputStream stream, String soapAction) throws IOException {
Body body = objectFactory.createBody();
Header header = objectFactory.createHeader();
Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
if (exception == null) {
exception = exchange.getIn().getHeader(Exchange.EXCEPTION_CAUGHT, Throwable.class);
}
final List<Object> bodyContent;
List<Object> headerContent = new ArrayList<Object>();
if (exception != null) {
bodyContent = new ArrayList<Object>();
bodyContent.add(createFaultFromException(exception));
} else {
if (!dataFormat.isIgnoreUnmarshalledHeaders()) {
List<Object> inboundSoapHeaders = (List<Object>) exchange.getIn().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
if (null != inboundSoapHeaders) {
headerContent.addAll(inboundSoapHeaders);
}
}
bodyContent = getDataFormat().createContentFromObject(inputObject, soapAction, headerContent);
}
for (Object elem : bodyContent) {
body.getAny().add(elem);
}
for (Object elem : headerContent) {
header.getAny().add(elem);
}
Envelope envelope = new Envelope();
if (headerContent.size() > 0) {
envelope.setHeader(header);
}
envelope.setBody(body);
JAXBElement<Envelope> envelopeEl = objectFactory.createEnvelope(envelope);
return envelopeEl;
}
use of org.w3.x2003.x05.soapEnvelope.Body in project arctic-sea by 52North.
the class Soap12Encoder method createSOAP12Envelope.
private XmlObject createSOAP12Envelope(SoapResponse response, EncodingContext additionalValues) throws EncodingException {
String action = null;
final EnvelopeDocument envelopeDoc = EnvelopeDocument.Factory.newInstance();
final Envelope envelope = envelopeDoc.addNewEnvelope();
final Body body = envelope.addNewBody();
if (response.getSoapFault() != null) {
body.set(createSOAP12Fault(response.getSoapFault()));
} else {
if (response.getException() != null) {
if (!response.getException().getExceptions().isEmpty()) {
final CodedException firstException = response.getException().getExceptions().get(0);
action = getExceptionActionURI(firstException.getCode());
}
body.set(createSOAP12FaultFromExceptionResponse(response.getException()));
N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, Sets.newHashSet(N52XmlHelper.getSchemaLocationForSOAP12(), N52XmlHelper.getSchemaLocationForOWS110Exception()));
} else {
action = response.getSoapAction();
final XmlObject bodyContent = getBodyContent(response);
String value = null;
Node nodeToRemove = null;
final NamedNodeMap attributeMap = bodyContent.getDomNode().getFirstChild().getAttributes();
for (int i = 0; i < attributeMap.getLength(); i++) {
final Node node = attributeMap.item(i);
if (node.getLocalName().equals(W3CConstants.AN_SCHEMA_LOCATION)) {
value = node.getNodeValue();
nodeToRemove = node;
}
}
if (nodeToRemove != null) {
attributeMap.removeNamedItem(nodeToRemove.getNodeName());
}
final Set<SchemaLocation> schemaLocations = Sets.newHashSet();
schemaLocations.add(N52XmlHelper.getSchemaLocationForSOAP12());
if (value != null && !value.isEmpty()) {
String[] split = value.split(" ");
for (int i = 0; i < split.length; i += 2) {
schemaLocations.add(new SchemaLocation(split[i], split[i + 1]));
}
}
N52XmlHelper.setSchemaLocationsToDocument(envelopeDoc, schemaLocations);
body.set(bodyContent);
}
}
if (response.getHeader() != null) {
createSOAP12Header(envelope, response.getHeader(), action);
} else {
envelope.addNewHeader();
}
// checkAndValidateSoapMessage(envelopeDoc);
return envelopeDoc;
}
Aggregations