I'm using JMeter to do some load tests on my JSF application and I'm having trouble passing the ViewState along the pages. The ViewState variable doesn't get extracted at all or it doesn't get passed along the pages.
I've recorded my test steps with a proxy server and this is what it looks like:
I've added the Regex extractor in the first GET request. Tested the regex and it is correct.
In every POST request I replace the hardwired View IDs with my variable.
And what I get when I send the request is the following:
The POST parameters are incorrect, as it sends the name of the variable.
POST data:
loginForm%3ArequestToken=&loginForm%3Ausername=heller&loginForm%3Apassword=%21QAYxsw2%A7EDC&loginForm%3AloginButton=Anmelden&com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm
Could you tell what I'm doing wrong here?
Thanks!
The ViewState parameter is an encoded value (Base64 I believe?) and may contain values that would be inappropriate if passed in a GET request through the url. URL parameters are typically encoded so that special values (Eg. space -> %20) can be represented and decoded when the request reaches the server.
The issue here is that the following request is a POST meaning that the parameters do not need to be URL encoded.
com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm
The above shows that JMeter or some other process is URL encoding the ViewState in the request which is incorrect. The value of the ViewState should simply be sent as is.
Found my problem: the regex was wrong, so it couldn't find anything in the response. I had to change the regex. Noticed it after adding a default value "NOT FOUND".
Related
I am using an RSS feed generated by our test application to verify if there are any broken links on our website.
When I use these URLs in the HTTP sampler after some pre-processing (to split the URL to extract protocol, host, domain), most of the URL's are working just fine but I am facing issues in some random cases as explained below.
for example: below mentioned URLs throw URI exception. The separator between the highlighted text in these URLs mentioned below does not seem to a normal hyphen. It's some special character which I guess needs special handling.
Failed URL from the feed
https://abc.xyz.com/article/worksheet-development-planning—manager-preparation-10200/download/
https://abc.xyz.com/article/worksheet-development-planning—worker-preparation-10201/download/
JMeter Result from Assertion Listener
See link below for JMeter Result from Assertion Listener
URL gets encoded with some unexpected characters
You're right, this — symbol needs to be URL-encoded, to wit your URL path should look like
article%252Fworksheet-development-planning%25E2%2580%2594manager-preparation-10200%252Fdownload%252F
JMeter provides __urlencode() function which can perform URL-encoding of the passed parameter on the fly so you can use it directly in the "Path" field of the HTTP Request sampler like:
${__urlencode(/article/worksheet-development-planning—manager-preparation-10200/download/)}
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept.
I am forming a url that contains another url as one of its query string parameters. This url is supposed to return some xml code from our webapp deployed on tomcat.
Below is the sample url that I am generating using Java:
http://localhost:8080/sample/url?id=1&uid=sfdgsdh&nurl=https%3A%2F%2Flocalhost%3A8080%2Fxmltag%2Freturn%3Fzid%3D1_0_1%26sid%3Dfdd61fce-29b4-11e7-9ac0-eb0a8802439b%26au_pc%3D%25%25TAG_PRICE%25%25
Now the issue is when I hit this url from browser or wget it, it returns 'ERROR 500: Internal Server Error'. But if I replace the last macro '%25%25TAG_PRICE%25%25' with some real value e.g. 5.2, then this url returns valid response.
So I assume the issue is with passing %%TAG_PRICE%% in the query string. Its not working no matter its encoded or not and I need to have this macro in my url. I tried to debug it using eclipse debugger, but its not even reaching init method of web servlet. I don't know how to fix this.
Any help is appreciated. Thanks in advance.
Finally I figured out that if I encode the macro %%TAG_PRICE%% twice, it works fine i.e. if I insert %2525TAG_PRICE%2525 as a query parameter in the above url, browser successfully loads its content.
I have been wondering if its possible to anonymize public URL. When user makes a request with this anonymized public URL, let Nginx decode, fetch and serve the URL.
Example
Public URL http://amazon.server.com/location/file.html
Anonymized URL https://amazon.server.com/09872340-932872389-390643289/983724.html
Nginx decodes 09872340-932872389-390643289/983724.html to location/file.html
Added image below for further clarification. Nginx has a reverse logic to decode, whereas Remote Server has the logic to Anonymize URL.
Question
All I need to know is how would Nginx decode anonymized URL? Nginx got anonymized URL request. There has to be a way to decode it.
This is an answer to the updated question:
Question All I need to know is how would Nginx decode anonymized URL? Nginx got anonymized URL request. There has to be a way to decode it.
Nginx would make a request to a script, e.g., either through proxy_pass or fastcgi_pass et al.
The script could decode the URL and provide the actual URL through a Location HTTP Response Header with a 302 Found HTTP Status.
Nginx would then have the decoded URL stored in the $upstream_http_location variable. It could subsequently be used in another proxy_pass et al within a named location #named, to which you could redirect the processing of the original request from the user through error_page 302 = #named.
In all, each user request would be processed twice within nginx, but it'll all be transparent to the user -- they simply receive the resource through the original URL, with all redirects being done internally within nginx.
Define Anonymize for a URL? You can use any of the same methods as URL shortners such as http://bitly.com. But that is not truely anonymous since there is a definite mapping between the shortened URL and the target public url. If you make this per user based there is still a mapping but it is user based.
Looks like what you are suggesting is a variation on the above scheme where instead of sending the user to the target URL via a redirect you want the your server to actually fetch the content and return to the user. You need to be aware of the linked content in the public URL such as style sheets and images and adjust them accordingly. Many of the standard proxies has this kind of functionality built in. Also take a look at
https://github.com/jenssegers/php-proxy
http://search.cpan.org/~book/HTTP-Proxy-0.304/lib/HTTP/Proxy.pm.
If you are planning to build your own these can serve as a base.
I think what you want to do here is somewhat similar to another question I've answered in the past, where for each request by the client, you effectively want to make two requests to two different upstreams under the hood (first one to an upstream capable of decoding the URL, second one to actually fetch said decoded URL), but, of course, only return one result.
https://serverfault.com/questions/202011/nginx-and-2-upstreams/485044#485044
As mentioned on serverfault, you could use error_page to process another request, after the first one is complete. You could then use $upstream_http_ to make the subsequent request based on the original one, for example, using $upstream_http_location.
You might also want to look into X-Accel-Redirect header, introduced in this context at proxy_ignore_headers.
I have an iframe and a textbox(to enter required url) in my main page, so when user enters required URL I load requested page to iframe.
I am using HttpServlet to handle get requests through doGet. I need to distinguish the requested content type, because if it is a file(img or script) I just read it and return, but if it is an html page, I make some modifications.
I tried to use request.getContentType() inside doGet but it returns null. So is there any way to do this? Thank You
HttpServletRequest#getContentType() returns the value of the Content-Type header if there is one.
You need to specify it when sending the request. You can use Javascript to do this.
Alternatively, but not ideally, you could use a query string parameter to hint at content type.
That's for getting the content type of the request body.
If you want to specify what content the response should have, you need to specify the Accept header with an appropriate media type.
You can alternatively, do URL extension matching. For example, www.host.com/some/path.xml would return XML.
The request.getContentType() method will only return a value if your request body contains data. Since it's a GET it does not contain any body. If you have any data it's either part of the URL or in a query-string attached to the URL. It's pointless to declare Content-type in GET requests, so there is no header to read.
You have to look for the data that you need in your request URL.
If it's a URL generated by a link or image, then get the name and extension from the URL.
It it's generated by a script, it might have that information elsewhere, such as in some variable in the query string (?file-name=xyz&file-type=png for example) or in extra path information (/servlet/xyz/jpeg for example). It depends on how your client is requesting the data.
Do you want to know content type of request, mabye you don't know what for you requests check your URL. If your request contain no data you can request.getContentType should return null value. You can do it on response not request. Mabye you can pass parameter do define what response do you want. I suppouse you have to check response type to determine behaviour of your application depends on the response type not request. Simple GET request only wait for response. And based on that response do some actions.
Sorry if this is a duplicate question but google isn't smart enough to understand me or I'm too dumb to express my question simple enough for it to understand.
I don't know if this is my problem but I'm 90% sure this is it.
I'd like to know how to represent a Unix path within a GET request so that my web service doesn't return a 404. I think it's because one of my JSON fields in the query is a Unix path and because of the slashes, the webservice thinks it's part of the URL and not a part of my query.
For example, I'm using a RESTClient that's an add-on to Mozilla to test my web service. For the POST request, I enter as the url
http://mytestserver:8080/mydir/
and in the body, I put in my JSON object
{"filename":"obit.jpg", "Path":"test/2/1"}
This method works fine. I get a status code 200 and a return JSON object with the expected output.
When I use the same string for a GET request, I get a status code 404 and no return JSON object. I put as the url in the RESTClient
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test/2/1"}
and I get a status code 404 and the response body just says 404 - Not found
To further test my theory, I entered the following url in a GET request, removing the /2/1 from the path, which works.
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test"}
I've tried encapsulating the whole JSON string in quotes but that didn't work either so I've run out of things to try.
Thanks in advance for any help you can give me. If I need to show some code, please let me know, although, I don't think it's a code problem, I think it's a representation problem. Thanks.
Found out that JSON objects are usually sent via POST, not GET. Since I appended it to the URL via GET, it gave me problems. Per How to send a GET request with a "/" in the query