I am trying to parse parts of the URL that I received from an API. I am trying to do this using Regex in Jmeter and save it into Variables.
I have a URL which looks like
I receive a URL as part of an API response and have extracted the URL into a variable named "UploadUrl". The value is similar to
https://Domain/path1/path2?queryParam1=Value1&queryParam2=Value2
I need to extract
Protocol as https
Host as Domain
Path as path1/path2
Parameters as queryParam1=Value1&queryParam2=Value2
so that I can pass them as inputs in the JMeter http Sampler.
enter image description here
but when I run the JMeter script the value is not getting extracted via the Regex.
What am I doing wrong?
You can put everything into "Path" field of the HTTP Request sampler
If you still want to extract protocol, host and so on it would be way easier to do using JSR223 PostProcessor and some Groovy code like:
URL url = new URL(vars.get('UploadUrl'))
def protocol = url.getProtocol()
def host = url.getHost()
def port = url.getPort()
if (port == -1) {
port = url.getDefaultPort()
}
def path = url.getPath()
def query = url.getQuery()
vars.put('protocol', protocol)
vars.put('host', host)
vars.put('port', port as String)
vars.put('path', path)
vars.put('query', query)
Demo:
You will be able to access the values like ${host}, ${port}, etc. where required.
Related
I am proxying the radius request to an external radius server for a specific realm.once the external radius replies back with an access accept packet and other attributes,I want to forward the attributes to an External api for some processing.
How can I achieve this?
I have configured my freeradius rest file with the appropriate endpoint and the default file under sites-enabled to forward the request to rest.
What I suggest you do is package the attributes in a JSON post to the external API via the rlm_rest post_proxy.
Configure your rest module as needed and grab the attributes you want to send over the wire.
post-proxy {
uri = "${..connect_uri}/at"
method = 'post'
body = 'json'
data = '{"User-Name":"%{User-Name}","User-Password":"%{User-Password}","NAS-IP-Address":"%{NAS-IP-Address}","NAS-Port":"%{NAS-Port}","Event-Timestamp":"%{Event-Timestamp}"}'
}
I am using the inputs.http plugin of Telegraf in order to import data from an API to influxdb. The API requires a time filter in the body of a POST request and responds with data between that time filter. I want to periodically call this API and retrieve data for the past 10 or so seconds. So I need to include the current timestamp in the body of the POST request. Can I pass the current server timestamp to telegraf.conf in the form of an environment variable or a command line argument? What I have attempted so far is using an environment variable in the telegraf.conf file as shown below. It did not work.
[[inputs.http]]
#URL
urls = ["url"]
#http method
method = "POST"
## Optional HTTP headers
headers = {"cache-control" = "no-cache","content-type" = "application/json"}
## HTTP entity-body to send with POST/PUT requests.
#body = "{\"measurement\":\"measurement_name\", \"time_filter\":[1593068400, 1593068800]}"
body = "{\"measurement\":\"measurement_name\", \"time_filter\":[1593562547, ${date +%s}]}"
#Data from HTTP in JSON format
data_format = "json"
I then run the command below
$telegraf -config telegraf.conf
and receive a 400 error. If I replace the body line (includes variable) with the line above it (no variable) everything works fine.
I am trying to call a POST api in the Jenkins groovy post-build section. I want to pass a groovy variable in the json body of the request.
def url = "someURL"
def body = '[{"PageName" :"worked2","pageurl" :"url variable value needs to be passed here"}]'
def http = new URL("some https url").openConnection();
http.setRequestMethod("POST")
http.setDoOutput(true)
http.setRequestProperty("Accept", "application/json")
http.setRequestProperty("Content-Type", "application/json")
http.getOutputStream().write(body.getBytes("UTF-8"));
http.connect()
def postRC = http.getResponseCode();
I have tried below but nothing worked for me:
'[{"PageName" :"worked2","pageurl" :$url}]'
'[{"PageName" :"worked2","pageurl" :"$url"}]'
'[{"PageName" :"worked2","pageurl" :url}]'
It only works fine when I hard-code the value. How can I achieve this?
This worked when I used below :
{"pageurl" :"'+ url +'"}
(double quotes single quotes + variableName + single quotes double quotes)
I have a Grails controller that receives a DefaultMultipartHttpServletRequest like so:
def myController() {
DefaultMultipartHttpServletRequest proxyRequest = (DefaultMultipartHttpServletRequest) request
}
This controller acts as a proxy by taking pieces of this request and then resends the request to another destination.
For non-multipart requests, this worked fine, I did something like:
IProxyService service = (IProxyService) clientFactory.create()
Response response = service.doPOST(proxyRequest.getRequestBody())
Where proxyRequest.getRequestBody() contains a JSON block containing the request payload.
However, I do not know how to get this to work with multipart request payload, since the request body is no longer a simple block of JSON, but something like the following (taken from Chrome devtools):
How can I can pass this request payload through using my proxy service above, where doPost takes a String?
Have you tried
def parameterValue = request.getParameter("parameterName")
to get the parameter value?
If you see the method signatures for DefaultMultipartHttpServletRequest you will see there are methods for getting the files and other parameters separately because the request body is getting used to both upload the file and to pass in other parameters.
In my Apigee API Proxy, I need to get the environment URL that is defined in my configuration, so that I can send it as part of the response.
For example: http://myorg-test.apigee.net/pricing
However, when I try to get it using proxy.url, I get an aliased path, like http://rrt18apigee.us-ea.4.apigee.com/pricing
Currently, I'm trying to get it like:
var response = {
proxyUrl : context.getVariable("proxy.url"),
};
Here is a work around. You can try to get the following variables and create the entire URL
Get the request scheme (http or https) from request.Headers.X-Forwarded-Proto (if you are using cloud version) or client.scheme if you are using on-prem
Get the host name from request.host
Get the entire request path from request.path
Entire list of URL query params and list from message.querystring
You can then construct the entire request URL.
( I know this should not be this painful. Please log a bug in case proxy.url is really broken. )