Jmeter calling rest url with query param - java

I'm trying to do a rest call which has the query params like:
https://www.tutorialspoint.com/?hasName=true
I have to set hasName=true in Jmeter. I'm getting a 500 and I do have JSON data that I want to post at the same time. If I set the parameters using the parameter tab then I can't update JSON data in the body data. How can I do both things at same time? I tried adding user defined variables and it did not work.

You can set in HTTP Request the JSON in Body Data tab and put full URL in Path field
https://www.tutorialspoint.com/?hasName=true
As a special case, if the path starts with "http://" or "https://" then this is used as the full URL.

Do a successful request in the browser or any other tool and compare the request you're sending through jmeter. Check everything including request urls, cookies, headers etc. If you think its all exactly the same. Reach out to the server admins/app devs to check the web server/application logs to find out what is wrong either in server or your request.
The 500 Internal Server Error is a very general HTTP status code that
means something has gone wrong on the website's server, but the server
could not be more specific on what the exact problem is.

Related

Imitating a "browserLike" POST request

I'm trying to get search results from this site, using Java's org.apache.http.impl.client.CloseableHttpClient. I'm able to login without any problems, but when I POST the search request, the response I get is the same page refreshed without the search results. So I checked what and where exactly Chrome sends via it's POST request and configured my request the same way. Well now the response I get is one of those capture images with text that one must type to proceed(that dose not happen when searching via Chrome).
Is there any way the server recognizes that the request was not POST'ed by a browser?

How should my URL encoding look if I enter it manually?

I want to "fill in" a form on a website from java. I used charles proxy to determine that pressing the "Register" button on this form sends a URL encoded Http post request.
For example, if the website were:
https://apps.business.com/register
Then the http post was sent to:
https://apps.business.com/registersend
I then used the Advanced Rest Client plug-in for chrome to send a sample registration request successfully.
However, I now want to manually send this request from Java. I thought that as it was URL encoding, it would be a simple case of appending a URL encoded string to the rest of the URL. Something like:
https://apps.business.com/registersend/?email=me%40hotmail.com
etc., but I can't seem to get this to work and assume I'm missing something.
Thanks for the help.
To send HTTP POST you will need something like the HTTP Client API.
http://hc.apache.org/httpclient-3.x/

Redirecting html page

Here is my problem :
I have to perform post from java code to some page , get the data and parse it.
The problem is that only my country ip can post to this page. Requests from another ip's are rejected.
I want to find workaround.
I have added my html page on server in my country (this server accessible from all ips) . Now I am sending a get request (in open to all server) to this page from Java code.
What I want to do is to redirect my html page to post to the original page.
I tried to use redirection , but it doesn't work - from Java code I get my html page and not redirected one.
Is there any solution or my problem ?
Thanks
I tried to use redirection , but it doesn't work - from Java code I
get my html page and not redirected one.
Yes it wont work because redirection works on client side. You perform a request to your HTML page which sends back a redirect header and your Java implementation doesnt know what to do with it. Even if it did, it had to make a new request to redirected page, which means that the request to the redirected page would still be from a denied IP.
Another option is that your redirection HTML uses JavaScript window.location.assign or something like that. The point remains the same, beacause this also is a client side solution.
You have to use some kind of server side language on the host where you placed your HTML and in that server side script you have to perform a (post or get as you wish) request to only-your-country URL. This way this only-your-country URL will see that the request came from the host where the script was, not the client itself.
For example if you can use java as your server side language on the place where currently your redirection html is, then you can check out this thread: How to send simple http post request with post parameters in java
You need a reverse proxy installed on a server located in your country. If you make a request to this reverse proxy, it will make a request to the only-your-country server and when it gets a response it will forward it to you.
So the only-your-country server will receive the same request as you make to the reverse proxy, but with a source IP address changed to the IP of the reverse proxy server.

How to change Target URL

I have developed an application which contacts a Sun One web server. The Web Server has Lotus domino and SiteMinder Plugin.
Below is the URL for the application
http://HostName.example.com
After hitting the URL in the browser, the URL is redirect to webserver and a login page appears with below URL.
http://HostName.example.com:9898/SiteMinderagent/forms/login.fcc?TYPE=
33554433&REALMOID=06-1716e557-15f3-100f-b9a4-835cc8200cb3&GUID=&SMAUTHREASON=
0&METHOD=GET&SMAGENTNAME=$SM$sHjbzl4f9R%2bcSa0%2fEgnu6oUQQPMQnUgkU6Zvx5zWZpQ%
3d&TARGET=$SM$http%3a%2f%2fshivalik%2ered%2eiplanet%2ecom%3a9898%2fvalidation%
2findex%2ehtml
After logging into the application, the request is redirect using the TARGET parameter( URL is decoded in the application) from the URL Now the login doesnot work if i block the HTTP requests. As the TARGET parameter is a HTTP request, I am unable to login into the application.
Is there any way I can change the TARGET parameter to HTTPS. Can i know in which file I can change it in the WebServer. The Sun One Web Server runs Solaris OS. I have tried hard finding the solution as I think the URL is appended with Query strings like SMAGENTNAME, SMAUTHREASON, TARGET in the Servlet of the Domino.
The TARGET parameter is populated with the URL originally presented by the user - i.e. in your example http://HostName.example.com will result in the TARGET query string parameter containing the same URL plus the other parameters generated by the SiteMinder agent.
Possible solutions in your case could be to hardcode the TARGET by putting something like the following on the top of login.fcc:
#TARGET=https://hostname.example.com/
That would cause the FCC to ignore the query string parameter that is POSTed and instead will hardcode it.
Alternatively if you need to preserve the path component of the URL (e.g. http://hostname.example.com/path/to/file.html) you could add some javascript to the FCC page. The standard implementation populates TARGET into an element so you could use JavaScript to parse the value and replace http:// with https:// if required. Make sure that your Agent Configuration has single and double quotes in BadFormChars (BadFormChars=%22,%27) to prevent XSS attacks.
There is also an Agent Config parameter HttpsPort that you can use to "trick" SiteMinder into thinking you're serving HTTPS traffic out of port 80 but you will have to test for any unintended side effects.

Java servlet - Forwarding/Redirecting from subpage

I am working on a project where I have running servlets packaged in a war that listen for requests and populate a foreign div on a separate page. An initial request is made to servlet (a) and if there is data to display, it renders that HTML. If there is NO data, it passes a query string to another servlet to handle the request and then renders a page with options to choose.
I am running Tomcat 6 with Windows Server 2008.
But I run into two problems:
When I use redirect, I get no response from the servlet being
redirected to. I have some javascript alerts up that are never called by the (b)
servlet. I AM using relative paths and confirm the link is
correct in logs.
When I copy that link in step 1 in a new window, I see
the results. Just not when it's embedded in another page that makes
the request. Why would that be? Is it possibly a limitation from the host page and not being able to render the response?
When I use a forward, I see the servlet response,
but then a new window opens. Thus taking the person away from the
original page. This would be great if the results render in the same page.
What's the best practice to assure that I can "redirect" from an initial servlet call to another servlet using the response object from that first servlet?
A redirect returns a HTTP 302 response with the new URL in Location header which the client needs to deal with. Basically, your JS code must check the response status code if it's 302 and then extract the Location header and then re-send a new request on it. Repeat this until the response status code is 200.
That it works when pasting the URL in browser's address bar is because the browser already knows how to deal with 3nn responses properly. If you open up the network traffic tracker in browser's webdeveloper toolset, then you'll see that a second GET request is been fired on the new URL.
Another way, if the servlets run in the same container, is to just use RequestDispatcher#forward() instead of HttpServletResponse#sendRedirect().

Categories