After setting up
<cxf:properties>
<entry key="faultStackTraceEnabled" value="true" />
</cxf:properties>
I was able to get the stack trace. But I am struggling to remove it from the outgoing message.
I tried with following code:
Fault fault = (Fault) message.getContent(Exception.class);
StackTraceElement[] stackTrace = fault.getCause().getStackTrace();
List<StackTraceElement> tempList = new ArrayList<StackTraceElement>(Arrays.asList(stackTrace));
tempList.removeAll(tempList);
stackTrace = tempList.toArray(new StackTraceElement[0]);
fault.getCause().setStackTrace(stackTrace);
message.setContent(Exception.class, fault);
Even though the last line is setting the content back with empty stackTrace but the outgoing message still has the full stack trace.
Can you provide some code snippet how to remove the <stackTrace>?
#soilworker I was able to achieve what I was looking for. I was looking for stackTrace for logging.
I removed the following lines
<cxf:properties>
<entry key="faultStackTraceEnabled" value="true" />
</cxf:properties>`
Code:
Fault fault = (Fault) message.getContent(Exception.class);
String exceptionMsg = null;
for (StackTraceElement element : fault.getCause().getStackTrace()) {
exceptionMsg = // concatenate
}
So no <stackTrace> present in outgoing message.
But it will interesting to know how to modify the outgoing fault (like add additional tags) in the outgoing interceptor.
Thanks.
Related
I am using PugiXml library for XML related operations.
My XML File:
<CurrentStatus>
<Time Stamp= "12:30">
<price>100</price>
<amount>1</amount>
</Time>
<Time Stamp= "14:50">
<price>10</price>
<amount>5</amount>
</Time>
<Time Stamp= "16:30">
<price>10</price>
<amount>5</amount>
</Time>
</CurrentStatus>
For testing purpose, I am giving a hard-coded value that I want to delete the node Time with attribute Stamp = 14:50.
XML Node Removal Code: I used this SO Question as reference to remove a node (name = Time and Attribute = 14:50).
for (xml_node child = doc.child("CurrentStatus").first_child(); child; )
{
xml_node next = child.next_sibling();
string attributeValue = child.attribute("Stamp").as_string();
if (attributeValue == "14:50")
{
cout << "delete" << endl;
child.parent().remove_child(child);
}
child = next;
}
Question: The above code runs without any error. It even enters into the if-statement but why the original XML file remains same after the execution?
PS: I am sure that the root node and the XML document is getting read properly in General since I am able to display the XML structure on the console.
I think that the problem was in Saving.
I executed the following save statement after the if-condition and it worked.
doc.save_file("D:/myfile.xml");
Here I have one doubt
I am creating log mediator in WSO2 and setting one property msg and it gives me output as follows
[2017-08-04 18:13:10,041] [] INFO - LogMediator Msg = Msg Coming************************
Here I just want the output like Msg Coming************************ I dont want to print property name...
How I will able to do it..
Example
<property name="*******************" value="hello" />
or
<property name="*******************" expression="translate('some string to log', 'abcdefg.....z', '****************************')" />
In first case you will get unknown property, in second unkond property with unknown value. Why you need such logging
I'm using a script mediator to convert the XML response to a JSON. The mediator works properly if the XML is well formatted but if the XML has self closing tags , it fails..
Any ideas to fix this issue is greatly appreciated..
<!-- XML data-->
<getMyClsScheduleResponse >
<RegisteredClass>
<ClassNumber>10757</ClassNumber>
<SubjectCode>AAS</SubjectCode>
<CatalogNumber>510</CatalogNumber>
<SectionNumber>001</SectionNumber>
<SectionType>IND</SectionType>
<SectionTypeDescr>Independent Study</SectionTypeDescr>
<SessionDescr>Regular</SessionDescr>
<CourseDescr>Supervised Research</CourseDescr>
<ClassTopic />
<CreditHours>1 - 6</CreditHours>
<LMSURL /> <!-- Self Closing tag -->
<Meeting>
<MeetingNumber>1</MeetingNumber>
<Days />
<Times />
<StartDate>09/02/2014</StartDate>
<EndDate>12/10/2014</EndDate>
<Location>TBA</Location>
<TopicDescr />
</Meeting>
/** Script Mediator */
function transformPayload(output) {
payload = output.getPayloadJSON();
results = payload.getMyClsScheduleResponse.RegisteredClasses;
var response = new Array();
var registeredClass = new Array();
for (i=0;i<results.length; i++ ) {
class_schedule = results[i];
newcls = new Object();
newcls.Link = class_schedule.LMSURL; // Error at this line..
}
}
Error Log :
TID: [0] [ESB] [2014-10-24 14:19:45,541] ERROR - The script engine returned an error executing the external js script : Value {name ='null', keyValue ='conf:/repository/esb/js/functions.js'} function transformPayload {org.apache.synapse.mediators.bsf.ScriptMediator}
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.WrappedException: Wrapped com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: syntax error (<Unknown source>#1) in <Unknown source> at line number 1 (<Unknown source>#53) in <Unknown source> at line number 53
at com.sun.phobos.script.javascript.RhinoScriptEngine.invokeMethod(RhinoScriptEngine.java:259)
Thanks
Kranthi
According to the given scenario that issue will be occur with self closing tags(As you described).In the case of self closing tags it returns the value as null.Workaround for this to check the value in the js mediator and handle the null value in the case of the self closing tags.
You can use the following js function to set the value in such a scenario within the js mediator.
function assignValuesWithNull(value){
var returnValue;
if(!value){
returnValue='';
}
else{
returnValue=value;
}
return returnValue;
}
Why do you use script mediator to change XML to JSON? what you have to do is , set content-type properly to get required format response.
I am developing a SOAP client in Matlab for connection a Web Service. What I am doing is the following script:
createClassFromWsdl('http://192.168.107.239/WSDL/v4.0/iLON100.wsdl')
obj = iLON100
methods(obj)
With the next result:
Methods for class iLON100:
Clear Get List Set display
Delete InvokeCmd Read Write iLON100
Then, I am editing for example the method List in order to request the list of Items for the service. The dot m file is:
% Build up the argument lists.
values = { '','//Item[#xsi:type="Dp_Cfg"]'};
names = { 'iLonItem','xSelect'};
types = {};
% Create the message, make the call, and convert the response into a variable.
soapMessage = createSoapMessage('http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/message/',
'List', values, names, types, 'document');
I have also a SOAP tester from the vendor of the device. Then, if I compare both XML requests, they differ as you can see in the next example (firstly the original request and secondly the Matlab one):
<SOAP-ENV:Body>
<List xmlns="http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/message/">
<iLonItem>
<xSelect>
//Item[#xsi:type="Dp_Cfg"]
</xSelect>
</iLonItem>
</List>
</SOAP-ENV:Body>
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<List xmlns="http://wsdl.echelon.com/web_services_ns/ilon100/v4.0/message/">
<iLonItem/>
<xSelect>Item</xSelect>
</List>
</soap:Body>
As you can observe, the tags are not included as sub-tags. I would like to know how to do it and generate the same structure of XML for sending the SOAP request correctly.
Thank you so much,
At the end, I have solved it by creating a structure as follows:
myStruct = struct('iLonItem',struct('xSelect','//Item[#xsi:type="Dp_Cfg"]'))
This structure is inserted into "values" and the method's name "iLONItem".
Using the MSXML2 functions from the "msxml3.dll" library, I'm trying to duplicate sections in an XML document, but it does not work as I expected.
Here is the XML:
<result>
<Target>
<Point>
<pos dimension="2">60.384005 5.333862</pos>
</Point>
</Target>
</result>
What I want is to add multiple sections. So I want to take the node, duplicate it and put it under the existing <Target> node. I'm almost convinced I should use the Clone method, but it does not seem to work.
The C++ code:
typedef MSXML2::IXMLDOMNodePtr XmlNode;
XmlNode pNode = pXMLRequest->selectSingleNode("//result");
if(pNode==NULL)
{ m_szErrorText = m_szErrorText + _T(" 'result' node not found");return FALSE;}
XmlNode pTargetNode = pNode->selectSingleNode("Target");
XmlNode pNewTargetNode = pTargetNode->cloneNode(true);
pNode->appendChild(pNewTargetNode);
But when I run this code nothing happens to the XML document. And when I inspect the XML text in pNewTargetNode I see it is '<result>' only which is just the name of the node While I would expect it to contain all the nodes in <Target>...</Target>. Is there something I am missing ?
I used the wrong kind of 'true'.
If I replace
XmlNode pNewTargetNode = pTargetNode->cloneNode(true);
with
XmlNode pNewTargetNode = pTargetNode->cloneNode(VARIANT_TRUE);
it works fine. I had already thought about this and used TRUE instead of true, but that does not work either.
So when using the msxml library alsways use VARIANT_BOOL, VARIANT_FALSE and VARIANT_TRUE.
Raymond Chen explains why there are so many variations:
http://blogs.msdn.com/b/oldnewthing/archive/2004/12/22/329884.aspx