Using JShell to write application extensions - beanshell

at the moment I use Beanshell to write application extensions. I just use BshMethod.invoke() to integrate it with the java application.
Could this be done with JShell too? Load a script and execute a method in the script? Via a JShell API, not via cmdline...

Related

How to run REST APIs using a shell script?

How to or what's the best way to run (not call with curl) a REST API service using purely shell commands or scripts?
I would typically run APIs with Python using FastAPI, however, I was wondering if it is possible to do it in a less-Pythonic and more-Linux way.
Sampo is most likely what you're looking for.
Written in bash, it is a shell script API server you can run directly in your terminal or via container on Kubernetes.
It exposes endpoints which could trigger different actions, running a script among others.

build jmeter-parellarel-request-master

I need to write a scenario where we make several calls to an API in parallel with JMeter. The solution is based on OAuth, where a token is extracted and passed along with every call made to the API. This works fine, however, JMeter has no built-in option to make multiple parallel calls. I could divide them into separate thread groups, but this would not be desired.
Thread group
oauth calls to get token
extract token
api call /getCustomerActions
api call /getCustomerBlabla1..
api call /getCustomerBlabla2..
I've found the following custom sampler by Franz See:
https://github.com/franz-see/jmeter-parellarel-request
As I'm not big on development/compiling, my question would be how do I compile this package and use in in JMeter?
Download and install Apache Maven.
Download latest jmeter-parallel-request release
Unpack downloaded sources and switch to that folder
Invoke maven package command from that folder
Copy file from target/jmeter-parallel-request-xx.jar to JMeter's lib/ext folder
Restart JMeter to pick the plugin up
You can also check out How to Load Test AJAX/XHR Enabled Sites With JMeter guide for alternative solutions.
this plugin seems to work, but using it as a seperate thread group, all extracted values or tokens from other (main) threads are not captured.. too bad

Is there any API to automate extension installation in XWiki?

I use xwiki Enterprise 7.4. The official way to install extensions is to use either Import feature or Extension Manager. Both ways require user interaction. I would like to automate extension installation process, so no user interactions for extension installation. Is it possible? I've automated spaces/pages creation via REST API. Maybe it's possible to use REST API to do it, I can't find it in documentation.
Why do I need it? It's simple: I've automated all the steps of deployment/migration process for my application and I would like to automate xwiki extension installation too.
As indicated by Vincent, you can use the extension script service from inside XWiki. This script service is what the UI is using so everything the UI is doing can be done also by any script (as long as the script author has proper rights).
I just wrote a Velocity example on http://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Script+Module#HNon-interactiveandsynchronousinstall:
{{velocity}}
## Create install request for extension with id org.xwiki.contrib:extension-tweak and version 1.3 on current wiki
#set($installRequest = $services.extension.createInstallRequest('org.xwiki.contrib:extension-tweak', '1.3', "wiki:${xcontext.database}"))
## Disable interactive mode
$installRequest.setInteractive(false)
## Start install
#set($installJob = $services.extension.install($installRequest))
## Wait until install is done
$installJob.join()
{{/velocity}}
All you need is to put the Thomas' script in a page. You can use the REST API for that. See: http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HPageresources
Then you call the URL from your application.
Ex: you put the code in XWiki/AutoInstall with a REST call and then you can call this page with the following url:
http://localhost:8080/xwiki/bin/get/XWiki/AutoInstall
I suggest to use the "get" action from the URL to avoid unnecessary informations.
The XWiki Core dev team is aware of this and it's in the roadmap but it's not done yet. For example you can see that it was planned for the 8.0 roadmap but it slipped (http://www.xwiki.org/xwiki/bin/view/Roadmaps/Archives8xCycle/).
Continue improving upgrade tools: Scriptable upgrades (priority 1), Simulation (priority 2)
It seems there's no issue created for this at the moment. Would be great if you could create a JIRA issue at http://xwiki.org in the XWiki Platform project.
Now regarding extensions, there's some Script Service that can be used to manipulate extensions, see http://extensions.xwiki.org/xwiki/bin/view/Extension/Extension+Script+Module
However this documentation is pretty terse. You could check the java code at https://github.com/xwiki/xwiki-platform/blob/95abd2951123431c1624c124b49ca7a88b41be00/xwiki-platform-core/xwiki-platform-extension/xwiki-platform-extension-script/src/main/java/org/xwiki/extension/script/ExtensionManagerScriptService.java#L84-L84
I've not personally used this script service so I can't give real examples of using this API

Migrating from LoadRunner/The Grinder to JMeter: Where are the Scripts?

I've done load tests for users building scripts in LoadRunner or The Grinder, and now I'm trying out JMeter and it all feels incredibly clunky. Where are the scripts? Does everything have to be done through the UI? Is JMeter able to do complex scripting?
JMeter has good user friendly GUI. We create scripts in JMeter using the UI. JMeter saves the script in XML format with .JMX extension. Script creation is NOT very difficult as you say.
Check this site to get an idea.
Complex scripting can be done in JMeter using logic controllers.
Also JMeter
Is Free & Open source
Is Light weight & easy to install
supports any platform
Supports many protocols - HTTP/HTTPS, FTP, SOAP, LDAP, JDBC, JMS, SMTP, POP etc
Supports external plugins
Can be extended with Beanshell scripts, Groovy, Javascript, Java.
I have tried out Jmeter briefly but I think to it's for you to try it out yourself, there are a number of Jmeter tutorials on the Jmeter site itself as well as on youtube which should prove useful.
Below are some links:
http://jmeter.apache.org/usermanual/intro.html
https://www.youtube.com/watch?v=cv7KqxaLZd8
Hope these links help you in getting a better understanding of Jmeter.
What do you call "scripts"?
JMeter is designed so anyone could create tests using UI only. JMeter's Logic Controllers, Pre/Post-Processors, Assertions, etc. are quite enough to build a load test of any complexity.
If you feel yourself too creative and you're limited by JMeter Test Elements you're welcome to extend it using
Code-enabled test elements like BSF, Beanshell, JSR-223 Pre/PostProcessors, Samplers, Timers and Assertions
Developing custom functions
Developing custom implementation of Java Request Sampler
Developing custom implementation of your own Sampler or Function
Finally it is possible to either run existing or create new tests using JMeter API

need a way to securely communicate between Priviliged Helper Tool (installed using SMJobBless) and the application

I am trying to install a privileged helper tool to perform some elevated work. I am using SMJobBless for the same.
I am able to install the tool fine and also able to communicate with it. I am using Mac OS X 10.8.4 and using NSXPCConnection for the same.
I have added .mach service in the plist which will be installed in /Library/LaunchDaemons. I am using [initWithMachServiceName:options:] in the app as the helper is privileged tool and [– initWithMachServiceName:] in the helper to listen. The communication is working fine.
But the problem is I tried the same communication with another application I created which did not have any codesign at all (the helper tool installer earlier was codesigned). I tried to connect to the mach service of the helper tool and was able to connect easily. This is a problem because anybody can communicate with it then and make it do anything.
I wanted some way to securely communicate between my application and the helper tool.
Thanks a lot.
As you've said that you're not signing the second app, I believe that that is the problem that is allowing a 2nd app from calling the helper application. From the Apple docs and specifically the ReadMe file in SMJobBless, it states: -
The Service Management framework uses code signatures to ensure that the helper tool is the one expected to be run by the main application
This document should be able to assist you in getting the helper app correctly associated with its owner.
Note that it references a python script, which is provided here.
Answering my own question: I had logged a radar bug for the same and Apple said that the behavior was intended:
"It is up to the privileged helper to not expose insecure operations"