Rest-assured is making an extra call - rest

I am testing REST API using rest-assured. When I send POST request it looks like rest-assured is making extra call. Here is the output from /var/log/httpd/access_log:
11.31.41.111 - - [26/Nov/2019:19:39:14 +0000] "POST /rest/v1/contact HTTP/1.1" 401 340 "-" "Apache-HttpClient/4.5.3 (Java/1.8.0_221)"
11.31.41.111 - - [26/Nov/2019:19:39:14 +0000] "POST /rest/v1/contact HTTP/1.1" 200 515 "-" "Apache-HttpClient/4.5.3 (Java/1.8.0_221)"
When I send exactly same request using Postman, access log shows only one request comes to the server:
11.31.41.111 - - [26/Nov/2019:19:40:44 +0000] "POST /rest/v1/contact/ HTTP/1.1" 200 529 "-" "PostmanRuntime/7.19.0"
Any idea why this is happening?

You should use Preemptive Authentication when building RestAssured request specification. Here's an example:
RestAssured.given().auth().preemptive().basic("username", "password")
.when().get("http://example.com")
.then().statusCode(200);

Related

increase the upload limit of HAProxy

When using HAProxy, I've been getting the error 413: Request Entity Too Large
This error occurs when I'm trying to upload some files which are too large, however I can not find any documentation on how to increase this limit.
How can you increase the maximum upload limit to a specified amount of MB's?
This is not a HAProxy error, as you can see here http://cbonte.github.io/haproxy-dconv/configuration-1.7#1.3.1, 413 Error is not in the list.
So this probably an error returned from the server and HAProxy is just "forwarding" the error to the client.
To be 100% sure, you can see the logs:
An error returned by HAProxy:
127.0.0.1:35494 fe_main be_app/websrv1 0/0/-1/-1/3002 503 212 - - SC-- 0/0/0/0/3 0/0 "GET /test HTTP/1.1"
An error returned by the backend server:
127.0.0.1:39055 fe_main be_app/websrv2 0/0/0/0/0 404 324 - - --NI 1/1/0/1/0 0/0 "GET /test HTTP/1.1"
Notice the "-1" in the timers.

Web App Returns Same Content Regardless of Request

Using Eclipse's internal representation of Tomcat8 (do not know if that is relevant), the following is a series of page requests. This comes from the file:
C:\Users\BS\Eclipse\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\logs\localhost_access_log.2016-04-25.txt:
"GET /ProjK/ HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Css/v02/openElement.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/Templates/BaseLayer.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/index.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Client/jQuery/migrate.js?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Client/Common/oe.min.js?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/Template/Top.png HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/Template/Logo.png HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/BioTransparent.png HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Image/WEImage/PuceImg-3f204a74.png HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Image/empty.png HTTP/1.1" 200 16354
Observe that each response is the same byte count. The browser receives the content of the same file regardless of the request.
The content is from "index.html" that has been renamed to "index.ftl" and renamed back to "index.html". I have been making simple edits to this file hoping to see any change in what the browser shows.
I see that the file "index.html" has been updated with the new content in both the workspace and the /tmp0/webapps/ folder.
Yet, there are no changes in what is delivered to the browser.
A number of conversations suggests that Tomcat caching be dealt with. I would have to wonder why, during app development, this is an actual consideration.
But caching does not explain why every page and page resource request is served the same unchanging content.
What common mistake would a new java web app developer be making with respect to the setup/configuration of Tomcat and/or Eclipse and or the webapp that would explain this behavior?

CURL vs Apache-HttpClient : variance in size of data received

I'm using 2 agents to consume a REST webservice : Apache HttpClient and CURL.
Both the clients receive different size of data for the same REST webservice. Moreover the CURL is receiving inconsistent amount of bytes all the time while the Apache HttpClient is consistent.
Below is the access log snippet with number to bytes received.
"POST <<url>> HTTP/1.1" 200 10083053 "-" "Apache-HttpClient/4.3.1 (java 1.5)"
"POST <<url>> HTTP/1.1" 200 10083053 "-" "Apache-HttpClient/4.3.1 (java 1.5)"
"POST <<url>> HTTP/1.1" 200 10083053 "-" "Apache-HttpClient/4.3.1 (java 1.5)"
"POST <<url>> HTTP/1.1" 200 10128377 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu)
"POST <<url>> HTTP/1.1" 200 10128674 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu)
"POST <<url>> HTTP/1.1" 200 8192 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu)
What could be the problem with CURL receiving inconsistent amount of bytes?

Facebook using a TON of BW on our site with facebookexternalhit

Over the last several weeks we have seen a HUGE increase in BW usage but not in page views. I finally researched the access_logs and found a TON of lines like this in there:
173.252.103.0 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-04/H_h90_110.jpg HTTP/1.1" 403 344 "-" "facebookexternalhit/1.1 (+h
ttp://www.facebook.com/externalhit_uatext.php)"
173.252.103.2 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-04/NT_audyssey_wireless_mediaa.jpg HTTP/1.1" 403 362 "-" "facebooke
xternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"
173.252.103.3 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-05/TR_board.jpg HTTP/1.1" 403 343 "-" "facebookexternalhit/1.1 (+ht
tp://www.facebook.com/externalhit_uatext.php)"
173.252.103.6 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-03/LG%20Optimus%20G.jpg HTTP/1.1" 403 347 "-" "facebookexternalhit/
1.1 (+http://www.facebook.com/externalhit_uatext.php)"
173.252.103.4 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/review/2013-03-04/5-lit.jpg HTTP/1.1" 403 342 "-" "facebookexternalhit/1.1 (+htt
p://www.facebook.com/externalhit_uatext.php)"
173.252.103.2 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/review/2013-03-02/IMG_9546.JPG HTTP/1.1" 403 345 "-" "facebookexternalhit/1.1 (+
http://www.facebook.com/externalhit_uatext.php)"
173.252.103.1 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-05/deal0305.png HTTP/1.1" 403 343 "-" "facebookexternalhit/1.1 (+ht
tp://www.facebook.com/externalhit_uatext.php)"
173.252.103.4 - - [09/Mar/2013:17:48:19 -0500] "GET /files/imagecache/article_max_width/news/2013-03-05/H_Geforce.jpg HTTP/1.1" 403 344 "-" "facebookexternalhit/1.1 (+h
ttp://www.facebook.com/externalhit_uatext.php)"
There is literally PAGES of them over days and days. I can't figure out what is going on here and I really don't want to use Apache to block the "facebookexternalhit" robot.
Any ideas?
I had same problems on my server. I solved it, by removing the og:url metatag and by changing the og:image metatag as I mentioned here: https://stackoverflow.com/a/24107181/3248313

already initialized constant, and required twice

Hi, all,
i think this is a bug about the constant defined in sinatra, let's look my code.
route.rb
require 'sinatra'
get '/' do
C = "this is a test for constant"
"Hello World!"
end
Gemfile
source 'http://rubygems.org'
gem 'rack'
gem 'sinatra'
config.ru
require './route'
run Sinatra::Application
Starting the web server, we will see the below
$ rackup
[2011-10-08 19:54:36] INFO WEBrick 1.3.1
[2011-10-08 19:54:36] INFO ruby 1.9.2 (2011-07-09) [i686-linux]
[2011-10-08 19:54:36] INFO WEBrick::HTTPServer#start: pid=3268 port=9292
127.0.0.1 - - [08/Oct/2011 19:54:42] "GET / HTTP/1.1" 200 25 0.0059
127.0.0.1 - - [08/Oct/2011 19:54:42] "GET / HTTP/1.1" 200 25 0.0142
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:43] "GET / HTTP/1.1" 200 25 0.0094
127.0.0.1 - - [08/Oct/2011 19:54:43] "GET / HTTP/1.1" 200 25 0.0098
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:55] "GET / HTTP/1.1" 200 25 0.0003
127.0.0.1 - - [08/Oct/2011 19:54:55] "GET / HTTP/1.1" 200 25 0.0006
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:56] "GET / HTTP/1.1" 200 25 0.0003
127.0.0.1 - - [08/Oct/2011 19:54:56] "GET / HTTP/1.1" 200 25 0.0005
Eidt
Fixing the file route.rb
require 'sinatra'
configure do
C = "this is a test for constant"
end
get '/' do
"Hello World!"
end
Now, the server no longer warning the constant be initialized.
But the log of server still appears double 'GET' require ,
i just want it requires for one to every client required, that is my question, How to solve it.
Thanks in advance.
What's wrong about that? If you define the constant twice (which happens if you have two GET requests or a GET and a HEAD request) then that warning will be displayed. You global variables instead. But if you don't have to, try to avoid global state at all cost, otherwise you might run in architectural issues (what if you want to serve more endpoints and globals clash) and make it hard to scale: if you rely on the internal state of a process, will you be able to serve the website from two processes? what about two machines?