Search in sources :

Example 26 with Processor

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

the class WSDLProcessFactory method getWSDLProcessor.

/**
 * Returns the appropriate WSDL 1.1 or 2.0 processor based on the content {@code wsdlContent}.
 *
 * @param wsdlContent Content of the WSDL
 * @return WSDL 1.1 or 2.0 processor for the provided content
 * @throws APIMgtWSDLException If an error occurs while determining the processor
 */
public WSDLProcessor getWSDLProcessor(byte[] wsdlContent) throws APIMgtWSDLException {
    for (String clazz : getWSDLProcessorClasses()) {
        WSDLProcessor processor;
        try {
            processor = (WSDLProcessor) Class.forName(clazz).newInstance();
            boolean canProcess = processor.init(wsdlContent);
            if (canProcess) {
                return processor;
            }
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
        }
    }
    // no processors found if this line reaches
    throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 27 with Processor

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

the class WSDLProcessFactory method getWSDLProcessorForPath.

/**
 * Returns the appropriate WSDL 1.1 or 2.0 processor based on the file path {@code wsdlPath}.
 *
 * @param wsdlPath File path containing WSDL files and dependant files
 * @return WSDL 1.1 or 2.0 processor for the provided content
 * @throws APIMgtWSDLException If an error occurs while determining the processor
 */
public WSDLProcessor getWSDLProcessorForPath(String wsdlPath) throws APIMgtWSDLException {
    for (String clazz : getWSDLProcessorClasses()) {
        WSDLProcessor processor;
        try {
            processor = (WSDLProcessor) Class.forName(clazz).newInstance();
            boolean canProcess = processor.initPath(wsdlPath);
            if (canProcess) {
                return processor;
            }
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new APIMgtWSDLException("Error while instantiating " + clazz, e, ExceptionCodes.INTERNAL_WSDL_EXCEPTION);
        }
    }
    // no processors found if this line reaches
    throw new APIMgtWSDLException("No WSDL processor found to process WSDL content", ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

Example 28 with Processor

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

the class WSDLProcessFactoryTestcase method testGetWSDLProcessorForContent.

@Test
public void testGetWSDLProcessorForContent() throws Exception {
    byte[] wsdl11Content = SampleTestObjectCreator.createDefaultWSDL11Content();
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl11Content);
    Assert.assertTrue(processor instanceof WSDL11ProcessorImpl);
    byte[] wsdl20Content = SampleTestObjectCreator.createDefaultWSDL20Content();
    processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdl20Content);
    Assert.assertTrue(processor instanceof WSDL20ProcessorImpl);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) Test(org.testng.annotations.Test)

Example 29 with Processor

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

the class WSDLProcessFactoryTestcase method testGetWSDLProcessorForPath.

@Test
public void testGetWSDLProcessorForPath() throws Exception {
    String extractedLocation = SampleTestObjectCreator.createDefaultWSDL11Archive();
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
    Assert.assertTrue(processor instanceof WSDL11ProcessorImpl);
    extractedLocation = SampleTestObjectCreator.createDefaultWSDL20Archive();
    processor = WSDLProcessFactory.getInstance().getWSDLProcessorForPath(extractedLocation);
    Assert.assertTrue(processor instanceof WSDL20ProcessorImpl);
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) Test(org.testng.annotations.Test)

Example 30 with Processor

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

the class ThrottleStreamProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
    synchronized (this) {
        if (expireEventTime == -1) {
            long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
            if (startTime != -1) {
                expireEventTime = addTimeShift(currentTime);
            } else {
                expireEventTime = siddhiAppContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
            }
            if (scheduler != null) {
                scheduler.notifyAt(expireEventTime);
            } else {
                log.error("scheduler is not initiated");
            }
        }
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        boolean sendEvents;
        if (currentTime >= expireEventTime) {
            expireEventTime += timeInMilliSeconds;
            if (scheduler != null) {
                scheduler.notifyAt(expireEventTime);
            } else {
                log.error("scheduler is not initiated");
            }
            sendEvents = true;
        } else {
            sendEvents = false;
        }
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
                continue;
            }
            complexEventPopulater.populateComplexEvent(streamEvent, new Object[] { expireEventTime });
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedStreamEvent.setType(StreamEvent.Type.EXPIRED);
            clonedStreamEvent.setTimestamp(expireEventTime);
            expiredEventChunk.add(clonedStreamEvent);
        }
        if (sendEvents) {
            expiredEventChunk.reset();
            if (expiredEventChunk.getFirst() != null) {
                streamEventChunk.add(expiredEventChunk.getFirst());
            }
            expiredEventChunk.clear();
        }
    }
    if (streamEventChunk.getFirst() != null) {
        streamEventChunk.setBatch(true);
        nextProcessor.process(streamEventChunk);
        streamEventChunk.setBatch(false);
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

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