Search in sources :

Example 56 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLArchive.

@Override
public String addAPIFromWSDLArchive(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
    WSDLArchiveInfo archiveInfo = extractAndValidateWSDLArchive(inputStream);
    if (log.isDebugEnabled()) {
        log.debug("Successfully extracted and validated WSDL file. Location: " + archiveInfo.getAbsoluteFilePath());
    }
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(archiveInfo.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    try (InputStream fileInputStream = new FileInputStream(archiveInfo.getAbsoluteFilePath())) {
        getApiDAO().addOrUpdateWSDLArchive(uuid, fileInputStream, getUsername());
        if (log.isDebugEnabled()) {
            log.debug("Successfully added/updated the WSDL archive. uuid: " + uuid);
        }
        if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(archiveInfo.getWsdlInfo().getVersion())) {
            log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
        }
        return uuid;
    } catch (IOException e) {
        throw new APIMgtWSDLException("Unable to process WSDL archive at " + archiveInfo.getAbsoluteFilePath(), e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    } finally {
        try {
            APIFileUtils.deleteDirectory(archiveInfo.getLocation());
        } catch (APIMgtDAOException e) {
            // This is not a blocker. Give a warning and continue
            log.warn("Error occured while deleting processed WSDL artifacts folder : " + archiveInfo.getLocation());
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 57 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLFile.

@Override
public String addAPIFromWSDLFile(API.APIBuilder apiBuilder, InputStream inputStream, boolean isHttpBinding) throws APIManagementException {
    byte[] wsdlContent;
    try {
        wsdlContent = IOUtils.toByteArray(inputStream);
    } catch (IOException e) {
        throw new APIMgtWSDLException("Error while converting input stream to byte array", e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    getApiDAO().addOrUpdateWSDL(uuid, wsdlContent, getUsername());
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the WSDL file to database. API uuid: " + uuid);
    }
    if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(processor.getWsdlInfo().getVersion())) {
        log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
    }
    return uuid;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) IOException(java.io.IOException)

Example 58 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetDocumentationContentFile.

@Test(description = "Getting Documentation content when source type is FILE")
public void testGetDocumentationContentFile() throws APIManagementException {
    ApiDAO apiDAO = mock(ApiDAO.class);
    AbstractAPIManager apiPublisher = getApiPublisherImpl(apiDAO);
    DocumentInfo.Builder builder = new DocumentInfo.Builder();
    builder.name("CalculatorDoc");
    builder.sourceType(DocumentInfo.SourceType.FILE);
    DocumentInfo documentInfo = builder.build();
    when(apiDAO.getDocumentInfo(DOC_ID)).thenReturn(documentInfo);
    String stream = "This is sample file content";
    InputStream inputStream = new ByteArrayInputStream(stream.getBytes());
    when(apiDAO.getDocumentFileContent(DOC_ID)).thenReturn(inputStream);
    apiPublisher.getDocumentationContent(DOC_ID);
    verify(apiDAO, times(1)).getDocumentFileContent(DOC_ID);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 59 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.

the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdImplementationGet.

@Test
public void testCompositeApisApiIdImplementationGet() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String apiID = UUID.randomUUID().toString();
    CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    InputStream implementation = null;
    Mockito.when(apiStore.getCompositeApiImplementation(apiID)).thenReturn(implementation);
    Response response = compositeApisApiService.compositeApisApiIdImplementationGet(apiID, null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) Request(org.wso2.msf4j.Request) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 60 with InputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project carbon-apimgt by wso2.

the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdPut.

@Test
public void testCompositeApisApiIdPut() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String apiID = UUID.randomUUID().toString();
    CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    CompositeAPI.Builder builder = null;
    InputStream implmentation = null;
    FileInfo fileInfo = new FileInfo();
    fileInfo.setFileName("sample.txt");
    fileInfo.setContentType(contentType);
    Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateCompositeApi(builder);
    Response response = compositeApisApiService.compositeApisApiIdImplementationPut(apiID, implmentation, fileInfo, null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) FileInfo(org.wso2.msf4j.formparam.FileInfo) InputStream(java.io.InputStream) Request(org.wso2.msf4j.Request) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.testng.annotations.Test)80 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)67 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)58 InputStream (java.io.InputStream)54 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)54 Event (org.wso2.siddhi.core.event.Event)48 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)47 IOException (java.io.IOException)32 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 API (org.wso2.carbon.apimgt.core.models.API)18 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)17 FileInputStream (java.io.FileInputStream)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)13 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)12 Response (javax.ws.rs.core.Response)11 HashMap (java.util.HashMap)9 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 File (java.io.File)7 Connection (java.sql.Connection)7