Guy Yafe

Greenhorn
+ Follow
since Sep 30, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Guy Yafe

I have a class named Attribute which basically has a uid, and type. (S, M, L for sizes, Square or Circle for shapes, etc.)
It is derived by a class named AttributeColor which also has an integer indicating the color.
Mapping them, I have a table called attributes and a table called attributes_colors. The inheritance is a 'Table Per Class' and annotated with @Inheritance(strategy = JOINED).
My question is if I have to use the @DiscriminatorColumn annotation? If so, this will of course require me to alter the tables themselves.
If I understand correctly, JOINED strategy doesn't require this annotation, but can make better performance.
So, when to use this annotation? How can it improve performance?

Guy
Hi,
I have a database which has an implicit @OneToMany association:
I have a table of items: Earrings, Shirts, Pants, etc..
Another table is called attribute_types and represents the type of attributes an item can get.

Example:
The attribute_types table contains the values 'colors' and 'sizes'.
The Earring item has the attribute_type field set to 'color' because an earring can come in several colors.
Pants and Shirt have both attribute_type 'sizes' because each can have many sizes.
Each item has only one attribute_type. This means for example that red shirt and blue shirt are different items and represented by different rows in the items table. Although, each can have several sizes.

The association between the attribute_types and items is One-To-Many: Each attribute_type has many items associated with it, and each item has exactly one attribute_type.

My question is how to annotate this relation?
On the Item object side, there is a @ManyToOne annotation on the attributeType field.
But what about the AttributeType object? Obviously there is no point having each AttributeType instance hold a collection of all the items associated with it because it is irrelevant. So Do I need to use this side's @OneToMany annotation anyway, or can I omit it?

Thanks,
Guy
Hi,

I am accepting user's input and then displaying it in the browser. So my goal is avoid any kind of XSS, and I thought of doing so by escaping 'malicious' characters.
Googling out, I came across Apache Commons EscapeUtils.
My question is what is the preferred method of doing so? All the posts related to it, referred to either escape HTML or Javascript, but I believe the best way is to escape both of them.
Do I need to use escapeHtml4 or escapeXml11 (ot both?) I am using HTML5 entities in my code.
Do I need to then use also escapeEcmaScript?
Does the order matter here?

I am not using JSTL (and this is why I am referring to this forum and not JSP or Servlets) because I am looking for a generic way to introduce these strings in views other than JSP.

Thanks,
Guy
Now that I think about it, Tomcat's engine translates a JSP into a Servlet and only than returns the HTML inside an HTTP response, which is exactly what I don't want to do.
So your solution is indeed the best one.
Thanks again.
9 years ago
Thank you,
I have never heard of FreeMark, but looks like it does exactly what I am asking.
But still it looks odd to me that I need a third party utility, and can't do the same with Tomcat.

Guy
9 years ago
Hi,
I am looking for a way to have a Servlet (my container is Tomcat) calling a JSP file and processing it in order to retrieve the generated HTML.
The compete scenario:
I have virtual shop and whenever a purchase is being carried out, the customer is redirected to a Servlet that post-processes the purchase (thank you, list of the items, etc.)
Among all these, the Servlet is also supposed to send me an email about the new purchase.
I would like to have nice designed HTML mail and not just a simple plain text notification.
I thought of having a designated JSP as a view, and it will only be available from the Servlet container, for this purpose.
One way is having the Servlet create an HTTPClient (or any other method of network communication) to my own host and ask for the JSP.
I wonder if there is a simpler way to ask my own container to process a JSP, since I am not really making a request to an outside web application.
Something like getServletContext.processAndReturnJsp("mail.jsp")
BTW, if you think my approach is too cumbersome to fill an email with HTML code, it would be great to know of a simpler way.

Thanks,
Guy
9 years ago
Exactly. this is why I don't combine tasks 2 and 3.
Combinig them would yield something like:
Take the (already) downladed page, parse the list of cities from it (task 2) and for each city, download its own page (task 3).
The current design parses the list of cities and then creates many tasks that each will in turn download the city's page. With this design I can also spread the cities' tasks between several threads.

Answering your question:
My main goal is to work in anasynchronous programming method, and have the program as concurrent as possible.
Basically I don't want any thread to wait for any network response. This is why I separate tasks 1 and 2 (same for 3 and 4).
Task 1 is creating a socket that will download the page and then putting task 2 in the queue. This is the part of the waiting I want to avoid: The socket will wait for a long time until the entire page is downloaded. I want the worker to to other things while we wait for the download.
While the page being downloaded, the worker will switch to other tasks, like downloading other pages. Eventually, the worker will extract the above task 2 from the queue. Task 2 will first check if the page has already been downloaded, and if so, it will start pasring the cities and preparing task(s) 3.

Hope this explanation is better.
Task one involves downloading a page and thus, must wait until the page is downloaded. This is why I sepparate it from task two.
Same for the separation between tasksk 3 and 4.
Tasks 2 doesn't include waiting and therefor can be combined with task 3. The reason I separate them is that there are many cities to crawl so I want to spread them between several queues.
BTW the main program crawls between many wether sites (for each country in Europe and North America), so I consider each site as a task.

Regarding HTMLUnit: This is actually the first time I hear about it, and it looks promising.
There are two issues: I wonder if there is much overhead of using an entire browser, including downloading Javascript, CSS (but if it is GUI-less maybe it doesn't download CSS), rendering (again GUI-less may bot render the page) and running JS.
The second issue, is that I want to have max performance by never waiting for anything, so I don't know if I can accomplish that with HTMLUnit.
Hi All,
I am starting to write a small crawler and wanted to consult about some issue.
More specifically, the crawler is supposed to crawl to weather sites and extract weather data. The base idea is to crawl to a weather site, extract the list of cities from it, and for each city crawl to its page and extract the spcific city's weather data.
I am interested in making the crawler as most asynchronous as possible, meaning never to wait on a blocking function. The basic design is as followed:
Have a thread pool of workers.
Each worker handles an async task which never blocks.

First task: "Download main site page, and put second task in queue".
Second task: "If page has been downloaded, parse the list of cities and for each city put third task in queue. If page has not been downloaded yet, return to queue".
Third task: "Download the citie's page, and put fourth task in queue".
Fourth task: "If city's page has been donloaded, parse its weather data and put it in a data structure. If the page has't been downloaded yet, return to queue."

Of course some failure and timeout mechanisms should be implemented, but they aren't relevant yet.
This design should promise max CPU utilization and as little waiting as possible.

I thought of using Java NIO package, and use a SocketChannel and a selector that will tell me if the page is ready. But what is happening unser the SocketChannel's hood? Where is the downloading mechnism being carried out?
If the HTTP call is carried out somwhere under the OS's responsibility, everything is fine. The JVM is free for the next task.
But if the JVM itself divide's the HTTP request into TCP packets, and handles the entire flow in the TCP layer, things are much compilcated. In order to achieve more utilization I should handle it myself, including dividing the request into packets, carry out the negotiation part, sending packets, receiving ACKs, receiving data and sending ACKs, rebuilding packets and closing connection.

So the question is how exactly the JVM works? Is it a good idea to consider the NIO flow which works above the TCP layer as a black box, or should I look into better resolution?

Thanks,
Guy
Thank you for your answers. I wasn't familiar with prepared statements and haven't thought that dumping an object would be easily safe.
Now that these are implemented, I am much more confident with my site.

Guy
11 years ago
My problem of serializing to disk is that I am afraid of SQL injection. I am still not sure how to build a mechanism that will prevent anyone from injection SQL queries into my DB.
For this reason, I only read from my DB but never write into it.

You have raised am important issue which I didn't think of: How to prevent memory overflow.
I think I will keep an expiration date for my sessions and have a daemon that will periodically review all the sessions and remove each session that has expired.

Guy
11 years ago
Thank you.
What I have done so far is create my own class named PersistentSession that holds a map from a String to an object an has an API as similar as possible to HttpSession (getAttribute, setAttribute, etc.)
Next I have created a class named SessionContainer that maps a string (session id) to a the above PersistentSession. The session id is the value in a special cookie that I handle. The creation of the value is by UUID class.
Finally, the SessionContainer is a common object for the entire application.
For now I am not dumping this into a DB, and if the application stops, the session disappears. This is because as a newbie I am too afraid of SQL injection, and my DB is read only.

Do you think this scheme is reasonable one for my own session handling?
11 years ago
Hi,
I am writing an application and want to have a session that will be persistent even if the user have closed their browser.
The default HttpSession received by request.getSession() is (AFAIK) based on a cookie named jsessionid and is destroyed after the user closed the browser.
Looking at this session API, it looks like you can change its maxInactiveInterval ,but still it won't help. However I coulsn't find any API that will allow me to set the session as I wish.

The only solution I came up with is ignoring this default session and use my own cookie and my own implemented session. This will allow me to manage my own session and set it to be persistent also when the user close their browser.
Is there a better, less ugly way to do so?
If I call my cookie also jsessionid, will it override the default cookie?

Thanks,
Guy
11 years ago
Thanks, I am aware of this approach.
Still, I want to have some common libraries for all my applications: User managment (Like BaseUser object) and some Logging utilities.
Is there a way to put these libraries inside the shares.loader property instead of the common.loader?

Guy
12 years ago
Hi all,
I am using the latest Tomcat version: 7.0.30.
I want to add an external library to the class loader, so web applications can use other classes I have written.
I tried adding the path to the shared.loader property in the catalina.properties file, and Tomcat just ignored this property and did not load my classes.
When I added the same path to the common.loader proprty, it worked perfectky and Tomcat loaded all my classes and the application worked well.

Has anyone encountered this problem before?
Is there another property I should set? Maybe I need to explicitly tell Tomcat to use the shared loader?

Thanks,
Guy
12 years ago