Two simultaneous requests cause 401 (cookie JSESSIONID?) - java

When I send requests at the same time I receive 401. What could be wrong?
Request URL: http://localhost:5000/api/***
Request Method: PUT
Status Code: 401
Date: Mon, 01 Nov 2021 23:20:08 GMT
Cookie: JSESSIONID=D0A23516553FAA68121D9013A986D62C
Request URL: http://localhost:5000/api/***
Request Method: PUT
Status Code: 401
Date: Mon, 01 Nov 2021 23:20:08 GMT
Cookie: JSESSIONID=D0A23516553FAA68121D9013A986D62C

Related

Stackify Prefix sfclient ERR_CONNECTION_REFUSED

Two part question that may or may not be related to each other.
I am running Stackify Prefix v3.0.28 for a Java application on Win10 and it generally seems to work OK: I can see the traces of various actions in our application.
Part 1:
When navigating to any page of our application I get two failed requests to load JS files:
http://127.0.0.1:2/scripts/sfclient.xhr.min.js
http://127.0.0.1:2/scripts/sfclient.perf.prefix.min.js
Both of these requests fail with ERR_CONNECTION_REFUSED. Those script references are not in my JSP page so I assume they are injected by Prefix.
Here is the raw HTML that tries to load the 2 scripts:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><script src="http://127.0.0.1:2/scripts/sfclient.xhr.min.js"></script>
<script>var SPerfLib = window.SPerfLib || {}; SPerfLib.RequestId = '54fd58d1-7f7e-d3a4-0001-331676a83598'; if(!SPerfLib.isAttached) { document.addEventListener('DOMContentLoaded', function() { var l = document.createElement('script'); l.src = 'http://127.0.0.1:2/scripts/sfclient.perf.prefix.min.js'; document.body.appendChild(l);}); SPerfLib.isAttached = true;}</script>
I have tried looking for configuration options, but found none. I was not sure if the scripts should be server from port 2 or not. The Prefix trace output is from port 2012 and that seems correct.
I tried uninstalling and re-installing Prefix, but with the same results. There does not seem to be any later version of Prefix to try.
How do I get those scripts to load successfully?
Part 2:
On one particular page we have an XHR to retrieve some JSON data. The server is returning data correctly, but it is somehow deleted before it arrives at the browser. The response headers show status 200 but 0 bytes content-length, which then causes some of our JS on the page to fail. If I run the same thing w/o Prefix everything works as expected - status is still 200, but content-length is 37 and JSON payload is visible.
This is the response header for the XHR when Prefix is in play (note content-length: 0)
cache-control: no-cache, must-revalidate
content-language: en-US
content-length: 0
content-type: text/html
date: Mon, 31 Aug 2020 14:19:24 GMT
expires: Thu, 01 Jan 1970 00:00:00 GMT
last-modified: Mon, 31 Aug 2020 14:19:24 GMT
pragma: no-cache
server: WildFly/10
status: 200
x-powered-by: Undertow/1
x-powered-by: JSP/2.3
x-stackifyid: V1|8bbdce1c-a507-bbdc-0001-3378bff33740|
If I remove the Stackify agent from the JVM options and disable the profiler, then the response header looks like this:
cache-control: no-cache, must-revalidate
content-language: en-US
content-length: 37
content-type: text/html;charset=UTF-8
date: Mon, 31 Aug 2020 14:25:12 GMT
expires: Thu, 01 Jan 1970 00:00:00 GMT
last-modified: Mon, 31 Aug 2020 14:25:12 GMT
pragma: no-cache
server: WildFly/10
status: 200
x-powered-by: Undertow/1
I'm appreciative of any suggestions!
These issues you are having with Prefix are known issues with Prefix. We are working on a complete re-write of Prefix (a reason why there has been such a big delay since our last release) and these items are things we are getting fixed in the new Prefix version. We are getting very close to releasing a Beta for Prefix, if you would like to be on the list to give the Prefix beta a try email the Stackify Support Team support#stackify.com

Failed to pass the challenge for domain

Using certbot fails to generate certificate with this error:
org.shredzone.acme4j.exception.AcmeException: Failed to pass the challenge for domain www.
mysampledomain123.com, ... Giving up.
I manually checked the challenge file and got
http://www.mysampledomain123.com/.well-known/acme-challenge/jU--PkDrn5tDZw2RN6NNJHbPD00ovHFkLFvN3mJdeQX
Inside the file:
jU--PkDrn5tDZw2RN6NNJHbPD00ovHFkLFvN3mJdeQX.tuMr-UijwpsJ1KVZkdWTYgodWZ2SxxKdB7_CMAAEfpg
And here's the complete HTTP response header:
Accept-Ranges: bytes
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/plain;charset=iso-8859-1
Date: Sun, 16 Feb 2020 14:15:22 GMT
Server: nginx/1.14.0 (Ubuntu)
Transfer-Encoding: chunked
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
X-Powered-By: MyServer
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 0
I'm wondering whether the problem is with the HTTP response headers or the content itself.
Any ideas would be appreciated.

When HTTP redirect occurs, apache HttpClient returns header from first response and not the last response

This is my java program
private static final String SAMPLE_URL = "https://www.dropbox.com/s/<something>/test_out4.mp4";
public static void main(String[] args) throws IOException, URISyntaxException {
HttpClient client = HttpClientBuilder.create().build();
HttpHead request = new HttpHead(new URI(SAMPLE_URL));
HttpResponse response = client.execute(request);
System.out.println(response.getStatusLine());
for (Header header : response.getAllHeaders()) {
System.out.println(header.getName() + ": " + header.getValue());
}
}
See a snippet of the output of the java program. The status line says it is HTTP/1.1 200 OK. However the header fields that are printed doesn't match what i get when i run curl manually. It seems to take the header values from the first response and not from the last response. Even more important Content Length field which is present in the last response is not set the response structure.
HTTP/1.1 200 OK <<< Status is 200
Server: nginx
Date: Thu, 20 Jun 2019 02:22:58 GMT
Content-Type: text/html; charset=utf-8 << Content type is char
When i run curl the output is correct. Is there any setting in HttpClient to return the most recent headers?
curl -I https://www.dropbox.com/s/<something>/test_out4.mp4
HTTP/1.1 301 Moved Permanently <<< Status 301
Server: nginx
Date: Thu, 20 Jun 2019 02:20:50 GMT
Content-Type: text/html; charset=utf-8 <<< Content type text
Connection: keep-alive
....
HTTP/1.1 302 Found << second redirect
Server: nginx
Date: Thu, 20 Jun 2019 02:36:03 GMT
Content-Type: text/html; charset=utf-8
....
HTTP/1.1 200 OK <<< Status finally 200
Server: nginx
Date: Thu, 20 Jun 2019 02:36:04 GMT
Content-Type: video/mp4 << content type correct
Content-Length: 92894175 << length correct
Connection: keep-alive

SOAP UI displays faultstring even after error 500 is received. need to view the same in JAVA

Here's the story:
Sending a request from SOAPUI (5.2.1) gives me either correct response or, in case of invalid parameters, the error in form of xml.
Looking at SoapUI log this is what i see:
Wed Jan 18 16:32:39 EST 2017:DEBUG:Attempt 1 to execute request
Wed Jan 18 16:32:39 EST 2017:DEBUG:Sending request: POST/XBC/services/TranslateGeometryService HTTP/1.1
Wed Jan 18 16:32:48 EST 2017:DEBUG:Receiving response: HTTP/1.1 401 Unauthorized
Wed Jan 18 16:32:48 EST 2017:DEBUG:Connection can be kept alive for 10000 MILLISECONDS
Wed Jan 18 16:32:48 EST 2017:DEBUG:Target requested authentication
Wed Jan 18 16:32:48 EST 2017:DEBUG:Authorization challenge processed
Wed Jan 18 16:32:48 EST 2017:DEBUG:Authentication scope: BASIC 'Spring Security Application'#mywebservice:80
Wed Jan 18 16:32:48 EST 2017:INFO:mywebservice:80 requires authentication with the realm 'Spring Security Application'
Wed Jan 18 16:32:48 EST 2017:DEBUG:Found credentials
Wed Jan 18 16:32:48 EST 2017:DEBUG:Attempt 2 to execute request
Wed Jan 18 16:32:48 EST 2017:DEBUG:Sending request: POST/XBC/services/TranslateGeometryService HTTP/1.1
Wed Jan 18 16:33:14 EST 2017:DEBUG:Receiving response: HTTP/1.1 500 Internal Server Error
Wed Jan 18 16:33:14 EST 2017:DEBUG:Connection shut down
Wed Jan 18 16:33:14 EST 2017:INFO:Got response for [TranslateGeometrySoap11.getLocationFromTramPoleTrackOffset:Request 1] in 35794ms (312 bytes)
(Note that those 312 bytes come after error 500 and connection shut down messages)
Response window, at the same time, in SOAPUI shows this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">Error: No Track exists with Track Code: CHS-CSK-UP-TW</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
This is perfect and works as i expect it to work.
Now for my problem that is seriously driving me mad.
When i attempt to send exactly the same request from my java code that is supposed to return the error above, i receive IOException that says:
Server returned HTTP response code: 500 for URL: http://mywebservice/XBC/services/TranslateGeometryService
So, pretty much same as what SOAPUI shows in its log.
But...
No matter what i do in my code i cannot get that message in faultstring that SOAPUI displays: "No Track exists with Track Code: CHS-CSK-UP-TW".
How is SOAPUI doing it after it receives error 500? Or, more importantly - how do i get it in JAVA after receiving error 500?
Tried playing with SoapFaultException class and SoapFault, but i could not find anything more anywhere.
Thanks to anyone who tries to answer this question.
Cheers,
Pierre
The next code in Java handler uses SOAPMessageContext TO detect SOAP fault and extract fault string from SOAPBody:
public bool handleFault(SOAPMessageContext context)
{
try {
if (context.getMessage().getSOAPBody().hasFault()) {
SOAPFault fa = context.getMessage().getSOAPBody().getFault();
System.err.println(fa.getFaultCode());
System.err.println(fa.getFaultString());
}
return true;
} catch (SOAPException ex) {
System.err.println("Fault parsing Exception:" + ex.getMessage());
return true;
}
return false;
}

Last-modified header doesn't work after second refresh

I want to load photourl from buffer if no change, but it works only after first refresh of page. When I open page for first time this is my response
Cache-Control no-cache
Content-Length 12279
Content-Type text/plain
Date Thu, 18 Aug 2016 10:26:45 GMT
Expires Mon, 01 Jan 1990 00:00:00 GMT
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Server Development/1.0
after refresh i have 304 status and response:
Cache-Control no-cache, no-store, max-age=0, must-revalidate
Date Thu, 18 Aug 2016 10:29:21 GMT
Expires 0
Last-Modified Thu, 18 Aug 2016 09:56:55 GMT
Pragma no-cache
Server Development/1.0
X-Frame-Options DENY
X-XSS-Protection 1; mode=block
x-content-type-options nosniff
and in request
If-Modified-Since Thu, 18 Aug 2016 09:56:55 GMT
after another refresh i have 200 status like on first visit and data are reloaded from server.
This is my controller.
#ResponseBody
#RequestMapping(value = "/photo", produces = "text/plain", method = RequestMethod.GET)
public String myPhoto(HttpServletResponse response, WebRequest request) {
Photo photo = photoService.getPhoto();
long lastModified = photo.getModificationDate().getTime();
if (request.checkNotModified(lastModified)) {
return null;
}
return photo.photoURL();
}

Categories