JBPM rest calls with JSON - json

We want to start a process in JBPM6 using the rest API. We need to pass an object as a process variable.
We know how to do it JAXB and the execute call. But we want to do it with JSON and /runtime/{deploymentId}/process/{processDefId}/start
Is it possible? we try and have no success.

I am not sure whether my answer exactly addresses the question. But for someones use in future I place couple of lines here.
If you want to set a process variable when starting a process using the RESTful API, you can do it like this.
If your variable name is myVar just add the value as a URL parameter by appending the phrase "map_" to the parameter name. It means the parameter name should now be map_myVar. For an example see below request.
http://<host>:<port>/jbpm-console/rest/runtime/{deploymentId}/process/{processDefId}/start?map_myVar=myValue
You can confirm whether the value is set by writing below code in a script task.
Object var = kcontext.getVariable("myVar");
System.out.println("myVar : " + var);
See the 17.1.1.3. Map query parameters section of JBPM6 documentation.

After talking to the dev that is responsible for the REST API. I was able to confirm how it works.
The
/runtime/{deploymentId}/process/{processDefId}/start
Is a POST request where all the contents in the payload are ignored. The variables are written as key=value in the GET string.
With deployment id: com.web:work:1.0
With processDefId: work.worload
2 variables: var1 and var2
For example:
/runtime/com.web:work:1.0/process/work.worload/start?var1=a&var2=b
I'm still after trying to understand how to define objects with the remote API.
Meanwhile, I also confirmed that it is impossible to define objects using this way. The only way to define objects is only by using the JaxB. This uses the "/execute" path

Related

How to pass both parameter and JSON in one single HTTP request body with having JSON a variable [JMeter]

I have a similar but extended question for the below question.
How to pass parameter and json both in http request request body in jmeter??
I will take the same example as mentioned in the above question/link.
Have to pass multiple parameters,
UserId=47
meeting={
"DeviceID":${deviceID},
"NetworkCarrierName":"VODAFONEIN",
"BatteryValue":"22",
"AppVersion":"1.1.3",
}
As you can see, DeviceID have a value from variable deviceID. I want to pass all these parameters and JSON in one single http request body.
What would be the approach for this?
In parameter I have to add the variable for value part for whichever key I want to refer to. It will work fine.
This image shows that..
The same approach will work fine, you can use JMeter Variables anywhere in your test plan, if there is a User Defined Variable or a pre-defined variable or a variable coming from a Post-Processor - JMeter will substitute the variable placeholder with its respective value in the runtime:
If you're uncertain regarding how to properly build your request the easiest is just recording it using HTTP(S) Test Script Recorder

Groovy to generate dynamic parameters based on JSON of job values?

I just found that Jenkins jobs via a JSON URL each job has using this format: https://jenkinsurl.net/job/_test/lastBuild/api/json provides info like below.
{"_class":"hudson.model.FreeStyleBuild","actions":[{"_class":"hudson.model.ParametersAction","parameters":[{"_class":"hudson.model.StringParameterValue","name":"build_num","value":""}]},{"_class":"hudson.model.CauseAction","causes":[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]},{},{},{},{},{},{"_class":"org.jenkinsci.plugins.buildenvironment.actions.BuildEnvironmentBuildAction"},{}],"artifacts":[],"building":false,"description":null,"displayName":"#1","duration":1850,"estimatedDuration":1850,"executor":null,"fullDisplayName":"_test #1","id":"1","keepLog":false,"number":1,"queueId":5753,"result":"SUCCESS","timestamp":1479700053274,"url":"http://jenkinsserver.net/job/_test/1/","builtOn":"node_name","changeSet":{"_class":"hudson.scm.EmptyChangeLogSet","items":[],"kind":null},"culprits":[]}
I'd like to know how I can query those fields with a Groovy script to help me build Dynamic parameters when selecting "Build with Parameters". I already have the Groovy and Dynamic parameter plugins and use them for some simple queries I've been using to generate some parameters, like timestamps not overwritten by Jenkins jobs downstream.
How do I query for these and return their values? For example, if I wanted to return the value of the user that started the build from this segment:
[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]
This isn't a question about getting the person that triggered the build. Sorry if that's not such a great example, but this one appears to be a bit nested, so presumably a good one to learn with.
I know how to reference the value of parameters and get some info to return to generate them, but not how to use that URL and extract specific info from it to help create a parameter's value before the build begins. Is this possible? If not, what other mechanism could I use?
You can do something similar to this one:
How do I discover the additional causes of my Jenkins build?
job = hudson.model.Hudson.instance.getItem("demo-job")
build = job.getLastBuild()
// get action first
def action = build.getAction(hudson.model.CauseAction.class)
cause = action.findCause(hudson.model.Cause.UserIdCause)
println cause.userId
http://javadoc.jenkins-ci.org/hudson/model/Cause.UserIdCause.html
The question is abit confusing so not sure if this helps at all. Anyway, you should be able to extract all the information you need from build returned by getLastBuild().
It not possible to extra parameters before the build begins. If that is what you mean.

Jmeter and Json, extracting and using variables for another request

I'm new to JMeter and I'm probably missing something quite simple...
Note: I'm using a json add-on as well.
After making a request, I extract a value from the response. If I check the view results I'm able to see the correct value in the variable I created.
-Initial extraction of value-
-how I tried to use my new value for a new request-
If I try use the variable in another request, I receive an error because the variable is now the default value.
What am I doing incorrectly that makes the second post request to use the default value and not the value it captured (if I did that correctly).
Thanks
JSON Path Extractor is a Post Processor. It is not a Sampler. It should be the child element of the first request 'Create Order' in your test plan if you are going to extract from the 'Create Order' response. If it is in same level with other requests, the post processor will be executed for each and every samplers in the same level. That is why, You are able to see the value for the first time. Now Post processor tries to extract the value from the Debug Sampler as well. As Debug Sampler does not match your JSON extract condition, It sets the default value.
2 years later (March 2018), with Jmeter version 4.0, solution it's the same.
With the new interface, simply by dragging the json extractor on the http request, the json is limited to perform the extraction operation on it, maintaining the results.

questions wcf rest service with webclient

I'm getting confused on a few things in regards to wcf rest.
If you call a login method, should I use a POST or GET? After implementing a POST, I started to find various articles saying you should only use post to update data, and get for retrieving data. Which is the most appropriate method?
If I had to change the Login method from a Post to a Get, how would I call this?
http://....myservice.svc/login/{username}/{passpord} or is there another way to call this?
Note that in my post method, I'm passing and returning data in json format.
I need to create a search function that requires to pass various parameters i.e. list, string, list, etc... I assume in this instance I would have to define GET method, but again how to I pass these list of objects? Convert them to json first and pass them as parameters?
A brief url sample would be great.
Ok, I guess I'll answer my own question based on further finding when researching it and remember that my answer is based on using JSON as parameters. I'm not sure how it would behave if xml was used as I did not try it.
It appears to make more sense to use POST when logging in as you do not want to display the information you are posting via a url. You could encrypt the data and pass it in the url using a GET method... Again I could be wrong, but that's how I interpreted the various articles I read.
Again, in this instance, it appears POST is the best solution if a) you require a large amount of data to be passed to your url and b) if you do not want to show this data to the user. If your query only requires simple parameters (i.e. userid, type, etc...) and you don't mind showing this info, you can use the GET method.
If you require to pass multiple parameters to a function, you should instead pass a single parameter. This parameter should be a single object. This object should be made of all the parameters you wanted to use in the first place, this way, when using the POST method, this object can easily be converted to JSON and it will handle passing multiple parameters through a single object and it will handle numeric, string, list<>, array<>, etc... very nicely.

submitting a parameterized hudson build via the REST API

hudson supports submitting a build by doing an HTTP GET to an API. I need to pass some parameters to such a build. Just adding them as additional URL parameters doesn't work for me. Is this supposed to work? Is there some other mechanism?
Is it possible to pass parameters in the Hudson's job that will be triggered remotely?
Check this question.
Instead of /build use /buildWithParameters. I'm currently using it with a simple wget
Based on the HTML source on the web interface for starting a parameterized build, you need to do a POST to http://hudson/job/NAME/build with the parameters.
Update: It's a little more complicated. There's a hidden input with name "name" and value "MyParameter", then the input you actually fill in with name "value" and value "MyInput". (Where MyParameter if your parameter name and MyInput is whatever you need to fill in.) I haven't checked to see how this works with more than one parameter.
the POST works with just the json url parameter that contains a JSON list of the build parameters: json=%7B%22parameter%22%3A+%5B%7B%22name%22%3A+%22Input%22%2C+%22value%22%3A+%22data1%22%7D%2C+%7B%22name%22%3A+%22Input2%22%2C+%22value%22%3A+%22data2%22%7D%5D%2C+%7D