I am using HTTP Request Plugin to make calls to a REST based Web service. In those calls I want to pass the console output URL in request body in JSON format.
I am constructing the console output URL using environment variable ${BUILD_URL}/console.
Environment variable substitution is working for the URL but not for the request body. Any suggestions on code changes that need to be made to the plugin code to make it work. Can someone please share information on how exactly does Jenkins does variable substitution and why it is not working in this case.
Below is the JSON request body:
{'state':'4', 'short_description':'${BUILD_URL}console'}
I was able to figure out the solution. Tested and confirmed that it's working.
You need to add below line in HttpRequest.java's perform method:
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener){ throws InterruptedException, IOException
requestBody = evaluate(requestBody, build.getBuildVariableResolver(), envVars);
//rest of the code as it is
}
Just make sure you add line to evaluate requestBody member for presence of environment variables in it before you call performHttpRequest(build, listener, evaluatedUrl, params) method.
Related
How to pass a range of validResponseCodes for Jenkins pipeline's httpRequest method?
Here is the reference for this method:
https://jenkins.io/doc/pipeline/steps/http_request/#httprequest-perform-an-http-request-and-return-a-response-object
Documentation says its a string. And no more examples are provided.
I would like the valid response codes to be 200 - 400 and build not to fail because of the response code 400.
validResponseCodes should be an interval from:to or a single value.
In your case it would be
httpRequest url: someUrl, validResponseCodes: '200:400'
See HttpRequest class for more information.
Also, based on the source code, it looks like it's possible to specify ranges and singe values separated by a comma. e.g. 200:400,409
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. )
I have never used JUnit or other testing frameworks. All i know is how to develop rest service. I recently saw REST assured framework to test REST api. But all the articles that i found looks like below. But i don't know how to pass request xml and how will i get response and when should i call this method.?
Do i need to use some other tool before this REST assured.? I am completely beginner in this kind of testing frameworks. Please show me some light in this world. All i know is how to send request and check values in the response in SOAPUI. I have never tried this.
expect().
statusCode(200).
body(
"user.email", equalTo("test#hascode.com"),
"user.firstName", equalTo("Tim"),
"user.lastName", equalTo("Testerman"),
"user.id", equalTo("1")).
when().
get("/service/single-user/xml");
expect() /* what u expect after sending a request to REST Service */
statusCode(200) /*you are expecting 200 as statuscode which tells request handled successfully at server */
body()
/* the conditions given in body are compare the value with expected values. "equalTo" hamcrest matcher condition (you need to have hamcrest jar in java classpath).*/
when(). /* as is name says above all will be done after sending get/post/put/delete request right so before you put these get,post,put,delete you will have this method as prefix */
get("/service/single-user/xml")
/* the actual REST API request url goes here. can be GET/POST/PUT/DELETE. the confusion for you is its only showing half part which is base path.you can give entire request url in get() method.*/
more on:
http://rest-assured.googlecode.com/svn/tags/1.8.1/apidocs/com/jayway/restassured/RestAssured.html
I hope this helps.
The following code works as expected on Grails 2.0.4 and Eclipse STS 3.2 using Eclipse's embedded tcServer 2.7 as the web container...
class TestController {
def service() {
println request.request.getRequestURL()
//render response here...
}
For a client request of http://svr1:8080/testapp/test/node1, the above code prints the full request URL, http://svr1:8080/testapp/test/node1.
We created a WAR and deployed it to Jetty 8.1.10, but found that request.request returns null, so the above code fails with a null pointer. We tried using request.getRequestURL() but it returns a URL containing grails dispatch syntax, so it does not match the original client request url which is what we need.
As a workaround, we manually constructed most of the URL using request.getServerName(), request.getServerPort(), and request.getContextPath(), giving http://svr1:8080/testapp, but that still leaves out the uri portion, /test/node1. We assume this problem may be attributed to Jetty's Servlet API implementation, but if that were the case surely someone else would have picked up on this before us.
Found a workaround that appears to work on tcServer and Jetty posted here. We construct the base URL manually, then use this utility to get the remaining portion.
How do I invoke a Service Operation in WCF from iOS?
I have a Service Operation defined in my WCF Data Service (tied to a stored procedure in my DB schema) that I need to invoke from iOS. Say I've got the following declaration in my .svc.cs file:
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public IQueryable<Foo> GetFoos(int param1, DateTime param2, string param3)
{
return CurrentDataSource.GetFoos(param1, param2, param3).AsQueryable();
}
And I've got it set up with the proper rights in InitializeService:
config.SetServiceOperationAccessRule("GetFoos", ServiceOperationRights.AllRead);
When I try to invoke this via HTTP POST from iOS, I get back an error wrapped in JSON:
Bad Request - Error in query syntax.
It seems like it doesn't like how I'm passing my parameters. I'm passing them JSON-encoded (using NSJSONSerialization to turn an NSDictionary into a JSON string) in the request body of a POST request. The same method works on another web service (.svc) not connected to WCF that has operations annotated the same way.
An answer to another question of mine in a similar vein suggests that data formats can be negotiated between client and server, and I've read that dates are a pain to format, so maybe it's my DateTime parameter that's a problem. But I've tried both the JSON format (\/Date(836438400000)\/ and /Date(836438400000)/) and the JSON Light format (1996-07-16T00:00:00) to no avail.
So my question is this: what is the proper way to invoke this operation? If I need to have my app tell the server what format to expect, how do I do that?
Update: I tried using the format datetime'1996-07-16T00:00:00' as mentioned in this question. Same error.
Update 2: The MSDN page for Service Operations seems to suggest that nothing besides Method = "POST" is supported when annotating the WebInvoke for a Service Operation. I tried removing everything from what is quoted in the above code and setting the method to POST. Same error.
Update 3: On Pawel's suggestion, I made a new Service Operation on my Data Service just like this:
[WebInvoke(Method = "POST")]
public IQueryable<string> GetFoos()
{
List<string> foos = new List<string>();
foos.Add("bar");
return foos.AsQueryable();
}
I was able to make it work in Fiddler's Composer pane by setting the method to POST, adding accept:application/json;charset=utf-8 and Content-Length:0 to the headers. Then I added a single int parameter to the operation (called param1). I set the body of my request in Fiddler to {"param1":"1"} and ran it (and Fiddler automatically updated my content-length header), and got the same error. I changed the type of my parameter to string and ran my request again and it worked. So my problem seems to be non-string types.
You need to send parameters in the Url and not in the request body.