Last-modified header doesn't work after second refresh - java

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();
}

Related

Two simultaneous requests cause 401 (cookie JSESSIONID?)

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

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

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

When I post a http in wildfly, the response part of the body is replace by header

I have a strange problem in WildFly 12. When I post a HTTP request sometimes body is replaced by HTTP response header. Sometimes it doesn't.
the error json data:
HTTP/1.1 200 OK^M Expires: 0^M Cache-Control: no-cache, no-store, max-age=0, must-revalidate^M X-Powered-By: Undertow/1^M Server: WildFly/11^M X-XSS-Protection: 1; mode=block^M Pragma: no-cache^M X-Frame-Options: SAMEORIGIN^M Date: Thu, 08 Nov 2018 13:00:25 GMT^M Connection: keep-alive^M X-Content-Type-Options: nosniff^M Content-Type: text/plain;charset=UTF-8^M Content-Length: 1569^M ^M ationId":"61e1e1b0867c11e8a9a81fbc702bb402","value":"MU5123","startStationName":"上海虹桥国际机场","endAreaName":"北京首都国际机场"},{"shiftId":"6c874935c59e11e8a4f557d52226d05c","startAreaId":"61e1e1b0867c11e8a9a81fbc702bb402","endStationName":"北京首都国际机场","lineId":"336fb55d-cc7c-11e8-9ed0-00163e02896a","label":"MU5159","dispatchTime":"14:30","endAreaId":"61e1e193867c11e8a9a81fbc702bb402","endStationId":"61e1e193867c11e8a9a81fbc702bb402","startAreaName":"上海虹桥国际机场","startStationId":"61e1e1b0867c11e8a9a81fbc702bb402","value":"MU5159","startStationName":"上海虹桥国际机场","endAreaName":"北京首都国际机场"},{"shiftId":"6c874930c59e11e8a4f557d52226d05c","startAreaId":"61e1e1b0867c11e8a9a81fbc702bb402","endStationName":"北京首都国际机场","lineId":"9db7b2a5c5a911e89ed000163e02896a","label":"MU5331","dispatchTime":"15:00","endAreaId":"61e1e193867c11e8a9a81fbc702bb402","endStationId":"61e1e193867c11e8a9a81fbc702bb402","startAreaName":"上海虹桥国际机场","startStationId":"61e1e1b0867c11e8a9a81fbc702bb402","value":"MU5331","startStationName":"上海虹桥国际机场","endAreaName":"北京首都国际机场"}]
Could someone let me know the reason would be for this behavior?

Cannot implement login in GWT

So, I have followed the tutorial for implementing simple login page over here https://varuntayur.wordpress.com/2012/01/25/session-management-in-gwt/
I tried communicating on the page itself, the author has been very helpful, but up to certain point.
The code is pretty long, so I've uploaded it here:
http://1drv.ms/1GZQqFV
Please be so kind to check it out.
The error displayed is the following:
[WARN] 404 - POST /atlas_emergency_status_page/LoginService (127.0.0.1) 1405 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Content-Length: 200
X-GWT-Module-Base: http://127.0.0.1:8888/atlas_emergency_status_page/
X-GWT-Permutation: 512BC5E71D8D41DD923CAA7193842B68
Origin: http://127.0.0.1:8888
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Content-Type: text/x-gwt-rpc; charset=UTF-8
Accept: */*
Referer: http://127.0.0.1:8888/ATLAS_Emergency_Status_Page.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,fr-CH;q=0.6,fr;q=0.4,ka;q=0.2,ru;q=0.2
Response headers
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1405
EDIT
I heva found the error, in web.xml I mapped servlet as LoginServiceImpl, had to be LoginService.
But now, I have another problem, on clicking the login button, nothing happens and no error is displayed, which is even worse...
What could be the problem?
EDIT 2
I have added the logger to be able to better understand what's happening.
Here is the output of logger:
Wed Nov 04 17:11:44 GMT+100 2015 logger1 INFO: enbl = false
Wed Nov 04 17:11:44 GMT+100 2015 logger1 INFO: enbl = false
Wed Nov 04 17:11:44 GMT+100 2015 logger1 INFO: No sessionID
Wed Nov 04 17:11:46 GMT+100 2015 logger1 INFO: Called login
Wed Nov 04 17:11:46 GMT+100 2015 logger1 INFO: Configured login dialog box
Wed Nov 04 17:11:47 GMT+100 2015 logger1 INFO: username: password:
Wed Nov 04 17:11:47 GMT+100 2015 logger1 INFO: Success
Wed Nov 04 17:11:47 GMT+100 2015 com.google.gwt.logging.client.LogConfiguration SEVERE: (TypeError) __gwt$exception: <skipped>: Cannot read property 'allowNestedValues' of nullcom.google.gwt.core.client.JavaScriptException: (TypeError) __gwt$exception: <skipped>: Cannot read property 'allowNestedValues' of null
at Unknown.$get(atlas_emergency_status_page-0.js#18:2152)
at Unknown.$getLoggedIn(atlas_emergency_status_page-0.js#36:2227)
at Unknown.$onSuccess_0(atlas_emergency_status_page-0.js#88:1182)
at Unknown.onSuccess_0(atlas_emergency_status_page-0.js#3:1213)
at Unknown.onResponseReceived(atlas_emergency_status_page-0.js#34:15260)
at Unknown.$fireOnResponseReceived(atlas_emergency_status_page-0.js#14:7513)
at Unknown.onReadyStateChange(atlas_emergency_status_page-0.js#5:7718)
at Unknown.<anonymous>(atlas_emergency_status_page-0.js#13:18406)
at Unknown.apply_0(atlas_emergency_status_page-0.js#23:3688)
at Unknown.entry0(atlas_emergency_status_page-0.js#16:3755)
It seems to go into error after calling
public void onSuccess(UserDTO result) {
logger.log(Level.INFO, "Success");
and somewhere on this line I would say...
logger.log(Level.INFO, "username from UserDTO: " + result.getName());
if (result.getLoggedIn()) {
Again, sorry for newbie questions, but this is way over my level...

Categories