use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class AbstractXmlBinding method getDecoderKey.
@VisibleForTesting
protected DecoderKey getDecoderKey(String xmlContent, String characterEncoding) throws CodedException {
try (ByteArrayInputStream stream = new ByteArrayInputStream(xmlContent.getBytes(characterEncoding))) {
// FIXME do not parse the complete request, if we only need the first element
Document document = documentFactory.newDocumentBuilder().parse(stream);
Element element = document.getDocumentElement();
// TODO is this REALLY needed!?
element.normalize();
if (element.hasAttributes() && element.hasAttribute(OWSConstants.RequestParams.service.name())) {
OwsOperationKey operationKey = getOperationKey(element);
XmlStringOperationDecoderKey decoderKey = new XmlStringOperationDecoderKey(operationKey, getDefaultContentType());
return decoderKey;
} else {
return getNamespaceOperationDecoderKey(element);
}
} catch (SAXException | IOException | ParserConfigurationException e) {
throw new NoApplicableCodeException().causedBy(e).withMessage("An error occured when parsing the request! Message: %s", e.getMessage());
}
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class AbstractSoapEncoder method createSOAPFaultFromExceptionResponse.
/**
* Creates a SOAPFault element from SOS exception
*
* @param soapFault SOAPFault element
* @param owsExceptionReport SOS exception
*
* @return SOAP action URI.
*
* @throws SOAPException if an error occurs.
*/
protected String createSOAPFaultFromExceptionResponse(SOAPFault soapFault, OwsExceptionReport owsExceptionReport) throws SOAPException {
// exceptions!
if (!owsExceptionReport.getExceptions().isEmpty()) {
CodedException firstException = owsExceptionReport.getExceptions().iterator().next();
if (soapFault.getNamespaceURI().equalsIgnoreCase(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
QName qname = new QName(soapFault.getNamespaceURI(), "Client", soapFault.getPrefix());
soapFault.setFaultCode(qname);
} else {
soapFault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
if (firstException.getCode() != null) {
soapFault.appendFaultSubcode(new QName(OWSConstants.NS_OWS, firstException.getCode().toString(), OWSConstants.NS_OWS_PREFIX));
} else {
soapFault.appendFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
}
}
soapFault.addFaultReasonText(SoapHelper.getSoapFaultReasonText(firstException.getCode()), Locale.ENGLISH);
Detail detail = soapFault.addDetail();
for (CodedException exception : owsExceptionReport.getExceptions()) {
createSOAPFaultDetail(detail, exception);
}
return getExceptionActionURI(firstException.getCode());
} else {
SoapFault fault = new SoapFault();
fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
fault.setFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
fault.setFaultReason(DEFAULT_FAULT_REASON);
fault.setLocale(Locale.ENGLISH);
fault.setDetailText(MISSING_EXCEPTION_DETAIL_TEXT);
createSOAPFault(soapFault, fault);
return SosSoapConstants.RESP_ACTION_SOS;
}
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method createMeasurementTimeseries.
/**
* Create a XML MeasurementTimeseries object from SOS observation for
* om:result
*
* @param sosObservation
* SOS observation
*
* @return XML MeasurementTimeseries object
*
* @throws CodedException
* if the encoding fails
*/
private XmlObject createMeasurementTimeseries(OmObservation sosObservation) throws OwsExceptionReport {
MeasurementTimeseriesDocument measurementTimeseriesDoc = MeasurementTimeseriesDocument.Factory.newInstance();
MeasurementTimeseriesType measurementTimeseries = measurementTimeseriesDoc.addNewMeasurementTimeseries();
measurementTimeseries.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
// Default value
TimeseriesMetadata timeseriesMetadata = new MeasurementTimeseriesMetadata().setCumulative(false);
if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getValue().getValue().getClass().isAssignableFrom(TVPValue.class) && sosObservation.getObservationConstellation().isSetMetadata() && sosObservation.getObservationConstellation().getMetadata().isSetTimeseriesMetadata()) {
timeseriesMetadata = sosObservation.getObservationConstellation().getMetadata().getTimeseriesmetadata();
}
addTimeseriesMetadata(measurementTimeseries, sosObservation.getPhenomenonTime().getGmlId(), timeseriesMetadata);
TVPDefaultMetadataPropertyType xbMetaComponent = measurementTimeseries.addNewDefaultPointMetadata();
DefaultTVPMeasurementMetadataDocument xbDefMeasureMetaComponent = DefaultTVPMeasurementMetadataDocument.Factory.newInstance();
TVPMeasurementMetadataType defaultTVPMeasurementMetadata = xbDefMeasureMetaComponent.addNewDefaultTVPMeasurementMetadata();
// Default value
InterpolationType interpolationType = InterpolationType.Continuous;
if (sosObservation.isSetValue() && sosObservation.getValue().isSetValue() && sosObservation.getObservationConstellation().isSetDefaultPointMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
interpolationType = sosObservation.getObservationConstellation().getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
}
defaultTVPMeasurementMetadata.addNewInterpolationType().setHref(interpolationType.getIdentifier());
xbDefMeasureMetaComponent.getDefaultTVPMeasurementMetadata().getInterpolationType().setTitle(interpolationType.getTitle());
String unit = addValues(measurementTimeseries, sosObservation.getValue());
// set uom
if (unit != null && !unit.isEmpty()) {
defaultTVPMeasurementMetadata.addNewUom().setCode(unit);
} else {
OmObservableProperty observableProperty = (OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty();
if (observableProperty.isSetUnit()) {
defaultTVPMeasurementMetadata.addNewUom().setCode(observableProperty.getUnit());
}
}
xbMetaComponent.set(xbDefMeasureMetaComponent);
return measurementTimeseriesDoc;
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method addValues.
private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
String time = getTimeString(singleObservationValue.getPhenomenonTime());
unit = singleObservationValue.getValue().getUnit();
String value = null;
if (singleObservationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (singleObservationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) singleObservationValue.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue());
}
} else if (singleObservationValue.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
TVPValue tvpValue = (TVPValue) mov.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
unit = tvpValue.getUnit();
for (TimeValuePair timeValuePair : timeValuePairs) {
String time = getTimeString(timeValuePair.getTime());
String value = null;
if (timeValuePair.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeValuePair.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
} else if (timeValuePair.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeValuePair.getValue();
if (countValue.isSetValue()) {
value = Integer.toString(countValue.getValue());
}
} else {
throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
}
}
return unit;
}
use of org.n52.shetland.ogc.ows.exception.CodedException in project arctic-sea by 52North.
the class Soap12Encoder method createSOAP12FaultFromExceptionResponse.
// see
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300
// for more details
private XmlObject createSOAP12FaultFromExceptionResponse(final OwsExceptionReport owsExceptionReport) throws EncodingException {
final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
final Fault fault = faultDoc.addNewFault();
final Faultcode code = fault.addNewCode();
code.setValue(SOAPConstants.SOAP_SENDER_FAULT);
// 19.2.3 SOAP 1.2 Fault Binding
if (!owsExceptionReport.getExceptions().isEmpty()) {
final CodedException firstException = owsExceptionReport.getExceptions().get(0);
final Subcode subcode = code.addNewSubcode();
QName qName;
if (firstException.getCode() != null) {
qName = OwsHelper.getQNameForLocalName(firstException.getCode().toString());
} else {
qName = OwsHelper.getQNameForLocalName(OwsExceptionCode.NoApplicableCode.name());
}
subcode.setValue(qName);
final Reasontext addNewText = fault.addNewReason().addNewText();
addNewText.setLang(Locale.ENGLISH.getLanguage());
addNewText.setStringValue(SoapHelper.getSoapFaultReasonText(firstException.getCode()));
fault.addNewDetail().set(encodeObjectToXml(OWSConstants.NS_OWS, firstException, EncodingContext.of(XmlBeansEncodingFlags.ENCODE_OWS_EXCEPTION_ONLY)));
}
return faultDoc;
}
Aggregations