Search in sources :

Example 36 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class Generator method annotFieldAnnotation.

/**
 * Get description annotation of the annotation attribute.
 * @param annotationNode parent node.
 * @param annotAttribute annotation attribute.
 * @return description of the annotation attribute.
 */
private static String annotFieldAnnotation(BLangAnnotation annotationNode, BLangAnnotAttribute annotAttribute) {
    List<? extends AnnotationAttachmentNode> annotationAttachments = getAnnotationAttachments(annotationNode);
    for (AnnotationAttachmentNode annotation : annotationAttachments) {
        if ("Field".equals(annotation.getAnnotationName().getValue())) {
            BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            String value = bLangLiteral.toString();
            if (value.startsWith(annotAttribute.getName().getValue())) {
                String[] valueParts = value.split(":");
                return valueParts.length == 2 ? valueParts[1] : valueParts[0];
            }
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 37 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class DocumentationTest method testDocAnnotation.

@Test(description = "Test doc annotation.")
public void testDocAnnotation() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/annotation.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for Test annotation\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
    docNodes = ((BLangAnnotation) packageNode.getAnnotations().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 38 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation 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)

Example 39 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class WebSubServiceCompilerPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotation : annotations) {
        if (!HttpConstants.PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals(WebSubSubscriberConstants.ANN_NAME_WEBSUB_SUBSCRIBER_SERVICE_CONFIG)) {
            handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
        }
    }
    if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
        List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
        resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
    }
}
Also used : BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) List(java.util.List) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 40 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ServiceTest method testConstantValueAsAnnAttributeVal.

@Test(description = "Test using constant as annotation attribute value")
public void testConstantValueAsAnnAttributeVal() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/constantPath", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
    Assert.assertNotNull(stringDataSource);
    Assert.assertEquals(stringDataSource.getValue(), "constant path test");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) StringDataSource(org.ballerinalang.runtime.message.StringDataSource) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7