My aim is to log a JSON object value fethed from a jsp file from the vxml. Is there any way to do that. I see that there is a function called JSON.stringify but thats giving me nothing as a log.
Below is my code:
<?xml version="1.0"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<var name="userId" expr="1" />
<!--form id="get_location"-->
<data name="userData" method="get" src="http://localhost:5000/userLocation.jsp" nameList="userId" />
<property name="inputmodes" value="dtmf"/>
<menu id="menuZero">
<choice dtmf="1" next="#choice1"/>
<choice dtmf="2" next="#choice2"/>
</menu>
<!--/form-->
<form id="choice1">
<block>
<if cond="userData.HttpResponse.do_queryResponse['return'].errorMsg.result_code != '0'">
<goto next="welcome.vxml"/>
<else/>
<goto next="welcome.vxml"/>
</if>
</block>
</form>
<form id="choice2">
<block>
<log expr="JSON.stringify(userData.HttpResponse)"/>
</block>
</form>
</vxml>
Maybe, VoiceXML is not supported "JSON.stringify".
Try to get "json2.js" and add code.
<script src="json2.js" />
For example,
<?xml version="1.0" encoding="UTF-8"?>
<vxml
version="2.0"
xmlns="http://www.w3.org/2001/vxml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<script src="json2.js" />
<var name="messageObject" expr="{keyA:'valueA',keyB:'valueB',keyC:'valueC'}" />
<form>
<block><prompt>Write Log!</prompt></block>
<block><log expr="JSON.stringify(messageObject)"/></block>
</form>
</vxml>
I tested this code on "Voxeo Prophecy 13".
I tried json2.js as described above and I had the same issue, 'assignment to undeclared variable JSON'. To fix this, I just declared in the same file (json2.js):
var JSON;
Then it worked properly. In the vxml:
<script><![CDATA[
prueba = new Object();
prueba.pepito = 1234;
prueba.OtraPrueba = "lalalapepe";
]]></script>
<log label="IVB_HISTORY">
<value expr="JSON.stringify(prueba)"/>
</log>
It gets logged as followed:
{"pepito":1234,"OtraPrueba":"lalalapepe"}
I'm using Convergy's InVision Studio
Related
i have written a scheduled task which call an Api in sequence in wso2 ei 6.4.0. my task is :
<task xmlns="http://ws.apache.org/ns/synapse"
name="GetMunicipalityAPIToken"
class="org.apache.synapse.startup.tasks.MessageInjector"
group="synapse.simple.quartz">
<trigger interval="60"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<test xmlns=""/>
</property>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="sequenceName"
value="GetTokenFromMunicipalityService"/>
<property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
name="injectTo"
value="sequence"/>
</task>
and my sequence is :
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="GetTokenFromMunicipalityService" xmlns="http://ws.apache.org/ns/synapse">
<send>
<endpoint>
<http method="POST" uri-template="http://x.x.x.x/api/MunicipalityBill/connect/token"/>
</endpoint>
</send>
</sequence>
but when i run integrator.bat in wso2eiHome/bin I got this error : "Could not initialize Start up controller. TaskManager not found" and the Api dont be called. Do i forget something ?
The error can be caused when you do not have org.wso2.carbon.mediation.ntask.NTaskTaskManager defined in the server. Could you please check whether the following is added in the synapse.xml file located in the [EI_HOME]/repository/deployment/server/synapse-configs/default/ directory
<definitions xmlns="http://ws.apache.org/ns/synapse">
<taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/>
</definitions>
I think I'm missing something as I can't seem to figure out how to have it write to a log file in json format using NLog setup in configuration file. The straight rolling file works fine, but not the json. The json target only outputs the message (not in json).
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target xsi:type="File" name="rollingFile" fileName="${basedir}/logs/${shortdate}.log" archiveFileName="${basedir}/logs/{shortdate}_Archive{###}.log" archiveAboveSize="1000000" archiveNumbering="Sequence" layout="${longdate} ${uppercase:${level}} ${callsite} ${message}" />
<target xsi:type="File"
name="rollingFileJson"
fileName="${basedir}/logs/${shortdate}.json"
archiveFileName="${basedir}/logs/{shortdate}_Archive{###}.json"
archiveAboveSize="1000000"
archiveNumbering="Sequence"
layout="${json-encode} ${message}">
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="rollingFile" />
<logger name="*" minlevel="Trace" writeTo="rollingFileJson" />
</rules>
</nlog>
As of the release of NLog 4.0.0 it is possible to use a layout that renders events as structured JSON documents.
Example taken from NLog project site:
<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json">
<layout xsi:type="JsonLayout">
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}" />
</layout>
</target>
Edit:
You can also create it in code.
Here is the link to the specific part of documentation.
And here the copied example:
var jsonLayout = new JsonLayout
{
Attributes =
{
new JsonAttribute("type", "${exception:format=Type}"),
new JsonAttribute("message", "${exception:format=Message}"),
new JsonAttribute("innerException", new JsonLayout
{
Attributes =
{
new JsonAttribute("type", "${exception:format=:innerFormat=Type:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
new JsonAttribute("message", "${exception:format=:innerFormat=Message:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
}
},
//don't escape layout
false)
}
};
For more info read the docs.
As per NLog documentation: json-encode will only escape output of another layout using JSON rules. It will not "convert" the output to JSON. You'll have to do that yourself.
'{ "date":"${longdate}","level":"${level}","message":${message}}'
Take a look at this question for more details.
I am trying to upload an XML file from a HTML page to Mule-3.5 (CE). In Mule, I am unable to retrieve the contents of the file. I am attaching the HTML and the Mule configuration xml. I hope someone could help me through this.
<html>
<body>
<form action="http://localhost:8081" method="post" enctype="text/xml" >
INVOIC IDOC File:<input type="file" name="uploadedFile" size="40" accept=".xml" />
<input type="submit" name="Submit" id="button" value="Send" />
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.5.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:connector name="HTTP_HTTPS" enableCookies="true" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP-HTTPS">
<reconnect/>
</http:connector>
<flow name="httpconnectorFlow1" doc:name="httpconnectorFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" connector-ref="HTTP_HTTPS"/>
<echo-component doc:name="Echo"/>
</flow>
</mule>
The Mule script is just a test for HTTP connector. I am searching ways to extract the contents of the file uploaded.
You could use this to get things working. The thing that I have changed in the HTML is the enctype and the name of the file input.
<html>
<body>
<form action="http://localhost:8081" method="post" enctype="multipart/form-data" >
INVOIC IDOC File:<input type="file" name="payload" size="40" accept=".xml" />
<input type="submit" name="Submit" id="button" value="Send" />
</form>
</body>
</html>
for the Mule part you can use the HttpMultipartMuleMessageFactory for the HTTP connector. This lets you receive multipart/form data. Since the file input was named payload it will be the payload om the mule message, it will be a streaming payload.
Below is a sample mule flow for receiving the xml in mule and logging the payload. I use a simple object-to-string transformer to read the stream.
<http:connector name="HTTP" doc:name="HTTP">
<service-overrides messageFactory="org.mule.transport.http.HttpMultipartMuleMessageFactory" />
</http:connector>
<flow name="http-xml-receive-flow" doc:name="http-xml-receive-flow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[message.payload]" doc:name="Logger" level="INFO"/>
</flow>
If you plan to include other form inputs they will be available as inboundAttachments on the mule message.
I'm using atocompleter in my form with json.
This is the part of my struts.xml
<package name="json" namespace="/" extends="json-default">
<result-types>
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult" />
</result-types>
<action name="test" class="testClass" method="populate">
<result type="json" name="success">
<param name="root">itemList</param>
<param name="contentType">text/html</param>
</result>
</action>
</package>
This is the jsp
<s:form id="frm_demo" name="frm_demo" theme="simple" action="test2">
<s:url id="remoteurl" action="test" />
<sj:autocompleter
id="lst"
name="lst"
list="%{remoteurl}"
listValue="name"
listKey="id"
selectBox="true"
/>
<s:submit value="submit"/>
</s:form>
This is the action class method
public String populate() throws Exception{
itemList.put("1", "a");
itemList.put("2", "b");
itemList.put("3", "c");
return "success";
}
With the above code in struts.xml my jsp renders like this.{"3":"c","2":"b","1":"a"}
But when I delete the "contentType" parameter, in other words the content type is "application/json" the jsp pops the download window.
I need theauto completer to return the key when i click submit button. But the page doesn't load with the autocompleter. Any solutions?
p.s. itemList i used in my action class is a HashMap... does that matter?
Using map is OK with collection-backed components. I think there's couple of problems with your code.
First in you action configuration you have set the root object to your itemList, this way only content of the list will be converted to json so you can't refer to the list itself in your autocompleter.
Second you have to set the href attribute for your autocompleter and set the remoteUrl as it's value. So your code could be like:
<package name="json" namespace="/" extends="json-default">
<action name="test" class="testClass" method="populate">
<result type="json"/>
</action>
</package>
In your autompleter:
<s:form id="frm_demo" theme="simple" action="test2">
<s:url id="remoteurl" action="test" />
<sj:autocompleter href="%{remoteurl}"
id="lst"
name="lst"
list="itemList"
listValue="name"
listKey="id"
selectBox="true"/>
<s:submit value="submit"/>
</s:form>
See if that works.
I think your code is ok,Just remove this code
<param name="contentType">text/html</param>
I want to use two exceptions.
the first:
The user can say (every time, in the whole application) "stop" and then the program exits.
the second:
I have following Code:
<form id="test">
<field name="test1">
<prompt bargein="true" bargeintype="hotword" > choose xy</prompt>
<grammar root="main" version="1.0" xml:lang="de-DE">
<rule id="main" scope="public">
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
</one-of>
</rule>
</grammar>
<nomatch>
didn't get it
<reprompt/>
</nomatch>
<noinput>
didn't hear you ?
<reprompt/>
</noinput>
<filled>
<assign name="myvar" expr="test1" />
<value expr="myvar"/> chosen
</filled>
</field>
</form>
I want that the user can say a word of my choice, and then a help-exception triggers - like
choose the following: x,y,z,...
how can i use such a exception handler?
thanks
I solved it like this:
I added an item:
<item>help</item>
and checked if the item was chosen:
<filled>
<if cond="test1 == 'help'">
<prompt>say xy.</prompt>
<goto next="#test" />
</if>
<assign name="myvar" expr="test1" />
<value expr="myZeitraum"/> chosen.
<goto next="#KPI" />
</filled>