use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class SoapBinding method encodeSoapResponse.
private Object encodeSoapResponse(SoapChain chain) throws OwsExceptionReport, NoEncoderForKeyException {
EncoderKey key = new XmlEncoderKey(chain.getSoapResponse().getSoapNamespace(), chain.getSoapResponse().getClass());
Encoder<?, SoapResponse> encoder = getEncoder(key);
if (encoder != null) {
try {
return encoder.encode(chain.getSoapResponse());
} catch (OwsEncodingException ex) {
throw ex.getCause();
} catch (EncodingException ex) {
throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
} else {
NoEncoderForKeyException cause = new NoEncoderForKeyException(key);
throw new NoApplicableCodeException().withMessage(cause.getMessage()).causedBy(cause);
}
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class SoapBinding method checkSoapInjection.
/**
* Check if SoapHeader information is contained in the body response and add the header information to the
* {@link SoapResponse}
*
* @param chain SoapChain to check
*/
private void checkSoapInjection(SoapChain chain) {
if (chain.getBodyResponse() instanceof CommunicationObjectWithSoapHeader) {
CommunicationObjectWithSoapHeader soapHeaderObject = (CommunicationObjectWithSoapHeader) chain.getBodyResponse();
if (soapHeaderObject.isSetSoapHeader()) {
List<SoapHeader> headers = ((CommunicationObjectWithSoapHeader) chain.getSoapRequest()).getSoapHeader();
// TODO do things
chain.getSoapResponse().setHeader(checkSoapHeaders(headers));
}
}
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class SoapChainResponseWriter method write.
private void write(SoapChain chain, OutputStream out) throws EncodingException, IOException {
String namespace = chain.getSoapResponse().getSoapNamespace();
EncoderKey key = CodingHelper.getEncoderKey(namespace, chain.getSoapResponse());
Encoder<?, SoapResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new NoEncoderForKeyException(key);
}
write(encoder, chain, out);
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class Soap11Encoder method encode.
@Override
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public SOAPMessage encode(SoapResponse soapResponse, EncodingContext additionalValues) throws EncodingException {
if (soapResponse == null) {
throw new UnsupportedEncoderInputException(this, soapResponse);
}
String soapVersion = soapResponse.getSoapVersion();
SOAPMessage soapResponseMessage;
String action = null;
try {
soapResponseMessage = SoapHelper.getSoapMessageForProtocol(soapVersion);
if (soapResponse.getSoapFault() != null) {
createSOAPFault(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getSoapFault());
} else {
if (soapResponse.getException() != null) {
action = createSOAPFaultFromExceptionResponse(soapResponseMessage.getSOAPBody().addFault(), soapResponse.getException());
addSchemaLocationForExceptionToSOAPMessage(soapResponseMessage);
} else {
action = createSOAPBody(soapResponseMessage, soapResponse, soapResponse.getSoapAction());
}
}
if (soapResponse.getHeader() != null) {
List<SoapHeader> headers = soapResponse.getHeader();
for (SoapHeader header : headers) {
if (WsaConstants.NS_WSA.equals(header.getNamespace()) && header instanceof WsaActionHeader) {
((WsaHeader) header).setValue(action);
}
Encoder<Map<QName, String>, SoapHeader> encoder = getEncoder(CodingHelper.getEncoderKey(header.getNamespace(), header));
if (encoder != null) {
Map<QName, String> headerElements = encoder.encode(header);
for (Entry<QName, String> entry : headerElements.entrySet()) {
QName qName = entry.getKey();
soapResponseMessage.getSOAPHeader().addChildElement(qName).setTextContent(headerElements.get(qName));
}
}
}
} else {
soapResponseMessage.getSOAPHeader().detachNode();
}
soapResponseMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, String.valueOf(true));
return soapResponseMessage;
} catch (SOAPException soape) {
throw new EncodingException("Error while encoding SOAPMessage!", soape);
}
}
use of org.n52.shetland.w3c.soap.SoapResponse in project arctic-sea by 52North.
the class Soap12Encoder method encode.
@Override
public void encode(Object element, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
if (element instanceof SoapResponse) {
try {
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
new Soap12XmlStreamWriter(context, outputStream, (SoapResponse) element).write();
} catch (XMLStreamException ex) {
throw new EncodingException(ex);
}
} else {
try {
encode(element, ctx).save(outputStream, getXmlOptions());
} catch (IOException ioe) {
throw new EncodingException("Error while writing element to stream!", ioe);
}
}
}
Aggregations