Search in sources :

Example 31 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project ballerina by ballerina-lang.

the class MatchStatementScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition          Position of the node
 * @param node                  Node
 * @param treeVisitor           {@link TreeVisitor} current tree visitor instance
 * @param completionContext     Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangMatch)) {
        // In the ideal case, this will not get triggered
        return false;
    }
    BLangMatch matchNode = (BLangMatch) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos matchNodePos = CommonUtil.toZeroBasedPosition(matchNode.getPosition());
    DiagnosticPos nodePos = CommonUtil.toZeroBasedPosition((DiagnosticPos) node.getPosition());
    List<BLangMatch.BLangMatchStmtPatternClause> patternClauseList = matchNode.getPatternClauses();
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    int nodeLine = nodePos.getStartLine();
    int nodeCol = nodePos.getStartColumn();
    boolean isBeforeNode = false;
    if ((line < nodeLine) || (line == nodeLine && col < nodeCol)) {
        isBeforeNode = true;
    } else if (patternClauseList.indexOf(node) == patternClauseList.size() - 1) {
        isBeforeNode = (line < matchNodePos.getEndLine()) || (line == matchNodePos.getEndLine() && col < matchNodePos.getEndColumn());
    }
    if (isBeforeNode) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        SymbolEnv matchEnv = createMatchEnv(matchNode, treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, matchEnv);
        treeVisitor.setTerminateVisitor(true);
    }
    return isBeforeNode;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 32 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project ballerina by ballerina-lang.

the class ObjectTypeScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition      Position of the node
 * @param node              Node
 * @param treeVisitor       {@link TreeVisitor} current tree visitor instance
 * @param completionContext Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangObject)) {
        return false;
    }
    BLangObject ownerObject = (BLangObject) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    DiagnosticPos blockOwnerPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) treeVisitor.getBlockOwnerStack().peek().getPosition());
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    boolean isLastField = false;
    if ((!ownerObject.fields.isEmpty() && node instanceof BLangVariable && ownerObject.fields.indexOf(node) == ownerObject.fields.size() - 1 && ownerObject.functions.isEmpty()) || (!ownerObject.functions.isEmpty() && node instanceof BLangFunction && ownerObject.functions.indexOf(node) == ownerObject.functions.size() - 1)) {
        isLastField = true;
    }
    if ((line < zeroBasedPos.getStartLine() || (line == zeroBasedPos.getStartLine() && col < zeroBasedPos.getStartColumn())) || (isLastField && ((blockOwnerPos.getEndLine() > line && zeroBasedPos.getEndLine() < line) || (blockOwnerPos.getEndLine() == line && blockOwnerPos.getEndColumn() > col)))) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, null);
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 33 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project ballerina by ballerina-lang.

the class CreateHttpClient method populateSenderConfigurationOptions.

private void populateSenderConfigurationOptions(SenderConfiguration senderConfiguration, Struct clientEndpointConfig) {
    ProxyServerConfiguration proxyServerConfiguration = null;
    boolean followRedirect = false;
    int maxRedirectCount = DEFAULT_MAX_REDIRECT_COUNT;
    Struct followRedirects = clientEndpointConfig.getStructField(HttpConstants.FOLLOW_REDIRECT_STRUCT_REFERENCE);
    if (followRedirects != null) {
        followRedirect = followRedirects.getBooleanField(HttpConstants.FOLLOW_REDIRECT_ENABLED);
        maxRedirectCount = (int) followRedirects.getIntField(HttpConstants.FOLLOW_REDIRECT_MAXCOUNT);
    }
    Struct secureSocket = null;
    Value[] targetServices = clientEndpointConfig.getArrayField(HttpConstants.TARGET_SERVICES);
    for (Value targetService : targetServices) {
        secureSocket = targetService.getStructValue().getStructField(HttpConstants.ENDPOINT_CONFIG_SECURE_SOCKET);
        if (secureSocket != null) {
            Struct trustStore = secureSocket.getStructField(HttpConstants.ENDPOINT_CONFIG_TRUST_STORE);
            Struct keyStore = secureSocket.getStructField(HttpConstants.ENDPOINT_CONFIG_KEY_STORE);
            Struct protocols = secureSocket.getStructField(HttpConstants.ENDPOINT_CONFIG_PROTOCOLS);
            Struct validateCert = secureSocket.getStructField(HttpConstants.ENDPOINT_CONFIG_VALIDATE_CERT);
            List<Parameter> clientParams = new ArrayList<>();
            if (trustStore != null) {
                String trustStoreFile = trustStore.getStringField(HttpConstants.FILE_PATH);
                if (StringUtils.isNotBlank(trustStoreFile)) {
                    senderConfiguration.setTrustStoreFile(trustStoreFile);
                }
                String trustStorePassword = trustStore.getStringField(HttpConstants.PASSWORD);
                if (StringUtils.isNotBlank(trustStorePassword)) {
                    senderConfiguration.setTrustStorePass(trustStorePassword);
                }
            }
            if (keyStore != null) {
                String keyStoreFile = keyStore.getStringField(HttpConstants.FILE_PATH);
                if (StringUtils.isNotBlank(keyStoreFile)) {
                    senderConfiguration.setKeyStoreFile(keyStoreFile);
                }
                String keyStorePassword = keyStore.getStringField(HttpConstants.PASSWORD);
                if (StringUtils.isNotBlank(keyStorePassword)) {
                    senderConfiguration.setKeyStorePassword(keyStorePassword);
                }
            }
            if (protocols != null) {
                String sslEnabledProtocols = protocols.getStringField(HttpConstants.ENABLED_PROTOCOLS);
                if (StringUtils.isNotBlank(sslEnabledProtocols)) {
                    Parameter clientProtocols = new Parameter(HttpConstants.SSL_ENABLED_PROTOCOLS, sslEnabledProtocols);
                    clientParams.add(clientProtocols);
                }
                String sslProtocol = protocols.getStringField(HttpConstants.PROTOCOL_VERSION);
                if (StringUtils.isNotBlank(sslProtocol)) {
                    senderConfiguration.setSSLProtocol(sslProtocol);
                }
            }
            if (validateCert != null) {
                boolean validateCertEnabled = validateCert.getBooleanField(HttpConstants.ENABLE);
                int cacheSize = (int) validateCert.getIntField(HttpConstants.SSL_CONFIG_CACHE_SIZE);
                int cacheValidityPeriod = (int) validateCert.getIntField(HttpConstants.SSL_CONFIG_CACHE_VALIDITY_PERIOD);
                senderConfiguration.setValidateCertEnabled(validateCertEnabled);
                if (cacheValidityPeriod != 0) {
                    senderConfiguration.setCacheValidityPeriod(cacheValidityPeriod);
                }
                if (cacheSize != 0) {
                    senderConfiguration.setCacheSize(cacheSize);
                }
            }
            boolean hostNameVerificationEnabled = secureSocket.getBooleanField(HttpConstants.SSL_CONFIG_HOST_NAME_VERIFICATION_ENABLED);
            senderConfiguration.setHostNameVerificationEnabled(hostNameVerificationEnabled);
            String ciphers = secureSocket.getStringField(HttpConstants.SSL_CONFIG_CIPHERS);
            if (StringUtils.isNotBlank(ciphers)) {
                Parameter clientCiphers = new Parameter(HttpConstants.CIPHERS, ciphers);
                clientParams.add(clientCiphers);
            }
            String enableSessionCreation = String.valueOf(secureSocket.getBooleanField(HttpConstants.SSL_CONFIG_ENABLE_SESSION_CREATION));
            Parameter clientEnableSessionCreation = new Parameter(HttpConstants.SSL_CONFIG_ENABLE_SESSION_CREATION, enableSessionCreation);
            clientParams.add(clientEnableSessionCreation);
            if (!clientParams.isEmpty()) {
                senderConfiguration.setParameters(clientParams);
            }
        }
    }
    Struct proxy = clientEndpointConfig.getStructField(HttpConstants.PROXY_STRUCT_REFERENCE);
    if (proxy != null) {
        String proxyHost = proxy.getStringField(HttpConstants.PROXY_HOST);
        int proxyPort = (int) proxy.getIntField(HttpConstants.PROXY_PORT);
        String proxyUserName = proxy.getStringField(HttpConstants.PROXY_USERNAME);
        String proxyPassword = proxy.getStringField(HttpConstants.PROXY_PASSWORD);
        try {
            proxyServerConfiguration = new ProxyServerConfiguration(proxyHost, proxyPort);
        } catch (UnknownHostException e) {
            throw new BallerinaConnectorException("Failed to resolve host" + proxyHost, e);
        }
        if (!proxyUserName.isEmpty()) {
            proxyServerConfiguration.setProxyUsername(proxyUserName);
        }
        if (!proxyPassword.isEmpty()) {
            proxyServerConfiguration.setProxyPassword(proxyPassword);
        }
        senderConfiguration.setProxyServerConfiguration(proxyServerConfiguration);
    }
    senderConfiguration.setFollowRedirect(followRedirect);
    senderConfiguration.setMaxRedirectCount(maxRedirectCount);
    // For the moment we don't have to pass it down to transport as we only support
    // chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
    String transferEncoding = clientEndpointConfig.getEnumField(HttpConstants.CLIENT_EP_TRNASFER_ENCODING);
    if (transferEncoding != null && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding)) {
        throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding);
    }
    String chunking = clientEndpointConfig.getEnumField(HttpConstants.CLIENT_EP_CHUNKING);
    senderConfiguration.setChunkingConfig(HttpUtil.getChunkConfig(chunking));
    long endpointTimeout = clientEndpointConfig.getIntField(HttpConstants.CLIENT_EP_ENDPOINT_TIMEOUT);
    if (endpointTimeout < 0 || !isInteger(endpointTimeout)) {
        throw new BallerinaConnectorException("invalid idle timeout: " + endpointTimeout);
    }
    senderConfiguration.setSocketIdleTimeout((int) endpointTimeout);
    boolean isKeepAlive = clientEndpointConfig.getBooleanField(HttpConstants.CLIENT_EP_IS_KEEP_ALIVE);
    senderConfiguration.setKeepAlive(isKeepAlive);
    String httpVersion = clientEndpointConfig.getStringField(HttpConstants.CLIENT_EP_HTTP_VERSION);
    if (httpVersion != null) {
        senderConfiguration.setHttpVersion(httpVersion);
    }
    String forwardedExtension = clientEndpointConfig.getStringField(HttpConstants.CLIENT_EP_FORWARDED);
    senderConfiguration.setForwardedExtensionConfig(HttpUtil.getForwardedExtensionConfig(forwardedExtension));
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) ProxyServerConfiguration(org.wso2.transport.http.netty.common.ProxyServerConfiguration) Value(org.ballerinalang.connector.api.Value) Parameter(org.wso2.transport.http.netty.config.Parameter)

Example 34 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project ballerina by ballerina-lang.

the class Register method startServerConnector.

private void startServerConnector(Struct serviceEndpoint, HTTPServicesRegistry httpServicesRegistry, WebSocketServicesRegistry webSocketServicesRegistry) {
    ServerConnector serverConnector = getServerConnector(serviceEndpoint);
    ServerConnectorFuture serverConnectorFuture = serverConnector.start();
    HashSet<FilterHolder> filterHolder = getFilters(serviceEndpoint);
    serverConnectorFuture.setHttpConnectorListener(new BallerinaHTTPConnectorListener(httpServicesRegistry, filterHolder));
    serverConnectorFuture.setWSConnectorListener(new WebSocketServerConnectorListener(webSocketServicesRegistry));
    serverConnectorFuture.setPortBindingEventListener(new HttpConnectorPortBindingListener());
    try {
        serverConnectorFuture.sync();
    } catch (Throwable ex) {
        throw new BallerinaException("failed to start server connector '" + serverConnector.getConnectorID() + "': " + ex.getMessage(), ex);
    }
    serviceEndpoint.addNativeData(HttpConstants.CONNECTOR_STARTED, true);
}
Also used : ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) WebSocketServerConnectorListener(org.ballerinalang.net.http.WebSocketServerConnectorListener) HttpConnectorPortBindingListener(org.ballerinalang.net.http.HttpConnectorPortBindingListener) ServerConnectorFuture(org.wso2.transport.http.netty.contract.ServerConnectorFuture) BallerinaHTTPConnectorListener(org.ballerinalang.net.http.BallerinaHTTPConnectorListener) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 35 with Start

use of org.wso2.carbon.humantask.core.engine.commands.Start in project ballerina by ballerina-lang.

the class HttpUtil method extractBasicConfig.

@Deprecated
private static void extractBasicConfig(Annotation configInfo, Set<ListenerConfiguration> listenerConfSet) {
    AnnAttrValue hostAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HOST);
    AnnAttrValue portAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_PORT);
    AnnAttrValue keepAliveAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEEP_ALIVE);
    AnnAttrValue transferEncoding = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRANSFER_ENCODING);
    AnnAttrValue chunking = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CHUNKING);
    AnnAttrValue maxUriLength = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_URL_LENGTH);
    AnnAttrValue maxHeaderSize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_HEADER_SIZE);
    AnnAttrValue maxEntityBodySize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_ENTITY_BODY_SIZE);
    AnnAttrValue versionAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTP_VERSION);
    ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
    if (portAttrVal != null && portAttrVal.getIntValue() > 0) {
        listenerConfiguration.setPort(Math.toIntExact(portAttrVal.getIntValue()));
        listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTP);
        if (hostAttrVal != null && hostAttrVal.getStringValue() != null) {
            listenerConfiguration.setHost(hostAttrVal.getStringValue());
        } else {
            listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
        }
        // chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
        if (transferEncoding != null && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding.getStringValue())) {
            throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding.getStringValue());
        }
        if (chunking != null) {
            ChunkConfig chunkConfig = getChunkConfig(chunking.getStringValue());
            listenerConfiguration.setChunkConfig(chunkConfig);
        } else {
            listenerConfiguration.setChunkConfig(ChunkConfig.AUTO);
        }
        if (keepAliveAttrVal != null) {
            KeepAliveConfig keepAliveConfig = getKeepAliveConfig(keepAliveAttrVal.getStringValue());
            listenerConfiguration.setKeepAliveConfig(keepAliveConfig);
        } else {
            listenerConfiguration.setKeepAliveConfig(KeepAliveConfig.AUTO);
        }
        RequestSizeValidationConfig requestSizeValidationConfig = listenerConfiguration.getRequestSizeValidationConfig();
        if (maxUriLength != null) {
            if (maxUriLength.getIntValue() > 0) {
                requestSizeValidationConfig.setMaxUriLength(Math.toIntExact(maxUriLength.getIntValue()));
            } else {
                throw new BallerinaConnectorException("Invalid configuration found for maxUriLength : " + maxUriLength.getIntValue());
            }
        }
        if (maxHeaderSize != null) {
            if (maxHeaderSize.getIntValue() > 0) {
                requestSizeValidationConfig.setMaxHeaderSize(Math.toIntExact(maxHeaderSize.getIntValue()));
            } else {
                throw new BallerinaConnectorException("Invalid configuration found for maxHeaderSize : " + maxHeaderSize.getIntValue());
            }
        }
        if (maxEntityBodySize != null) {
            if (maxEntityBodySize.getIntValue() > 0) {
                requestSizeValidationConfig.setMaxEntityBodySize(Math.toIntExact(maxEntityBodySize.getIntValue()));
            } else {
                throw new BallerinaConnectorException("Invalid configuration found for maxEntityBodySize : " + maxEntityBodySize.getIntValue());
            }
        }
        if (versionAttrVal != null) {
            listenerConfiguration.setVersion(versionAttrVal.getStringValue());
        }
        listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
        listenerConfSet.add(listenerConfiguration);
    }
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) AnnAttrValue(org.ballerinalang.connector.api.AnnAttrValue) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) ChunkConfig(org.wso2.transport.http.netty.config.ChunkConfig) RequestSizeValidationConfig(org.wso2.transport.http.netty.config.RequestSizeValidationConfig) KeepAliveConfig(org.wso2.transport.http.netty.config.KeepAliveConfig)

Aggregations

SVGCoordinates (org.wso2.carbon.bpel.ui.bpel2svg.SVGCoordinates)57 ActivityInterface (org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)47 Test (org.testng.annotations.Test)17 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)17 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)17 Event (org.wso2.siddhi.core.event.Event)17 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)13 SVGDimension (org.wso2.carbon.bpel.ui.bpel2svg.SVGDimension)11 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)11 ArrayList (java.util.ArrayList)10 OMElement (org.apache.axiom.om.OMElement)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)10 Element (org.w3c.dom.Element)9 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)9 TopLevelNode (org.ballerinalang.model.tree.TopLevelNode)7 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 ZoneId (java.time.ZoneId)5 HashMap (java.util.HashMap)5 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5