ExtJS loading multiple stores from a single servlet - java

I have 2 comboboxes on a window that have their store loaded when the window is created. I have a single servlet that calls the same function for both comboboxes we are trying to load however I have found that this causes problems and the stores don't get loaded correctly. Any ideas?
EDIT: So the more appropriate question would be: How to handle multiple requests on the same servlet? Is that a multithreading issue? I'd really like to avoid having to deal with that since I'm not that experienced even though this one seems easy...

I still think there are problems if you call the same servlet from different XHR requests but the way to solve the loading problem is by calling the store.load functions in a cascading fashion inside each other's callback function:
store1.load({
callback: function() {
store2.load();
}
});
This way stuff doesn't get in the way of the ajax request. However I still don't know why this is happening, the server is supposed to take care of the multithreading of the servlets...

Related

Is it a good idea to call PUT from POST method

I have to automate certain operations of PUT/POST operation in my case, I have those endpoints already-in-place which will do their part.
My planning is to have another method which will drive this whole automation, consider this method as new POST endpoint which would gonna call each either POST and PUT endpoint from the same service which I already mentioned.
I will gonna call those existing PUT and POST based on input, if consider the input is new I will call existing POST and if given input exists in database I will going to call PUT.
Till I am good, But I have a question in my mind, Which is bugging me a lot that my new endpoint which is of POST is calling PUT as well as POST, I each method type has to do its type of operations only but here I am calling PUT as well as POST whereas my parent calling method type is POST.
I am not sure if I am working in right direction to achieve my use-case.
Please correct me in a different way.
Note - I am having Spring Boot application which would always need some endpoint to trigger any logic which I am talking about.
Update my question for better understanding.
I dont really know what you mean exactly. The HTTP methods are considered to do a specific task, but yet again its ok to use POST to update something - might be not best practice, but works. If you want to seperate the concerns (adding, updating), then just implement two different endpoints, one handling the creation the other one the update. The client (whether its a web-app or desktop app or whatever) has to handle this issue.

java ajax method getting confused when called by multiple sources

I have some a java portlet application which calls a restful service. I have struck a problem where it looks like I am coming across a threadsafe issue. I have a servlet specifically used for Ajax calls. This servlet is called from myultiple locations at the same time.
It looks like my application is getting confused because the Ajax servlet is receiving multiple requests from different locations at the same time. I didn't think that this would be a problem.
Can someone help me understand the issue and secondly suggest a way to fix/improve? I think I will struggle to put a code snippet here because it will be too large to demonstrate the issue.
But basically the pattern is that I fire some 2 ajax requests from javascript to a servlet at the same time with different parameters. The handling of the servlet request is different based ont he different parameters passed in. But they both call the same java static methods to handle creating json objects. And it's those static methods that look like they are getting confused.
When I'm printing debug messages in the static methods the static methods show the debug info from the first call and then the static methods start showing debug info from the second call before the first is finished.
thanks for the help and sorry for no code snippet (probably too long)
All you need is to check if there are methods that using same non-threadsafe resources (i.e. HashMap in the field, or something). If there are, add locks or get rid of these fields (make them local).

Java Filter and count of calls

I have written test Filter (javax.servlet.Filter) and started to debug. And I was surprised that one refresh of html page calls twice method doFilter().
Could anybody describe me why it happens ?
Thanks.
Perhaps your filter was called also for static elements (images, etc.). Check your filter path declaration in web.xml.
One way to check what's really happening is to use either Fiddler or Firebug. Or both.
Another strategy to use is printing value of request.getRequestURL().toString() before doFilter(), so you can see what requests are being served. It's difficult to pinpoint why are you seeing 2 requests because the cause might be hidden somewhere in your environment or configuration.
Fire up Fiddler and watch the requests being made.

Redirecting Icefaces page from an independent thread?

I'm performing a validation task that takes a while and am spinning the validation process into a separate thread. I've got the progress bar side of things working, with PortableRenderer and a ViewScope allowing it to update the progress bar component.
However, I'm trying to redirect the user once the page either finishes or a error in validation occurs, without the need of user interaction.
I'm using AND new to icefaces2.0(beta 1) and JSF 2.0, so the answer might be right in front of me. Sorry if this is a pretty simple question.
Have ajax to execute this job rather than spawning a thread yourself.
Update as per the comments: well, that was a bit curt. But spawning a thread yourself inside a servletcontainer is recipe for major trouble if you don't know what you're doing. The functional requirement makes now a bit more sense. Your best bet is using IceFaces' push or poll component which in turn causes JavaScript in the client side to do a window.location on the desired URL.
I eventually fell back to my own way of doing it.
I'm putting the JSF bean into a session attribute with a portable renderer injected as a property. The session attribute is used since Spring cannot get the "View" scope. If there is a way for Spring to do so, that saves a lot of potential pitfalls, but alas I do not know how.
Once the page loads, a jquery AJAX call is made to a Spring Controller, which gets the JSF bean out of the session, removing it in the process, and proceeds to "validate it". As it proceeds, it sticks the current completion status into a session attribute and calls the bean function that invokes the portable renderer, which in turn updates the progress meter.
Also part of the page load function, is a separate function that calls another Spring Controller, which returns the completed status object, which may/may not have error messages.
I plan to remove the second controller by just checking values already on the page that get rendered by the portable renderer and publishing all those errors into the bean, which can then be rendered easily and dependably.
This way, as BalusC said, removes the creation of threads not directly spawned by the container and allows me to redirect automatically via window.location on successful completion.
If there is a better way to do this, which I imagine there is, please do add an answer. My knowledge with Icefaces and JSF is severely lacking currently and I'd thank anyone with the best way to do this.

Get status of servlet request before the response is returned

Good evening,
I am in the process of writing a Java Servlet (Struts 2, Tomcat, JSP etc) which is capable of doing some fairly complex simulations. These can take up to 2 minutes to complete on the and will return a graph of the results. It is trivial to calculate the percentage of the simulation completed because the process works by repeating the same calculations 1000s of times.
I would be interested to know if anyone has ever tried to use client side technology to provide any estimate of the percentage complete. I.e query the servlet processing to get the number of cycles completed at various point throughout the simulation. This could then be displayed as a bar in the client browser.
Any thoughts, advice, resources would be much appreciated.
Thanks,
Alex
In your database, have a table to maintain a list of simulations along with their server-calculated progress.
In your web-application, use AJAX to query the server every few seconds (1-20 depending on load is what I'd go with) and update a graphical progress bar. Most javascript libraries have simple timer-based AJAX functions to do exactly this sort of thing.
There's a few details to figure out, such as whether or not completed simulations remain in the DB (could be useful logging info), but overall, this should be fairly simple.
You could encapsulate your response in a mime/multipart message and sends your updates until you have a full response done.
Bugzilla uses this in their search to show "Searching ..."-screen until the searchresult is done.
If you want to use plain Struts2, you should take a look at the ExecuteAndWait Interceptor.
It works by the old refresh-with-timeout method. Sure, it has lower coolness factor than some AJAX thing, but it's simple and works (I've used it).
Struts2 takes care (by using this interceptor) of executing the action method (which would typically take a long time) in a separate thread, and it returns a special result wait until the work is completed. You just have to code a jsp that shows some "waiting..." message for this result, and make it refresh to the same action, repeatedly, with (say) two or three seconds of timeout. The jsp has access to the action properties, of course, hence you can code some getProgress() method to show a progress message or bar.
AJAX is the way to go here.

Categories