how to get webscript url parameters - alfresco

i have a webscript where i try to get two parameters filename and content passed on the url when i call this webscript but when i call the webscript whith this url http://localhost:8080/alfresco/service/fr/starxpert/workflows-repository/create-save-workflow-files?filename=testFileName="testFileName"&&content="testContent" i get this error:
The Web Script /alfresco/service/fr/starxpert/workflows-repository/create-save-workflow-files has responded with a status of 404 - Not Found.
404 Description: Requested resource is not available.
Message: 06280086 Script url /fr/starxpert/workflows-repository/create-save-workflow-files does not map to a Web Script.
There is my webscript files:
createAndSaveWorkflowFile.get.desc.xml:
<webscript>
<shortname>Creation and save new workflow file</shortname>
<description>create an workflow JSON file and save it into StarXpert Workflow repository</description>
<url>/fr/starxpert/workflows-repository/create-save-workflow-files/{filename}/{content}</url>
<format default="json">extension</format>
<authentication>user</authentication>
<family>StarXpert</family>
</webscript>
createAndSaveWorkflowFile.get.js:
var fileName=args.filename;
var properties=args.content;
logger.log(fileName);
model.filename=fileName;
model.properties=properties;
createAndSaveWorkflowFile.get.json.ftl:
{
"arguments":[
"fileName":"${fileName}",
"properties":"${properties}"
]
}
Can you tell me what i make wrong, or take me an example to how call the webscript using two arguments on the url, and then get these argument on the webscript.

You have declared that your URL uses path arguments:
/fr/starxpert/workflows-repository/create-save-workflow-files/{filename}/{content}
But when you are invoking your script you are using query string arguments:
/alfresco/service/fr/starxpert/workflows-repository/create-save-workflow-files?filename=testFileName="testFileName"&&content="testContent"
Your controller assumes query string arguments, so I will assume that's what you intend.
Further, your URL looks off.
To use query string arguments your URL should be:
/alfresco/service/fr/starxpert/workflows-repository/create-save-workflow-files?filename=testFileName&content=testContent
If you want your descriptor to match that, you need to change it to:
<url>/fr/starxpert/workflows-repository/create-save-workflow-files?filename={filename}&content={content}</url>
Notice that the ampersand is escaped so that the XML remains valid.

Related

How to make async http request from jmeter while changing path dynamically before each call

Following are the steps that I need to peform
Make http request call to a sevice which returns a json that has many urls.
Extract all the urls using regular expression extractor
Make http request call to all the exctracted urls asynchronously.
Is there a way we can achieve this? I tried parallel controller but, if I am not wrong, it requires all the request to be mentioned as its child sampler. I don't want to write each and every request manually. Is there a way we can change urls dynamically after running the test plan?
It's better to use JSON Extractor if the server returns URLs in JSON format
Once you have the URLs in form of JMeter Variables like:
url_1=http://example.com
url_2=http://example.org
........
........
url_matchNr=X
add Parallel Sampler to your Test Plan
add JSR223 PreProcessor as a child of the Parallel Sampler
Put the following code into "Script" area:
1.upto(vars.get('url_matchNr') as int, { index ->
sampler.addURL(vars.get('url_' + index))
})

openapi documentation how to handle extension in the path

I have URLs like:
/return/{pid}.xml?d1='123'&d2='345'
/return/{pid}.json?d1='123'&d2='345'
the swagger specification calls for:
path:/return/{pid}
....
but how can I map the extension ie
path:/return/{pid}.xml
or
path:/return/{pid}.json
It is a jersey+spring mvc application - so both the URLs are hitting the same controller and only based on the extension the rest framework is going to generate the xml / json output.
I can't ignore the extension from the path ie:
path:/return/{pid}
because the user needs to know that he/she has to provide the file extension as part of the URL. Also I can't use two paths corresponding to xml / json because they are treated the same by the application. In addition it will duplicate things (I am not sure whether there is a fall-through like mechanism just like "case" statements in c++/java "switch" block)
In Swagger specs,You can define the file extensions in the path as below :
/return/{pId}.{fileExtension}
and define the fileExtension in parameters .
also the below is valid (not for your case) :
/return/pid.{fileExtension}

Http call parameters SoapUI

How can I Parameterize an http call parameter in soapui to read parameters from a txt file for each iteration.
If needed can the parameters be encoded(url or gzip) before the call was sent?
Any help (pointers/links/code) is greatly appreciated? Thank You
Use groovy script test step to read data from txt file and store the data in TestCase property .
Something like this would work:
String fileContents = new File('/path/to/file').text;
testRunner.testCase.setPropertyValue(property_name, fileContents);
More information about groovy script steps here.
You can access this property as ${#TestCase#property_name} in your requests. Then you can use template parameters for your request url - I've already answered about it here.
If i'm not wrong you are asking about parametrization of URL which you send as HTTP Request for your Rest call. Let me explain you with an example :
Suppose you are looking for a resource and invoking the WebService using the GET method by making use of the ResourceID already present in the DB...Parametrize it as below :
http://${#Project#HOST}:${#Project#PORT}/rest/${#Project#WebApplicationName}/Resource/${#TestCase#ResourceID}
where HOST, PORT, WebApplicationName are the Project Level properties and ResourceID is a Test Case Level property(as it may change with the test cases i.e., dynamic in nature).
This is my approach of parametrization instead of taking it from a local file. Hope this helps!

How to Route to Url *with* Extension

I'm trying to deliver my blog's sitemap.xml file generated by a Razor view, like so in my _AppStart.cshtml file:
//sitemap
RouteTable.Routes.MapWebPageRoute("sitemap.xml", "~/pages/shared/sitemap.cshtml");
This route is ignored for some reason, and I get a 404. It works fine if I route it to "/sitemap", but the moment I include the file extension it breaks. I'm assuming IIS is doing something with the request before ASP.NET gets hold of it, but I"m not sure what to do about it.
Try making the extension a parameter:
RouteTable.Routes.MapWebPageRoute(
"sitemap.{extension}", // route pattern
"~/pages/shared/sitemap.cshtml", // physical file
defaultValues: new {extension = "xml"}, // defaults
constraints: new {extension = "xml"}); // constraints (regex)

HTTP request parameters are not available by request.getAttribute()

I am sending an url parameter to servlet using the following jQuery piece:
$.getJSON("http://localhost:8080/JsoupPrj/JasonGen?url=" + url, function(data) {
$("#content").html(data);
});
On the server side, the servlet gets the parameter, for that I coded as below:
String url = (String) request.getAttribute("url");
But it is not working, can you tell me where I am doing wrong? I believe I am not passing the parameter properly to the servlet. The servlet triggers each time through the JavaScript, but it is not seeing the parameters passed from the browser.
Here,
String url = (String) request.getAttribute("url");
you're trying to get a request parameter as a request attribute instead of as a request parameter. This will obviously not do what you want.
You need to get a request parameter as a request parameter, not as a request attribute.
String url = request.getParameter("url");
Unrelated to the concrete problem: you don't seem to be URL-encoding the parameter at all before sending. This will possibly cause other problems, unrelated to this one, when the url contains special characters. Look at the JS encodeURIComponent() function, or the data argument of the $.getJSON() function. See for more hints also How to use Servlets and Ajax?

Resources