Search in sources :

Example 31 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLURL.

@Override
public String addAPIFromWSDLURL(API.APIBuilder apiBuilder, String wsdlUrl, boolean isHttpBinding) throws APIManagementException {
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlUrl);
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    byte[] wsdlContentBytes = processor.getWSDL();
    getApiDAO().addOrUpdateWSDL(uuid, wsdlContentBytes, getUsername());
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the content of WSDL URL to database. WSDL URL: " + wsdlUrl);
    }
    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)

Example 32 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project carbon-apimgt by wso2.

the class APIStoreImpl method getAPIWSDLArchive.

@Override
public WSDLArchiveInfo getAPIWSDLArchive(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
    API api = getApiDAO().getAPI(apiId);
    if (api == null) {
        throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
    }
    // api.getLabels() should not be null and the labels should contain labelName
    if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
        throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
    }
    try (InputStream wsdlZipInputStream = getApiDAO().getWSDLArchive(apiId)) {
        String rootPath = System.getProperty(APIMgtConstants.JAVA_IO_TMPDIR) + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVES_FOLDERNAME + File.separator + UUID.randomUUID().toString();
        String archivePath = rootPath + File.separator + APIMgtConstants.WSDLConstants.WSDL_ARCHIVE_FILENAME;
        String extractedLocation = APIFileUtils.extractUploadedArchive(wsdlZipInputStream, APIMgtConstants.WSDLConstants.EXTRACTED_WSDL_ARCHIVE_FOLDERNAME, archivePath, rootPath);
        if (log.isDebugEnabled()) {
            log.debug("Successfully extracted WSDL archive in path: " + extractedLocation);
        }
        Label label = getLabelDAO().getLabelByName(labelName);
        WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
        String wsdlPath = processor.getUpdatedWSDLPath(api, label);
        if (log.isDebugEnabled()) {
            log.debug("Successfully updated WSDLs in path [" + extractedLocation + "] with endpoints of label: " + labelName + " and context of API " + api.getContext());
        }
        String wsdlArchiveProcessedFileName = api.getProvider() + "-" + api.getName() + "-" + api.getVersion() + "-" + labelName + "-wsdl";
        APIFileUtils.archiveDirectory(wsdlPath, rootPath, wsdlArchiveProcessedFileName);
        if (log.isDebugEnabled()) {
            log.debug("Successfully archived WSDL files: " + wsdlPath);
        }
        WSDLArchiveInfo archiveInfo = new WSDLArchiveInfo(rootPath, wsdlArchiveProcessedFileName + ".zip");
        archiveInfo.setWsdlInfo(processor.getWsdlInfo());
        return archiveInfo;
    } catch (IOException e) {
        throw new APIMgtWSDLException(e);
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Label(org.wso2.carbon.apimgt.core.models.Label) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) WSDLArchiveInfo(org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo) IOException(java.io.IOException) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APINotFoundException(org.wso2.carbon.apimgt.core.exception.APINotFoundException)

Example 33 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project carbon-apimgt by wso2.

the class APIStoreImpl method getAPIWSDL.

@Override
public String getAPIWSDL(String apiId, String labelName) throws APIMgtDAOException, APIMgtWSDLException, APINotFoundException, LabelException {
    API api = getApiDAO().getAPI(apiId);
    if (api == null) {
        throw new APINotFoundException("API with id " + apiId + " not found.", ExceptionCodes.API_NOT_FOUND);
    }
    // api.getLabels() should not be null and the labels should contain labelName
    if ((api.getLabels() == null || !api.getLabels().contains(labelName))) {
        throw new LabelException("API with id " + apiId + " does not contain label " + labelName, ExceptionCodes.LABEL_NOT_FOUND_IN_API);
    }
    String wsdl = getApiDAO().getWSDL(apiId);
    Label label = getLabelDAO().getLabelByName(labelName);
    if (!StringUtils.isEmpty(wsdl)) {
        WSDLProcessor processor;
        try {
            processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl.getBytes(APIMgtConstants.ENCODING_UTF_8));
            return new String(processor.getUpdatedWSDL(api, label), APIMgtConstants.ENCODING_UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new APIMgtWSDLException("WSDL content is not in utf-8 encoding", e, ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
        }
    }
    return null;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) Label(org.wso2.carbon.apimgt.core.models.Label) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelException(org.wso2.carbon.apimgt.core.exception.LabelException) APINotFoundException(org.wso2.carbon.apimgt.core.exception.APINotFoundException)

Example 34 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project carbon-apimgt by wso2.

the class APIPublisherImpl method updateAPIWSDL.

@Override
public String updateAPIWSDL(String apiId, InputStream inputStream) throws APIMgtDAOException, APIMgtWSDLException {
    byte[] wsdlContent;
    try {
        wsdlContent = IOUtils.toByteArray(inputStream);
        WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlContent);
        if (!processor.canProcess()) {
            throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
        }
        if (log.isDebugEnabled()) {
            log.debug("Successfully validated the content of WSDL. API uuid: " + apiId);
        }
        getApiDAO().addOrUpdateWSDL(apiId, wsdlContent, getUsername());
        if (log.isDebugEnabled()) {
            log.debug("Successfully added WSDL to the DB. API uuid: " + apiId);
        }
        return new String(wsdlContent, APIMgtConstants.ENCODING_UTF_8);
    } catch (IOException e) {
        throw new APIMgtWSDLException("Error while updating WSDL of API " + apiId, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
    }
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) IOException(java.io.IOException)

Example 35 with Processor

use of org.wso2.siddhi.core.query.processor.Processor in project siddhi by wso2.

the class QueryParserHelper method initSingleStreamRuntime.

private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex, MetaComplexEvent metaComplexEvent, StateEventPool stateEventPool, LockWrapper lockWrapper, String queryName) {
    MetaStreamEvent metaStreamEvent;
    if (metaComplexEvent instanceof MetaStateEvent) {
        metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
    }
    StreamEventPool streamEventPool = new StreamEventPool(metaStreamEvent, 5);
    ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
    processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
    processStreamReceiver.setStreamEventPool(streamEventPool);
    processStreamReceiver.setLockWrapper(lockWrapper);
    processStreamReceiver.init();
    Processor processor = singleStreamRuntime.getProcessorChain();
    while (processor != null) {
        if (processor instanceof SchedulingProcessor) {
            ((SchedulingProcessor) processor).getScheduler().setStreamEventPool(streamEventPool);
            ((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
        }
        if (processor instanceof AbstractStreamProcessor) {
            ((AbstractStreamProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
            ((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent, streamEventChainIndex);
        }
        if (stateEventPool != null && processor instanceof JoinProcessor) {
            if (((JoinProcessor) processor).getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
                IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) ((JoinProcessor) processor).getCompiledCondition();
                ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
                compiledCondition.setComplexEventPopulater(complexEventPopulater);
            }
            ((JoinProcessor) processor).setStateEventPool(stateEventPool);
            ((JoinProcessor) processor).setJoinLock(lockWrapper);
        }
        if (stateEventPool != null && processor instanceof StreamPreStateProcessor) {
            ((StreamPreStateProcessor) processor).setStateEventPool(stateEventPool);
            ((StreamPreStateProcessor) processor).setStreamEventPool(streamEventPool);
            ((StreamPreStateProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((StreamPreStateProcessor) processor).setStateEventCloner(new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventPool));
            }
        }
        processor = processor.getNextProcessor();
    }
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) Processor(org.wso2.siddhi.core.query.processor.Processor) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) IncrementalAggregateCompileCondition(org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(org.wso2.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)15 WSDLProcessor (org.wso2.carbon.apimgt.core.api.WSDLProcessor)11 APIMgtWSDLException (org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)8 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)6 Processor (org.wso2.siddhi.core.query.processor.Processor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)5 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)5 Test (org.testng.annotations.Test)4 API (org.wso2.carbon.apimgt.core.models.API)4 Label (org.wso2.carbon.apimgt.core.models.Label)4 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 SiddhiAppRuntimeException (org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)4 WindowProcessor (org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor)4 WSDLArchiveInfo (org.wso2.carbon.apimgt.core.models.WSDLArchiveInfo)3 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)3 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 SchedulingProcessor (org.wso2.siddhi.core.query.processor.SchedulingProcessor)3