Search in sources :

Example 91 with Resource

use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResource.

@Test(description = "Test accessing changed global var in another resource in same service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResource() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/get-changed-resource-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarFloatChange":77.87}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
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) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 92 with Resource

use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResourceInAnotherService.

@Test(description = "Test accessing changed global var in another resource in different service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResourceInAnotherService() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second/get-changed-resource-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarFloatChange":77.87}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
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) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 93 with Resource

use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.

the class DocumentationTest method testDocService.

@Test(description = "Test doc service.", enabled = false)
public void testDocService() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/service.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangService service = (BLangService) packageNode.getServices().get(0);
    List<BLangDocumentation> docNodes = service.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
    dNode = service.getResources().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
    dNode = service.getResources().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Check status resource. ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 94 with Resource

use of org.wso2.carbon.registry.api.Resource in project ballerina by ballerina-lang.

the class BallerinaWebSubConnectionListener method autoRespondToIntentVerification.

/**
 * Method to automatically respond to intent verification requests for subscriptions/unsubscriptions if a resource
 * named {@link WebSubSubscriberConstants#RESOURCE_NAME_VERIFY_INTENT} is not specified.
 *
 * @param httpCarbonMessage the message/request received
 */
private void autoRespondToIntentVerification(HTTPCarbonMessage httpCarbonMessage) {
    String annotatedTopic = httpCarbonMessage.getProperty(WebSubSubscriberConstants.ANNOTATED_TOPIC).toString();
    PrintStream console = System.out;
    if (httpCarbonMessage.getProperty(HttpConstants.QUERY_STR) != null) {
        String queryString = (String) httpCarbonMessage.getProperty(HttpConstants.QUERY_STR);
        BMap<String, BString> params = new BMap<>();
        try {
            HTTPCarbonMessage response = HttpUtil.createHttpCarbonMessage(false);
            response.waitAndReleaseAllEntities();
            URIUtil.populateQueryParamMap(queryString, params);
            String mode = params.get(WebSubSubscriberConstants.PARAM_HUB_MODE).stringValue();
            if ((WebSubSubscriberConstants.SUBSCRIBE.equals(mode) || WebSubSubscriberConstants.UNSUBSCRIBE.equals(mode)) && annotatedTopic.equals(params.get(WebSubSubscriberConstants.PARAM_HUB_TOPIC).stringValue())) {
                String challenge = params.get(WebSubSubscriberConstants.PARAM_HUB_CHALLENGE).stringValue();
                response.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(challenge.getBytes(StandardCharsets.UTF_8))));
                response.setProperty(HttpConstants.HTTP_STATUS_CODE, 202);
                console.println("ballerina: Intent Verification agreed - Mode [" + mode + "], Topic [" + annotatedTopic + "], Lease Seconds [" + params.get(WebSubSubscriberConstants.PARAM_HUB_LEASE_SECONDS) + "]");
            } else {
                console.println("ballerina: Intent Verification denied - Mode [" + mode + "] for Incorrect Topic [" + annotatedTopic + "]");
                response.setProperty(HttpConstants.HTTP_STATUS_CODE, 404);
            }
            HttpUtil.sendOutboundResponse(httpCarbonMessage, response);
        } catch (UnsupportedEncodingException e) {
            throw new BallerinaException("Error responding to intent verification request: " + e.getMessage());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BString(org.ballerinalang.model.values.BString) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 95 with Resource

use of org.wso2.carbon.registry.api.Resource 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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)102 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)64 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)59 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)56 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)53 BJSON (org.ballerinalang.model.values.BJSON)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)38 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)29 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)27 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)24 CharonException (org.wso2.charon3.core.exceptions.CharonException)24 IOException (java.io.IOException)23 Map (java.util.Map)20 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)20 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)17 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)17 ArrayList (java.util.ArrayList)15 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)15