@Override
    public Response getApiDefinition(String organizationId, String apiId, String version)
            throws ApiVersionNotFoundException, NotAuthorizedException {
        try {
            storage.beginTx();
            ApiVersionBean apiVersion = storage.getApiVersion(organizationId, apiId, version);
            if (apiVersion == null) {
                throw ExceptionFactory.apiVersionNotFoundException(apiId, version);
            }
            if (apiVersion.getDefinitionType() == ApiDefinitionType.None || apiVersion.getDefinitionType() == null) {
                throw ExceptionFactory.apiDefinitionNotFoundException(apiId, version);
            }
            InputStream definition = storage.getApiDefinition(apiVersion);
            if (definition == null) {
                throw ExceptionFactory.apiDefinitionNotFoundException(apiId, version);
            }
            ResponseBuilder builder = Response.ok().entity(definition);
            if (apiVersion.getDefinitionType() == ApiDefinitionType.SwaggerJSON) {
                builder.type(MediaType.APPLICATION_JSON);
            } else if (apiVersion.getDefinitionType() == ApiDefinitionType.SwaggerYAML) {
                builder.type("application/x-yaml"); //$NON-NLS-1$
            } else if (apiVersion.getDefinitionType() == ApiDefinitionType.WSDL) {
                builder.type("application/wsdl+xml"); //$NON-NLS-1$
            } else {
                IOUtils.closeQuietly(definition);
                throw new Exception("API definition type not supported: " + apiVersion.getDefinitionType()); //$NON-NLS-1$
            }
            storage.commitTx();
            return builder.build();
        } catch (AbstractRestException e) {
            storage.rollbackTx();
            throw e;
        } catch (Exception e) {
            storage.rollbackTx();
            throw new SystemErrorException(e);
        }
    }
@ Override public Response getApiDefinition ( String organizationId , String apiId , String version ) throws ApiVersionNotFoundException , NotAuthorizedException { try { storage . beginTx ( ) ; ApiVersionBean apiVersion = storage . getApiVersion ( organizationId , apiId , version ) ; if ( apiVersion == null ) { throw ExceptionFactory . apiVersionNotFoundException ( apiId , version ) ; } if ( apiVersion . getDefinitionType ( ) == ApiDefinitionType . None || apiVersion . getDefinitionType ( ) == null ) { throw ExceptionFactory . apiDefinitionNotFoundException ( apiId , version ) ; } InputStream definition = storage . getApiDefinition ( apiVersion ) ; if ( definition == null ) { throw ExceptionFactory . apiDefinitionNotFoundException ( apiId , version ) ; } ResponseBuilder builder = Response . ok ( ) . entity ( definition ) ; if ( apiVersion . getDefinitionType ( ) == ApiDefinitionType . SwaggerJSON ) { builder . type ( MediaType . APPLICATION_JSON ) ; } else if ( apiVersion . getDefinitionType ( ) == ApiDefinitionType . SwaggerYAML ) { builder . type ( "application/x-yaml" ) ; } else if ( apiVersion . getDefinitionType ( ) == ApiDefinitionType . WSDL ) { builder . type ( "application/wsdl+xml" ) ; } else { IOUtils . closeQuietly ( definition ) ; throw new Exception ( "API definition type not supported: " + apiVersion . getDefinitionType ( ) ) ; } storage . commitTx ( ) ; return builder . build ( ) ; } catch ( AbstractRestException e ) { storage . rollbackTx ( ) ; throw e ; } catch ( Exception e ) { storage . rollbackTx ( ) ; throw new SystemErrorException ( e ) ; } }
@see io.apiman.manager.api.rest.contract.IOrganizationResource#getApiDefinition(java.lang.String, java.lang.String, java.lang.String)