You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by James Neff <jn...@tethyshealth.com> on 2007/09/25 22:16:22 UTC
Axis2, Session not keeping.
in my services.xml I have the attribute scope="TransportSession".
In my client I have this:
myServiceStub stub = new myServiceStub();
myServiceStub.MyMethod myServiceRequest = new myServiceStub .MyMethod();
myServiceRequest .setParameter(parameterValue);
stub._getServiceClient().getOptions().setManageSession(true);
But the session is not keeping.
It looks like the myService is getting instantiated for each call, and
not being held in a session.
What am I doing wrong?
Thanks in advance,
Jim
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: Axis2, Session not keeping. - SOLVED
Posted by James Neff <jn...@tethyshealth.com>.
Thanks again Andrew. You helped me think about my problem and then the
light bulb went on for me.
Here is the code for the JSP client if anyone else is interested:
<%
String returnValue = "-99";
try {
MyServiceStub stub;
stub = (MyServiceStub)session.getAttribute("myServiceStub");
if (stub == null) {
stub = new MyServiceStub();
stub._getServiceClient().getOptions().setManageSession(true);
session.setAttribute("myServiceStub", stub) ;
}
MyServiceStub.TestSessionMethod myServicerequest = new
MyServiceStub.TestSessionMethod();
TestSessionMethodResponse myServiceResponse =
stub.TestSessionMethod(myServicerequest);
returnValue = String.valueOf(myServiceResponse .get_return());
}
catch (Exception e) {
returnValue = "Exception: " + e;
}
out.println(returnValue);
%>
I store the stub (created by WSDL2Java) in a session object within my
Tomcat Servlet.
If the stub isn't there, then create it and then use it. Otherwise it
attempts to use what it finds.
I don't know if you need the setManageSession(true) part. Currently I
am using scope="transportsession" but from my understanding of the
documentation for Axis2 you don't need to set ManageSession = true (but
I might be wrong).
Thanks again for this great list. Even though my question wasn't
answered directly reading the responses got me to think about my problem
differently.
--James
Andrew Martin wrote:
> I don't know JSP.
>
> Andrew
>
> James Neff wrote:
>
>> Andrew Martin wrote:
>>
>>> ...
>>>
>>> It looks like you're creating a new client each time you call the
>>> service, so each call would be in a separate session. What happens if
>>> you invoke the service multiple times with the same client object?
>>>
>>>
>>>
>> How do I do that from a JSP page? Is there an example somewhere I can
>> follow?
>>
>>
>>
>>>> I added to my Web Service class a constructor:
>>>>
>>>> public MyService() {
>>>> System.out.println("MyService.constructing!");
>>>>
>>>> int testCounter = 0;
>>>> SessionContext sessionContext =
>>>> MessageContext.getCurrentMessageContext().getSessionContext();
>>>> sessionContext.setProperty("thisCounter", testCounter);
>>>> }
>>>>
>>>>
>>>> And when I go to /logs/catalina.out I see :
>>>>
>>>> MyService.constructing!
>>>>
>>>> for as many times as I call the method from my RPC client.
>>>>
>>>>
>>> That's what I would expect. If you store session information in the
>>> SessionContext, then that wouldn't matter.
>>>
>>>
>> I thought thats what I was doing here with SessionContext. Did I do it
>> wrong?
>>
>>
>>
>>>
>>>
>>>> Also, the session does work when I use "application" for the scope. But
>>>> when I try "transportsession" or "soapsession" in the "scope" attribute
>>>> of services.xml it always acts like "request" scope.
>>>>
>>>>
>>> If you use "application", then you wouldn't get a separate counter for
>>> each session. Every user would be incrementing the same counter. If
>>> that's what you want, then do that. If you really want to store
>>> separate variables for each session, then your server's already doing
>>> the right thing with "transportsession", according to your web browser
>>> test. You just need to change your client.
>>>
>> Yes, I want a separate session for each user. I said the thing about
>> "application" because I just wanted to make sure the thing was working
>> at least at some level. Now it seems, as you've pointed out, my client
>> is getting created anew each time I click the button my JSP web page.
>> How can I call the same session from my JSP page?
>>
>> Thanks again in advance,
>> James
>>
>>
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: Axis2, Session not keeping.
Posted by Andrew Martin <am...@regenstrief.org>.
I don't know JSP.
Andrew
James Neff wrote:
> Andrew Martin wrote:
>> ...
>>
>> It looks like you're creating a new client each time you call the
>> service, so each call would be in a separate session. What happens if
>> you invoke the service multiple times with the same client object?
>>
>>
>
> How do I do that from a JSP page? Is there an example somewhere I can
> follow?
>
>
>>> I added to my Web Service class a constructor:
>>>
>>> public MyService() {
>>> System.out.println("MyService.constructing!");
>>>
>>> int testCounter = 0;
>>> SessionContext sessionContext =
>>> MessageContext.getCurrentMessageContext().getSessionContext();
>>> sessionContext.setProperty("thisCounter", testCounter);
>>> }
>>>
>>>
>>> And when I go to /logs/catalina.out I see :
>>>
>>> MyService.constructing!
>>>
>>> for as many times as I call the method from my RPC client.
>>>
>>
>> That's what I would expect. If you store session information in the
>> SessionContext, then that wouldn't matter.
>>
>
> I thought thats what I was doing here with SessionContext. Did I do it
> wrong?
>
>
>>
>>> Also, the session does work when I use "application" for the scope. But
>>> when I try "transportsession" or "soapsession" in the "scope" attribute
>>> of services.xml it always acts like "request" scope.
>>>
>>
>> If you use "application", then you wouldn't get a separate counter for
>> each session. Every user would be incrementing the same counter. If
>> that's what you want, then do that. If you really want to store
>> separate variables for each session, then your server's already doing
>> the right thing with "transportsession", according to your web browser
>> test. You just need to change your client.
>
> Yes, I want a separate session for each user. I said the thing about
> "application" because I just wanted to make sure the thing was working
> at least at some level. Now it seems, as you've pointed out, my client
> is getting created anew each time I click the button my JSP web page.
> How can I call the same session from my JSP page?
>
> Thanks again in advance,
> James
>
>
>
--
Andrew Martin
Computer Programmer
Regenstrief Institute, Inc.
410 West 10th Street, Suite 2000
Indianapolis, IN 46202-3012
Phone: (317) 423-5542
Fax: (317) 423-5695
amartin@regenstrief.org
Confidentiality Notice: The contents of this message and any files
transmitted with it may contain confidential and/or privileged
information and are intended solely for the use of the named
addressee(s). Additionally, the information contained herein may have
been disclosed to you from medical records with confidentiality
protected by federal and state laws. Federal regulations and State laws
prohibit you from making further disclosure of such information without
the specific written consent of the person to whom the information
pertains or as otherwise permitted by such regulations. A general
authorization for the release of medical or other information is not
sufficient for this purpose.
If you have received this message in error, please notify the sender by
return e-mail and delete the original message. Any retention,
disclosure, copying, distribution or use of this information by anyone
other than the intended recipient is strictly prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: Axis2, Session not keeping.
Posted by James Neff <jn...@tethyshealth.com>.
Andrew Martin wrote:
> ...
>
>
> It looks like you're creating a new client each time you call the
> service, so each call would be in a separate session. What happens if
> you invoke the service multiple times with the same client object?
>
>
How do I do that from a JSP page? Is there an example somewhere I can
follow?
>> I added to my Web Service class a constructor:
>>
>> public MyService() {
>> System.out.println("MyService.constructing!");
>>
>> int testCounter = 0;
>> SessionContext sessionContext =
>> MessageContext.getCurrentMessageContext().getSessionContext();
>> sessionContext.setProperty("thisCounter", testCounter);
>> }
>>
>>
>> And when I go to /logs/catalina.out I see :
>>
>> MyService.constructing!
>>
>> for as many times as I call the method from my RPC client.
>>
>
> That's what I would expect. If you store session information in the
> SessionContext, then that wouldn't matter.
>
I thought thats what I was doing here with SessionContext. Did I do it
wrong?
>
>> Also, the session does work when I use "application" for the scope. But
>> when I try "transportsession" or "soapsession" in the "scope" attribute
>> of services.xml it always acts like "request" scope.
>>
>
> If you use "application", then you wouldn't get a separate counter for
> each session. Every user would be incrementing the same counter. If
> that's what you want, then do that. If you really want to store
> separate variables for each session, then your server's already doing
> the right thing with "transportsession", according to your web browser
> test. You just need to change your client.
Yes, I want a separate session for each user. I said the thing about
"application" because I just wanted to make sure the thing was working
at least at some level. Now it seems, as you've pointed out, my client
is getting created anew each time I click the button my JSP web page.
How can I call the same session from my JSP page?
Thanks again in advance,
James
Re: Axis2, Session not keeping.
Posted by Andrew Martin <am...@regenstrief.org>.
James Neff wrote:
> Andrew,
>
> Thank you for responding to my e-mail however I still cannot get
> sessions to work on my Axis2 setup.
>
> I added the code you provided to the method like this:
>
> public int TestSessionMethod() {
> SessionContext sessionContext =
> MessageContext.getCurrentMessageContext().getSessionContext();
> int myCounter = 0;
> myCounter = 1 +
> Integer.parseInt((String)sessionContext.getProperty("thisCounter").toString());
>
> sessionContext.setProperty("thisCounter", myCounter );
> return myCounter ;
> }
>
>
> When I call this method from my Mozilla web browser:
>
> http://localhost:8080/axis2/services/MyService/TestSessionMethod
>
> The method is working correctly and I get returned a soap message
> containing an incrementing result. I've confirmed the session working
> (versus application) by opening IE and calling the same method. The
> results from IE are as expected : 1, 2, 3 ... etc.
>
> I cannot get this method working from an RPC client though. Here is my
> code from my jsp client:
>
> <%
> returnValue = "-99";
>
> try {
>
> MyServiceStub stub = new MyServiceStub();
> stub._getServiceClient().getOptions().setManageSession(true);
> MyServiceStub.TestSessionMethod myServicerequest = new
> MyServiceStub.TestSessionMethod();
> TestSessionMethodResponse myServiceResponse =
> stub.TestSessionMethod(myServicerequest);
> returnValue = String.valueOf(myServiceResponse.get_return());
> }
> catch (Exception e) {
> returnValue = "Exception: " + e;
> } out.println(returnValue);
> %>
>
> The result is always : 1, 1, 1, ... etc.
It looks like you're creating a new client each time you call the
service, so each call would be in a separate session. What happens if
you invoke the service multiple times with the same client object?
> I added to my Web Service class a constructor:
>
> public MyService() {
> System.out.println("MyService.constructing!");
>
> int testCounter = 0;
> SessionContext sessionContext =
> MessageContext.getCurrentMessageContext().getSessionContext();
> sessionContext.setProperty("thisCounter", testCounter);
> }
>
>
> And when I go to /logs/catalina.out I see :
>
> MyService.constructing!
>
> for as many times as I call the method from my RPC client.
That's what I would expect. If you store session information in the
SessionContext, then that wouldn't matter.
> Also, the session does work when I use "application" for the scope. But
> when I try "transportsession" or "soapsession" in the "scope" attribute
> of services.xml it always acts like "request" scope.
If you use "application", then you wouldn't get a separate counter for
each session. Every user would be incrementing the same counter. If
that's what you want, then do that. If you really want to store
separate variables for each session, then your server's already doing
the right thing with "transportsession", according to your web browser
test. You just need to change your client.
Andrew
> What else am I missing to get sessions working for Axis2?
>
> Thank you in advance,
> James
>
>
>
>
>
> Andrew Martin wrote:
>> Store session information like this:
>> MessageContext.getCurrentMessageContext().getSessionContext().setProperty(key,
>>
>> val)
>> Retrieve it like this:
>> MessageContext.getCurrentMessageContext().getSessionContext().getProperty(key)
>>
>>
>> Andrew
>>
>> James Neff wrote:
>>
>>> in my services.xml I have the attribute scope="TransportSession".
>>>
>>> In my client I have this:
>>>
>>> myServiceStub stub = new myServiceStub();
>>> myServiceStub.MyMethod myServiceRequest = new myServiceStub .MyMethod();
>>> myServiceRequest .setParameter(parameterValue);
>>> stub._getServiceClient().getOptions().setManageSession(true);
>>>
>>> But the session is not keeping.
>>>
>>> It looks like the myService is getting instantiated for each call, and
>>> not being held in a session.
>>>
>>> What am I doing wrong?
>>>
>>> Thanks in advance,
>>> Jim
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>
>>
>
>
--
Andrew Martin
Computer Programmer
Regenstrief Institute, Inc.
410 West 10th Street, Suite 2000
Indianapolis, IN 46202-3012
Phone: (317) 423-5542
Fax: (317) 423-5695
amartin@regenstrief.org
Confidentiality Notice: The contents of this message and any files
transmitted with it may contain confidential and/or privileged
information and are intended solely for the use of the named
addressee(s). Additionally, the information contained herein may have
been disclosed to you from medical records with confidentiality
protected by federal and state laws. Federal regulations and State laws
prohibit you from making further disclosure of such information without
the specific written consent of the person to whom the information
pertains or as otherwise permitted by such regulations. A general
authorization for the release of medical or other information is not
sufficient for this purpose.
If you have received this message in error, please notify the sender by
return e-mail and delete the original message. Any retention,
disclosure, copying, distribution or use of this information by anyone
other than the intended recipient is strictly prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: Axis2, Session not keeping.
Posted by James Neff <jn...@tethyshealth.com>.
Andrew,
Thank you for responding to my e-mail however I still cannot get
sessions to work on my Axis2 setup.
I added the code you provided to the method like this:
public int TestSessionMethod() {
SessionContext sessionContext =
MessageContext.getCurrentMessageContext().getSessionContext();
int myCounter = 0;
myCounter = 1 +
Integer.parseInt((String)sessionContext.getProperty("thisCounter").toString());
sessionContext.setProperty("thisCounter", myCounter );
return myCounter ;
}
When I call this method from my Mozilla web browser:
http://localhost:8080/axis2/services/MyService/TestSessionMethod
The method is working correctly and I get returned a soap message
containing an incrementing result. I've confirmed the session working
(versus application) by opening IE and calling the same method. The
results from IE are as expected : 1, 2, 3 ... etc.
I cannot get this method working from an RPC client though. Here is my
code from my jsp client:
<%
returnValue = "-99";
try {
MyServiceStub stub = new MyServiceStub();
stub._getServiceClient().getOptions().setManageSession(true);
MyServiceStub.TestSessionMethod myServicerequest = new
MyServiceStub.TestSessionMethod();
TestSessionMethodResponse myServiceResponse =
stub.TestSessionMethod(myServicerequest);
returnValue = String.valueOf(myServiceResponse.get_return());
}
catch (Exception e) {
returnValue = "Exception: " + e;
}
out.println(returnValue);
%>
The result is always : 1, 1, 1, ... etc.
I added to my Web Service class a constructor:
public MyService() {
System.out.println("MyService.constructing!");
int testCounter = 0;
SessionContext sessionContext =
MessageContext.getCurrentMessageContext().getSessionContext();
sessionContext.setProperty("thisCounter", testCounter);
}
And when I go to /logs/catalina.out I see :
MyService.constructing!
for as many times as I call the method from my RPC client.
Also, the session does work when I use "application" for the scope. But
when I try "transportsession" or "soapsession" in the "scope" attribute
of services.xml it always acts like "request" scope.
What else am I missing to get sessions working for Axis2?
Thank you in advance,
James
Andrew Martin wrote:
> Store session information like this:
> MessageContext.getCurrentMessageContext().getSessionContext().setProperty(key,
> val)
> Retrieve it like this:
> MessageContext.getCurrentMessageContext().getSessionContext().getProperty(key)
>
> Andrew
>
> James Neff wrote:
>
>> in my services.xml I have the attribute scope="TransportSession".
>>
>> In my client I have this:
>>
>> myServiceStub stub = new myServiceStub();
>> myServiceStub.MyMethod myServiceRequest = new myServiceStub .MyMethod();
>> myServiceRequest .setParameter(parameterValue);
>> stub._getServiceClient().getOptions().setManageSession(true);
>>
>> But the session is not keeping.
>>
>> It looks like the myService is getting instantiated for each call, and
>> not being held in a session.
>>
>> What am I doing wrong?
>>
>> Thanks in advance,
>> Jim
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>
>
Re: Axis2, Session not keeping.
Posted by Andrew Martin <am...@regenstrief.org>.
Store session information like this:
MessageContext.getCurrentMessageContext().getSessionContext().setProperty(key,
val)
Retrieve it like this:
MessageContext.getCurrentMessageContext().getSessionContext().getProperty(key)
Andrew
James Neff wrote:
> in my services.xml I have the attribute scope="TransportSession".
>
> In my client I have this:
>
> myServiceStub stub = new myServiceStub();
> myServiceStub.MyMethod myServiceRequest = new myServiceStub .MyMethod();
> myServiceRequest .setParameter(parameterValue);
> stub._getServiceClient().getOptions().setManageSession(true);
>
> But the session is not keeping.
>
> It looks like the myService is getting instantiated for each call, and
> not being held in a session.
>
> What am I doing wrong?
>
> Thanks in advance,
> Jim
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
--
Andrew Martin
Computer Programmer
Regenstrief Institute, Inc.
410 West 10th Street, Suite 2000
Indianapolis, IN 46202-3012
Phone: (317) 423-5542
Fax: (317) 423-5695
amartin@regenstrief.org
Confidentiality Notice: The contents of this message and any files
transmitted with it may contain confidential and/or privileged
information and are intended solely for the use of the named
addressee(s). Additionally, the information contained herein may have
been disclosed to you from medical records with confidentiality
protected by federal and state laws. Federal regulations and State laws
prohibit you from making further disclosure of such information without
the specific written consent of the person to whom the information
pertains or as otherwise permitted by such regulations. A general
authorization for the release of medical or other information is not
sufficient for this purpose.
If you have received this message in error, please notify the sender by
return e-mail and delete the original message. Any retention,
disclosure, copying, distribution or use of this information by anyone
other than the intended recipient is strictly prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org