Search in sources :

Example 1 with OwsOperationKey

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());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) Element(org.w3c.dom.Element) XmlStringOperationDecoderKey(org.n52.svalbard.decode.XmlStringOperationDecoderKey) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) SAXException(org.xml.sax.SAXException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with OwsOperationKey

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())));
}
Also used : Binding(org.n52.iceland.binding.Binding) HTTPException(org.n52.iceland.exception.HTTPException) ConfigurationError(org.n52.faroe.ConfigurationError) HashMap(java.util.HashMap) OwsDCP(org.n52.shetland.ogc.ows.OwsDCP) MediaType(org.n52.janmayen.http.MediaType) I18NSettings(org.n52.iceland.i18n.I18NSettings) OwsAllowedValues(org.n52.shetland.ogc.ows.OwsAllowedValues) HashSet(java.util.HashSet) Inject(javax.inject.Inject) BindingRepository(org.n52.iceland.binding.BindingRepository) Locale(java.util.Locale) Map(java.util.Map) Validation(org.n52.faroe.Validation) URI(java.net.URI) OwsRequestMethod(org.n52.shetland.ogc.ows.OwsRequestMethod) Functions(org.n52.janmayen.function.Functions) OwsValue(org.n52.shetland.ogc.ows.OwsValue) Collectors.toSet(java.util.stream.Collectors.toSet) MediaTypeBindingKey(org.n52.iceland.binding.MediaTypeBindingKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) Predicate(java.util.function.Predicate) Set(java.util.Set) Setting(org.n52.faroe.annotation.Setting) LocaleHelper(org.n52.janmayen.i18n.LocaleHelper) OwsMetadata(org.n52.shetland.ogc.ows.OwsMetadata) HTTPMethods(org.n52.janmayen.http.HTTPMethods) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OwsServiceRequest(org.n52.shetland.ogc.ows.service.OwsServiceRequest) Objects(java.util.Objects) Stream(java.util.stream.Stream) OwsHttp(org.n52.shetland.ogc.ows.OwsHttp) HTTPHeaders(org.n52.janmayen.http.HTTPHeaders) Optional(java.util.Optional) Configurable(org.n52.faroe.annotation.Configurable) PathBindingKey(org.n52.iceland.binding.PathBindingKey) ServiceSettings(org.n52.iceland.service.ServiceSettings) OwsOperation(org.n52.shetland.ogc.ows.OwsOperation) Collections(java.util.Collections) OwsDomain(org.n52.shetland.ogc.ows.OwsDomain) HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HashMap(java.util.HashMap) OwsRequestMethod(org.n52.shetland.ogc.ows.OwsRequestMethod) HashSet(java.util.HashSet)

Example 3 with OwsOperationKey

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;
}
Also used : Encoder(org.n52.svalbard.encode.Encoder) EncoderRepository(org.n52.svalbard.encode.EncoderRepository) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey)

Example 4 with OwsOperationKey

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;
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) XmlObject(org.apache.xmlbeans.XmlObject) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 5 with OwsOperationKey

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);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Aggregations

OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)7 XmlObject (org.apache.xmlbeans.XmlObject)3 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)3 OperationResponseEncoderKey (org.n52.svalbard.encode.OperationResponseEncoderKey)2 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1