Search in sources :

Example 1 with Binding

use of org.n52.iceland.binding.Binding 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 2 with Binding

use of org.n52.iceland.binding.Binding in project arctic-sea by 52North.

the class Service method getBinding.

/**
 * Get the implementation of {@link Binding} that is registered for the given <code>request</code>.
 *
 * @param request URL pattern from request URL
 *
 * @return The implementation of {@link Binding} that is registered for the given <code>urlPattern</code>.
 *
 * @throws HTTPException If the URL pattern or ContentType is not supported by this service.
 */
private Binding getBinding(HttpServletRequest request) throws HTTPException {
    final String requestURI = request.getPathInfo();
    if (requestURI == null || requestURI.isEmpty() || requestURI.equals("/")) {
        MediaType contentType = getContentType(request);
        // strip of the parameters to get rid of things like encoding
        Binding binding = this.bindingRepository.getBinding(contentType.withoutParameters());
        if (binding == null) {
            if (contentType.equals(MediaTypes.APPLICATION_KVP)) {
                throw new HTTPException(HTTPStatus.METHOD_NOT_ALLOWED);
            } else {
                throw new HTTPException(HTTPStatus.UNSUPPORTED_MEDIA_TYPE);
            }
        } else {
            if (requestTimeout > 0) {
                try {
                    return TIME_LIMITER.newProxy(binding, Binding.class, requestTimeout, TimeUnit.SECONDS);
                } catch (UncheckedTimeoutException ute) {
                    HTTPException httpException = new HTTPException(HTTPStatus.GATEWAY_TIME_OUT);
                    httpException.addSuppressed(ute);
                    throw httpException;
                }
            }
            return binding;
        }
    }
    throw new HTTPException(HTTPStatus.NOT_FOUND);
}
Also used : Binding(org.n52.iceland.binding.Binding) HTTPException(org.n52.iceland.exception.HTTPException) MediaType(org.n52.janmayen.http.MediaType) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException)

Example 3 with Binding

use of org.n52.iceland.binding.Binding in project arctic-sea by 52North.

the class Service method options.

@RequestMapping(method = RequestMethod.OPTIONS)
private void options(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    Binding binding = null;
    try {
        binding = getBinding(request);
        binding.doOptionsOperation(request, response);
    } catch (HTTPException exception) {
        if (exception.getStatus() == HTTPStatus.METHOD_NOT_ALLOWED && binding != null) {
            doDefaultOptions(binding, request, response);
        } else {
            onHttpException(request, response, exception);
        }
    } finally {
        logResponse(request, response, currentCount, stopwatch);
    }
}
Also used : Binding(org.n52.iceland.binding.Binding) HTTPException(org.n52.iceland.exception.HTTPException) Stopwatch(com.google.common.base.Stopwatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Binding

use of org.n52.iceland.binding.Binding 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;
}
Also used : Faultcode(org.w3.x2003.x05.soapEnvelope.Faultcode) Subcode(org.w3.x2003.x05.soapEnvelope.Subcode) FaultDocument(org.w3.x2003.x05.soapEnvelope.FaultDocument) Reasontext(org.w3.x2003.x05.soapEnvelope.Reasontext) CodedException(org.n52.shetland.ogc.ows.exception.CodedException) QName(javax.xml.namespace.QName) SoapFault(org.n52.shetland.w3c.soap.SoapFault) Fault(org.w3.x2003.x05.soapEnvelope.Fault)

Aggregations

Binding (org.n52.iceland.binding.Binding)3 HTTPException (org.n52.iceland.exception.HTTPException)3 MediaType (org.n52.janmayen.http.MediaType)2 Stopwatch (com.google.common.base.Stopwatch)1 UncheckedTimeoutException (com.google.common.util.concurrent.UncheckedTimeoutException)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 Inject (javax.inject.Inject)1 QName (javax.xml.namespace.QName)1 ConfigurationError (org.n52.faroe.ConfigurationError)1