use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class AbstractXmlBindingTest method test_SoapPrefix.
@Test
public void test_SoapPrefix() throws CodedException {
DecoderKey decoderKey = binding.getDecoderKey(xmlStringSoapPrefix, characterEncoding);
assertTrue(decoderKey instanceof XmlNamespaceOperationDecoderKey);
assertTrue(SoapConstants.NS_SOAP_12.equals(((XmlNamespaceOperationDecoderKey) decoderKey).getNamespace()));
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class OwsExceptionReportDecoder method decode.
private OwsExceptionReport decode(ExceptionReport report) {
String version = report.getVersion();
ExceptionType[] exceptionTypes = report.getExceptionArray();
List<CodedException> exceptions = Streams.stream(exceptionTypes).map(this::decode).collect(toList());
return new CompositeOwsException(exceptions).setVersion(version);
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class OwsEncoderv110 method encodeOwsException.
@SuppressFBWarnings("DM_DEFAULT_ENCODING")
private ExceptionDocument encodeOwsException(CodedException owsException) {
ExceptionDocument exceptionDoc = ExceptionDocument.Factory.newInstance(getXmlOptions());
ExceptionType exceptionType = exceptionDoc.addNewException();
String exceptionCode;
if (owsException.getCode() == null) {
exceptionCode = OwsExceptionCode.NoApplicableCode.toString();
} else {
exceptionCode = owsException.getCode().toString();
}
exceptionType.setExceptionCode(exceptionCode);
if (owsException.getLocator() != null) {
exceptionType.setLocator(owsException.getLocator());
}
final StringBuilder exceptionText = new StringBuilder();
if (owsException.getMessage() != null) {
exceptionText.append(owsException.getMessage());
exceptionText.append("\n");
}
if (owsException.getCause() != null) {
exceptionText.append("[EXEPTION]: \n");
final String localizedMessage = owsException.getCause().getLocalizedMessage();
final String message = owsException.getCause().getMessage();
if (localizedMessage != null && message != null) {
if (!message.equals(localizedMessage)) {
exceptionText.append(message).append('\n');
}
exceptionText.append(localizedMessage).append('\n');
} else if (localizedMessage != null) {
exceptionText.append(localizedMessage).append('\n');
} else if (message != null) {
exceptionText.append(message).append('\n');
}
if (includeStackTraceInExceptionReport) {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
owsException.getCause().printStackTrace(new PrintStream(os));
exceptionText.append(os.toString());
}
}
exceptionType.addExceptionText(exceptionText.toString());
return exceptionDoc;
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class OwsExceptionReportEncoder method encodeJSON.
@Override
public JsonNode encodeJSON(OwsExceptionReport t) throws JSONEncodingException {
final ObjectNode exceptionReport = Json.nodeFactory().objectNode();
exceptionReport.put(JSONConstants.VERSION, t.getVersion());
final ArrayNode exceptions = exceptionReport.putArray(JSONConstants.EXCEPTIONS);
for (CodedException ce : t.getExceptions()) {
final ObjectNode exception = exceptions.addObject();
exception.put(JSONConstants.CODE, ce.getCode() != null ? ce.getCode().toString() : OwsExceptionCode.NoApplicableCode.toString());
if (ce.getLocator() != null && !ce.getLocator().isEmpty()) {
exception.put(JSONConstants.LOCATOR, ce.getLocator());
}
final String message = getExceptionText(ce);
if (message != null && !message.isEmpty()) {
exception.put(JSONConstants.TEXT, message);
}
if (log.isDebugEnabled()) {
exception.set(STACK_TRACE, encodeStackTrace(ce));
}
}
return exceptionReport;
}
use of org.n52.shetland.ogc.ows.exception.CodedException 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