kourosh parsa

Ranch Hand
+ Follow
since Jan 22, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kourosh parsa

I figured it out and share it:

10 years ago
I think I need to mention that this is NOT for production environment so the data is not critical.
I want to do it automatically by spinning an ec2 instance, so if there must be no manual step.

- regarding suggestion 1, basically you're saying I put the properties in a file. I guess that means you have to copy over the file to the right location depending on what app server you're deploying on or alternatively place it in the app before packaging it.
- regarding using a datasource, can you elaborate please in details?

10 years ago
Hi.
What I want to achieve is to automatically make a war file and load database info (such as host, port, password,...) to my app.
I do not want to hardcode the info in java code; instead it better be in a config file.
I'm using maven (I'm new to this) for creating the war file so please guide me how this is commonly done.

My guess is there could be at least 4 possibilities:
- using jndi
- use environment variables which is problematic because if you have many apps, the variables might collide and also I need to set them before running my app server.
- passing parameters to maven like "mvn package -Ddb_host="10.4.4.2"
- use pom.xml.

I've also read about jndi but I do not know how it is supposed to know where the context.xml file...
thanks
10 years ago
Thanks for the reply. I myself was the one who set the tomcat 7 server and also on the production server, tomcat already was setup and it had been working just fine...
I do not exactly know what you mean by using a filter. Would you be able to elaborate with a pseudo code please?
10 years ago
Hi. I developed some servlet to get unicode parameters via post request.
It worked perfectly fine since I set the encoding as below:

Now that I have set up my dev environment on a new machine with new eclipse, it does not work.
It displays Ï instead of π.
I've already tried adding URIEncoding="UTF-8" to server.xml which did not help since it only affect get not post.
I figured out how to get the parameter with correct encoding on the new system:


but I cannot believe that this is the solution because then what's the point of having request.getParameter.
I already know that:

would not work.
If there is an expert who knows about this issue, please let me know what you think and whether there is a better solution than this.
Thanks
10 years ago
The best I could do is:


I do not like hard coding the port like so. If anyone knows a way to avoid it, please let me know.
10 years ago
Thanks. I'll give it a try.
10 years ago
Thanks.
My understanding is that you're suggesting that I have a startup servlet and in the xml file I specify it to be a startup:


How would it know whether to run the get or the post handler?
10 years ago
Hi. I have a data.json in my J2EE web app.
I need to load it either from local path when unit testing or from url when the server starts up.
so I've set it to get the local path by default and what I'm trying to do is that it is is running on a server, I'd like to change the path to a url.
Here is my code:

which works fine. The only issue is that I had to place this in the login page. Is there a way I can only set the path to the base url upon server start up?
Logically I should not even have to wait for a request so please let me know if you know a better way.
10 years ago
Well the whole code is large and it's illegal to share, but here is the gist of it.

I sent an object to a method called simplify.
The object had a property called toString() which was overridden. In my toString() method, I had a bug that under a rare scenario a negative sign was introduced and it should not have.

this is the pseudo code of that class


Now, the strange thing was that when using the debug mode, it automatically calls this method any time you pause at a break point or step; hence the.
The root cause is that the array of data in the object was actually modified in the toString() method.
I fixed it by tracking down the invalid operation in simplifySigns but a better thing to do is to avoid using the toString() method because it is used by the debugger.
In short, toString() for for any object better not modify the content of the object or else you'd face this sort of behaviour.
10 years ago
I figure it out.
There must have been a bug in my overridden toString() method that only triggers in the debug mode.
Tricky one
10 years ago
Hi folks.
I've made a java program that simplifies algebraic expressions via recursive calls.
I have about 30 complex equations as strings and they are simplified and they all pass, until I added a new expression to test and now I see this behaviour:
- when I run the junit test in debug mode, it succeeds; the simplified result is "v*r*(-1-r*g)/((r/R)*(R+r*g*R+r))"
- when I run the junit test in normal mode, it fails ; the simplified result is "-v*r*(-1-r*g)/((r/R)*(R+r*g*R+r))"
- so now somewhere in the code I place a

and re-run in the normal mode. Now it succeeds again.
What makes this weird:
- I'm not multi-threading or multi-processing
- I'm not using any events, timers or randomized components at all
- This is reproducible. If I remove the print statement, it fails again.
Any idea how to debug this?
I've developed java for 7 years and never seen such a thing!
10 years ago
I've mixed up the 2 topics.
Here is the improved question: how would I make a common invalid session handler for my servlets?
I guess a possibility if jsf; I hope there is a simpler solution to suggest.
10 years ago

Bear Bibeault wrote:Generally, exceptions in servlets should not be caught and just let propagate outward to the container where an error handler that you establish in the deployment descriptor can handle them in a consistent fashion.

Errors in script I usually handle differently, because they are simply so very different in nature, but you can always make script errors emit that same type of output as your server-side error handler for consistency.



Thanks. I think that you are referring to using the error codes like so:

I still would like to know how to indicate errors with specific error numbers. Also, for the case when the session is null, in all my servlets, I have to write if session is null then ...
That's the main thing that should be fixed.
Also, one concern is that what if the user made a change while not knowing that the session was expired, then he clicked save. You do not want to automatically redirect. Instead, you want to open a pop up dialog and ask them to login again; just like an email service.

Anyways, please continue to elaborate.
10 years ago