use of org.wso2.charon3.core.attributes.Attribute in project ballerina by ballerina-lang.
the class TestAnnotationProcessor method process.
@Override
public void process(FunctionNode functionNode, List<AnnotationAttachmentNode> annotations) {
// to avoid processing those, we have to have below check.
if (!suite.getSuiteName().equals(functionNode.getPosition().getSource().getPackageName())) {
return;
}
// traverse through the annotations of this function
for (AnnotationAttachmentNode attachmentNode : annotations) {
String annotationName = attachmentNode.getAnnotationName().getValue();
String functionName = functionNode.getName().getValue();
if (BEFORE_SUITE_ANNOTATION_NAME.equals(annotationName)) {
suite.addBeforeSuiteFunction(functionName);
} else if (AFTER_SUITE_ANNOTATION_NAME.equals(annotationName)) {
suite.addAfterSuiteFunction(functionName);
} else if (BEFORE_EACH_ANNOTATION_NAME.equals(annotationName)) {
suite.addBeforeEachFunction(functionName);
} else if (AFTER_EACH_ANNOTATION_NAME.equals(annotationName)) {
suite.addAfterEachFunction(functionName);
} else if (MOCK_ANNOTATION_NAME.equals(annotationName)) {
String[] vals = new String[2];
// If package property not present the package is .
// TODO: when default values are supported in annotation struct we can remove this
vals[0] = ".";
if (attachmentNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) attachmentNode.getExpression()).getKeyValuePairs();
attributes.forEach(attributeNode -> {
String name = attributeNode.getKey().toString();
String value = attributeNode.getValue().toString();
if (PACKAGE.equals(name)) {
vals[0] = value;
} else if (FUNCTION.equals(name)) {
vals[1] = value;
}
});
suite.addMockFunction(vals[0] + MOCK_ANNOTATION_DELIMITER + vals[1], functionName);
}
} else if (TEST_ANNOTATION_NAME.equals(annotationName)) {
Test test = new Test();
test.setTestName(functionName);
AtomicBoolean shouldSkip = new AtomicBoolean();
AtomicBoolean groupsFound = new AtomicBoolean();
List<String> groups = registry.getGroups();
boolean shouldIncludeGroups = registry.shouldIncludeGroups();
if (attachmentNode.getExpression() instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) attachmentNode.getExpression()).getKeyValuePairs();
attributes.forEach(attributeNode -> {
String name = attributeNode.getKey().toString();
// Check if enable property is present in the annotation
if (TEST_ENABLE_ANNOTATION_NAME.equals(name) && "false".equals(attributeNode.getValue().toString())) {
// If enable is false, disable the test, no further processing is needed
shouldSkip.set(true);
return;
}
// Check whether user has provided a group list
if (groups != null && !groups.isEmpty()) {
// check if groups attribute is present in the annotation
if (GROUP_ANNOTATION_NAME.equals(name)) {
if (attributeNode.getValue() instanceof BLangArrayLiteral) {
BLangArrayLiteral values = (BLangArrayLiteral) attributeNode.getValue();
boolean isGroupPresent = isGroupAvailable(groups, values.exprs.stream().map(node -> node.toString()).collect(Collectors.toList()));
if (shouldIncludeGroups) {
// include only if the test belong to one of these groups
if (!isGroupPresent) {
// skip the test if this group is not defined in this test
shouldSkip.set(true);
return;
}
} else {
// exclude only if the test belong to one of these groups
if (isGroupPresent) {
// skip if this test belongs to one of the excluded groups
shouldSkip.set(true);
return;
}
}
groupsFound.set(true);
}
}
}
if (VALUE_SET_ANNOTATION_NAME.equals(name)) {
test.setDataProvider(attributeNode.getValue().toString());
}
if (BEFORE_FUNCTION.equals(name)) {
test.setBeforeTestFunction(attributeNode.getValue().toString());
}
if (AFTER_FUNCTION.equals(name)) {
test.setAfterTestFunction(attributeNode.getValue().toString());
}
if (DEPENDS_ON_FUNCTIONS.equals(name)) {
if (attributeNode.getValue() instanceof BLangArrayLiteral) {
BLangArrayLiteral values = (BLangArrayLiteral) attributeNode.getValue();
values.exprs.stream().map(node -> node.toString()).forEach(test::addDependsOnTestFunction);
}
}
});
}
if (groups != null && !groups.isEmpty() && !groupsFound.get() && shouldIncludeGroups) {
// if the user has asked to run only a specific list of groups and this test doesn't have
// that group, we should skip the test
shouldSkip.set(true);
}
if (!shouldSkip.get()) {
suite.addTests(test);
}
} else {
// disregard this annotation
}
}
}
use of org.wso2.charon3.core.attributes.Attribute in project ballerina by ballerina-lang.
the class HtmlDocTest method testAnnotationPropertiesExtracted.
@Test(description = "Annotation properties should be available via construct", enabled = false)
public void testAnnotationPropertiesExtracted() throws Exception {
BLangPackage bLangPackage = createPackage("package x.y; " + "@Description {value: \"AnnotationDoc to upgrade connection from HTTP to WS in the " + "same base path\"}\n" + "@Field {value:\"upgradePath:Upgrade path for the WebSocket service from " + "HTTP to WS\"}\n" + "@Field {value:\"serviceName:Name of the WebSocket service where the HTTP service should " + " upgrade to\"}\n" + "public annotation webSocket attach service<> {\n" + " string upgradePath;\n" + " string serviceName;\n" + "}");
AnnotationDoc annotationDoc = Generator.createDocForNode(bLangPackage.getAnnotations().get(0));
Assert.assertEquals(annotationDoc.name, "webSocket", "Annotation name should be extracted");
Assert.assertEquals(annotationDoc.description, "AnnotationDoc to upgrade connection from HTTP to WS " + "in the same base path", "Description of the annotation should be extracted");
// Annotation Fields
Assert.assertEquals(annotationDoc.attributes.get(0).name, "upgradePath", "Annotation attribute name " + "should be extracted");
Assert.assertEquals(annotationDoc.attributes.get(0).dataType, "string", "Annotation attribute type " + "should be extracted");
Assert.assertEquals(annotationDoc.attributes.get(0).description, "Upgrade path for the WebSocket service " + "from HTTP to WS", "Description of the annotation attribute should be extracted");
}
use of org.wso2.charon3.core.attributes.Attribute in project carbon-business-process by wso2.
the class SOAPUtils method handleSOAPHeaderElementsInBindingOperation.
@SuppressWarnings("unchecked")
private static void handleSOAPHeaderElementsInBindingOperation(SOAPEnvelope soapEnvelope, SOAPFactory soapFactory, org.apache.ode.bpel.iapi.Message messageFromOde, Operation wsdlOperation, final javax.wsdl.extensions.soap.SOAPHeader soapHeaderElementDefinition) throws BPELFault {
Map<String, Node> headerParts = messageFromOde.getHeaderParts();
Message responseMessageDefinition = wsdlOperation.getOutput() != null ? wsdlOperation.getOutput().getMessage() : null;
// If there isn't a message attribute in header element definition or if the
// message attribute value is equal to the response message QName, then this
// header element is part of the actual payload.
// Refer SOAP Binding specification at http://www.w3.org/TR/wsdl#_soap-b.
final boolean isHeaderElementAPartOfPayload = soapHeaderElementDefinition.getMessage() == null || ((wsdlOperation.getStyle() != OperationType.ONE_WAY) && soapHeaderElementDefinition.getMessage().equals(responseMessageDefinition.getQName()));
if (soapHeaderElementDefinition.getPart() == null) {
// Part information not found. Ignoring this header definition.
return;
}
if (isHeaderElementAPartOfPayload && (responseMessageDefinition != null && responseMessageDefinition.getPart(soapHeaderElementDefinition.getPart()) == null)) {
// we should throw a exception.
throw new BPELFault("SOAP Header Element Definition refer unknown part.");
}
Element partElement = null;
if (headerParts.size() > 0 && isHeaderElementAPartOfPayload) {
try {
partElement = (Element) headerParts.get(soapHeaderElementDefinition.getPart());
} catch (ClassCastException e) {
throw new BPELFault("SOAP Header must be a DOM Element.", e);
}
}
// message payload. This is because, some headers will provided by SOAP engine.
if (partElement == null && isHeaderElementAPartOfPayload) {
if (messageFromOde.getPart(soapHeaderElementDefinition.getPart()) != null) {
partElement = messageFromOde.getPart(soapHeaderElementDefinition.getPart());
} else {
throw new BPELFault("Missing Required part in response message.");
}
}
// and can be found and extracted from the odeMessage object
if (partElement == null && messageFromOde.getParts().size() > 0 && !isHeaderElementAPartOfPayload) {
try {
partElement = (Element) messageFromOde.getPart(soapHeaderElementDefinition.getPart());
} catch (ClassCastException e) {
throw new BPELFault("Soap header must be an element" + messageFromOde.getPart(soapHeaderElementDefinition.getPart()));
}
}
// just ignore this case.
if (partElement == null) {
return;
}
org.apache.axiom.soap.SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader == null) {
soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
}
OMElement omPart = OMUtils.toOM(partElement, soapFactory);
for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
soapHeader.addChild(i.next());
}
}
use of org.wso2.charon3.core.attributes.Attribute in project carbon-business-process by wso2.
the class PeopleActivity method invoke.
public String invoke(ExtensionContext extensionContext) throws FaultException {
BPELMessageContext taskMessageContext = new BPELMessageContext(hiWSDL);
UUID messageID = null;
int tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
String tenantDomain = null;
try {
tenantDomain = B4PContentHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
} catch (UserStoreException e) {
log.error(" Cannot find the tenant domain " + e.toString());
}
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
try {
// Setting the attachment id attachmentIDList
List<Long> attachmentIDList = extractAttachmentIDsToBeSentToHumanTask(extensionContext, taskMessageContext);
taskMessageContext.setOperationName(getOperationName());
SOAPHelper soapHelper = new SOAPHelper(getBinding(), getSoapFactory(), isRPC);
MessageContext messageContext = new MessageContext();
/*
Adding attachment ID list as a method input to createSoapRequest makes no sense.
Have to fix. Here we can't embed attachments in MessageContext, as we have only a
list of attachment ids.
*/
soapHelper.createSoapRequest(messageContext, (Element) extensionContext.readVariable(inputVarName), getOperation(extensionContext), attachmentIDList);
// Coordination Context and skipable attribute is only valid for a Task.
if (InteractionType.TASK.equals(activityType)) {
// Note: If registration service is not enabled, we don't need to send coor-context.
if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
messageID = UUID.randomUUID();
soapHelper.addCoordinationContext(messageContext, messageID.toString(), getRegistrationServiceURL());
}
// Adding HumanTask Context overriding attributes.
soapHelper.addOverridingHumanTaskAttributes(messageContext, isSkipable);
}
taskMessageContext.setInMessageContext(messageContext);
taskMessageContext.setPort(getServicePort());
taskMessageContext.setService(getServiceName());
taskMessageContext.setRPCStyleOperation(isRPC);
taskMessageContext.setTwoWay(isTwoWay);
taskMessageContext.setSoapFactoryForCurrentMessageFlow(getSoapFactory());
taskMessageContext.setWsdlBindingForCurrentMessageFlow(getBinding());
taskMessageContext.setUep(getUnifiedEndpoint());
taskMessageContext.setCaller(processId.getLocalPart());
AxisServiceUtils.invokeService(taskMessageContext, getConfigurationContext());
} catch (AxisFault axisFault) {
log.error(axisFault, axisFault);
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while invoking service " + serviceName, axisFault);
} catch (B4PCoordinationException coordinationFault) {
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while generating Registration Service URL" + serviceName, coordinationFault);
}
if (taskMessageContext.getFaultMessageContext() != null || taskMessageContext.getOutMessageContext().isFault()) {
MessageContext faultContext = taskMessageContext.getFaultMessageContext() != null ? taskMessageContext.getFaultMessageContext() : taskMessageContext.getOutMessageContext();
log.warn("SOAP Fault: " + faultContext.getEnvelope().toString());
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, faultContext.getEnvelope().toString());
}
String taskID = SOAPHelper.parseResponseFeedback(taskMessageContext.getOutMessageContext().getEnvelope().getBody());
// Ignore Notifications, since we are ignore coordination context for notification.
if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && InteractionType.TASK.equals(activityType)) {
Long instanceID = extensionContext.getProcessId();
if (CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
try {
// Already coordinated with Registration service.
updateCoordinationData(messageID.toString(), Long.toString(instanceID), taskID);
} catch (Exception e) {
log.error("Error occurred while updating humantask coordination data.", e);
}
} else {
// Handler URL by manually.
try {
messageID = UUID.randomUUID();
String protocolHandlerURL = generateTaskProtocolHandlerURL(taskMessageContext);
if (log.isDebugEnabled()) {
log.debug("Generated Protocol Handler URL : " + protocolHandlerURL);
}
createCoordinationData(messageID.toString(), protocolHandlerURL, Long.toString(instanceID), taskID);
} catch (Exception e) {
log.error("Error occurred while creating humantask coordination data for coordinated task.", e);
}
}
}
return taskID;
}
use of org.wso2.charon3.core.attributes.Attribute in project ballerina by ballerina-lang.
the class SymbolEnter method visit.
public void visit(BLangXMLAttribute bLangXMLAttribute) {
if (!(bLangXMLAttribute.name.getKind() == NodeKind.XML_QNAME)) {
return;
}
BLangXMLQName qname = (BLangXMLQName) bLangXMLAttribute.name;
// If no duplicates, then define this attribute symbol.
if (!bLangXMLAttribute.isNamespaceDeclr) {
BXMLAttributeSymbol attrSymbol = new BXMLAttributeSymbol(qname.localname.value, qname.namespaceURI, env.enclPkg.symbol.pkgID, env.scope.owner);
if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, attrSymbol)) {
env.scope.define(attrSymbol.name, attrSymbol);
bLangXMLAttribute.symbol = attrSymbol;
}
return;
}
List<BLangExpression> exprs = bLangXMLAttribute.value.textFragments;
String nsURI = null;
// TODO: find a better way to get the statically defined URI.
if (exprs.size() == 1 && exprs.get(0).getKind() == NodeKind.LITERAL) {
nsURI = (String) ((BLangLiteral) exprs.get(0)).value;
}
String symbolName = qname.localname.value;
if (symbolName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
symbolName = XMLConstants.DEFAULT_NS_PREFIX;
}
BXMLNSSymbol xmlnsSymbol = new BXMLNSSymbol(names.fromString(symbolName), nsURI, env.enclPkg.symbol.pkgID, env.scope.owner);
if (symResolver.checkForUniqueMemberSymbol(bLangXMLAttribute.pos, env, xmlnsSymbol)) {
env.scope.define(xmlnsSymbol.name, xmlnsSymbol);
bLangXMLAttribute.symbol = xmlnsSymbol;
}
}
Aggregations