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 Mik Goodhelp <ws...@gmail.com> on 2005/04/21 14:21:02 UTC

How to pass information between handlers and services.

I am trying to implement  an application  that does the following.
Assume we have a client :

startSomething(XMLFLAG)
call.invoke(EndpointReference_1)
call.invoke(EndpointReference_2)
call.invoke(EndpointReference_3)

An Handler has to intercept the different calls and put the XMLFLAG in
the SOAPHeader of all the calls.

On the Provider  side an Handler has to intercept the call, get the
XMLFLAG from the SOAPHeader and pass it to the provider service.

In simple words there is a way to directly pass information between
Client-Services and Client-Handlers and between Provider-Handlers and
Provider-Services
???
Thanks in advance.

Re: How to pass information between handlers and services.

Posted by Mik Goodhelp <ws...@gmail.com>.
The idea is that to pass information to an handler from the client-Application
in such way that all subsequent service invocations will be intercepted,
then Information will be added into the SOAPHeader 
and  deliverd to different provider-services

It should like really like the following:
{
// one time passing the info to an Handler in the General chain
PassInformationToHandler( Info );

Service serice_1=new Service();
Service serice_2=new Service();
Service serice_3=new Service();
// Calls
Call call_1 = (Call) service_1.createCall();
Call call_2 = (Call) service_1.createCall();
...........

call_1.invoke(...)
call_2.invoke(...)
call_3.invoke(...)
}

////////////////////////// i don't want to do  something like the following :
{
...........
// Calls
Call call_1 = (Call) service_1.createCall();
Call call_2 = (Call) service_1.createCall();
...........
MessageContext messageContext_1 = call_1.getMessageContext() ;
MessageContext messageContext_2 = call_2.getMessageContext() ;
MessageContext messageContext_3 = call_3.getMessageContext() ;

messageContext_1.setProperty("MyInfo", Info );
messageContext_2.setProperty("MyInfo", Info );
messageContext_3.setProperty("MyInfo", Info );

call_1.invoke(...)
call_2.invoke(...)
call_3.invoke(...)

}

I was thinking at two ways  to solve this problem 
1) Making use of the singleton pattern. 
Exchanging information saving it into a singleton object, and sharing it.

2) Dynamically attaching an Handler to all the Services, 
passing the information each time the handler is attached (configured).
But this dynamic configuration works per service but i did'nt manage
to attach an Handler to all the services.

Any other idea ?

Thanks for the previous responses :)
 
  
 
On 4/21/05, mmalinos@aessuccess.org <mm...@aessuccess.org> wrote:
> You can pass information in the MessageContext itself using
> 
> the MessageContext.setProperty(String, Object) in the handler and then
> using
> the MessageContext.getProperty(String) in the Service or Client.
> 
> // Example Handler Code
>    public void invoke(MessageContext msgContext) throws AxisFault
>    {
>            System.out.println("Inside Handler");
>            msgContext.setProperty("SomeReference", "Some Text if String");
> // Could be any object not just string
>    }
> 
> // Example Service Code
> 
>      MessageContext ctx = MessageContext.getCurrentContext();
>      String SomeReference = (String) ctx.getProperty("SomeReference");
> 
>      System.out.println("SomeReference = " + SomeReference);  // You
> should get 'Some Text if String'
> 
> I've only tested this server side, but it should work client side as well.
> Hope this helps,
> Mark A. Malinoski
> AES/PHEAA
> Technical Coordinator/Web Development
> 717-720-2413
> mmalinos@aessuccess.org
> 
>             Robert Gombotz
>             <robert.gombotz@g
>             mail.com>                                                  To
>                                       axis-user@ws.apache.org, Mik
>             04/21/2005 09:34          Goodhelp <ws...@gmail.com>
>             AM                                                         cc
> 
>                                                                   Subject
>             Please respond to         Re: How to pass information between
>             axis-user@ws.apac         handlers and services.
>                  he.org
> 
> 
> as far as I know there is no way for a handler to talk to a WS
> directly. but you can get the message inside your WS implementation:
> 
> in your WS you can get the soap message using
> org.apache.axis.MessageContext.getCurrentContext() which gives you an
> object of type MessageContext. that you can use just like in your
> handlers, so just retrieve any info fram the message you want.
> 
> hope I could be of help.
> 
> Rob
> 
> On 4/21/05, Mik Goodhelp <ws...@gmail.com> wrote:
> > I am trying to implement  an application  that does the following.
> > Assume we have a client :
> >
> > startSomething(XMLFLAG)
> > call.invoke(EndpointReference_1)
> > call.invoke(EndpointReference_2)
> > call.invoke(EndpointReference_3)
> >
> > An Handler has to intercept the different calls and put the XMLFLAG in
> > the SOAPHeader of all the calls.
> >
> > On the Provider  side an Handler has to intercept the call, get the
> > XMLFLAG from the SOAPHeader and pass it to the provider service.
> >
> > In simple words there is a way to directly pass information between
> > Client-Services and Client-Handlers and between Provider-Handlers and
> > Provider-Services
> > ???
> > Thanks in advance.
> >
> 
>

Re: How to pass information between handlers and services.

Posted by mm...@aessuccess.org.
You can pass information in the MessageContext itself using

the MessageContext.setProperty(String, Object) in the handler and then
using
the MessageContext.getProperty(String) in the Service or Client.

// Example Handler Code
    public void invoke(MessageContext msgContext) throws AxisFault
    {
            System.out.println("Inside Handler");
            msgContext.setProperty("SomeReference", "Some Text if String");
// Could be any object not just string
    }

// Example Service Code

      MessageContext ctx = MessageContext.getCurrentContext();
      String SomeReference = (String) ctx.getProperty("SomeReference");

      System.out.println("SomeReference = " + SomeReference);  // You
should get 'Some Text if String'


I've only tested this server side, but it should work client side as well.
Hope this helps,
Mark A. Malinoski
AES/PHEAA
Technical Coordinator/Web Development
717-720-2413
mmalinos@aessuccess.org




                                                                           
             Robert Gombotz                                                
             <robert.gombotz@g                                             
             mail.com>                                                  To 
                                       axis-user@ws.apache.org, Mik        
             04/21/2005 09:34          Goodhelp <ws...@gmail.com>    
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: How to pass information between 
             axis-user@ws.apac         handlers and services.              
                  he.org                                                   
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




as far as I know there is no way for a handler to talk to a WS
directly. but you can get the message inside your WS implementation:

in your WS you can get the soap message using
org.apache.axis.MessageContext.getCurrentContext() which gives you an
object of type MessageContext. that you can use just like in your
handlers, so just retrieve any info fram the message you want.

hope I could be of help.

Rob


On 4/21/05, Mik Goodhelp <ws...@gmail.com> wrote:
> I am trying to implement  an application  that does the following.
> Assume we have a client :
>
> startSomething(XMLFLAG)
> call.invoke(EndpointReference_1)
> call.invoke(EndpointReference_2)
> call.invoke(EndpointReference_3)
>
> An Handler has to intercept the different calls and put the XMLFLAG in
> the SOAPHeader of all the calls.
>
> On the Provider  side an Handler has to intercept the call, get the
> XMLFLAG from the SOAPHeader and pass it to the provider service.
>
> In simple words there is a way to directly pass information between
> Client-Services and Client-Handlers and between Provider-Handlers and
> Provider-Services
> ???
> Thanks in advance.
>



Re: How to pass information between handlers and services.

Posted by Robert Gombotz <ro...@gmail.com>.
as far as I know there is no way for a handler to talk to a WS
directly. but you can get the message inside your WS implementation:

in your WS you can get the soap message using
org.apache.axis.MessageContext.getCurrentContext() which gives you an
object of type MessageContext. that you can use just like in your
handlers, so just retrieve any info fram the message you want.

hope I could be of help.

Rob


On 4/21/05, Mik Goodhelp <ws...@gmail.com> wrote:
> I am trying to implement  an application  that does the following.
> Assume we have a client :
> 
> startSomething(XMLFLAG)
> call.invoke(EndpointReference_1)
> call.invoke(EndpointReference_2)
> call.invoke(EndpointReference_3)
> 
> An Handler has to intercept the different calls and put the XMLFLAG in
> the SOAPHeader of all the calls.
> 
> On the Provider  side an Handler has to intercept the call, get the
> XMLFLAG from the SOAPHeader and pass it to the provider service.
> 
> In simple words there is a way to directly pass information between
> Client-Services and Client-Handlers and between Provider-Handlers and
> Provider-Services
> ???
> Thanks in advance.
>