use of org.wso2.charon3.core.utils.codeutils.Node 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.utils.codeutils.Node in project carbon-business-process by wso2.
the class TenantProcessStoreImpl method undeploy.
/**
* Undeploying BPEL package.
*
* @param bpelPackageName Name of the BPEL package which going to be undeployed
*/
public void undeploy(String bpelPackageName) throws RegistryException, BPELUIException {
if (log.isDebugEnabled()) {
log.debug("Un-deploying BPEL package " + bpelPackageName + " ....");
}
if (!repository.isExistingBPELPackage(bpelPackageName)) {
// This can be a situation where we un-deploy the archive through management console,
// so that, the archive is deleted from the repo. As a result this method get invoked.
// to handle this case we just log the message but does not throw an exception.
final String warningMsg = "Cannot find BPEL package with name " + bpelPackageName + " in the repository. If the bpel package is un-deployed through the management" + " console or if this node is a member of a cluster, please ignore this warning.";
if (isConfigRegistryReadOnly()) {
// This is for the deployment synchronizer scenarios where package un-deployment on a worker node
// has to remove the deployed bpel package from the memory and remove associated services
handleUndeployOnSlaveNode(bpelPackageName);
} else {
log.warn(warningMsg);
}
return;
}
if (repository.isExistingBPELPackage(bpelPackageName) && isConfigRegistryReadOnly()) {
log.warn("This node seems to be a slave, since the configuration registry is in read-only mode, hence " + "processes cannot be directly undeployed from this node. Please undeploy the process in Master " + "node first.");
return;
}
List<String> versionsOfThePackage;
try {
versionsOfThePackage = repository.getAllVersionsForPackage(bpelPackageName);
} catch (RegistryException re) {
String errMessage = "Cannot get all versions of the package " + bpelPackageName + " from registry.";
log.error(errMessage);
throw re;
}
// check the instance count to be deleted
long instanceCount = getInstanceCountForPackage(versionsOfThePackage);
if (instanceCount > BPELServerImpl.getInstance().getBpelServerConfiguration().getBpelInstanceDeletionLimit()) {
throw new BPELUIException("Instance deletion limit reached.");
}
for (String nameWithVersion : versionsOfThePackage) {
parentProcessStore.deleteDeploymentUnitDataFromDB(nameWithVersion);
Utils.deleteInstances(getProcessesInPackage(nameWithVersion));
// location for extracted BPEL package
String bpelPackageLocation = parentProcessStore.getLocalDeploymentUnitRepo().getAbsolutePath() + File.separator + tenantId + File.separator + nameWithVersion;
File bpelPackage = new File(bpelPackageLocation);
// removing extracted bpel package at repository/bpel/0/
deleteBpelPackageFromRepo(bpelPackage);
for (QName pid : getProcessesInPackage(nameWithVersion)) {
ProcessConfigurationImpl processConf = (ProcessConfigurationImpl) getProcessConfiguration(pid);
// This property is read when we removing the axis service for this process.
// So that we can decide whether we should persist service QOS configs
processConf.setUndeploying(true);
}
}
try {
repository.handleBPELPackageUndeploy(bpelPackageName);
} catch (RegistryException re) {
String errMessage = "Cannot update the BPEL package repository for undeployment of" + "package " + bpelPackageName + ".";
log.error(errMessage);
throw re;
}
updateLocalInstanceWithUndeployment(bpelPackageName, versionsOfThePackage);
// We should use the deployment synchronizer, instead of the code below.
// parentProcessStore.sendProcessDeploymentNotificationsToCluster(
// new BPELPackageUndeployedCommand(versionsOfThePackage, bpelPackageName, tenantId),
// configurationContext);
}
use of org.wso2.charon3.core.utils.codeutils.Node in project carbon-business-process by wso2.
the class XMLDocument method set.
/**
* Function to set/replace/update an object (String / Element) to matching the xPath provided. (In case new element
* is added, this api will clone it and merge the new node to the target location pointed by xPath and return the new cloned node)
*
* @param xPathStr xPath to the location object need to set
* @param obj String or Node
* @return returns the node get updated when the set object is String, or returns newly added Node in case object is Element
* @throws XPathExpressionException If expression cannot be evaluated
* @throws BPMNXmlException is thrown due to : Provided XPath and object does not match, provided object is not a Node or String
* result is NodeList, not a Text node or Element
*/
public Node set(String xPathStr, Object obj) throws XPathExpressionException, BPMNXmlException {
NodeList evalResult = (NodeList) Utils.evaluateXPath(this.doc, xPathStr, XPathConstants.NODESET);
if (evalResult.getLength() == 1) {
Node targetNode = evalResult.item(0);
if (obj instanceof String && targetNode instanceof Text) {
// if string is provided, assume that user
// need to replace the node value
targetNode.setNodeValue((String) obj);
// return updated Text Node
return targetNode;
} else if ((obj instanceof Integer || obj instanceof Byte || obj instanceof Character || obj instanceof Short || obj instanceof Long || obj instanceof Float || obj instanceof Double || obj instanceof Boolean) && targetNode instanceof Text) {
// need to replace the node value
targetNode.setNodeValue(obj.toString());
// return updated Text Node
return targetNode;
} else if (obj instanceof Element && targetNode instanceof Element && targetNode.getParentNode() != null) {
// if the user provides Node object,
// assume that need to replace the target node
Node targetParent = targetNode.getParentNode();
Node nextSibling = targetNode.getNextSibling();
// remove the target node
targetParent.removeChild(targetNode);
// add new node
Node newNode = doc.importNode((Node) obj, true);
if (nextSibling != null) {
// If next sibling exists we have to put the new node before it
targetParent.insertBefore(newNode, nextSibling);
} else {
targetParent.appendChild(newNode);
}
// return new node
return newNode;
} else {
// provided XPath and object to set does not match
throw new BPMNXmlException("Provided XPath and provided object does not match");
}
} else if (evalResult.getLength() > 0) {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is NodeList, not a Text node or Element");
} else {
throw new BPMNXmlException("Error in provided xPath. Evaluation result is not a Text node or Element");
}
}
use of org.wso2.charon3.core.utils.codeutils.Node in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method fillProcessInfo.
/**
* Fill in the <code>ProcessInfo</code> element of the transfer object.
*
* @param info destination XMLBean
* @param pconf process configuration object (from store)
* @param custom used to customize the quantity of information produced in the
* info
* @param tenantProcessStore Tenant's Process store
* @throws ProcessManagementException If an error occurred while filling process information
*/
private void fillProcessInfo(ProcessInfoType info, ProcessConf pconf, ProcessInfoCustomizer custom, TenantProcessStoreImpl tenantProcessStore) throws ProcessManagementException {
if (pconf == null) {
String errMsg = "Process configuration cannot be null.";
log.error(errMsg);
throw new ProcessManagementException(errMsg);
}
info.setPid(pconf.getProcessId().toString());
// Active process may be retired at the same time
if (pconf.getState() == ProcessState.RETIRED) {
info.setStatus(ProcessStatus.RETIRED);
info.setOlderVersion(AdminServiceUtils.isOlderVersion(pconf, tenantProcessStore));
} else if (pconf.getState() == ProcessState.DISABLED) {
info.setStatus(ProcessStatus.DISABLED);
info.setOlderVersion(0);
} else {
info.setStatus(ProcessStatus.ACTIVE);
info.setOlderVersion(0);
}
info.setVersion(pconf.getVersion());
DefinitionInfo defInfo = new DefinitionInfo();
defInfo.setProcessName(pconf.getType());
BpelDefinition bpelDefinition = new BpelDefinition();
bpelDefinition.setExtraElement(getProcessDefinition(pconf));
defInfo.setDefinition(bpelDefinition);
info.setDefinitionInfo(defInfo);
DeploymentInfo depInfo = new DeploymentInfo();
depInfo.setPackageName(pconf.getPackage());
depInfo.setDocument(pconf.getBpelDocument());
depInfo.setDeployDate(AdminServiceUtils.toCalendar(pconf.getDeployDate()));
// TODO: Need to fix this by adding info to process conf.
depInfo.setDeployer(org.wso2.carbon.bpel.core.BPELConstants.BPEL_DEPLOYER_NAME);
info.setDeploymentInfo(depInfo);
if (custom.includeInstanceSummary()) {
InstanceSummary instanceSummary = new InstanceSummary();
addInstanceSummaryEntry(instanceSummary, pconf, InstanceStatus.ACTIVE);
addInstanceSummaryEntry(instanceSummary, pconf, InstanceStatus.COMPLETED);
addInstanceSummaryEntry(instanceSummary, pconf, InstanceStatus.FAILED);
addInstanceSummaryEntry(instanceSummary, pconf, InstanceStatus.SUSPENDED);
addInstanceSummaryEntry(instanceSummary, pconf, InstanceStatus.TERMINATED);
addFailuresToInstanceSummary(instanceSummary, pconf);
info.setInstanceSummary(instanceSummary);
}
if (custom.includeProcessProperties()) {
ProcessProperties processProps = new ProcessProperties();
for (Map.Entry<QName, Node> propEntry : pconf.getProcessProperties().entrySet()) {
QName key = propEntry.getKey();
if (key != null) {
Property_type0 prop = new Property_type0();
prop.setName(new QName(key.getNamespaceURI(), key.getLocalPart()));
OMFactory omFac = OMAbstractFactory.getOMFactory();
OMElement propEle = omFac.createOMElement("PropertyValue", null);
propEle.setText(propEntry.getValue().getNodeValue());
prop.addExtraElement(propEle);
processProps.addProperty(prop);
}
}
info.setProperties(processProps);
}
fillPartnerLinks(info, ((ProcessConfigurationImpl) pconf).getProcessDeploymentInfo());
}
use of org.wso2.charon3.core.utils.codeutils.Node in project carbon-business-process by wso2.
the class XPathExpressionRuntime method evaluate.
private Object evaluate(String exp, EvaluationContext evalCtx, QName type) {
try {
XPathFactory xpf = new XPathFactoryImpl();
JaxpFunctionResolver funcResolve = new JaxpFunctionResolver(evalCtx);
xpf.setXPathFunctionResolver(funcResolve);
XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath();
xpe.setXPathFunctionResolver(funcResolve);
xpe.setBackwardsCompatible(true);
xpe.setNamespaceContext(evalCtx.getNameSpaceContextOfTask());
XPathExpression xpathExpression = xpe.compile(exp);
Node contextNode = evalCtx.getRootNode() == null ? DOMUtils.newDocument() : evalCtx.getRootNode();
Object evalResult = xpathExpression.evaluate(contextNode, type);
if (evalResult != null && log.isDebugEnabled()) {
log.debug("Expression " + exp + " generate result " + evalResult + " - type=" + evalResult.getClass().getName());
if (evalCtx.getRootNode() != null) {
log.debug("Was using context node " + DOMUtils.domToString(evalCtx.getRootNode()));
}
}
return evalResult;
} catch (XPathFactoryConfigurationException e) {
log.error("Exception occurred while creating XPathFactory.", e);
throw new XPathProcessingException("Exception occurred while creating XPathFactory.", e);
} catch (XPathExpressionException e) {
String msg = "Error evaluating XPath expression: " + exp;
log.error(msg, e);
throw new XPathProcessingException(msg, e);
} catch (ParserConfigurationException e) {
String msg = "XML Parsing error.";
log.error(msg, e);
throw new XPathProcessingException(msg, e);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new XPathProcessingException(e.getMessage(), e);
}
}
Aggregations