Rajat Sharmanaive

Ranch Hand
+ Follow
since Jun 30, 2011
Rajat likes ...
Eclipse IDE Firefox Browser Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rajat Sharmanaive

Solution obtained.
Get the url via Application.application.url and use URLutils that has various static utility methods to obtain different tokens of the obtained url. These tokens can then be used to construct server url.
Thanks
12 years ago
Hi

I have a flex application using BlazeDS for connectivity with java. As those who have used it would know, BlazeDS requires me to sort of hardcode the endpoint url for any given channel in the services-config.xml. This services-config.xml is also given as a compiler argument to flex application.
for e.g.

Channels like these are then used by remote objects for invoking back end java methods. Here, though {server.name} and {server.port} are loaded at run time, {context.root} is loaded at compile time. Moreover at times, there may be no {server.port} in prod environment. My requirement is to find some way by which the application can dynamically create the channel for any remote object. To further elaborate, I need to do these two steps:
1) to figure out the server where the swf is installed at run time and obtain details like protocol, server:port etc.
2) to create a channel dynamically using the above details.
Now I have an idea about the second step - How to create a channel and assign it to a remote object. This is what I think can be done:


With this approach, services.config.xml is as good as absent. Because as far as the channel aspect of it is concerned, we are setting the details at runtime. I cannot find any APIs in flex that will help me give the details of the server where the swf is installed. Something like this.getServer() etc. I know this might seem a strange requirement to some but that is what I have to do. My hint (a hint also means that this is "exaclty" how the boss wants it to be done- no other way !) is to find the APIs in flex that I just mentioned
Please give any suggestions if anyone has any knowledge about this.
12 years ago
Hi

Checked on net. Commons-logging is listed as a dependency for Spring. Not sure what that means exactly but it is clear I need it. I am trying to figure out what it means exactly. Any help on that is appreciated. Thanks.
12 years ago
Hi

I was just doing a basic hands on of spring DI. I have a couple of beans in my xml and I try to instantiate the Spring container so that it loads the beans. Here is the code.


I removed all the lines because the first line itself causes an exception. I am sure on this. Everything is normal if I do not load container (that is, comment the first line )and just treat it as a normal core java program. Here is the exception.

I then add commons-logging jar to my project. There is no exception once I add it. My question is why is it so ? I have clearly checked all my code. Nowhere am i performing any logging. In fact, I do not even have any import statements related to logging. Why does Spring need this jar then. Does it need it internally or does any other jar I am using need logging features? I am pasting all the jars I am using. Most of them are not being used but I have kept them there because I keep trying different features back and forth. Is there some compulsion to use logging with Spring? I am deliberately not pasting xml or any more code for that matter because I am pretty sure the error is not related to anything else. I have thoroughly checked my code and there is no shred of logging. Still if anyone thinks I am wrong, please ask for more code. Thanks for help.

List of jars (I know its stupid enough but could there be a case that any of these jars need logging.)
12 years ago
Campbell, Matthew

Thanks for you replies. I now understand that the answer to my question lies both in the working of the advanced for loop (The value of the array element gets copied into the local block scoped variable, that value could be a reference, in case of array of Objects) and the fact that Strings are immutable.

you can change the state of an object in an array or Iterable using any of the object's public interface.

This is very insightful. Never noticed.
As far as immutability is concerned, this is what i know of it:
Similarly, in every iteration, s is a local variable which points to the same String Object as sa[i]. Whatever changes i made to s will at max lead s to point to the "changed" value and have no affect on sa[i]. So the array remains intact.
Please confirm/correct this.
Also,

(Actually your example shows poor design; it would be better to say Dog.setName("Fido")

Indeed Campbell. It is sinful to expose variables like this. Didn't pay attention.
Thanks once again
12 years ago
Rishi

Thanks for the reply. Yes it was quite obvious there, i should have noticed it. I have manually replaced "owner bean" in greetingService with another bean that i created. But can you please elaborate this.

What you have done in not recommended, instead of replacing the complete bean reference you should retrieve the instance from Spring & then set the property.


I mean I am sure it is not recommended. But the latter part. Do you want me to do something like:

. So that I am modifying the single existent bean, rather than adding new beans.
12 years ago
Ove

Fair enough. So does this mean that we can never modify array elements (string array elements, to be precise) using this for loop. If you can see in the earlier message, i was able to modify the contents of an array of Dog objects.

If the address of each array element(which is a Dog object) can come into the loop variable s upon every iteration, why does something similar does not happen in case of Strings. Has it got anything to do with immutability.
12 years ago
Hi Bhanu

Thanks for the reply. I got that. What you said is fine for primitives. But shouldn't String Objects be changed. I pasted the snippet where i tried with strings but result was similar to that in case of an array of primitives. Has it got anything to do with String immutability or is it the expected behavior. I tried it with an Object array. It worked as expected.

I know the value in "s" in every iteration is the reference of the actual respective Dog Object. And hence the changes are reflected. Why not Strings then? Here is the code again. This time with constructors.

"s" is a reference variable. Why then changes made through it are not reflected. Please help.
12 years ago
Hi All
I am new to Spring. Reading through a book and docs on net. I have a query with respect to bean scoping. As we know, the default scope in spring is singleton. As per my understanding, this means that only one instance of the bean will be created and shared whenever required. Required means either being wired into another bean or directly called through getBean method. Please correct if there is anything incorrect here.
Now please look at the following code.


All the beans (especially, "owner" bean) are default scoped as singleton. In a sample application however when I access owner via greetingService and useowner respectively, changes made by one are not reflected in the other. Aren't these two sharing a "single" owner instance?


If only one instance of owner is created then why this behavior. Is it one instance per container or something like one instance per "class type" per container. I am confused. I hope there isn't any basic java polymorphism stuff here that I am not getting. Please help.
12 years ago
Hi

I have been using foreach loops for quite some time now. I have yet again been humbled by how little I know. Consider the code.


After this the contents of the array did not change. A normal for loop would have required me to use "arr[0]+=1" and yes, that would obviously have changed the contents. So is it that we cannot modify anything using these advanced loops. I mean i know "s" here is a block scoped variable. But still, somehow I am not able to give myself a solid explanation. Is it because it is an array of primitives and "copy of" value from the array is in "s". I used the String array too.


Since Strings are objects, shouldn't the first loop have changed the contents.
Can someone please clear this. It's discomforting to have such huge conceptual flaws in head. Thanks.
12 years ago
Hi Bear

Yes, the browser caches the form submission values as well as the URL.



In hindsight it appears a common sense stuff. I should have observed it, especially with that typical message where the browser asks the user if she wants to resubmit the form data.
Thank you for the peace my brain now feels.
12 years ago
Hi Pankaj

I understand refresh will achieve that. I am using POST method to submit data from login form. But still your point is valid. I agree that i AM sending the data. But how come that data is saved after 8 requests.

Assume I login with "user" and "pass" values for username and password respectively. Assume these are valid values so on my home page i see : "you logged in with user and pass". It is fine up to here, I navigate further (example homepage-->page1--page2 )making NEW requests. Now i start coming back from page 2 using back button. Since I have forced no caching, i manually hit refresh to get each page from server.

I am at page 1 now and press back to see the home page. Since there is no caching, first i see "page expired". Then i hit refresh and see home page with message "you logged in with user and pass".
This is where i am stuck. Since the page is coming from server, how come these request values which were entered about 4 requests back, are coming from server. Where are they saved. I hope I am clear now.

when you are refreshing you are effectively sending the same information which you would have previously sent from the login form.



What does same mean here? The old information? Does browser keep track of HTML field values. Can you elaborate please.
Thanks for your reply.
12 years ago


I did a small prototype ,clicking on browser's back or forth button did not trigger any request at all.



Hi Manjesh

Perhaps i missed out on something important yet again. I agree clicking on back button does not make browser query the server, on it's own, unless i refresh. You have already made that clear in your reply to my other post and i too am clear about that.

I do press refresh. Here it is again. (please read the original post for remaining part...the only thing added here is that I DO hit refresh)
while traversing backward through back button. All requests hit server by explicitly pressing refresh.
next page 3 --> next page 2 --> next page 1 --> home page
home page is one after login page. So the request parameters for home page are the ones that are entered in the login page.
for debugging purposes i display the user id and password text box values on home page. It is more like "this is what i entered while logging in". I see those values while going forward , and rightly so. But while coming backward too, i see those values. How is it possible. There have been many requests in between and each must have changed the request parameter value.

My question is that even though i click refresh, how does the browser "remember" my login parameters that i entered about 7 requests ago. I was under the impression that request parameters are valid for this request only. Then how come, when i traverse backwards, browser sends the request to server (up to here it is ok, since im pressing refresh, server will be hit), with the request parameters that i entered while logging in. I hope i am clear now.
12 years ago
Manjesh

Yes you correctly pointed out that scenario, where despite being in a valid session, user sees page expired while navigating backwards, if I put cache control headers. This is not necessary as per my requirements. I will follow the advice of putting the headers on only the sensitive pages.


And about your question on expired pages: browser wont query the server when you hit the back button until you explicitly click on refresh. If its too much required to refresh the page automatically when you hit the back button..



This is what i was keen on knowing. Thanks for clearing that up. I will see how to make it automatically refresh upon back button click. Meanwhile, there is another query i have posted recently pertaining to request parameter values. Please help on that as per your convenience.
Thanks.
12 years ago