I'm running a local Rails server (WEBrick) via JRuby and want to test some code that will eventually be running on Torquebox. I'm trying to access some custom Java system properties via ENV_JAVA. These system properties will be available when running on Torquebox so to test my code locally, I'm passing in the system properties on the command line using the "-J" argument.
When I run just JRuby, everything works fine, I can access my custom property.
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value -e "puts ENV_JAVA['my_prop']"
This simply prints "my_value" to output.
My problem is trying access these custom properties when running a local Rails server. My command line to startup the local Rails server looks something like this:
C:\jruby\jruby-1.7.24\bin\jruby.exe -J-Dmy_prop=my_value C:\jruby\jruby-1.7.24\bin\rails s
When WEBrick starts up, my custom property "my_prop" is no longer in ENV_JAVA. It looks like this is because inside the railties Rails::AppRailsLoader module, exec_app_rails simply replaces the current process with another one by calling the Kernel exec method and passing in the command arguments.
This does NOT keep the custom properties around. Does anyone know how I can work around this? I'm currently running Rails 4.2.6. It looks like in Rails 5 the module name changed to Rails::AppLoader.
So I figured out a better(?) way to handle this. Instead of:
exec RUBY, exe, *ARGV
I can do this:
custom_sys_props = {}
current_sys_props = ENV_JAVA.to_hash
default_sys_props = eval(%x(#{RUBY} -e "puts ENV_JAVA"))
current_sys_props.each {|k,v| custom_sys_props[k] = v if default_sys_props[k] != v }
jruby_props = []
custom_sys_props.each{|k,v| jruby_props << "-J-D#{k}=#{v}"}
exec RUBY, *jruby_props, exe, *ARGV
Its ugly and really only works for JRuby, but I dont know of a better way to handle it. Still a shame that this hasn't been addressed before
After discussing with a colleague, turns out I can run my rails server by calling
jruby.exe -J-Dmy_prop=my_value script/rails
from within my project directory. So I dont even need to run the rails.bat script. Hope this helps someone
Related
Here's a Progress program that creates a record in the Symix database:
create audit.
assign audit.table_name = "JavaSample"
audit.key_id = "12345"
audit.field_name = "<FieldName>"
audit.audit_dt = today
audit.audit_tm = time
audit.audit_user_id = "javauser".
I want to call this .p file from the java code.
Progress offers Open Client runtime package to call .p through AppServer.
It is required to generate java classes from compiled .r file using ProxyGen from Progress OpenEdge Studio installation, then put those generated classes put into Java project.
But this variant is complicated and not easy to use, especially if parameters changes frequently.
Alternative way to ProxyGen is to use opa library. It simplifies Progress .p procedures call from Java.
All you need is this case - it is to create a simple parameters object and to call runProc method. Parameters will be mapped on the fly.
Of course, you still require an AppServer on Progress side to run those .p.
More info in https://github.com/labai/opa
When using the AppServer you can run the .p file on the AppServer using the OpenClient proxies for Java:
http://documentation.progress.com/output/OpenEdge116/pdfs/dvjav/dvjav.pdf
You could use Runtime to execute a shell script, as covered in for example this question: How to run Unix shell script from Java code?
We all know pretty well that JMeter is a server performance testing tool for both static and dynamic resources. I've had successfully used JMeter for the above written purpose through it's easy to use GUI interface. Recently we've been experiencing a lot of "server down" issue but we're unable to find out when exactly server is down until we're requesting something to it and get nothing in return.
So I thought of using JMeter as a solution here. Using JMeter I would be hitting the server at particular intervals, say once in every 3hours and get a response back which will correctly identify that server is working fine. Using it in GUI mode is not apt. It needs to be scheduled for every 3 hours.
Through a bit of Google's help I learnt JMeter could also be used in "non GUI mode". So I took the script and made a bat file of it. I then triggered the bat file using Java cod with the help of Timer class for scheduling. The script inside the bat file is :
jmeter -n -t E:\Jmeter.jmx -l E:\test.txt
Using above script I get summary report in test.txt which looks like:
1440049645804,576,SOAP/XML-RPC Request,200,OK,Thread Group 1-1,text,true,583,1,1,574
The result was same even when the server was down. I added "View Results Tree" as listener in GUI and saved it but still the result was same. By default the non GUI mode gets just the summary. I would want the Response data of Result tree as well.
The Response data shown above confirms whether server is returning valid data or not. Is there any way I could add up the Response data to my result file?
Also I found the test plans could be run inside the java code using the JMeter API's and Interface i.e JavaSamplerClient . I searched but could not find a live example that I could understand clearly.
Thanks in advance.
In order to see response data you need to do the following:
Switch JMeter output format to XML
"Tell" it to save response data
Command line solution will look like:
jmeter -Jjmeter.save.saveservice.output_format=xml -Jjmeter.save.saveservice.response_data=true -n -t E:\Jmeter.jmx -l E:\test.txt
In regards to running JMeter test from Java see chapter 4.2 Running an existing JMeter Test from Java code of the 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide.
JavaSamplerClient - is the way of creating custom Java Request Samplers, I doubt that it is what you looking for
I'm having a problem runnig Java class run through a Python script, that is in turn executed by an Apache web server.
I have the following file, accesible via an Apache webserver
script.cgi
#!/usr/bin/python
os.system("java HelloWorld")
sys.stdout.flush()
The I run the script from the shell, it runs properly. However, when I access it via a web browser, the os.system("java ...") returns exit status 1536.
Any idea why this is happening?
This is running on Linux Mint 13. Please let me know what extra information I can provide.
Thank you
When running the script from your command line you probably have different enviroment variables set and you have a different security content.
Make sure that your webserver finds the files (E.g. try using full path names) and check if everyone has the execute permission for java and read to the folder and file(For security reasons I'm not sure if that is a good idea tough).
as part of my eclipse plugin I try to start an external program by using process.exec. This works with some tools (I tested it with gedit, for example), but with the one I need it does not work: isimgui: cannot connect to X server.
This is part of the XILINX webpack, none of the included graphic tools can be started like this.
Any ideas how I met get it to work?
You probably need to pass the -display argument to the executable you are running, or better (more widely supported) set the environment variable DISPLAY to the right value (try ':0')
use for example: process.exec(String[] cmdarray, String[] envp)
envp should contain at least one string "DISPLAY=:0"
You must inherit the DISPLAY variable from your shell (and possibly also the X11 authentication file information).
Can I test/call a Java Service from QTP and how?
You could look into the QTP Service Test add-in which is used for testing "non GUI-based services."
You can also test directly from VBScript in QTP, without the Service Test add-in. See this SQAForums post.
To call the jar file:
To call the jar file, you can use QTP’s SystemUtil.Run like this:
SystemUtil.Run “cmd”,”/c java -jar parsingclass.jar”,””
To call the java class:
For a java class you would do something like this:
SystemUtil.Run “cmd”,”/K java D:\HL7Parser\bin\CORUExtractorFlow1151.class”,””
Explanation About the Code:
SystemUtil Object is a QTP object that can be used to control an application or process during a test run.
The Run method runs a file or application. cmd starts a new instance of a command interpreter.
/K is a parameter that runs the command and leaves the command window open. (If you want to close the command window instead of keeping it open, you would need to replace the /K parameters with the /C parameter.) For more info on CMD and its parameters, check out Microsoft’s documentation website
For move complicate Java calls
If you have a more complicated Java DLL that you need to interact with, you could use Service Test 11, which contains a call java class activity. With a “Unified Functional license ,” you could call Service Test from QTP; in our case, however, this would have been overkill, so we kept it simple by using the method described above.