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())));
}
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);
}
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);
}
}
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;
}
Aggregations