use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class SoapBinding method createSoapResponse.
// private void parseBodyRequest(SoapChain chain) throws OwsExceptionReport,
// OwsExceptionReport {
//
// final XmlObject xmlObject = chain.getSoapRequest().getSoapBodyContent();
// DecoderKey key = CodingHelper.getDecoderKey(xmlObject);
// final Decoder<?, XmlObject> bodyDecoder = getDecoder(key);
// if (bodyDecoder == null) {
// throw new NoDecoderForKeyException(key).setStatus(BAD_REQUEST);
// }
// final Object aBodyRequest = bodyDecoder.decode(xmlObject);
// if (!(aBodyRequest instanceof AbstractServiceRequest)) {
// throw new NoApplicableCodeException().withMessage(
// "The returned object is not an AbstractServiceRequest implementation").setStatus(BAD_REQUEST);
// }
// AbstractServiceRequest bodyRequest = (AbstractServiceRequest)
// aBodyRequest;
// bodyRequest.setRequestContext(getRequestContext(chain.getHttpRequest()));
// if (bodyRequest instanceof CommunicationObjectWithSoapHeader) {
// ((CommunicationObjectWithSoapHeader)
// bodyRequest).setSoapHeader(chain.getSoapRequest().getSoapHeader());
// }
// chain.setBodyRequest(bodyRequest);
// }
private void createSoapResponse(SoapChain chain) {
SoapResponse soapResponse = new SoapResponse();
soapResponse.setSoapVersion(chain.getSoapRequest().getSoapVersion());
soapResponse.setSoapNamespace(chain.getSoapRequest().getSoapNamespace());
soapResponse.setHeader(checkSoapHeaders(chain.getSoapRequest().getSoapHeader()));
chain.setSoapResponse(soapResponse);
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class AbstractSoapEncoder method getBodyContent.
/**
* Get the content for the SOAPBody as {@link XmlObject}
*
* @param response SOAP response
*
* @return SOAPBody content as {@link XmlObject}
*
* @throws EncodingException If no encoder is available, the object to encode is not supported or an error occurs
* during the encoding
*/
protected XmlObject getBodyContent(SoapResponse response) throws EncodingException {
OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response.getBodyContent()), MediaTypes.APPLICATION_XML);
Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new NoEncoderForKeyException(key);
}
return (XmlObject) encoder.encode(response.getBodyContent());
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class Soap12XmlStreamWriter method writeSoapBody.
/**
* Write the SOAP 1.2 body element
*
* @throws XMLStreamException If an error occurs when writing to {@link OutputStream}
* @throws EncodingException If an encoding error occurs
*/
protected void writeSoapBody() throws XMLStreamException, EncodingException {
start(SoapConstants.SOAP_12_BODY);
SoapResponse response = getElement();
if (response != null) {
if (response.isSetSoapFault()) {
writeSoapFault(response.getSoapFault());
} else if (response.hasException()) {
writeSoapFaultFromException(response.getException());
} else if (response.isSetBodyContent()) {
writeBodyContent(response.getBodyContent());
}
}
end(SoapConstants.SOAP_12_BODY);
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class Soap12XmlStreamWriter method getSchemaLocation.
protected Set<SchemaLocation> getSchemaLocation() throws EncodingException, XMLStreamException {
SoapResponse response = getElement();
Set<SchemaLocation> schemaLocations = Sets.newHashSet();
schemaLocations.add(SoapConstants.SOAP_12_SCHEMA_LOCATION);
if (response.isSetBodyContent()) {
Encoder<Object, OwsServiceResponse> encoder = getEncoder(response.getBodyContent());
if (encoder != null && encoder instanceof SchemaAwareEncoder) {
schemaLocations.addAll(((SchemaAwareEncoder<?, ?>) encoder).getSchemaLocations());
}
}
return schemaLocations;
}
use of org.n52.shetland.w3c.soap.SoapResponse 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