use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApisPut.
/**
* Imports an updates a set of existing APIs which have been exported as a zip file
*
* @param fileInputStream content stream of the zip file which contains exported API(s)
* @param fileDetail meta information of the zip file
* @param provider provider of the API (if it needs to be updated)
* @param request ms4j request object
* @return List of APIs that were imported
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response importApisPut(InputStream fileInputStream, FileInfo fileDetail, String provider, Request request) throws NotFoundException {
APIPublisher publisher = null;
try {
publisher = RestAPIPublisherUtil.getApiPublisher(RestApiUtil.getLoggedInUsername(request));
FileBasedApiImportExportManager importManager = new FileBasedApiImportExportManager(publisher, System.getProperty("java.io.tmpdir") + File.separator + "imported-api-archives-" + UUID.randomUUID().toString());
APIListDTO apiList = importManager.importAPIs(fileInputStream, provider);
return Response.status(Response.Status.OK).entity(apiList).build();
} catch (APIManagementException e) {
String errorMessage = "Error while importing the APIs";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ImportApiServiceImpl method importApisPost.
/**
* Imports a set of new APIs which have been exported as a zip file
*
* @param fileInputStream content stream of the zip file which contains exported API(s)
* @param fileDetail meta information of the zip file
* @param provider provider of the API (if it needs to be updated)
* @param request ms4j request object
* @return List of APIs that were imported
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response importApisPost(InputStream fileInputStream, FileInfo fileDetail, String provider, Request request) throws NotFoundException {
APIPublisher publisher = null;
try {
publisher = RestAPIPublisherUtil.getApiPublisher(RestApiUtil.getLoggedInUsername(request));
FileBasedApiImportExportManager importManager = new FileBasedApiImportExportManager(publisher, System.getProperty("java.io.tmpdir") + File.separator + "imported-api-archives-" + UUID.randomUUID().toString());
APIListDTO apiList = importManager.importAndCreateAPIs(fileInputStream, provider);
return Response.status(Response.Status.OK).entity(apiList).build();
} catch (APIManagementException e) {
String errorMessage = "Error while importing the APIs";
log.error(errorMessage, e);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisValidateDefinitionPost.
/**
* Validates a provided API definition
*
* @param type API definition type (SWAGGER or WSDL)
* @param fileInputStream file content stream
* @param fileDetail file details
* @param url URL of the definition
* @param request msf4j request
* @return API definition validation information
* @throws NotFoundException
*/
@Override
public Response apisValidateDefinitionPost(String type, InputStream fileInputStream, FileInfo fileDetail, String url, Request request) throws NotFoundException {
String errorMessage = "Error while validating the definition";
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (StringUtils.isBlank(type)) {
type = APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString();
}
Response responseIfParamsInvalid = buildResponseIfParamsInvalid(type, fileInputStream, url);
if (responseIfParamsInvalid != null) {
return responseIfParamsInvalid;
}
if (APIDefinitionValidationResponseDTO.DefinitionTypeEnum.SWAGGER.toString().equals(type)) {
if (log.isDebugEnabled()) {
log.debug("Validating a swagger file.");
}
// TODO implement swagger validation
return Response.noContent().build();
} else {
// WSDL type
WSDLProcessor processor = null;
WSDLInfo info = null;
if (!StringUtils.isBlank(url)) {
processor = WSDLProcessFactory.getInstance().getWSDLProcessor(url);
info = processor.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL URL " + url);
}
} else {
if (fileDetail.getFileName().endsWith(".zip")) {
WSDLArchiveInfo archiveInfo = apiPublisher.extractAndValidateWSDLArchive(fileInputStream);
info = archiveInfo.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL archive " + fileDetail.getFileName());
}
} else if (fileDetail.getFileName().endsWith(".wsdl")) {
byte[] wsdlContent = IOUtils.toByteArray(fileInputStream);
processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
info = processor.getWsdlInfo();
if (log.isDebugEnabled()) {
log.debug("Successfully validated WSDL file " + fileDetail.getFileName());
}
} else {
String msg = "Unsupported extension type of file: " + fileDetail.getFileName();
log.error(msg);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(msg, 900700L, msg);
return Response.status(Response.Status.BAD_REQUEST).entity(errorDTO).build();
}
}
if (info != null) {
APIDefinitionValidationResponseDTO responseDTO = MappingUtil.toWSDLValidationResponseDTO(info);
return Response.ok(responseDTO).build();
}
APIDefinitionValidationResponseDTO responseDTO = new APIDefinitionValidationResponseDTO();
responseDTO.isValid(false);
return Response.ok().entity(responseDTO).build();
}
} catch (APIManagementException e) {
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (IOException e) {
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class FileBasedApplicationImportExportManager method importApplication.
/**
* Import a given Application from an InputStream
*
* @param uploadedAppArchiveInputStream Content stream of the zip file which contains exported Application
* @return the imported application
* @throws APIMgtEntityImportExportException
*/
public Application importApplication(InputStream uploadedAppArchiveInputStream) throws APIMgtEntityImportExportException {
String appArchiveLocation = path + File.separator + IMPORTED_APPLICATIONS_DIRECTORY_NAME + ".zip";
String archiveExtractLocation = null;
try {
archiveExtractLocation = extractUploadedArchiveApplication(uploadedAppArchiveInputStream, IMPORTED_APPLICATIONS_DIRECTORY_NAME, appArchiveLocation, path);
} catch (APIManagementException e) {
String errorMsg = "Error in accessing uploaded Application archive" + appArchiveLocation;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.APPLICATION_IMPORT_ERROR);
}
Application applicationDetails = parseApplicationFile(archiveExtractLocation);
return applicationDetails;
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImpl method compositeApisApiIdImplementationGet.
@Override
public Response compositeApisApiIdImplementationGet(String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String existingFingerprint = compositeApisApiIdImplementationGetFingerprint(apiId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
InputStream implementation = apiStore.getCompositeApiImplementation(apiId);
return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(implementation).build();
} catch (APIManagementException e) {
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations