use of org.n52.shetland.ogc.ows.service.OwsOperationKey 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.service.OwsOperationKey in project arctic-sea by 52North.
the class AbstractOperationHandler method getRequestMethodsForServiceURL.
private Stream<OwsRequestMethod> getRequestMethodsForServiceURL(OwsOperationKey operation) {
Map<String, Set<OwsValue>> mediaTypesByMethod = new HashMap<>(HTTPMethods.METHODS.size());
this.bindingRepository.getBindings().values().stream().forEach(binding -> HTTPMethods.METHODS.stream().filter(isMethodSupported(binding, operation)).forEach(method -> mediaTypesByMethod.computeIfAbsent(method, Functions.forSupplier(HashSet::new)).addAll(getMediaTypes(binding))));
return mediaTypesByMethod.entrySet().stream().map(e -> new OwsRequestMethod(this.serviceURL, e.getKey(), createContentTypeDomains(e.getValue())));
}
use of org.n52.shetland.ogc.ows.service.OwsOperationKey in project arctic-sea by 52North.
the class SimpleBindingTest method mockEncoderRepository.
@SuppressWarnings({ "rawtypes", "unchecked" })
private EncoderRepository mockEncoderRepository() {
EncoderRepository encoderRepository = mock(EncoderRepository.class);
OwsOperationKey operationKey = new OwsOperationKey(response);
OperationResponseEncoderKey operationEncoderKey = new OperationResponseEncoderKey(operationKey, MediaTypes.APPLICATION_JSON);
Encoder encoder = Mockito.mock(Encoder.class);
when(encoderRepository.getEncoder(operationEncoderKey)).thenReturn(encoder);
return encoderRepository;
}
use of org.n52.shetland.ogc.ows.service.OwsOperationKey in project arctic-sea by 52North.
the class AbstractAqdResponseEncoder method getEncoder.
/**
* Get the {@link Encoder} for the {@link OwsServiceResponse} and the
* requested contentType
*
* @param asr
* {@link OwsServiceResponse} to get {@link Encoder} for
* @return {@link Encoder} for the {@link OwsServiceResponse}
*/
protected Encoder<Object, OwsServiceResponse> getEncoder(OwsServiceResponse asr) {
OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(asr), getContentType());
Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new RuntimeException(new NoEncoderForKeyException(key));
}
return encoder;
}
use of org.n52.shetland.ogc.ows.service.OwsOperationKey in project arctic-sea by 52North.
the class SimpleBinding method encodeResponse.
protected Object encodeResponse(OwsServiceResponse response, MediaType contentType) throws OwsExceptionReport {
try {
OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response), contentType);
Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new NoEncoderForKeyException(key);
}
return encoder.encode(response);
} catch (EncodingException ex) {
throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
}
Aggregations