How to send a Solr spatial query using JSON request API - json

What is the equivalent JSON request for querying a spatial location field in Apache Solr to:
&fq={!bbox sfield=locfield}&pt=45.15,-93.85&d=5

You can use a params block.
Parameters placed in a params block act as if they were added verbatim
to the query-parameters of the request.
For example using curl :
curl "http://hostname:8983/solr/corename/query?" -d '
{
params: {
q: "*:*",
fq: "{!bbox sfield=locfield}",
pt: "45.15,-93.85",
d: "5"
}
}'
#see JSON Request API Supported Properties and Syntax

Related

Regex for JMeter JSON Extractor

I'm using JMeter to validate some HTTPS requests, and for that, I'm using one JSON extractor and I want to extract data from the JSON response I'm getting. So from the below payload, I want to extract oper_state from any resource where service_name is equal to "Japan-1-3-12_service".
{
"resource":[
{
"id":"de04c6b1-a5a3-11ec-a02b-765e38f104a5-19",
"name":"Tokyo-1-1-10",
"service_name":"Tokyo-1-1-10_service",
"oper_state":"UP",
"type":"admin"
},
{
"id":"me05c6b1-a903-11ec-a02b-764313f104a5-19",
"name":"Japan-1-3-12",
"service_name":"Japan-1-3-12_service",
"oper_state":"UP",
"type":"admin"
},
{
"id":"5e04c691-a5a3-11ec-a02b-765e38f3q4a5-19",
"name":"France-1-1-3",
"service_name":"France-1-1-3_service",
"oper_state":"DOWN",
"type":"admin"
}
]}
I was using "$.resource[?(#.service_name=="Japan-1-3-12_service")].operational_state", but not getting any output in the variable.
Why you're using operational_state when in your JSON response it's oper_state everywhere?
Just change your JSON Path query to
$.resource[?(#.service_name=="Japan-1-3-12_service")].oper_state
and it should start working as expected
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

freeradius 3.0.17 rlm_rest parsing json response

I'm trying to authenticate RADIUS Requests against a RESTful API (provided by Customer) using rlm_rest.
The problem I am facing is that
response JSON format (of REST API provided by Customer), is different from rlm_rest default format (indicated in etc/raddb/mods-enabled/rest).
My Virtual Server configuration as below:
Default
authorize {
...
...
rest
if (ok) {
update control {
Auth-Type := rest
}
}
}
mods-enabled/rest
authorize {
uri = "https://3rd-party-API/auth"
method = 'post'
body = 'json'
chunk = 0
tls = ${..tls}
data = '{
"code": 1,
"identifier": %I,
"avps": {
"User-Name": ["%{User-Name}"],
"NAS-IP-Address": ["%{NAS-IP-Address}"],
"Called-Station-Id": ["%{Called-Station-Id}"],
"Calling-Station-Id": ["%{Calling-Station-Id}"],
"NAS-Identifier": ["%{NAS-Identifier}"]
}
}'
}
Result
/sbin/radiusd -Xxx
HTTP response code
200
JSON Body
{
"code": "2",
"identifier": "91",
"avps": {
"Customer-Attributes": "Hello"
...
...
"Acct-Interim-Interval": "300"
}
}
The JSON structure is different from the example, and xlat parse
"code"
"identifier"
"avps"
And, of course, xlat finds no attributes match with the dictionary, while it cannot find "avps" and won't dig deeper.
So I was wondering is there anyway to either
Define the response JSON structure for xlat to parsing
Insert a "is_json" or "do_xlat" flag into the JSON ("avps"), and hope xlat will then dig deeper
Save the JSON and parse with exec/rlm_exec (using JQ or any other bash/JSON tools)
Please advise if there is any workaround. Thanks!
In FreeRADIUS version 4, there's a rlm_json module, which implements a custom node query language based on xpath (jpath), it is extremely limited and only supports some very basic queries (feel free to enhance it via PR :) ).
Below is an example I pulled out of my library of customer configurations. You can see here it's pulling out two keys (externalID and macAddress) from the root level of the JSON doc and assigning them to a couple of custom attributes (Subscriber-ID and Provisioned-MAC).
map json "%{rest_api:https://${modules.rest[rest_api].server}/admin/api/${modules.rest[rest_api].api_key}/external/getDeviceBySerialNumber?certificateSerialNumber=%{lpad:&TLS-Client-Cert-Serial 40 0}}" {
&Subscriber-ID := '$.externalId'
&Provisioned-MAC := '$.macAddress'
}
The xlat expansion can also be modified to send HTTP body data. Just put a space after the URL and pass your custom JSON blob.

How to load a json file with unit ML test examples into jmeter http request payload

I have an endpoint that serves a ML model and I want to perform load testing on it. I'm using Jmeter 4.0 and its UI to construct a simple plan test. With 1 thread group that loops for a given duration and continuosly performs https requests.
How do I parse multiple test examples into the payload of a http request, one by one and in json format. These examples are contained in a json file called samples.json. The nested structure is the following:
{ "dataset": [
{"id": 1,
"in":[
{
"Feature1": 8.9
"Feature2":7.1
}],
"out": "Class1",
},
{"id": 2,
"in":[
{
"Feature1": 3.2
"Feature2":5.1
}],
"out": "Class1",
}]
}
IMPORTANT: I do not know the number of attributes a priori, so I need to retrieve them from the in key as that may change for other types of models, therefore I can't make use of harcoded jmeter variables, similar to what it's used in the CSV Config Set add-on, where they need to specify the variables names for each column of the csv file
I have no idea how you're gonna use the values from JSON in the HTTP Request sampler, however this is how you can parse your samples.json file and get in values from it in the JSR223 Sampler
new groovy.json.JsonSlurper().parse(new File('samples.json')).dataset.each { entry ->
entry.get('in').each { feature ->
feature.each { value ->
log.info(value.key + '=' + value.value)
}
}
}
The above code basically prints the keys and respective values into jmeter.log file
But you can easily amend it to store the values into JMeter Variables, write them into a CSV file, set HTTP Request sampler to use them on the fly, etc.
More information:
Groovy: Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
Apache JMeter API

NoJson found on an http request on play 2.3.2

i'm writing a Play 2.3.2 application using Scala.
In my controller i had a method which get the json object from the request.
The implementation is like the following:
def firstTags = Action.async { request =>
def elaborate(n: Int): Future[Result] = {//some implementation}
//get the json Object
val jsonObject = request.body.asJson
//parse the json object
jsonObject match {
case Some(json) => json \ "number" match {
case x: JsNumber => elaborate(x.as[Int])
case _ => Future{BadRequest}
}
case None => Future{BadRequest("Need a Json")}
}
}
In my route files i had:
GET /recommendation/statistic/first #recommendationsystem.controllers.manager.StatisticsController.firstTags
When i try to call the method with the curl i get always a "Need a Json" response.
I call my server with curl like the following:
curl -H "Accept: application/json" -H "Content-Type: application/json" -d '{"number": 3}' -X GET http://localhost:9000/recommendation/statistic/first
What's wrong??
GET shouldn't have body. look at HTTP GET with request body.
POST method is not only for modify the server state, but also to process data.
From RFC 2616 - HTTP/1.1:
The POST method is used to request that the origin server accept the
entity enclosed in the request as a new subordinate of the resource
identified by the Request-URI in the Request-Line. POST is designed
to allow a uniform method to cover the following functions:
Annotation of existing resources;
Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles;
Providing a block of data, such as the result of submitting a
form, to a data-handling process;
Extending a database through an append operation.
The actual function performed by the POST method is determined by the
server and is usually dependent on the Request-URI. [...]

Posting JSON with curl to Grails JSON REST API plugin

I have a Grails app running on 1.3.7 with the json-rest-api plugin version 1.0.8 installed. I'm trying to post data from the command line using curl in order to create a new instance of a domain class, but cannot seem to figure out the correct way to format the JSON so that the parser is satisfied. I can't find any documentation either that would conclusively describe how the data is supposed to be formatted.
The domain class is defined like this:
package foo
class Foo {
static expose = 'foo'
String name
static constraints = {
name(inList: ['xyzzy', 'quux'])
}
}
Given the above, this doesn't work:
$ curl -X POST --header "Content-Type: application/json" --data-urlencode '{"name":"xyzzy"}' http://myapp/api/foo
The app returns a 500 error code and the content of the reply is
{"success":false,"message":"Property [name] of class [class foo.Foo] cannot be null"}
What kind of data does the API expect me to send?
Try the following format:
{ data: { name: "Blabla" } }
This isn't specific to the json-rest API. I've only ever used the built in RESTful capabilities of Grails.
You need your URL Mapping so that parseRequest = true. You have to include the class in your JSON:
{"class":"Foo", "name":"blabla"}
In your controller, you do this...
def fooInstance = new Foo(params['foo'])
And your gold.