Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

Dinkar Chaturvedi

Ranch Hand
+ Follow
since Mar 27, 2007
Dinkar likes ...
Android Java Spring
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
1
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dinkar Chaturvedi

A ver warm welcome to Heartin Kanikathottu!

I have been reading articles and blogs about serverless programming and AWS lamdas for some time now. However, some of them raise concerns about the drawbacks of the same for instance, vendor lock-in etc.

Does this book address these problems and provide solutions or workarounds?

Also, does the book provide guidelines on the kind of problems this is suitable for and where it is not?

Thanks!
Not at all. There isn't any specific thing that is bothering us with Eclipse. Its just that we wanted to explore what options do we have and if they are any better than eclipse or even worth the investment. If yes, we could evaluate how better they are in comparison to eclipse and decide if we want to use them.
4 years ago
Yes we are using GSON. However, I believe Spring internally uses Jackson for all its JSON conversion needs (though I maybe wrong).

Spring configuration might be overwhelming because we have more than 20 modules as part of the build. What exactly are you looking for?

Regards
Dinkar
4 years ago
Hello everybody,

I am using JDK 1.6 and Spring 3.1.3 to create a RESTful service that accepts an object as JSON which gets converted into a Java object by Spring that I have specified in my service method. Now Spring takes care of parsing the JSON into the Java object and everything works fine.

The problem appears when I add a property to my primary object which is a superclass reference and can hold a reference to one of its many subclasses. When the JSON is received, the data for the superclass reference is equivalent to one of the subclasses. I found this link that talks about writing a custom deserializer (http://stackoverflow.com/questions/16872492/gson-and-abstract-superclasses-deserialization-issue) but I dont understand how to configure spring to use this.

Any pointers?

Regards
Dinkar
4 years ago
Hi All,

Though we have been using the bundled eclipse-based IDE for android that comes with the ADT, we wanted to explore better IDE options as we have received some budget to buy licenses and hence we are exploring options.

I came across IntelliJ Idea which has an android development plugin which is known to provide its rich feature set while enabling Android - relevant features.

Does anybody have experience with IntelliJ or would like to recommend other options to explore?

Any inputs will be greatly appreciated.

Regards
Dinkar
4 years ago

Ulf Dittmer wrote:Sounds complicated. Why does it matter whether the file is served by a servlet or directly? Why not always serve it via the servlet? If performance is of utmost concern, the file contents can be cached in memory after it has been fetched initially, thereby avoiding disk access on all instances.
If you have an Apache in front of the app server, you could put the file into a directory that is handled by Apache, thus avoiding the cluster issue altogether.



The data in the file changes every minute and we would like to serve the latest content always. So caching is not an option. Performance is not a big concern however, I was just exploring if it is possible to serve the content directly by the container instead of having my servlet streaming the content in the response. Though in this case also, (please correct me if I am wrong) the content will be served by the container's default servlet so I guess I wont gain much here.

Unfortunately, we dont have Apache but we have a load balancer before the cluster so the file has to be there on one of the cluster instances.

Roberto Perillo wrote:So the problem is that there is some data that is generated externally, and since your application is in a clustered environment, it might be handled more than one time (i.e. the number of servers in the cluster), and if you save this set of data as a file, then it would exist in only one of the servers, and if a server different from the one the file is saved in handles a request, then the file won't be found.


Exactly!

Roberto Perillo wrote:Well, what you can do is, since this set of data is handled on regular intervals, you could create a Quartz job and configure it to work in a clustered environment


The file contents are going to be a JSON format text which I would like to serve as is. Can Quartz be configured to fire the job to write a file instead of a database?
4 years ago
Hi All,

Apologies if this is not the right forum but this seems to be the best fit for my question. So please feel free to move it around.

I am working on an application that is deployed on a cluster of JBoss servers accessible via a load balancer. There is a set of data originating from another external service that I would like to expose as part of my application. But since this service is load sensitive, I would like to call this service from a separate standalone Java application only from one instance on regular intervals and put the data in a file which will be statically accessible over HTTP by the container itself. However, since this file will exist only one instance, if a request is routed to any other instance in that cluster, it will result in a 404 File Not Found. So this means that I need to make this file accessible on all instances.

One approach that I was considering was to have a servlet with the servlet mapping url pattern match exactly as the file name that will hold the data. If the instance on which a request lands is the one instance where the file exists, it should serve the file or else the request goes to the servlet with the same url pattern as the file, which will then fetch the file from the one instance where the file exists and return that in response.

However, when I use the same url pattern for a servlet as a static file, the servlet is picked up first and the static resource is not looked up at all. Is there a way I can tell the container to look for the static resource first before looking up the servlet?

Second approach that I could think of was to use a filter with the same url pattern that will check for the existence of the file and if the file exists, let the container handle it or else get the file from instance where this file exists and return the same back in the response.

Can you think of any other approaches and the pros and cons of each before I decide which approach to take forward?

Regards
Dinkar
4 years ago
Hi Ishan,

Yes, that was the first thing I tried. Everything works fine outside attributes. I am able to see the expected output for both <%= %> and <jsp:expression> when used outside attributes.

Regards
Dinkar
Howdy Ranchers,

I decided to try the mock exam that comes free with the book. I found that the version indicated there is Java EE 1.4. However the book is meant to be used with the Java EE 6 version of the exam.

Did anybody else notice the same discrepancy? Or Garner Press has not updated the exam at all?

Regards
Dinkar
Thanks a ton Frits. You not only gave me the answers I was looking for but also guided me to the right place where to look for answers - the spec. It is indeed very helpful and now I mostly look there for answers. Sadly, you cant rely on the words of the book if they are not clear to you.

Maybe Charles can fix this up in the next edition or include this in errata.

Thanks once again.

Regards
Dinkar
Howdy ranchers,

Today I came across an interesting behaviour while trying to pass an object to tag attribute via scripting. Basically I wanted to test if both formats of scripting expression are identical in behaviour. From the output, I feel like they aren't. Not sure if this is correct behaviour or not.

So I passed two attributes (using dynamic attributes) one with the usual syntax: <%=application.getAttribute("obj")%> and the other with <jsp:expression>application.getAttribute("obj")</jsp:expression>. The tag file simply prints the attributes with the details like name, value, type etc.

JSP that calls my tag file. It simply passes two attributes with same values. The only difference is the syntax elements used to pass the objects.


Tag file code is simple. It just iterates thru all the dynamic attributes and prints the name and value to the output stream along with their class type of the attribute value.


Output:
Please note that the mymodel.Dog's toString() method has been overriden to print the default implementation value (the object class@hashcode) + the name of the property in the object which is dalmatian by default as in this case.


newScrVar='application.getAttribute("appDog")'----java.lang.String
scriptingVar='mymodel.Dog@6e72d873: breed=dalmatian'----mymodel.Dog



Is this the expected behaviour? If not, is this a bug? Or something wrong with my understanding or doing things?

I am using Tomcat 7.0.46.

Regards
Dinkar
Howdy ranchers,

I am reading the OCEJWCD Study companion chapter 6 and I came across the topic which talks about additional request attributes that are set by the container when you call forward/include method on a RequestDispatcher instance.

The book says that the various paths in request object are updated by the container on calling forward/include to reflect the path of the resource included or forwarded. It also states that the path of the original servlet making this call is stored in the request as special attributes. However, I found that this doesnt agree with the execution results. I am using Tomcat 7.0.42

In case I call forward, I see that the paths in the request object passed to the forwarded resource reflects that of the resource itself and the attributes are set to reflect the path of the original servlet that made the call. However, in case of include, I noticed that when I access the path information from the included resource, the path still reflects the original servlet that made the call and not the included resource. However, the additional request attributes were holding the included resource path information. So basically, here the information got swapped between the request object paths and the attributes.

Which one is correct? Logically, the execution results seem correct to me. I check the book's errata but couldnt find anything related to this.

Did anybody try this and found similar results?

Another discrepancy I found is as follows:
As per the book, ServletException can be either temporary or permanent but UnavailableException is always permanent. However the API has two constructors for UnavailableException one for temporary and one for permanent whereas the ServletException doesn't have any constructor for indicating that this is a temporary. Which one is correct?

Lastly, whats the difference between HttpServletResponse.flushBuffer() and PrintWriter.flush() (latter is obtained from the former)

Your expert answers are warmly appreciated.

Regards
Dinkar
Thanks a lot!! I didnt realize that there are other methods as I am used to the functionality with find() method instead of looking for the entire string as a match.

Thanks anyway, this helped a big lot!!
7 years ago
Hmm!! That is interesting.

What if I want to find if the pattern v* occurs in the string vyadav?
7 years ago
The following code works fine



The following doesn't.


Any idea why?
7 years ago