Recording network traffic for test driven development - java

I ruby there is great https://github.com/vcr/vcr gem, but works only with ruby HTTP libraries. Is there tool that can be used to record and play network traffic, but from system level, or at least in java?? If not, could you give me proof of concept how to create such tool (only for linux)?

You can use TCPRelay to play network packets captured in libpcap format.
If you are using a protocol like sip, you can use Sipp, other option is to use mts-project.

Checkout betamax. It's a port of VCR for the JVM.

I use wireshark... which has a command line version called tshark. you can install that on centos via yum install wireshark-gnome (wireshark will install the gui, but wireshark-gnome ads it to your /bin and gives you tshark.)
I use Jenkins CI to run all my tests... for example, I work with VOIP/SIP testing a lot... so I have a jenkins job that when run:
starts SIPP load to a server
starts tshark recording to a file
I use a command line param to keep thsark to running for a duration - however you can use a signal to stop tshark as well.
you can set tshark to do a packet capture and pick up everything, or filter just certain layers, like RTP only or SIP only, etc.
If you dont want to use Jenkins to manage this, you can call tshark programatically via Ruby or any scripting language... Just use Ruby to open and run the application... like: Running command line commands within Ruby script

for Java. try anystub. you could record/playback any invocation in your project

Related

How do I run a gui Java application headless, without control of the source code?

I want to execute a Jar file using javax swing GUI with 1 radial option, a file selector and a button. The goal is to be able to automate the jar through CLI and select the radial option, file and then click the button.
I do not have access to edit the source of the jar
Is this possible?
You can look up JAuto, which is a JVMTI agent that is capable of expose UI widget attributes such as class names, screen coordinates. You talk to JAuto by sending a command to a named pipe. It responds by writing a file. A communication scheme like this works in bash scripts.
With the help of xdotool as an input simulator, you can achieve automation under the Linux X11 environment, inside a docker container.
Although depending on the complexity of the Java app, automating it in a headless manner can also be time-consuming. You may also need a VNC setup to inspect program behavior. Checkout this project IBGA and see how it uses JAuto and xdotool to automate a program.
Disclaimer: I'm the author of both JAuto and IBGA.

WIX installer execute vbscript from CustomAction

I can't execute VBScript using WIX installer. Currently I have this part of WiX config:
<Binary Id='KillThatProcessBinary' SourceFile='KillThatProcess.vbs' />
<CustomAction Id="KillThatProcessAction"
Execute="immediate"
BinaryKey='KillThatProcessBinary'
VBScriptCall='KillThatProcessFunction'
Return="check"/>
<InstallExecuteSequence>
<Custom Action='KillThatProcessAction' Before='InstallValidate'/>
<ScheduleReboot After="InstallFinalize"/>
</InstallExecuteSequence>
And this VBS script (KillThatProcess.vbs):
Public Function KillThatProcessFunction()
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "cmd /C wmic process where ""name like '%java%'"" delete"
Return 0
End Function
I already try to insert this script into CustomAction (as innerText), and add attribute: Script="vbscript". But nothing works, every time I got the error message - "There is a problem with this Windows Installer package. A script reqired for this install to complete could not be run. Contact your support personnel or package vendor."
And errors in log file:
Error 0x80070643: Failed to install MSI package.
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to configure per-user MSI package.
[1A88:2FA4][2018-08-21T14:11:17]i319: Applied execute package: LPGateway, result: 0x80070643, restart: None
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to execute MSI package.
I already execute this vbs script (not from installer) and it works. Anybody know what I do wrong?
There are a few issues I want to summarize:
VBA & VBScript Functions: That VBScript looks like it is actually VBA and calling VBScript in an MSI requires a bit of tweaking
to call VBScript functions properly.
Reboot: The reboot you schedule must get a better condition to avoid unexpected reboots.
Process Kill: What process are you trying to kill?
Elevation: If it is elevated you need to run the kill elevated for it to succeed. Your per-user setup is likely not set to
elevate at all (so you can generally only end processes running as yourself).
Restart Manager: Very often you do not need to kill processes, due to the Restart Manager feature of Windows that Windows
Installer tries to use. Attempt to explain this feature (look for
yellow sections).
Issue 1: That must be a VBA script and not a VBScript? For the record: I haven't seen return in VBScript? In VBScript you return from a function by setting the function name equal to whatever you want to return, quick sample:
result = IsEmptyString("")
MsgBox CStr(result)
Function IsEmptyString(str)
If str = "" Then
IsEmptyString = True
Else
IsEmptyString = False
End If
End Function
Note: The above is just a silly, rather meaningless example. For more elaborate checking try
IsBlank from ss64.com. VBScript comes with the functions IsEmpty and IsNull and IsObject.
When used in MSI files, I normally don't add a function in the VBScript, but just run the script directly, so running this VBScript should work:
MsgBox(Session.Property("ProductName"))
Inserting it into the WiX source (notice no function call specified):
<Binary Id='Sample.vbs' SourceFile='Sample.vbs' />
<CustomAction Id='Sample.vbs' VBScriptCall='' BinaryKey='Sample.vbs' Execute='immediate' Return='ignore'/>
Crucially your VBScript can still call other functions available in the same VBScript file. So in the above sample "IsEmptyString" can be called from the main "nameless" function at the top of the file.
Check Exit Code: And finally, any custom action set to check exit code can throw your setup into abort (immediate mode) or rollback (deferred mode). I would only check the exit code if you have to end the setup if the custom action can not run.
Issue 2: Reboots. This is a very serious issue in my opinion. I have seen people sent out the door for causing unexpected reboots during large scale deployments. Rebooting a knowledge worker's PC (and their managers) with a dozen Visual Studio windows open, dozens of browser windows and Word and Excel and you name it. It can cause a great deal of problems. And they may know where you live! :-)
Please read the following answer (at least its 3 bullet points at the beginning): Reboot on install, Don't reboot on uninstall
Issue 3: Process Kill. As indicated above the killing of processes is related to the reboot issues. It is not always necessary to kill processes if they are compliant with Windows Restart Manager as explained in the link above. Let me repeat it here (yellow sections should give you the gist of it - especially the second one I think).
There are a few different ways to kill processes. Note that the most common problem might be that you don't have the access rights and / or privileges to kill the process - no matter what tool or approach you use to do so.
Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
In Wix MSI: Killing a process upon uninstallation
Kill windows service forcefully in WIX (towards bottom)
Kill process using WMI / VBScript
Some people combine taskill.exe and WiX by means of the Quiet Execution Custom Action (CAQuietExec: hide command line windows). FireGiant documentation.
I am not sure which of these options to recommend. I don't like the concept of killing processes altogether, but sometimes there is no other option I guess.

How to execute ssh commands in an Android application

Relatively new to this but, I was planning to write a simple android application which can run and execute simple terminal commads like ssh, change directories etc. But i want to create buttons for each command. so (cd..) command will be a button, (mkdir) will be another. The main idea is to connect to a Linux server and then execute these commands on them, I would also use some commands which start services or kill services.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
Thanks in advance.
I want to know if there is any class in Android which allows me to run these commands programmatically?.
No, unless you count Socket.
Instead, you would need to find an SSH client library for Android, or perhaps for ordinary Java (and hope that it runs unmodified on Android).

can I write a DialUp listener program for ubuntu with java?

I want to develop a program for ubuntu platform, That listens to DialUp modem and get Calls and send them to my php program that's running on my localhost.
for example when somebody calls my phone line, my listener program give the number and run this query:
http://127.0.0.1:80/listen.php?caller=ThePhoneNumber
How can I do that? is there any classes in java for that?
I think you'd need native tools for that. You can make pppd answer the call and run a custom script or program. But I have not fiddled with that for a long time. See linux modem howto. There should be plenty of information.

automate java desktop application actions

I developed a java desktop application where the user can manually load a file and press a button to start a simulation process. I want to automate the above two steps so that an external program can iteratively call this desktop application multiple times and run the simulation process without any human intervention every time. Any thoughts on how I can go about doing this?
It depends on which OS you do it.
If OS X, use automator, for Windows you can use winautomation and for Linux use google and search (for example) kde automation.
I know this is an old question. But there is a new solution now,
JAuto: a JVMTI agent that runs in Java VM and expose UI widget attributes such as class names, screen coordinates. You talk to JAuto by sending a command to a named pipe. It responds by writing a file. It lets you control a Java program via bash scripts.
Using an input simulator such as xdotool, you can achieve automation under the Linux X11 settings.
Disclaimer: I'm the author of JAuto.

Categories

Resources