Retry function for karate dsl is not working - dsl

I have been using a feature in my test which calls the retry function for calling an end point.
It used to work fine before but in last few days the same code has stopped working .
my code is :
Feature: Invoke External
Background:
* configure retry = { count: 5, interval: 5000 }
#parallel=false
Scenario: Invoke gateway
Given url externalGateway
And path domain + '/' + basepath + '/' + path
And header Authorization = accessTokenforProd
And request 'test'
When method requestMethod
Then retry until responseStatus == externalGatewayResponse
Then print ' response code from Qantas External Gateway: ' , responseStatus
and I am calling this feature with the following syntax:
Then def responseFromAuthenticatedExternalWSO2Gateway = call read('classpath:examples/Services/InvokeAuthenticatedProdQantasExternalWSO2Gateway.feature') {'domain': '#(domain)' , 'basepath': '#(basepath)' , 'path': '#(path)' , 'externalGatewayResponse': '#(externalGatewayResponse)' , 'method': '#(requestMethod)' , 'accessTokenforSandbox': '#(accessTokenforSandbox)' }
Then match responseFromAuthenticatedExternalWSO2Gateway.responseStatus == 200
Is there any issue with the syntax? If not , then have we made any changes which might affect the functioning of retry function ?

Please read the docs: https://github.com/intuit/karate#retry-until
You have got it wrong, the retry until part should be before the method step.
On a related note - especially when I see requestMethod as a variable - I feel you have over-engineered your tests, which I strongly advise against. Avoid using call except for setup kind of stuff - else you will end up with hard to maintain tests.
See this answer for details: https://stackoverflow.com/a/54126724/143475

Related

Inline component is not defined or not allowed (HTTP PUT)

I have been looking at this for quite some time and I don't know why it fails, because in another controller I have the same code and it updates the model. What do you think it could be?
onAcepta: function(oEvent) {
var oModel = this.getOwnerComponent().getModel();
var oDataModel = this.getOwnerComponent().mainIdentJson;
console.log(oDataModel);
var sPath = "/IdentitiesSet(Userid='" + oDataModel.Userid + "',Ident='" + oDataModel.Ident + "')";
oModel.update(sPath, oDataModel, {
success: function(oData, oResponse){
console.log("OK");
},
error: function(oResponse){
console.log("No");
}
});
this.closeParent();
this.selectedItems = [];
}
Error in Log-dbg.js:
2021-08-13 14:01:40.161899 Request failed with status code 400: MERGE IdentitiesSet(Userid='?????????'.Ident='?') - [{"code":"SY/530","message":"Inline component is not defined or not allowed (HTTP PUT)","persistent":false,"targets":["/IdentitiesSet(Userid='?????????'.Ident='?')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
[![2021-08-13 14:01:40.161899 Request failed with status code 400: MERGE IdentitiesSet(Userid='?????????'.Ident='?') - [{"code":"SY/530","message":"Inline component is not defined or not allowed (HTTP PUT)","persistent":false,"targets":["/IdentitiesSet(Userid='?????????'.Ident='?')"],"type":"Error"}]
this is the batch:
and the changes that I want are okay
batch:
so, I think that the batch is doing okay? so I don't know the error
and the weird thing is that in other view in this project, I have an update with this same path and works perfectly.
Are you trying to pass nested payload like we pass to deep insert.
If yes, it wont work as the feature is not supported for Put operation. Instead you need to process it via batch.
Deep Entity Update

Problems with getRoutingService().calculateRoute parameters

I am looking into the HereMaps as a possible map provider for our company and am having difficulty with the return params for calculateRoute. I am trying to get the route instructions to be returned from the endpoint but it fails when trying to do so. I am currently passing in ...
var routingParameters = {
routingMode: 'fast',
transportMode: 'truck',
// The start point of the route:
origin: position.coords.latitude + ',' + position.coords.longitude,
// The end point of the route:
destination: '50.672770,-120.375370',
return: 'polyline',
};
This seems to work however when i try to do return: 'polyline, actions, instructions', to get the instruction info the route request fails. I noticed in the docs that these are available but don't seem to work for my case. My guess is it may be due to being on the free version for now. Any help is appreciated.

http.get and http.post through error in scheduled script Netsuite - Error: Cannot find function post in object

I'm using schedule script and http.get method but throws error as "Cannot find function get in object".
code snapshot:
var headers_= []
headers_["Content-Type"] = "application/x-www-form-urlencoded";
headers_["Accept"] = "appli`enter code here`cation/json";
headers_["cache-control"] = "no-cache";
var response = http.get({
url: URL_,
headers: headers_
});
Check your define statement. It should be:
define(["N/http"], function (http) {
...
});
If there are other dependencies as well, double-check that the order of the dependencies in the Array matches exactly the order of the parameters in the callback.
If the order matches exactly, make sure you don't have a typo in the parameter name you use for the http module.

completely failed to read post data in vertx route handler chain - tried all ways no success

i'm running a gradle build with vertx web. my library dependecies include
// for mock API serving https://mvnrepository.com/artifact/io.vertx/vertx-core
compile group: 'io.vertx', name: 'vertx-core', version: '3.5.3'
compile group: 'io.vertx', name: 'vertx-web', version: '3.5.3'
so in my groovy script code i do this
Vertx vertx = Vertx.vertx()
HttpServer server = vertx.createHttpServer()
...
I then declare a route to catch all requests on resource and process the request and form a response - trying to keep it simple - just return simple string as response
Router allRouter = Router.router(vertx)
allRouter.route ( "/api/now/table/incident")
.handler(BodyHandler.create())
.blockingHandler { routingContext ->
def request = routingContext.request()
HttpMethod method = request.method()
def response = routingContext.response()
response.putHeader ("content-type", "text/plain")
def uri = routingContext.request().absoluteURI()
switch (method) {
case HttpMethod.GET:
println "processing a resource GET on uri : $uri "
response.end ("(GET) howdi will")
break
case HttpMethod.POST:
String bodyEnc = routingContext.getBodyAsJson().encodePrettily()
println "processing a resource POST on uri : $uri"
println "post request received post data : " + bodyEnc
response.end ("(POST) howdi will")
break
}
}
I create a handler for BodyHandling, before the general handler in the route.
Then I start the server with the route
server.requestHandler(allRouter.&accept)
server.listen(8081, "localhost")
works all fine for a get request from postman.
when i use a post request with a request body data - the service hangs and i have to cancel - it never gets to the switch statement. All that happens in the console when i issue the post is
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 32768
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
23:30:16.455 [vert.x-eventloop-thread-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
23:30:16.478 [vert.x-eventloop-thread-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
23:30:16.482 [vert.x-eventloop-thread-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector#51d486
This is the nearest to being a related topic enter link description here
I have tried this countless ways now, set bodyHandler inside the request when i get it etc - can't get it to work.
my postman post looks like this - where the headers are set to Content-Type application/json, Content-Length is 296 bytes (length of bytes in utf16), and Accept is text/plain to receive simple response
The documentation is just not clear. Blown 12 hours trying to crack this.
Does any one know exactly how one should get the post data on a request when using vertx web please
It appears as though my problem was the size of bytes being sent. I had calculated the bytes of the reqBody string as 296 bytes (using UTF16 charset), and set this into the Postman request.
So the vertx server was trying to read that many when processing the body and hanged. When I just did reqBody.getBytes().size - effectively UTF8, this returned 147 bytes. When I changed the content-length to this in postman, it started to work.
There is a timing issue in where you setup the BodyHandler. I tried this is tin the switch case, and it fails with request has already been read.
However neither of these seem to work successfully.
option 1 : ' create body handler before the route (path) call'
allRouter.route().handler(BodyHandler.create())
//now try and setup the route for API path interception
allRouter.route ( "/api/now/table/incident")
.blockingHandler { routingContext -> ...
option 2 : 'chain the handlers but put the Body Handler first'
//now try and setup the route for API path interception, followed by body handler
allRouter.route ( "/api/now/table/incident")
.handler(BodyHandler.create())
.blockingHandler { routingContext ->...
This was setting the content-length, assuming UTF16 for internal byte size that was the real problem. Now back to trying to complete what I set out to do.

How to troubleshoot 'Invalid Page Parameter' error in Netsuite

I'm still relatively new to NetSuite, and have taken over a project that a contractor did for us, so this may be a simple question. We have a Suitelet that is calling another Suitelet with nlapiRequestURL. The Suitelet that is being called, is supposed to return a single ID. Instead, we get a 'Invalid Page Parameter' response.
I looked at the configuration for the Suitelet that is called, and there is a parameter setup, but the 'Preference' field on that parameter is blank, which according to the documentation suggests that when that is the case, the parameter value should be defined in the Deployment, on the Parameter tab. Which it is, and appears to be the correct value.
So I assume the issue is with one of the parameters in the URL that is being used in nlapiRequestURL, and not the parameter defined on the script record in Netsuite. Here is an example of one of those URLs. I just changed the compid for obvious reasons:
https://forms.sandbox.netsuite.com/app/site/hosting/scriptlet.nl?script=147&deploy=1&compid=12345&h=e06792b0e7727d53f816&internalIds=17509
I verified that '147' is the correct script id. I also tried removing each of the parameters one by one from the URL, but that doesn't work. Depending on which one I remove, I either get 'An unexpected error occurred', or 'Missing a required parameter'. The only parameter that is being used inside the Suitelet that is called is 'internalids'. I can see that it's being obtained with 'request.getParameter("internalIds")'. (See code below)
As a sidenote, I'm not sure what the 'h' parameter is for in the URL, and can't find where that, or compid, or deploy is configured. I'm wondering if that 'h' value is incorrect, but am not sure what it's for. Why are 'compid', 'deploy' and 'h' being included in the URL? I can assume the compid is for identifying our company, but I'm not seeing how someone can determine how to build a URL for a request, since I don't know what mandatory parameters there are like that. I'm guessing I don't know where to look in Netsuite to find that configuration. Are there settings for base URLs somewhere?
Anyway, this is the script below that is being called. The other script is quite a bit longer, and has some company related info, so I'm not going to include it, but I don't think that matters anyway. The only thing that needs to be known is that we're using the URL above with nlapiRequestURL to call the script below, and calling 'getBody' on the result.
function suitelet(request, response){
nlapiLogExecution('DEBUG', 'suitelet', 'In the Preview_Link.suitelet function');
nlapiLogExecution('DEBUG', 'suitelet', 'The request is ' + JSON.stringify(request));
nlapiLogExecution('DEBUG', 'suitelet', 'The response is ' + JSON.stringify(response));
var context = nlapiGetContext();
var folderInternalId = context.getSetting('SCRIPT', 'custscript_buffer_folder_for_temp_pdf');
var strInternalIds = request.getParameter('internalIds');
if(!strInternalIds)
return;
var internalIds = strInternalIds.split(',');
if(!internalIds || internalIds.length == 0)
return;
var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
xml += "<pdfset>";
for (var index = 0; index < internalIds.length; index++)
{
var internalId = internalIds[index];
xml += "<pdf src='"+ nlapiEscapeXML(nlapiLoadFile(internalId).getURL()) +"'/>";
}
xml += "</pdfset>";
var file = nlapiXMLToPDF(xml);
file.setName(internalIds[0] + '_' + internalIds.length + '_' + Math.random() +'.pdf');
file.setFolder(folderInternalId);
file.setIsOnline(true);
var internalIDUpdatedData = nlapiSubmitFile(file);
response.writeLine(internalIDUpdatedData);
}
So 'custscript_buffer_folder_for_temp_pdf' is the parameter defined on the Script record in Netsuite, and there is a value for it on that script's Deployment tab, on the Parameter tab, of '36', which is the value we want. That's our 'TEMP' folder in the File Cabinet. 'internalIds' is defined in the script that calls the one above, and it's either a single integer, or a comma separated list of them. (although it seems to always be a single value)
I should mention that this works in our production instance, and we just refreshed our Sandbox instance two days ago based on production. It didn't work in Sandbox prior to the refresh either. The only difference I can see, is that in production, the domain name is different in the URL, which of course it must be. All the code and settings appear to be identical besides that between the two environments.
Like I said, I'm new to Netsuite, so I haven't used nlapiRequestURL before. So this may be something incredibly stupid I'm overlooking. I've stepped through the code in the script that does the calling, but I can't seem to debug the Suitelet that is being called with nlapiRequestURL. I placed a nlapiLogExecution call as the first line in the script that is being called though, and it never even seems to hit that. I just get one of the errors I mentioned above before it actually steps into that script.
If anyone has any advice, I'd appreciate it. I've more or less exhausted my knowledge and resources. Thanks in advance, and let me know if you need further info.
Some things you may want to try:
var baseSuiteletURL = nlapiResolveURL('SUITELET', SUITELET_SCRIPT_ID, SUITELET_DEPLOYMENT_ID, true); //Getting URL from script id and deployment id
var reqUrl = baseSuiteletURL + "&internalids=17509"; //Adding your GET parameter here (all in lowercase)
var requestBody = {}; //Alternatively you could send your parameters within the POST body
requestBody.internalids = 17509;
var reqBody = JSON.stringify(requestBody);
var reqHeaders = {};
reqHeaders["User-Agent"] = "Mozilla/5.0"; //Sending user agent header to allow Suitelet to Suitelet calls
var myResponse = nlapiRequestURL(reqUrl, reqBody, reqHeaders);
Test sending your GET Query parameters (internalids) all in lowercase, I have experienced issues before in which the parameters case gets converted and it creates unnecessary troubles.

Resources