How do I send a POST request to Spring Boot from terminal? - bash

A Spring Boot service running at localhost:7090/someurl accepts parameters Var1 and Var2 in POST requests. How can I test this from the CentOS 7 terminal?
When I type localhost:7090/someurl?Var1=something&Var2=anotherthing into the web browser, the logs show that an unsuported GET request was made. How do I mimmick a POST request to test this service? What do I type into the CentOS 7 terminal?

if it is a normal bash shell, you can always use curl (you maybe need to install it), for example:
curl -X POST -d "Var1=VALUE1&Var2=VALUE2" localhost:7090/someurl

Related

spring cloud data flow application properties / environment variables

Have a docker container running a single spring cloud data flow application. Up until version 2.7.2 of data flow, I was able to pass all the database url/username/password properties to the application by defining them as environment variables in the container.
The application has application.yml defined to fetch the properties from variables, like this:
appname:
datasource:
url: ${APP_DB_URL:jdbc:sqlserver://127.0.0.1:1433}
password: ${APP_DB_PASSWORD:D3faultP4ss!}
username: ${APP_DB_USER:sa}
As said previously these variables was able to be defined by just having them as env variables in the container, now this method doesn't seem to work anymore starting from data flow 2.8 upwards.
Setup is configured to automatically register the application to the spring cloud data flow after startup, with following logic
1st delete all old tasks
curl "http://localhost:9393/tasks/definitions/${APP_NAME}?cleanup=false" -o /dev/null -s -w "%{http_code}" -X DELETE
2nd delete all old applications
curl "http://localhost:9393/apps" -o /dev/null -s -w "%{http_code}" -X DELETE
3rd register application
curl "http://localhost:9393/apps/task/${APP_NAME}/${APP_VERSION}" -o /dev/null -s -w "%{http_code}" -X POST -d "uri=file%3A%2F%2Fapp%2F${APP_JAR}&force=true"
4th register task
curl "http://localhost:9393/tasks/definitions" -o /dev/null -s -w "%{http_code}" -X POST -d "name=${APP_NAME}&definition=${APP_NAME}"
APP_NAME, APP_VERSION and APP_JAR are env variables put into the container in the build phase.
The on schedule, daily, the job is triggered with the following call:
curl "http://localhost:9393/tasks/executions" -o /dev/null -s -w "%{http_code}" -X POST -d "name=${APP_NAME}&properties=deployer.${APP_NAME}.local.workingDirectoriesRoot%3D%2Fapp%2Flogs&arguments=--date%3D$(date --date='yesterday' +\%Y-\%m-\%d)+--range%3D${range}+--dataSource%3DApplication+SourceProperty"
As said, until 2.7.2 version this worked, now when trying to update to 2.8 or newer the application tries to connect to the default database url defined in the application.yml. How can I override these using env variables?
And obviously if there's a better way to do the auto registration of the app, all tips are appreciated.
Spring Cloud Data Flow 2.7.x used Spring Boot 2.3
Spring Cloud Data Flow 2.8.x used Spring Boot 2.4
There are changes to property names and the data source initialisation will override your configuration unless you disable autoconfiguration of datasources.
We suggest you move to latest Spring Cloud Data Flow and update your applications to Spring Boot 2.7.x
The you provide properties like:
app.<appname>.spring.datasource.url etc.

JMeter gives me bad request once I run the thread

it seems to be jmeter doesn't see the parameter required even I wrote them. I tried a lot of versions and still the samee. It works fine using postman (curl)
Most probably it's not JMeter who "gives" you bad request, it's the system under test tells you that request is malformed via HTTP Status Code 400
There is only one version which will "work" but we cannot tell you which one unless you're willing to share the "working" request details from curl and/or postman.
If you can run the request successfully using curl or Postman you can:
Create a test plan from Curl command
Record curl command execution via JMeter's HTTP(S) Test Script Recorder by running your curl request via JMeter's proxy:
curl -k -x http://localhost:8888 your-request-parameters http://your-server-endpoint
Record Postman request execution via JMeter's HTTP(S) Test Script Recorder

How to bypass multiple proxy in jmeter

I am using the command
jmeter -H proxy -P 4145 -N 10.24.27.57;10.5.213.40;10.5.247.126 -u username -a password
I want to bypass these 3 proxy 10.24.27.57;10.5.213.40;10.5.247.126.
How will it work?
Unfortunately, it won't work. JMeter relies on Java Networking Properties for proxy configuration, which supports only 1 proxy server.
Hard to tell without any further details, but for example you could split your load to 3 machines, each running 1/3 of the load against different proxy.

Jmeter Proxy giving 504 gateway timeout error

I have URL which is like this:
https://110.111.72.72:8001?id=username1
when I use the same URL in browser it works fine and return a result but when I use the same in Jmeter I get a 504 Gateway Timeout error.
In my organisation we do have the proxy which I have mentioned in the browser LAN -> proxy server settings.
I have tried many things but none worked please help.
You need to configure JMeter to use the same proxy server your browser is using. It can be done in 2 ways:
Via command-line arguments. In this case you will need to run JMeter as:
jmeter -H your_company_proxy_host -P your_company_proxy_port-u username -a password
Via Java System Network Properties. In this case you will need to add the following lines to system.properties file (located in "bin" folder of your JMeter installation)
http.proxyHost=your_company_proxy_host
http.proxyPort=your_company_proxy_port
https.proxyHost=your_company_proxy_host
https.proxyPort=your_company_proxy_port
More information:
Using JMeter behind a proxy
Apache JMeter Properties Customization Guide
Thanks Dmitri T
jmeter -H your_company_proxy_host -P your_company_proxy_port-u username -a password ---- Worked Fine
I didn't try the 2nd option.
Thanks for solving another

Kill a framework in Mesos

I have a Mesos cluster and was running a Spark shell connected to it. I shut down the client, but Mesos still believes the framework should be active.
I am trying to have Mesos drop the framework by using DELETE with curl
(https://issues.apache.org/jira/browse/MESOS-1390)
but I am getting no response from the server. Also, I am not sure how exactly to connect to the master: I have a multi-master setup managed by ZooKeeper, and I was trying to connect just to the active master:
curl -X DELETE http://<active master url>:5050/framworks/<framework id>
Can anyone verify if the above is the correct request?
I am using mesos-0.20.0.
Thanks
There is a restfull option calling by post the url http://your_mesos:5050/master/teardown passing frameworkId parameter
curl -d#/tmp/post.txt -X POST http://your_mesos:5050/master/teardown
/tmp/post.txt is a file with the follow content:
frameworkId=23423-23423-234234-234234
I know is late but for future askers
EDIT: The endpoint is now called teardown.
Example (thanks #Jeff): curl -X POST http://your_mesos:5050/master/teardown -d 'frameworkId=23423-23423-234234-234234'
Just to keep this up to date: The master endpoint was renamed to teardown i.e. http://localhost:5050/master/teardown is the new way to go.
TEARDOWN Request (JSON):
POST /master/teardown HTTP/1.1
Host: masterhost:5050
Content-Type: application/json
frameworkId=12220-3440-12532-2345
TEARDOWN Response:
HTTP/1.1 200 Ok
Riffing on #montells work, a one-liner would be
echo "frameworkId= 23423-23423-234234-234234" | curl -d#- -X POST http://localhost:5050/master/shutdown
Even though that JIRA issue mentions DELETE (in comments) it's not how framework shutdown is implemented. You need to do a POST request to /shutdown endpoint.
Examples: https://github.com/apache/mesos/blob/master/src/tests/teardown_tests.cpp
Regarding why the spark framework is not removed after you shutdown the client, I'm guessing it is because spark uses a high failover timeout? Nonetheless, I'm surprised that Mesos UI shows it as active instead of inactive.
Add this in your .bashrc:
#Mesos
killtask(){ curl -XPOST http://mesos_url:5050/master/teardown -d 'frameworkId='$#''; } ;
Sample usage:
killtask 123

Resources