All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.bard.webservice.web.FiliResponseWriter Maven / Gradle / Ivy

Go to download

Fili web service library provides core capabilities for RESTful aggregation navigation, query planning and metadata

There is a newer version: 1.1.13
Show newest version
// Copyright 2017 Oath Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.web;

import com.yahoo.bard.webservice.web.apirequest.ApiRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.OutputStream;


/**
 * Default writer for response. FiliResponseWriter choose a proper writer type using FiliResponseWriterSelector.
 */
public class FiliResponseWriter implements ResponseWriter {

    private final ResponseWriterSelector responseWriterSelector;
    private static final Logger LOG = LoggerFactory.getLogger(FiliResponseWriter.class);

    /**
     * Constructor.
     *
     * @param responseWriterSelector A strategy for deciding which ResponseWriter to use to serialize the ResultSet.
     */
    public FiliResponseWriter(ResponseWriterSelector responseWriterSelector) {
        this.responseWriterSelector = responseWriterSelector;
    }

    @Override
    public void write(
            ApiRequest request,
            ResponseData responseData,
            OutputStream os) throws IOException {
        responseWriterSelector.select(request).orElseThrow(() -> {
            String errorMsg = "Format type " + request.getFormat() + " is not recognized.";
            LOG.error(errorMsg);
            return new IllegalArgumentException(errorMsg);
        }).write(request, responseData, os);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy