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");
}
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");
}
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.");
}
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());
}
}
}
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()));
}
}
Aggregations