aspose file tools*
The moose likes Web Services and the fly likes Getting Session on web service client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Getting Session on web service client" Watch "Getting Session on web service client" New topic
Author

Getting Session on web service client

Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Hello.

I have web method "GetCategory" on WebServiceServer. In that method i save the category list in as session attribute.
On WebServiceServer I have:


I have a desktop app and I want to pass username (which is stored in session) to getCategory webmethod. But I don't know how to do this, how to get this session object. In WebSevice client I have:



but of course i can't get Session. How can I do this?
I will add more infomartion about what I want to do. I have getLogin in my WebServiceServer. On the client side I pass through it login and password. getLogin method check if login and password is correct, return true if they are, false if they aren't. It also saves username in session. In getCategory I want to pass username, and select categories from database which are assigned to this username. The problem is, that I can't get username from session.
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
maybe somebody knows if I can get session object with those attributes? I was looking on the google for solution, but no results. Anyone please?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 637
Firstly, I won't be able to help as I am not sure I understood the question. OR I may not have the knowledge in this area.

But are you trying to access server session in client app? Sounds bit unrealistic to me (or as I said I may not have knowledge in this).

Now you mention you first login with username and password then SERVER will save userName in session.
In second call you want to pass userName to webservice so it can retrieve data from session. why can't you pass the same username that you passed to login?

well this is surly not secure as any user can pass different username and fetch data, so what you should search for is how to maintain session between two different webservice calls.
in your case when you login, the webservice should return session id (JSESSIONID) that should be used for getCategory call and sever will identify the user for this request.

-P


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
I thought that session works like on websites. User login in, webserver creates session and client (for websites it would be browser) have access to the session attributes. I was thinking about the solution which you have provided (pass the username to getCategory). It's good enough for me, but if I can't save anything in session, and I can't pass arguments using session I will have other problem, The category list then should be returned in getCategory ( it would be public List getCategory(String username) ), but the web service (jax-ws) can't return List, ArrayList, Maps etc. It can return only simple arrays and raw types. It's bad solution I think. I don't know how I would solve that.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 637
(for websites it would be browser) have access to the session attributes


hell NO

All that browsers knows is the session id that is mostly stored in cookies by browser and with every request browser sends this session id to server and that's how server identifies session for given user.

I don't get the remaining points you made, , I thought getCategory was returning list of categories after reterving ti from session for given user.

but the web service (jax-ws) can't return List, ArrayList, Maps etc


are you sure? did you try it? did you try HashMap (concrete type) instead of Map (Interface).

-P
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Praful Thakare wrote:
(for websites it would be browser) have access to the session attributes


hell NO

All that browsers knows is the session id that is mostly stored in cookies by browser and with every request browser sends this session id to server and that's how server identifies session for given user.


ooops :>


I don't get the remaining points you made, , I thought getCategory was returning list of categories after reterving ti from session for given user.

but the web service (jax-ws) can't return List, ArrayList, Maps etc


are you sure? did you try it? did you try HashMap (concrete type) instead of Map (Interface).

-P


No, no, my first plan was saving category list in session, and then retriving it from session on client - now I know it's impossible or hard to code. Yes I have checked that. I was trying with HashMap, Map, ArrayList and Object. I also found http://docs.oracle.com/javaee/6/tutorial/doc/bnazc.html .
I can't belive, that returning simple HashMap is so hard :/
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 637
I have returned ArrayList N number of times from webservice. do not remember ofusing HashMap. I quickly created webservices using this article and replaced all the methods with my own methods returning list and map.
and it worked fine for List using Axis2 and for both using CXF 2.x.

the link you mention is describing the basic types those can participate in Jax-WS it is not talking about collections, of instance it did not mention Arrays as well, but as you already know arrays can be used. So it depends on what framework are you using. I prefer CXF over Axis.

following is my code for Axis2 server and client and then CXF server and client with output


Axis 2 Server Code


Axis 2 Client Code


Notice here, Axis is converting list to array hence we have to use []0] instead of get(0)

output :-
Index 1



============



CXF 2.x Server Code


CXF2.x Client Code


Notice here, cxf is NOT converting list to array but Map is returned as list of Entry that has key and value inside which makes perfect sense.

output :-
Invoking getMapData...
getMapData.result : ABC = XYZ
Invoking getListData...
getListData.result=List 1
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
I'm using jax-ws, and here is the problem, I have chosen wrong web service framework ;) I will think about changeing framework for one of them. If I won't find any other solution for my problem then I will have to do this, thank you for help Praful Thakare (again )
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 637
I have chosen wrong web service framework ;)


which one ?
Marek Krokosinski
Ranch Hand

Joined: Jun 10, 2011
Posts: 64
Praful Thakare wrote:
I have chosen wrong web service framework ;)


which one ?


JAX-WS. I should choose axis or CXF
 
wood burning stoves
 
subject: Getting Session on web service client