badarg when trying to read a csv file in erlang, with tsung - parsing

I am using tsung to load test my websocket server. I am new to tsung and to erlang.
I have a list of users and keys exported to a .csv file. To get it running i reduced the csv file to:
1;2
with no empty line at the end of the file.
This is a snippet of my tsung config (otherwise working fine):
<options>
<option name="file_server" id="users" value="PATH_TO_MY_CSV/users.csv"/>
</options>
[...]
<setdynvars sourcetype="erlang" callback="loadusers:user">
<var name="connection_url" />
</setdynvars>
[...]
<request subst="true">
<websocket type="connect" path="/?%%_connection_url%%"/>
</request>
Here's my loadusers.erl, which makes use of a ts_file_server tsung module:
-module(loadusers).
-export([user/1]).
user({Pid,DynVar})->
{ok,Line} = ts_file_server:get_next_line(),
[Username, Passwd] = string:tokens(Line,";"),
"username=" ++ Username ++"&password=" ++ Passwd.
Here's the erlang error stack:
** State machine <0.90.0> terminating
** Last message in was {timeout,#Ref<0.0.0.414>,end_thinktime}
** When State == think
** Data == {state_rcv,none,
{{0,0,0,0},0},
undefined,0,10000,"192.168.59.103",443,ts_tcp,
{proto_opts,negociate,"/http-bind/","/chat","binary",10,
600000,infinity,32768,32768,undefined,undefined,[]},
true,1,undefined,true,undefined,
{1431,872144,388666},
6,6,false,undefined,0,[],<<>>,
{websocket_session,undefined,undefined},
0,2,524288,524288,
[{tsung_userid,2}],
ts_websocket,[],undefined,none}
** Reason for termination =
** {{badarg,[{dict,fetch,
[default,
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],
[[users|{file,{<<"1;2">>},1,-1}]],
[],[],[],[],[],[],[],[],[],[],[],[]}}}],
[{file,"dict.erl"},{line,130}]},
{ts_file_server,handle_call,3,
[{file,"src/tsung_controller/ts_file_server.erl"},
{line,159}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,[{global,ts_file_server},{get_next_line,default}]}}
I know dynvars can be directly pulled from a tsung config, but I need to do it in the script since later I will need to dynamically manipulate the data. IMPORTANT: reading the same csv file works fine, so it seems like the script is the problem.
Can someone explain to me what erlang is complaining about here?

The error message is saying that dict:fetch(default, SomeDict) was called and threw a badarg exception. Typically this would happen when the key (default in your case) doesn't exist.
The problem is that in the Tsung config you set id="users", which sets the file id to users. But ts_file_server:get_next_line/0 expects the file id to be default.
Either remove id="users" from the config or change the Erlang part to use ts_file_server:get_next_line/1, passing in the file id you used in the config file.

Related

How to add to a Lua DissectorTable?

I'm writing a Lua dissector for Wireshark for a complex protocol. The protocol has a message header that includes a msgType field. I want to write a subdissector for each message type, with each subdissector stored in a separate source file.
My top-level script is general.lua which dissects the message header and creates the dissector table:
DissectorTable.new("myProtocol.Message")
dofile(DATA_DIR.."cplane.lua")
cplane.lua is a subdissector for message type 'cplane' and includes the code:
my_dissector_table = DissectorTable.get("myProtocol.Message")
my_dissector_table:add(0x02, myProtocol_cplane_proto)
Both scripts are in the same subdirectory of Wireshark's plugins directory.
When I load the plugins I get error:
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:170: bad
argument #1 to 'dofile' (dofile: file does not exist)
How can I fix this? Is the problem to do with the loading order of the scripts? Is the dofile() call necessary?
It is not necessary to use dofile as all scripts in the plugins directory are loaded. The order of loading is however not fixed (at least, it is not documented to be fixed). Currently Lua plugins are loaded after other dissectors, so trying to lookup dissector tables in the "global scope" will only work for built-in dissectors, such as tcp.port:
local myproto = Proto("myproto", "My Protocol")
function myproto.dissector(tvb, pinfo, tree)
...
end
-- Register with a built-in dissector table
DissectorTable.get("tcp.port"):add(1234, myproto)
For registering with custom dissector tables, this registration has to be deferred. In C dissectors, you would put the registration in proto_reg_handoff_PROTOABBREV (where PROTOABBREV should be substituted accordingly), but in Lua there is no such function.
The closest you can get is the "init" routine (a property of the Proto class, proto.init). These are called when a capture file is opened, before dissecting any packets. Example:
function myproto.init()
DissectorTable.get("your-custom-table"):add(1234, myproto)
end
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Answer: This error means that Dissector table is not found. Reason could be that the path is not correct, or the sequence of the file execution.
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:170: bad argument #1 to 'dofile'
(dofile: file does not exist)
Answer: For me this error is gone by entering the exactly correct path

Custom configuration not getting reflected in applicationcontext.xml

I am using custom configuration for my RabbitMQ connectivity. I'm connecting to multiple hosts.
<context:property-placeholder location="classpath:/test_setting.properties" ignore-unresolvable="true"/>
...
<rabbit:connection-factory id="testConnectionFactory"
addresses="${test.addresses}"
username="${test.username}"
password="${test.password}"
virtual-host="${test.virtualhost}"
connection-factory="rhb" />
<bean id="rhb" class="com.rabbitmq.client.ConnectionFactory">
<property name="requestedHeartbeat" value="${test.connection.heartbeat}" />
</bean>
My property file looks like: test_setting.properties
test.queue=testQueue
test.virtualhost=/global_api
test.addresses=host1:5672,
host2:5672
test.username=guest
test.password=guest
test.connection.heartbeat=60
test.consumer.concurrency=1
When i trigger my main class properties not getting replaced inside applicationcontext.xml in Spring. Thereby I am getting connection refused exception.
Please note if I hard code the connection details everything works fine.
ignore-unresolvable="true"
It looks like the file is not being found - change that to false to see the error.
Also, turning on DEBUG logging for org.springframework will provide a great deal of information about property resolution.
test.addresses=host1:5672,
host2:5672
Properties have to be on one line (you can terminate a line with \) for continuation.
test.addresses=host1:5672, \
host2:5672

ANT SCRIPT: http url property value is not loaded and giving error java.net.MalformedURLException: For input string: "${amx.admin.port}"

I am busy with automation of tasks using ant script.
In main properties ( Connection.properties) file I had defined properties values which will be used at runtime in script.
admin.url.protocol=${amx.admin.url.protocol}
amx.admin.hostname=shrijeet
amx.admin.port=8120
amx.admin.url=${amx.admin.url.protocol}://${amx.admin.hostname}:${amx.admin.port}
Later in script another property file (build.properties) is used at runtime where it uses above values as below.
adminURL=http://${amx.admin.hostname}:${amx.admin.port}
Now issue is , whenever script is reading value of "adminURL" property it fails with below error
[AMXAdminTask] 08 Apr 2017 18:15:14 WARN - TIBCO-AMX-CLI-000743: Failed to parse the admin base
url 'http://${amx.admin.hostname}:${amx.admin.port}'. Not a valid url.
[AMXAdminTask] java.net.MalformedURLException: For input string: "${amx.admin.port}".
when I hard code value like adminURL=http://shrijeet:8120 , then script works fine. But I need hostname:port number to be externalised in main connection.properties.
Please suggect is there is any other way to externalize http url type of properties.
I see i have found solution
where i am creating temporary file ,say build-temp.properties and given tokens in property.
Ex
adminURL=adminuRL_temp
And then i am replacing token with values mentioned in Connection.properies file.
In build-temp.properties file:
adminURL=adminurl_temp
username=username_temp
password=password_temp
Target:
<target name="setBuildProperty">
<copy file="${ScriptFilesPath}/StandAloneTibcohost/build-temp.properties" tofile="${ScriptFilesPath}/StandAloneTibcohost/build.properties" overwrite="true"/>
<replace file="${ScriptFilesPath}/StandAloneTibcohost/build.properties" propertyFile="${ScriptFilesPath}/Connection.properties">
<replacefilter token="adminurl_temp" property="adminurl"/>
<replacefilter token="username_temp" property="username"/>
<replacefilter token="password_temp" property="password"/>
</replace>
</target>
This works perfectly and values are now getting updated.

TFS Database Backup Failed : There is an error in XML document - but which Doc?

Our Nightly TFS 2012 backup has just started to fail. It also fails when run directly through TFS Express Administration Console.
Which file is the following error actually referring to? If I can find it then I should be able to fix the "Root element is missing" error :)
[13/08/2014 23:00:00] [Info] Full database backup job
[13/08/2014 23:00:00] [Info] Getting backup lock
[13/08/2014 23:00:05] [Error]
Exception Message: There is an error in XML document (0, 0). (type InvalidOperationException)
Exception Stack Trace: at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at Microsoft.TeamFoundation.Admin.BackupSets.Load(String folder)
at Microsoft.TeamFoundation.Admin.Jobs.FullDatabaseBackupJobExtension.Run(TeamFoundationRequestContext requestContext, TeamFoundationJobDefinition jobDefinition, DateTime jobQueueTime, String& resultMessage)
Inner Exception Details:
Exception Message: Root element is missing. (type XmlException)
Exception Stack Trace: at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlReader.MoveToContent()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderBackupSets.Read7_BackupSets()
[13/08/2014 23:00:05] [Info] Full Backups Failed
Thanks.
Dylan answered my original question as to where to find the unspecified xml file that was in error, but in case it helps anyone else...
The Backupsets.xml file was empty. Why this is I do not know...
Attempting to configure backups through TFS Express Administration Console also failed with the same error, so I
Deleted the Backupsets.xml file altogether
Reconfigured Backups using the wizard - Now that it didn't find the xml file at all it created a new one.
Ran a full backup - which was sucessful. Hopefully the scheduled backups will now also work from now on.
NB The newly created Backupsets.xml file (Before the first full backup) :
<?xml version="1.0"?>
<BackupSets xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Version>1</Version>
<BackupSets />
</BackupSets>
Look in the folder where your backups are configured to be placed. there will be an XML file there, can't remember the name, but maybe something like BackupSets.xml
FIX (user workaround):
Rename the file BackupSets.xml in the backup destination folder
Re-run Full Backup*
In TFS Admin Console select Scheduled Backups, then click Take Full Backup Now. Or use command line, PowerShell script, API call as desired.
CAUSE: backupsets.xml in backup destination does not contain valid XML.
Why does this cause failure? Backup wizard opens backupsettings.xml then calls XML deserializer function System.Xml.Serialization.XmlSerializer.Deserialize preparing to add new entry. Invalid XML content including empty/zero byte or text-only content will cause deserialize exception.
PRODUCTS IMPACTED: Repro confirmed in TFS2010 and on 2017-11-25 I had repro with TFS2015 SP3 :-O
Fix is fairly straightforward... once you understand what is going on. -Zephan
MICROSOFT CODE BUGFIX/feature improvement request:
BACKUP Wizard exception handling for backupsets.xml deserialize or parsing exceptions.
If XML deserialization error then close backupsets.xml, rename it to backupsets-YYMMDD-hhmm-corrupt-backup.xml, then jump to backupsets.xml file not found functionality.
SEVERITY: HIGH (data loss)
This is a long-standing problem that can lead to major data loss. I've personally seen over 1 month of data loss due to this issue silently blocking backups and making all earlier restore sets unusable (since parsing BackupSets.xml is VERY finicky I couldn't even hack to restore last successful backup.)

WSDL Endpoint example throwing errors in Mule

Posting here is always my last resort, but I'm going crazy here. I'm a Mule ESB beginner. I've been trying to do some simple examples to get me on the right track.
But I've encountered a problem with one of the examples I've seen on the mule website...
http://www.mulesoft.org/documentation/display/current/WSDL+Connectors
I'm trying to set up a generic WSDL endpoint, which invokes a web service without generating a client.
The WSDL I'm trying to access...
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL&method=ConversionRate
The problem is, I keep getting the following error
[ERROR] IOException during exec() of compiler "javac". Check your path environment variable.
ERROR 2013-04-19 09:27:07,920 [[soap].soapFlow1.stage1.02] org.apache.cxf.endpoint.dynamic.DynamicClientFactory: Could not compile java files for http://www.webservicex.net/CurrencyConvertor.asmx?WSDL&method=ConversionRate?wsdl.
ERROR 2013-04-19 09:27:07,934 [[soap].soapFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index (java.lang.IllegalStateException)
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index (javax.xml.bind.JAXBException)
com.sun.xml.bind.v2.ContextFactory:183 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/xml/bind/JAXBException.html)
2. Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index (javax.xml.bind.JAXBException)
javax.xml.bind.ContextFinder:-1 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/xml/bind/JAXBException.html)
3. Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index (java.lang.IllegalStateException)
org.apache.cxf.endpoint.dynamic.DynamicClientFactory:363 (null)
4. Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index (java.lang.IllegalStateException) (org.mule.api.DefaultMuleException)
org.mule.module.cxf.builder.AbstractOutboundMessageProcessorBuilder:96 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/DefaultMuleException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
javax.xml.bind.JAXBException: "net.webservicex" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
And yes, I've hunted around the internet for hours looking for a solution.
Things I've done to try fix the problem.
Make sure the javac path is set in the environment variables.
(%JAVA_HOME%\bin)
Make sure that mule studio has the correct path to JRE
I know it's a simple problem, but I need to figure it out to tackle a larger project that I have in mind.
If anyone could shed some light on a solution this problem, then I'd be extremely grateful.
Thanks :)
Other info:
Using Java 1.7
Using MuleStudio 3.4
Ok, after trying and failing at many different solutions, I've figured it out.
I've seen a lot of people asking the same question as me, with very few solutions.
Here is mine...
The JRE was incorrect.
My java directory consisted of..
And Mule studio was using the folder jre7
So I changed it to use the JRE in the directory jdk1.7.0_17/jre
Ran it again and.. OMG it worked!!
Here is how to do it in mule studio/eclipse...Right Click on your Project --> Properties --> Java Build Path --> Libraries Tab --> Click JRE System Library --> Press Edit --> Click Alternate JRE --> Click Installed JREs.. --> Then Add the JRE from the correct directory like I stated above.
Hope this helps anyone with the same problem! :)

Resources