• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Google chrome, glassfish local server and servlet being called twice

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everyone,

I have been studying for JPA and struggled with a bug which made me very confused and later I have found out that it was Chrome caused the program run incorrectly.

I recently switched from Firefox to Chrome. And when I use glassfish admin console in Chrome, whenever after I deployed the app and try to open http://<mymachinename>:8080/myapp/runservlet, I found out the servlet (I don't include code here as it is not specific but generally every servlet dealing with JPA and javadb) will be called TWICE.

Normally if behave correctly, after persisted a entity and auto generate ID, I should get one entity in the database. However, I always get another duplicate in the database. For example, I have a employee named John Smith and I should have a row in Employee table with auto-gen'ed ID 1 and John Smith, but instead somehow, I got ID 1/John Smith and ID 2/John Smith.

At first I thought it was a bug in my code and I tried for a long time to find out but no success. Then I tried same code in IE, the same code behaves correctly no matter how many times I try!

And I tried to run different code and I found it is a general problem not the specific program which I found the problem first with.

Then I found out more:
If I open the app in Chrome at the following address the problem will be gone:
-https://<mymachinename>:8181/myapp/runservlet
-http://localhost:8080/myapp/runservlet
-https://localhost:8181/myapp/runservlet

Do anyone know why app running by Chrome is behaved this way and how to fix it?

Thanks in advance.

 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check in your server.xml if the port 8080 redirects to 8081. Looks like there is some ambiguity in resolution of the ports.
 
Paul.J Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

I checked Glassfish settings and couldn't find any port redirect configs. And should it be a Chrome specific problem rather then Glassfish since I can not reproduce the problem in IE or Firefox?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would need to sit down myself and check this Paul. I can't say from the other side of the globe. Yes, different browers do behave differently for different scripting languages. I am not sure though that the problem that you describe is related to the browser. It could be or there could be a different reason to it. These type of issues need a lot of hit and trial, careful observation and experience to home in on. For now , I suggest you continue with FireFox or IE.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google Chrome has "Developer Tools" which you can use to track the requests being sent to the server. It will also show you the HTTP response code and such. On the server side I think you can enable "access logs" - I don't know how it's done in GlassFish. Those access logs should ideally show you the requests to the server and the response codes. Either or both of these should probably give you an hint on what's going on. In fact, you could even compare the server side access logs with IE and Chrome and see if there's any difference.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Jai. There would certainly be a plugin or a built in tool to monitor requests made. That would be of great help. Just check this portal Paul. It just might help. Install this and monitor the requests like Jai suggested.
 
Paul.J Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

I will continue to try the suggested.

But there is a little progress: I found the request header from Chrome and IE are different by one line, in Chrome there is "Cache-Control: max-age=0" but not in IE. And if I config setting to disable cache in Chrome developer tools, everything works fine.

 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That explains it Paul. Cache-Control max-age setting instructs the client about whether it should re-validate every request again or pick it up from the cache as per the max age setting. Read this.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul.J Wong wrote:I found the request header from Chrome and IE are different by one line, in Chrome there is "Cache-Control: max-age=0" but not in IE. And if I config setting to disable cache in Chrome developer tools, everything works fine.


From your question, the servlet is hit twice per request. I don't understand how cache-control affects the first request. If Chrome is making one request to render the page and another to cache it, then that would be a bug.
 
Paul.J Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me post codes, they are fairly simple. Two entities, one stateless bean and one servlet. In Chrome only, from line 14 and 15 of the servlet everything works, but when hit line 17 to 20, there will be 8 PrintJobs records in the database so basically every line of 17 to 20 caused a printjob entities persisted twice.







 
Paul.J Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mansukhdeep Thind wrote:That explains it Paul. Cache-Control max-age setting instructs the client about whether it should re-validate every request again or pick it up from the cache as per the max age setting. Read this.



I have Chrome in all its default settings, and I disabled all extensions.

But I found that from line 14 and 15 of the servlet above everything works but 17 to 20 cause entities to persisted twice, those two portion of codes belong to same doGet method.

So strange.
 
reply
    Bookmark Topic Watch Topic
  • New Topic