Hi Chris,

Chris Thatcher wrote:
> Just spouting this off the top of my head (or pulling it out of my ...;) but
> there is always an implementing class for the service, and somewhere in the
> handler chain that class is resolved to an instance, which may be new for
> each call, live across a session, or be a persistent instance of the service.
> Regardless, what about putting a getter/setter for message context in the
> service impl class and then shouldn't it be possible to create a handler that
> is invoked after the servicecall-to-instance resolution (is the the
> 'dispatch' phase? Anyone know for sure?) that injects the message context
> into the service impl for you?
> 
> Micheal, this is probably close to what you annotation does?  If so I
> actually be interested the details of how it is accomplished.

I think I did more or less exactly what you described - I wrote my own
ObjectInvoker - I attached it to this mail, together with the Annotation
Interface.

Then you do something like the following in you server environment:
    ...
    JaxbServiceFactory sf = new JaxbServiceFactory();
    Service svc           = sf.create( ServiceImpl.class );
    svc.setInvoker( new MyObjectInvoker() );
    XFire xfire = XFireFactory.newInstance().getXFire();
    xfire.getServiceRegistry().register( service );
    ...


Cheers,
Michel

-- 
Michel <dot> Drescher <at> uk <dot> fujitsu <dot> com
Fujitsu Laboratories of Europe
+44 20 8606 4834
package com.fujitsu.arcon.xfire;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.fault.XFireFault;
import org.codehaus.xfire.service.invoker.ApplicationScopePolicy;
import org.codehaus.xfire.service.invoker.ObjectInvoker;

/**
 * @author mDrescher
 *
 */
public class MyObjectInvoker extends ObjectInvoker {
        
        public static final String MSG_CONTEXT_REQIRED = 
"com.fuitsu.arcon.xfire.MsgContextRequired";

        public MyObjectInvoker() {
                super( ApplicationScopePolicy.instance() );
        }

    public Object invoke(Method m, Object[] params, MessageContext context)
    throws XFireFault {
        boolean setMessageContext = false;
        Field msgCtxField = null;
        /** Check the flag whether a MessageContext is requested by the service 
object **/
        Object serviceObject = getServiceObject(context);
        MsgContext mcAnnot = 
serviceObject.getClass().getAnnotation(MsgContext.class);
        msgCtxField = getMsgContext(serviceObject.getClass());
        if ( mcAnnot != null && msgCtxField != null ) {
                setMessageContext = true;
        }
        
        /** if we need to set the message context, then do so! **/
        if ( setMessageContext ) {
                try {
                        msgCtxField.set( serviceObject, context );
                }
                catch ( Exception e ) {
                        throw new XFireFault(e);
                }
        }
        
        // then invoke the super implementation
        return super.invoke( m, params, context);
    }

    /**
     * Attempts to retrieve a field of type org.codehaus.xfire.MessageContext 
from the given class.
     * 
     * @param clazz The class to reflect
     * @return the field, <code>null</code> otherwise.
     */
    private Field getMsgContext( Class clazz ) {
        Field[] fields = clazz.getDeclaredFields();
        for (int i=0; i<fields.length; i++) {
                if (fields[i].getType() == 
org.codehaus.xfire.MessageContext.class )
                        return fields[i];
        }
        return null;
    }
}
package com.fujitsu.arcon.xfire;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author mDrescher
 *
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface MsgContext {

}
---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to