private static OMElement generateRequestSuccessElement() { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement result = fac.createOMElement(new QName(DBConstants.WSO2_DS_NAMESPACE, DBConstants.REQUEST_STATUS_WRAPPER_ELEMENT)); result.setText(DBConstants.REQUEST_STATUS_SUCCESSFUL_MESSAGE); OMDocument doc = fac.createOMDocument(); doc.addChild(result); return doc.getOMDocumentElement(); }
public static OMElement wrapBoxCarringResponse(OMElement result) { OMFactory fac = OMAbstractFactory.getOMFactory(); OMElement wrapperElement = fac.createOMElement(new QName(DBConstants.WSO2_DS_NAMESPACE, DBConstants.DATA_SERVICE_REQUEST_BOX_RESPONSE_WRAPPER_ELEMENT)); if (result != null) { wrapperElement.addChild(result); } OMDocument doc = fac.createOMDocument(); doc.addChild(wrapperElement); return doc.getOMDocumentElement(); }
public String serialize() throws Exception { String result = null; OMDocument document = factory.createOMDocument(); OMElement documentElement = getDocumentElement(); document.addChild(documentElement); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { prettify(documentElement, outputStream); } catch (Exception e) { throw new MojoExecutionException("Error serializing",e); } result = outputStream.toString(); return result; }
public String serialize() { String result = null; OMDocument document = factory.createOMDocument(); OMElement documentElement = getDocumentElement(); document.addChild(documentElement); try { result = getPretifiedString(documentElement); } catch (Exception e) { e.printStackTrace(); return null; } return result; }
omDocument.addChild(result);
@Override public boolean accept(NotificationMessage message) { boolean result = true; try { OMElement messageElement = WsnHelper .notificationMessageToOM(message); OMDocument document = AxiomHelper.createEmptyDocument(); document.addChild(messageElement); XPathEvaluator eval = new XPathEvaluator(); List list = eval.evaluateXpath(xpathPattern, document, null); // accept the message only if the evaluation returns a non empty // list result = (list.size() > 0); } catch (Exception e) { result = false; } return result; } }
private OMElement createEventMessage(DataService dataService, String queryId, OMElement data) { OMFactory fac = DBUtils.getOMFactory(); OMElement result = fac.createOMElement( new QName(DBConstants.EventNotification.MESSAGE_WRAPPER)); OMElement serviceNameEl = fac.createOMElement( new QName(DBConstants.EventNotification.SERVICE_NAME)); serviceNameEl.setText(dataService.getName()); result.addChild(serviceNameEl); OMElement queryIdEl = fac.createOMElement( new QName(DBConstants.EventNotification.QUERY_ID)); queryIdEl.setText(queryId); result.addChild(queryIdEl); OMElement timeEl = fac.createOMElement( new QName(DBConstants.EventNotification.TIME)); timeEl.setText(Calendar.getInstance().getTime().toString()); result.addChild(timeEl); OMElement contentEl = fac.createOMElement( new QName(DBConstants.EventNotification.CONTENT)); contentEl.addChild(data); result.addChild(contentEl); /* clone required, or else the content in 'content' element is missing in result */ result = result.cloneOMElement(); OMDocument doc = fac.createOMDocument(); doc.addChild(result); return doc.getOMDocumentElement(); }
doc.addChild(omNode); return new BXMLItem(omNode); } catch (BallerinaException e) {
/** * {@inheritDoc} */ public CAppArtifactDependency export(OMElement artifactDefinition, CAppArtifactDependency synapseArtifactClone, File workDir) throws Exception { // Create the temporary directory. workDir.mkdirs(); // Serialize the sequence definition. String artifactName = getArtifactName(artifactDefinition); File artifactContentFile = new File(workDir, String.format("%s.xml", artifactName)); FileOutputStream fos = null; try { fos = new FileOutputStream(artifactContentFile); OMFactory omFactory = OMAbstractFactory.getOMFactory(); OMDocument omDocument = omFactory.createOMDocument(); omDocument.addChild(artifactDefinition); omDocument.serialize(fos); } finally { IOUtils.closeQuietly(fos); } // Create the sequence artifact. MavenProject dummyMavenProject = MavenUtils.createMavenProject(synapseArtifactClone.getcAppArtifact().getProject().getGroupId(), artifactName, synapseArtifactClone.getVersion(), getArtifactType()); CAppArtifactDependency cAppArtifactDependency = new CAppArtifactDependency(dummyMavenProject, getArtifactType(), synapseArtifactClone.getServerRole()); cAppArtifactDependency.setDummyDependency(true); cAppArtifactDependency.setArtifactFiles(new File[]{artifactContentFile}); cAppArtifactDependency.getcAppArtifact().setFile(artifactContentFile.getName()); return cAppArtifactDependency; }
private void write(OutputStream out) throws IOException, XMLStreamException { if (targetNamespace == null) { targetNamespace = detectTargetNamespace(); } if (targetNamespace == null) { throw new PaxmlRuntimeException("No @targetNamespace attribute given on <soap> tag," + " and the target namespace cannot be detected from WSDL: " + getWsdlUrl()); } OMFactory factory = AxiomUtils.getOMFactory(); Map<?, ?> bd = (Map<?, ?>) this.body; OMNamespace targetNs = factory.createOMNamespace(targetNamespace, "ns"); OMNamespace ns = factory.createOMNamespace(SOAP_NS, "soapenv"); OMDocument doc = AxiomUtils.newDocument(); doc.setXMLEncoding("UTF-8"); OMElement root = factory.createOMElement("Envelope", ns); doc.addChild(root); OMElement headerEle = factory.createOMElement("Header", ns); root.addChild(headerEle); OMElement bodyEle = factory.createOMElement("Body", ns); root.addChild(bodyEle); Iterator<?> it = bd.entrySet().iterator(); if (!it.hasNext()) { throw new PaxmlRuntimeException("No webservice operation name given!"); } toXml(bodyEle, bd, targetNs, factory); doc.serializeAndConsume(out); }
private void write(OutputStream out) throws IOException, XMLStreamException { if (targetNamespace == null) { targetNamespace = detectTargetNamespace(); } if (targetNamespace == null) { throw new PaxmlRuntimeException("No @targetNamespace attribute given on <soap> tag," + " and the target namespace cannot be detected from WSDL: " + getWsdlUrl()); } OMFactory factory = AxiomUtils.getOMFactory(); Map<?, ?> bd = (Map<?, ?>) this.body; OMNamespace targetNs = factory.createOMNamespace(targetNamespace, "ns"); OMNamespace ns = factory.createOMNamespace(SOAP_NS, "soapenv"); OMDocument doc = AxiomUtils.newDocument(); doc.setXMLEncoding("UTF-8"); OMElement root = factory.createOMElement("Envelope", ns); doc.addChild(root); OMElement headerEle = factory.createOMElement("Header", ns); root.addChild(headerEle); OMElement bodyEle = factory.createOMElement("Body", ns); root.addChild(bodyEle); Iterator<?> it = bd.entrySet().iterator(); if (!it.hasNext()) { throw new PaxmlRuntimeException("No webservice operation name given!"); } toXml(bodyEle, bd, targetNs, factory); doc.serializeAndConsume(out); }
public Object clone() { Document<T> doc = ((FOMFactory)factory).newDocument(); OMDocument omdoc = (OMDocument)doc; for (Iterator i = getChildren(); i.hasNext();) { OMNode node = (OMNode)i.next(); switch (node.getType()) { case OMNode.COMMENT_NODE: OMComment comment = (OMComment)node; factory.createOMComment(omdoc, comment.getValue()); break; // TODO: Decide what to do with this code; it will no longer work in Axiom 1.2.14 (because of AXIOM-437). // On the other hand, since we filter out DTDs, this code is never triggered. // case OMNode.DTD_NODE: // OMDocType doctype = (OMDocType)node; // factory.createOMDocType(omdoc, doctype.getValue()); // break; case OMNode.ELEMENT_NODE: Element el = (Element)node; omdoc.addChild((OMNode)el.clone()); break; case OMNode.PI_NODE: OMProcessingInstruction pi = (OMProcessingInstruction)node; factory.createOMProcessingInstruction(omdoc, pi.getTarget(), pi.getValue()); break; } } return doc; }
/** * This method accesses a resource defined in the data service. * @param dataService The DataService object which represents the data service. * @param resourcePath The resource path of the data service resource. * @param params The parameters destined for the resource. * @param accessMethod The HTTP access method defined in the data service resource. * @return returns the XML result if it exists. * @throws DataServiceFault thrown if an error condition occurs in accessing the resource. */ public static OMElement accessResource(DataService dataService, String resourcePath, Map<String, ParamValue> params, String accessMethod) throws DataServiceFault { OMElement result = (new SingleDataServiceRequest(dataService, Resource .generateRequestName(resourcePath, accessMethod), params)).dispatch(); OMDocument doc = DBUtils.getOMFactory().createOMDocument(); doc.addChild(result); return doc.getOMDocumentElement(); }
private OMElement createOMElementFromInputParams(InternalParamCollection params) { OMFactory fac = DBUtils.getOMFactory(); OMDocument doc = fac.createOMDocument(); OMElement retEl = fac.createOMElement(new QName(this.getQueryId())); OMElement scalarEl; List<OMElement> arrayEl; ParamValue paramValue; for (InternalParam param : params.getParams()) { paramValue = param.getValue(); if (paramValue.getValueType() == ParamValue.PARAM_VALUE_SCALAR || paramValue.getValueType() == ParamValue.PARAM_VALUE_UDT) { scalarEl = fac.createOMElement(new QName(param.getName())); scalarEl.setText(paramValue.getScalarValue()); retEl.addChild(scalarEl); } else if (paramValue.getValueType() == ParamValue.PARAM_VALUE_ARRAY) { arrayEl = this.createOMElementsFromArrayValue(param.getName(), paramValue, fac); for (OMElement el : arrayEl) { retEl.addChild(el); } } } doc.addChild(retEl); return doc.getOMDocumentElement(); }
/** * This method invokes a single operation defined in the given data service. * @param dataService The DataService object which represents the data service. * @param operationName The name of the operation. * @param params The parameters destined for the operation. * @return returns the XML result if it exists. * @throws DataServiceFault thrown if an error condition occurs in executing the operation. * @see DSTools#invokeOperation(DataService, String, List) */ public static OMElement invokeOperation(DataService dataService, String operationName, Map<String, ParamValue> params) throws DataServiceFault { if (DataServiceRequest.isBoxcarringRequest(operationName)) { return callBoxcarringOp(dataService, operationName, params); } OMElement result = (new SingleDataServiceRequest(dataService, operationName, params)).dispatch(); if (result == null) { return null; } /* result must have a parent, or there are problems when it comes to XPath expressions etc.. */ OMDocument doc = DBUtils.getOMFactory().createOMDocument(); doc.addChild(result); return doc.getOMDocumentElement(); }
dataService.getResource(resourceId))); fac.createOMDocument().addChild(dataEl); return dataEl;
public static MessageContext createLightweightSynapseMessageContext( String payload, SynapseConfiguration config) throws Exception { org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext(); SynapseEnvironment env = new Axis2SynapseEnvironment(config); MessageContext synMc = new Axis2MessageContext(mc, config, env); SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument(); omDoc.addChild(envelope); envelope.getBody().addChild(createOMElement(payload)); synMc.setEnvelope(envelope); return synMc; }
soapFaultDocument.addChild(faultEnvelope);
doc.addChild(clonedNode); return new BXMLItem(clonedNode);
public static MessageContext createSynapseMessageContext( String payload, SynapseConfiguration config) throws Exception { org.apache.axis2.context.MessageContext mc = new org.apache.axis2.context.MessageContext(); AxisConfiguration axisConfig = config.getAxisConfiguration(); if (axisConfig == null) { axisConfig = new AxisConfiguration(); config.setAxisConfiguration(axisConfig); } ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig); SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, config); MessageContext synMc = new Axis2MessageContext(mc, config, env); SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope(); OMDocument omDoc = OMAbstractFactory.getSOAP11Factory().createOMDocument(); omDoc.addChild(envelope); envelope.getBody().addChild(createOMElement(payload)); synMc.setEnvelope(envelope); return synMc; }