You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Vassilis Virvilis <v....@biovista.com> on 2008/03/26 15:47:19 UTC

scope="session" client side configuraion

Hi,

I am new to the list and a newbie to apache-cxf.

I would like to have servlets to have session scope
I think I manage to do that in the server part thanks to
that post

http://www.nabble.com/Share-object-in-request-scope-on-ws-server-td14611572.html

server bean configuration includes:
	<bean id="ServerService" class="com.company.lib.Server" scope="session">
		<aop:scoped-proxy />
	</bean>

but I am having great troubles setting up the property SESSION_MAINTAIN_PROPERTY in the client

I am using spring configuration with the following fragment

		<bean id="Client" class="ClientInterface" factory-bean="ClientFactory" factory-method="create" />
        <bean id="ClientFactory" class="org.apache.cxf.frontend.ClientProxyFactoryBean">
			<property name="serviceClass" value="ClientInterface" />
			<property name="address" value="http://localhost:/ws/ClientImpl" />
            <property name="dataBinding" ref="aegisDatabinding"/>
        </bean>

Is it possible to maintain the session client side when I am ClientProxyFactoryBean and not JaxWSFactorySomething

    Thanks

Re: scope="session" client side configuraion

Posted by Vassilis Virvilis <v....@biovista.com>.
On Friday 28 March 2008, Daniel Kulp wrote:
> 
> Hmm...  not sure what phase you get if you don't specify one.  That might 
> be why it's not working.
> 
> I would suggest doing:
> 
> public static class MyInterceptor 
>     extends AbstractPhaseInterceptor<Message> {
> 
>     public MyInterceptor() {
>         super(Phase.SETUP);
>     }
> 
>     public void handleMessage(Message message) throws Fault {
>         logger.info("Hi there");
>         message.put(Message.MAINTAIN_SESSION, true);
>     }
> }
> 

Hi Dan,

This works beautifully. Thanks a lot. I can now get rid of
the JaxWS requirement client side.

Thanks again.

       .bill

Re: scope="session" client side configuraion

Posted by Daniel Kulp <dk...@apache.org>.
Hmm...  not sure what phase you get if you don't specify one.  That might 
be why it's not working.

I would suggest doing:

public static class MyInterceptor 
    extends AbstractPhaseInterceptor<Message> {

    public MyInterceptor() {
        super(Phase.SETUP);
    }

    public void handleMessage(Message message) throws Fault {
        logger.info("Hi there");
        message.put(Message.MAINTAIN_SESSION, true);
    }
}

That should make it run at the earliest part of the outgoing chain.

Dan


> thanks for the info.
> I would like to get rid of the JaxWS dependency since SimpleClient is
> good enough for me
>
> I did take a look at
> http://cwiki.apache.org/CXF20DOC/interceptors.html and I ended up
> with:
>
> -------------------------------------
>     public static class MyInterceptor extends AbstractSoapInterceptor
> { public void handleMessage(SoapMessage message) throws Fault {
> logger.info("Hi there");
>             message.put(Message.MAINTAIN_SESSION, true);
>         }
>     }
>
> ...
>    TestInterface ldap = (TestInterface) context.getBean(TestClient");
>
>    ClientProxy.getClient(test).getOutInterceptors().add(new
> MyInterceptor());
>
>                           |____ This is my proxy client
>
> --------------------------------------
>
> but the message "Hi there" is never printed.
>
> I am obviously missing something but what?
> Maybe the type of the Interceptor that I am extending?
>
> 	.bill



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: scope="session" client side configuraion

Posted by Vassilis Virvilis <v....@biovista.com>.
On Thursday 27 March 2008, Daniel Kulp wrote:
> 
> Yea, looking at the code for the sessions stuff in the http conduit, the 
> sessionMaintain setting is only read from current message. Thus, that 
> requires being able to set properties on the currently dispatching 
> message.  The JAX-WS frontend has the 
> BindingProvider.getRequestContext() stuff to set those properties.   The 
> simple frontend doesn't have any sort of request context or ability to 
> pre-set properties on the message.   Thus, it wouldn't work.
> 
> The only way to get it to work would be to write a simple interceptor 
> that just does:
> message.put(Message.MAINTAIN_SESSION, Boolean.TRUE);
> 
> and configure that on the outbound chain for the client.
> 
> Dan
> 

Hi Dan,

thanks for the info.
I would like to get rid of the JaxWS dependency since SimpleClient is good enough for me

I did take a look at http://cwiki.apache.org/CXF20DOC/interceptors.html
and I ended up with:

-------------------------------------
    public static class MyInterceptor extends AbstractSoapInterceptor {
        public void handleMessage(SoapMessage message) throws Fault {
            logger.info("Hi there");
            message.put(Message.MAINTAIN_SESSION, true);
        }
    }

...
   TestInterface ldap = (TestInterface) context.getBean(TestClient");

   ClientProxy.getClient(test).getOutInterceptors().add(new MyInterceptor());
                          |
                          |____ This is my proxy client
--------------------------------------

but the message "Hi there" is never printed.

I am obviously missing something but what?
Maybe the type of the Interceptor that I am extending?

	.bill

Re: scope="session" client side configuraion

Posted by Daniel Kulp <dk...@apache.org>.
Yea, looking at the code for the sessions stuff in the http conduit, the 
sessionMaintain setting is only read from current message. Thus, that 
requires being able to set properties on the currently dispatching 
message.  The JAX-WS frontend has the 
BindingProvider.getRequestContext() stuff to set those properties.   The 
simple frontend doesn't have any sort of request context or ability to 
pre-set properties on the message.   Thus, it wouldn't work.

The only way to get it to work would be to write a simple interceptor 
that just does:
message.put(Message.MAINTAIN_SESSION, Boolean.TRUE);

and configure that on the outbound chain for the client.

Dan


On Thursday 27 March 2008, Vassilis Virvilis wrote:
> On Thursday 27 March 2008, Glen Mazza wrote:
> > Actually, I didn't realize I had replied to you privately, something
> > is strange with your email account--for a few accounts, including
> > yours, when you hit "reply" it goes not to the list but to just back
> > to the person.
>
> I think that's normal. You need to hit reply-all in order to reply to
> the list and to the person.
> http://www.unicom.com/pw/reply-to-harmful.html
>
> Anyway it *** works *** now. (that is with 2.0.4,
> 		 still crashes with 2.0.5 see other thread)
>
> I was confused by the fact that
>
>   ClientInterface test = (ClientInterface) context.getBean("Client");
>
> returns the same object every time you called it
> and even if I set the scope to prototype (for the client)
> looks like all the proxy object are using the same client / connection
> aka session.
>
> So I couldn't test the session scope from one java program but I could
> from two or  a java program and a browser.
>
> So the trick is to use tha jaxws frontend (doesn't work with simple
> client frontend) and do
>
> client side:
> ClientInterface test = (ClientInterface) context.getBean("Client");
> ((BindingProvider) test).getRequestContext().put(
>                 BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
>
> along with the scope="session" documented in a previous link in this
> thread.
>
>            .bill



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: scope="session" client side configuraion

Posted by Vassilis Virvilis <v....@biovista.com>.
On Thursday 27 March 2008, Glen Mazza wrote:
> Actually, I didn't realize I had replied to you privately, something is
> strange with your email account--for a few accounts, including yours,
> when you hit "reply" it goes not to the list but to just back to the
> person.

I think that's normal. You need to hit reply-all in order to reply to the list
and to the person.
http://www.unicom.com/pw/reply-to-harmful.html

Anyway it *** works *** now. (that is with 2.0.4,
		 still crashes with 2.0.5 see other thread)

I was confused by the fact that 

  ClientInterface test = (ClientInterface) context.getBean("Client");

returns the same object every time you called it
and even if I set the scope to prototype (for the client)
looks like all the proxy object are using the same client / connection
aka session.

So I couldn't test the session scope from one java program but I could from
two or  a java program and a browser.

So the trick is to use tha jaxws frontend (doesn't work with simple client frontend)
and do

client side:
ClientInterface test = (ClientInterface) context.getBean("Client");
((BindingProvider) test).getRequestContext().put(
                BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

along with the scope="session" documented in a previous link in this thread.

           .bill

Re: scope="session" client side configuraion

Posted by Glen Mazza <gl...@verizon.net>.
Actually, I didn't realize I had replied to you privately, something is
strange with your email account--for a few accounts, including yours,
when you hit "reply" it goes not to the list but to just back to the
person.

I may be wrong about CXF not handling what you're asking for though. I'm
forwarding back to the list so somebody else can hopefully answer (I
don't know myself.)

Am Donnerstag, den 27.03.2008, 12:49 +0200 schrieb Vassilis Virvilis:
> On Wednesday 26 March 2008, Glen Mazza wrote:
> > Metro may be a little bit ahead of us with respect to stateful web
> 
> yest that's true. It was possible with axis and cxf looks much more advance
> at least from java first point of view
> 
> > service calls (which I believe is what you're ultimately asking for
> > here) -- see Kohsuke's blog entry here:
> > http://weblogs.java.net/blog/kohsuke/archive/2007/06/stateful_web_se_1.html
> > 
> > I do not know if this has been implemented in CXF, however.
> > 
> 
> Hi Glen,
> 
> thanks for answering (but why privately?)
> 
> What's the point then of
> 
> server side:
>        <bean id="ServerService" class="com.company.lib.Server" scope="session">
>                <aop:scoped-proxy />
>        </bean>
> 
> client side:
> 
> ((BindingProvider)proxy).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
> 
> Right now I am up to the point where the ws behaves like a singleton.
> 
> 	.bill