use of org.wso2.carbon.registry.core.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.core.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.core.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()));
}
}
use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testSpecialCharacterURI.
@Test(description = "Test dispatching with OPTIONS request with wildcard")
public void testSpecialCharacterURI() {
String path = "/ech%5Bo/ech%5Bo/b%5Bar";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET", null);
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo113").asText(), "b[ar", "Resource dispatched to wrong template");
}
use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSMethods.
@Test(description = "Test dispatching with OPTIONS method")
public void testOPTIONSMethods() {
String path = "/options/hi";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "hi");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo").asText(), "wso2", "Resource dispatched to wrong template");
}
Aggregations