io.swagger.samples.inflector.dropwizard.controllers.SampleController.java Source code

Java tutorial

Introduction

Here is the source code for io.swagger.samples.inflector.dropwizard.controllers.SampleController.java

Source

/*
 *  Copyright 2016 SmartBear Software
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package io.swagger.samples.inflector.dropwizard.controllers;

import io.swagger.inflector.models.RequestContext;
import io.swagger.inflector.models.ResponseContext;
import io.swagger.samples.inflector.dropwizard.InflectorServerConfiguration;
import io.swagger.samples.inflector.dropwizard.models.Pet;
import org.apache.commons.io.IOUtils;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.Response.Status;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

@Singleton
public class SampleController {

    private final InflectorServerConfiguration configuration;

    @Inject
    public SampleController(InflectorServerConfiguration configuration) {
        this.configuration = configuration;
    }

    public ResponseContext addPet(RequestContext request, Pet body) {
        return new ResponseContext().status(Status.OK).entity(body);
    }

    public ResponseContext uploadFile(RequestContext request, Long petId, String additionalMetadata,
            java.io.InputStream file) {
        ByteArrayOutputStream outputStream;
        try {
            outputStream = new ByteArrayOutputStream();
            IOUtils.copy(file, outputStream);
            outputStream.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }
}