use of org.n52.svalbard.decode.Decoder 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.Decoder in project arctic-sea by 52North.
the class AbstractStringRequestDecoder method decode.
@Override
public OwsServiceCommunicationObject decode(String string) throws DecodingException {
XmlObject xml = CodingHelper.readXML(string);
DecoderKey key = CodingHelper.getDecoderKey(xml);
Decoder<OwsServiceCommunicationObject, XmlObject> decoder = decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
return decoder.decode(xml);
}
use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.
the class GetFeatureOfInterestResponseDecoderTest method testMultiCurve.
@Test
public void testMultiCurve() throws XmlException, IOException, DecodingException {
try {
XmlObject xml = XmlObject.Factory.parse(getClass().getResourceAsStream("/GetFeatureOfInterestResponse.xml"));
DecoderKey decoderKey = CodingHelper.getDecoderKey(xml);
System.out.println(decoderKey);
Decoder<GetFeatureOfInterestResponse, XmlObject> decoder = decoderRepository.getDecoder(decoderKey);
GetFeatureOfInterestResponse response = decoder.decode(xml);
assertThat(response, is(notNullValue()));
assertThat(response.getAbstractFeature(), is(instanceOf(FeatureCollection.class)));
FeatureCollection abstractFeature = (FeatureCollection) response.getAbstractFeature();
assertThat(abstractFeature.getMembers().size(), is(266));
System.out.println("feature: " + response.getAbstractFeature());
} catch (Throwable t) {
t.printStackTrace(System.out);
throw t;
}
}
use of org.n52.svalbard.decode.Decoder in project arctic-sea by 52North.
the class BatchRequestDecoder method getDecoder.
private Decoder<OwsServiceRequest, JsonNode> getDecoder(JsonNode n) throws DecodingException {
String service = n.path(JSONConstants.SERVICE).textValue();
String version = n.path(JSONConstants.VERSION).textValue();
String request = n.path(JSONConstants.REQUEST).textValue();
OperationDecoderKey k = new OperationDecoderKey(service, version, request, MediaTypes.APPLICATION_JSON);
Decoder<OwsServiceRequest, JsonNode> decoder = getDecoder(k);
if (decoder == null) {
// TODO other exception?
throw new NoDecoderForKeyException(k);
}
return decoder;
}
use of org.n52.svalbard.decode.Decoder 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);
}
}
Aggregations