how to remove the xmlns attribute that gets added after my transformation? - mule

I'm facing an issue when I transform a json input to an xml output. After transformation i want to remove the xmlns namespace before closing tag. These Namespace (xmlns:ind="." and xmlns:att="d") need to be removed
sample input:
{
"order": "Electronic",
"productId": 6548790,
"status": "COMPLETED",
"recieved": "YES",
"orderId": "12453",
"desc": "NASQ123",
"details": [{
"attributes": [{
"linetype": "DFU"
}]
}]
}
I'm using this below dataweave script:
%dw 2.0
output application/xml writeDeclaration=false
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
ns ind .
ns att d
---
{
soapenv#Envelope:{
soapenv#Header: {},
soapenv#Body: {
ind#updateorder: {
ind#orderId: payload.orderId,
ind#orderName: payload.order,
ind#quantity: "5",
ind#order: {
att#productId: payload.productId,
att#desc: payload.desc,
att#shipping: "MAIL",
att#status: payload.status,
att#type1: payload.order,
att#recieved: payload.recieved,
att#otherDetails: payload. *details map ()-> {
att#details1: $.attributeS.linetype,
},
}
}
}
}
}
Current Ouput:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ind:updateorder xmlns:ind=".">
<ind:orderId>12453</ind:orderId>
<ind:orderName>Electronic</ind:orderName>
<ind:quantity>5</ind:quantity>
<ind:order>
<att:productId xmlns:att="d">6548790</att:productId>
<att:desc xmlns:att="d">NASQ123</att:desc>
<att:shipping xmlns:att="d">MAIL</att:shipping>
<att:status xmlns:att="d">COMPLETED</att:status>
<att:type1 xmlns:att="d">Electronic</att:type1>
<att:recieved xmlns:att="d">YES</att:recieved>
<att:otherDetails xmlns:att="d">
<att:details1/>
</att:otherDetails>
</ind:order>
</ind:updateorder>
</soapenv:Body>
</soapenv:Envelope>
However, This is my expected Output After Transformation is done:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<typ:updateorder>
<ind:orderId>12453</typ:orderId>
<ind:orderName>Electronic</typ:orderName>
<ind:quantity>5</typ:quantity>
<ind:order>
<att:productId>6548790</pur:productId>
<att:desc>NASQ123</pur:desc>
<att:shipping>MAIL</pur:shipping>
<att:status>COMPLETED</pur:status>
<att:type1>NA</pur:type1>
<att:recieved>YES</pur:recieved>
<att:otherDetails>
<pur:details1/>
</pur:otherDetails>
</typ:order>
</typ:updateorder>
</soapenv:Body>
</soapenv:Envelope>

What you are trying to get is not a valid XML. Because all name spaces used in an XML needs to be declared within the XML. While writing dataweave, when you add an element like ind#updateorder what you mean is "Add an element with name updateorder from the namespace ind".
If you really want the output without namespace declaration. you can think of it as you need an element with name ind:updateorder and not updateorder from ind.
In other words, replace ind#updateorder with "ind:updateorder" and similarly at other places. something like this
%dw 2.0
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
output application/xml writeDeclaration=false
---
{
soapenv#Envelope: {
soapenv#Header: {},
soapenv#Body: {
"ind:updateorder": {
"ind:orderId": payload.orderId,
"ind:orderName": payload.order,
"ind:quantity": "5",
"ind:order": {
"att:productId": payload.productId,
"att:desc": payload.desc,
"att:shipping": "MAIL",
"att:status": payload.status,
"att:type1": payload.order,
"att:recieved": payload.recieved,
"att:otherDetails": payload.*details map () -> {
"att:details1": $.attributeS.linetype
}
}
}
}
}
}
However, as I mentioned earlier, this is not a valid XML. You can try the w3school validator or any other online tool to validate to check.

Related

Shopware 6 custom entity fields are not updated via admin api

i have a custom entity defined in entities.xml:
<?xml version="1.0" encoding="utf-8" ?>
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/System/CustomEntity/Xml/entity-1.0.xsd">
<entity name="custom_entity_search">
<fields>
<string name="media_hash" store-api-aware="true" />
<json name="data" store-api-aware="true" />
</fields>
</entity>
</entities>
when i use the admin api to insert a new custom entity i don't get all my fields updated.
request url:
http://localhost/api/custom-entity-search
request body:
{
"name": "custom-entity-search",
"fields": {
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
}
The entity is created but fields "media_hash" and "data" remain null.
How can i update those fields ?
You need to pass the fields directly in the payload there is no need to specify the entity name in the payload itself, the mapping to the concrete custom entity is done over the REST-API endpoint api/custom-entity-search
so the request body should look like this:
{
"media_hash": "123hashmedia",
"data": {"test": "1234"}
}
Edit (to many relations)
{
"media_hash": "123hashmedia",
"data": {"test": "1234"},
"customer_to_many_field": [
{
"id": "my first customer id",
"firstName": "The new name",
},
{
... // data for second customer if needed
}
]
}

Setting Http response data as a varible in Mule4

I am trying to set http response values in variable. Below is response from http request
{
"kind": "drive#file",
"id": "1MxumGPQD9dH161BQJCoJ_",
"name": "2020_August",
"mimeType": "application/vnd.google-apps.folder"
}
How can i set only the id field in a variable after getting above reponse.
Am trying this logic in trans form message
%dw 2.0
output application/json
---
{
"id":payload.id
}
But giving me error
The content that's returned from your HttpRequest call is binary.
Try this:
%dw 2.0
output application/json
---
id: read(payload, "application/json").'id'
which should return what you're looking for:
{
"id": "1MxumGPQD9dH161BQJCoJ_"
}
If you are capturing that into a local variable, define the same using a set-variable, like this:
<set-variable value="#[read(payload, "application/json").'id']" doc:name="id" variableName="id"/>

Type mismatch for 'mapObject' operator in Mule 3.8.0 DataWeave that worked in 3.9.0

I built an API project that builds and sends a SOAP request to another service, based on parameters sent to the API. I inadvertently built the project in Mule 3.9.0 EE, when our production and dev Mule environments are 3.8.0 EE. The project works fine locally in 3.9.0, and it runs in 3.8.0 until it builds the request in Dataweave. It reports the following exception in 3.8.0:
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.UnexpectedOperationTypesException: Type mismatch for 'mapObject' operator
found :array, :function
required :object, :function
I use two Dataweaves to build the request. The first builds the prompts used in the SOAP request from the parameters. The second builds the SOAP request and inserts the prompts.
The first Dataweave:
%dw 1.0
%output application/json
---
[flowVars.parameterMap mapObject (value, key)->{
PROMPT: {
PSQueryName: "",
UniquePromptName: key,
FieldValue: value
}
}]
The second Dataweave:
%dw 1.0
%output application/xml encoding="UTF-8"
%namespace SOAP-ENV http://schemas.xmlsoap.org/soap/envelope/
%namespace wsse http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
%namespace qas http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ_MSG.VERSION_1
%namespace qas1 http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ.VERSION_1
---
{
SOAP-ENV#Envelope: {
SOAP-ENV#Header: {
wsse#Security #(SOAP-ENV#mustUnderstand: "1"): {
wsse#UsernameToken: {
wsse#Username: "someUsername",
wsse#Password #(Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"): "somePassword"
}
}
},
SOAP-ENV#Body: {
qas#QAS_EXEQRY_SYNC_REQ_MSG: {
qas1#QAS_EXEQRY_SYNC_REQ: {
QueryName: flowVars.queryName,
isConnectedQuery: "N",
OwnerType: flowVars.queryType,
BlockSizeKB: 0,
MaxRow: 0,
OutResultType: "webrowset",
OutResultFormat: "nonfile",
PROMPTS: payload.*PROMPT mapObject {
PROMPT: {
PSQueryName: $.PSQueryName when $.PSQueryName != "" otherwise {},
UniquePromptName: $.UniquePromptName,
FieldValue: $.FieldValue
}
}
}
}
}
}
}
In 3.9.0, the Dataweave transformed the SOAP request perfectly. In 3.8.0, it has issue with the PROMPTS: payload.*PROMPT mapObject statement in the second DataWeave.
What changed in 3.9.0 that made this work properly?
What work around can I do to resolve this issue in 3.8.0?
I solved this on my own by combining the two Dataweaves, which separating the two proved to be unnecessary.
It does not answer what changes occurred in 3.9.0 that allowed it to work in the original project.
%dw 1.0
%output application/xml encoding="UTF-8"
%namespace SOAP-ENV http://schemas.xmlsoap.org/soap/envelope/
%namespace wsse http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
%namespace qas http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ_MSG.VERSION_1
%namespace qas1 http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ.VERSION_1
---
{
SOAP-ENV#Envelope: {
SOAP-ENV#Header: {
wsse#Security #(SOAP-ENV#mustUnderstand: "1"): {
wsse#UsernameToken: {
wsse#Username: "someUser",
wsse#Password #(Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"): "somePassword"
}
}
},
SOAP-ENV#Body: {
qas#QAS_EXEQRY_SYNC_REQ_MSG: {
qas1#QAS_EXEQRY_SYNC_REQ: {
QueryName: flowVars.queryName,
isConnectedQuery: "N",
OwnerType: flowVars.queryType,
BlockSizeKB: 0,
MaxRow: 0,
OutResultType: "webrowset",
OutResultFormat: "nonfile",
PROMPTS: flowVars.parameterMap mapObject (value, key)->{
PROMPT: {
PSQueryName: "",
UniquePromptName: key,
FieldValue: value
}
}
}
}
}
}
}

How to add a simple flow rule via OpenDaylight DLUX using the /operations/sal-flow:add-flow api

I am trying to add a simple flow rule via Lithium's DLUX using the /operations/sal-flow:add-flow api call but getting nothing but errors, please can someone help?
Even a preview of a sample flow someone has added would be really helpful?
My current input as displayed in the preview frame is:
http://localhost:8181/restconf/operations/sal-flow:add-flow
{
"add-flow": {
"input": {
"match": {
"ethernet-match": {
"ethernet-type": {
"type": "2048"
}
},
"ipv4-source": "10.0.0.1/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"drop-action": {},
"order": "0"
}
]
}
}
]
},
"flow-name": "test",
"table_id": "0"
}
}
}
The current error is:
"Server Error : The server encountered an unexpected condition which prevented it from fulfilling the request. - : The operation encountered an unexpected error while"
The same request in Postman gives the error:
{
"errors": {
"error": [
{
"error-type": "protocol",
"error-tag": "malformed-message",
"error-message": "Error parsing input: Schema node with name add-flow wasn't found under (urn:opendaylight:flow:service?revision=2013-08-19)add-flow."
}
]
}
}
I have seen examples using xml but nothing that seems to work. I am able to view the network topology via dlux so I presume I am connected to everything ok.
Many thanks in advance.
Remove the add-flow and the corresponding brackets from the input data. Use things like
{
input: {...},
output: {...}
}
I am having the same problem using DLUX. Anyway I managed to find a solution using XML POST requests from this link https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:End_to_End_Flows. You can use POSTMAN application on Chrome to send requests. The body of the request should be something like:
POST http://localhost:8080/restconf/operations/sal-flow:add-flow
Add authentication header too.
Content-type: application/xml
Accept: application/xml
Body:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<input xmlns="urn:opendaylight:flow:service">
<barrier>false</barrier>
<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="openflow:1"]</node>
<cookie>55</cookie>
<flags>SEND_FLOW_REM</flags>
<hard-timeout>0</hard-timeout>
<idle-timeout>0</idle-timeout>
<installHw>false</installHw>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.10.2/32</ipv4-destination>
</match>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
<order>0</order>
</action>
</apply-actions>
</instruction>
</instructions>
<priority>0</priority>
<strict>false</strict>
<table_id>0</table_id>
</input>

Having trouble understanding how npm soap package works

I'm using the npm soap package to connect to a SOAP API and call methods, and I'm not grasping how this is supposed to work.
For instance, in the API documentation, it gives this as an example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://xxx">
<soapenv:Header/>
<soapenv:Body>
<ser:setSessionParameters>
<viewSettings>
<forceLogoutSession>yes</forceLogoutSession>
<rollingPeriod>Minutes30</rollingPeriod>
<shiftStart>21600000</shiftStart>
<statisticsRange>CurrentDay</statisticsRange>
<timeZone>-28800000</timeZone>
<idleTimeOut>1800</idleTimeOut>
</viewSettings>
</ser:setSessionParameters>
</soapenv:Body>
</soapenv:Envelope>
And if I use a REST tool to send this content to the API endpoint, it works as expected.
In my code, if I invoke this method call:
var x = client.describe();
console.log(x.WsSupervisorService.WsSupervisorPort.setSessionParameters);
I get this response:
{
input: {
viewSettings: {
appType: 'xs:string',
forceLogoutSession: 'xs:boolean',
rollingPeriod: 'rollingPeriod|xs:string|Minutes5,Minutes10,Minutes15,Minutes30,Hour1,Hours2,Hours3,Today',
shiftStart: 'xs:int',
statisticsRange: 'statisticsRange|xs:string|RollingHour,CurrentDay,CurrentWeek,CurrentMonth,Lifetime,CurrentShift',
timeZone: 'xs:int',
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
},
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
},
output: {
targetNSAlias: 'tns',
targetNamespace: 'http://xxx'
}
}
But this fails:
client.setSessionParameters({
input: {
viewSettings: {
forceLogoutSession: true,
rollingPeriod: 'Minutes30',
shiftStart: 216000000,
statisticsRange: 'CurrentDay',
timeZone: -288000000,
idleTimeOut: 1800
}
}
});
...yielding this error:
{ [Error: env:Client: Endpoint {http://xxx/}WsSupervisorPort does not contain operation meta data for: setSessionParameters] stack: [Getter] }
I'm at a loss here. Any help would be hugely appreciated!
Simply try:
client.setSessionParameters({
viewSettings: {
forceLogoutSession: true,
rollingPeriod: 'Minutes30',
shiftStart: 216000000,
statisticsRange: 'CurrentDay',
timeZone: -288000000,
idleTimeOut: 1800
}
});