use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultStructure.
private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
SweAbstractDataComponent structure;
SosResultStructure rs = t.getResultStructure();
if (rs.isDecoded()) {
structure = t.getResultStructure().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (structure instanceof SweDataRecord) {
encodeSweDataRecord(structure, jrs);
} else {
LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
}
}
use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.
the class SwesDecoderv20 method parseInsertSensor.
private OwsServiceRequest parseInsertSensor(final InsertSensorDocument xbInsSensDoc) throws DecodingException {
final InsertSensorRequest request = new InsertSensorRequest();
final InsertSensorType xbInsertSensor = xbInsSensDoc.getInsertSensor();
request.setService(xbInsertSensor.getService());
request.setVersion(xbInsertSensor.getVersion());
// format
request.setProcedureDescriptionFormat(xbInsertSensor.getProcedureDescriptionFormat());
// observable properties
if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getObservablePropertyArray())) {
request.setObservableProperty(Arrays.asList(xbInsertSensor.getObservablePropertyArray()));
}
// related features
if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getRelatedFeatureArray())) {
request.setRelatedFeature(parseRelatedFeature(xbInsertSensor.getRelatedFeatureArray()));
}
// metadata
if (CollectionHelper.isNotNullOrEmpty(xbInsertSensor.getMetadataArray())) {
request.setMetadata(parseMetadata(xbInsertSensor.getMetadataArray()));
}
// extensions
request.setExtensions(parseExtensibleRequest(xbInsertSensor));
try {
final XmlObject xbProcedureDescription = XmlObject.Factory.parse(getNodeFromNodeList(xbInsertSensor.getProcedureDescription().getDomNode().getChildNodes()));
checkFormatWithNamespace(xbInsertSensor.getProcedureDescriptionFormat(), XmlHelper.getNamespace(xbProcedureDescription));
final Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(xbInsertSensor.getProcedureDescriptionFormat(), xbProcedureDescription.getClass()));
if (decoder != null) {
final Object decodedProcedureDescription = decoder.decode(xbProcedureDescription);
if (decodedProcedureDescription instanceof SosProcedureDescription) {
request.setProcedureDescription((SosProcedureDescription) decodedProcedureDescription);
} else if (decodedProcedureDescription instanceof AbstractFeature) {
request.setProcedureDescription(new SosProcedureDescription<>((AbstractFeature) decodedProcedureDescription));
}
}
} catch (final XmlException xmle) {
throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
}
return request;
}
use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.
the class AbstractSoapDecoder method getSoapHeader.
protected List<SoapHeader> getSoapHeader(SOAPHeader soapHeader) {
Map<String, List<SOAPHeaderElement>> headersByNamespace = new HashMap<>();
Iterator<?> headerElements = soapHeader.extractAllHeaderElements();
while (headerElements.hasNext()) {
SOAPHeaderElement element = (SOAPHeaderElement) headerElements.next();
headersByNamespace.computeIfAbsent(element.getNamespaceURI(), Functions.forSupplier(LinkedList::new)).add(element);
}
List<SoapHeader> soapHeaders = Lists.newArrayList();
for (Entry<String, List<SOAPHeaderElement>> key : headersByNamespace.entrySet()) {
String namespace = key.getKey();
try {
Decoder<?, List<SOAPHeaderElement>> decoder = getDecoder(new XmlNamespaceDecoderKey(namespace, SOAPHeaderElement.class));
if (decoder != null) {
Object object = decoder.decode(headersByNamespace.get(namespace));
if (object instanceof SoapHeader) {
soapHeaders.add((SoapHeader) object);
} else if (object instanceof List<?>) {
for (Object o : (List<?>) object) {
if (o instanceof SoapHeader) {
soapHeaders.add((SoapHeader) o);
}
}
}
} else {
LOGGER.info("The SOAP-Header elements for namespace '{}' are not supported by this server!", namespace);
}
} catch (DecodingException owse) {
LOGGER.debug("Requested SOAPHeader element is not supported", owse);
}
}
return soapHeaders;
}
use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.
the class UpdateSensorRequestDecoder method parseProcedureDesciption.
private SosProcedureDescription<?> parseProcedureDesciption(String xml, String pdf) throws DecodingException {
try {
final XmlObject xb = XmlObject.Factory.parse(xml);
Decoder<?, XmlObject> decoder = getDecoder(new XmlNamespaceDecoderKey(pdf, xb.getClass()));
if (decoder == null) {
throw new DecodingException(JSONConstants.PROCEDURE_DESCRIPTION_FORMAT, "The requested %s is not supported!", JSONConstants.PROCEDURE_DESCRIPTION_FORMAT);
}
Object decode = decoder.decode(xb);
if (decode instanceof SosProcedureDescription<?>) {
return (SosProcedureDescription<?>) decode;
} else if (decode instanceof AbstractFeature) {
return new SosProcedureDescription<AbstractFeature>((AbstractFeature) decode);
} else {
throw new DecodingException("The decoded element {} is not of type {}!", decode.getClass().getName(), AbstractFeature.class.getName());
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing procedure description of InsertSensor request!", xmle);
}
}
use of org.n52.svalbard.decode.XmlNamespaceDecoderKey in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultEncoding.
private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
SweAbstractEncoding encoding = null;
SosResultEncoding re = t.getResultEncoding();
if (re.isDecoded()) {
encoding = t.getResultEncoding().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (encoding instanceof SweTextEncoding) {
encodeSweTextEncoding(encoding, jre);
} else {
LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
}
}
Aggregations