package demo.interceptors.proprietary;

/**
 * An example message-level interceptor
 * The interceptor reverses the contents of any
 * message after the GIOP message header
 *
*/

import jacorb.util.Debug;

public class ServerMessageInterceptor
    implements jacorb.orb.ServerMessageInterceptor
{
    public org.omg.CORBA.ORB orb;

    public  byte [] post_invoke( byte [] buf )
    {
		// don't do anything here
		Debug.output(1,"ServerMessageInterceptor.post_invoke");
		return buf;
    }

    public  byte [] pre_invoke( byte [] buf )
    {
	try
	{
	    org.omg.PortableServer.Current poa_current = org.omg.PortableServer.CurrentHelper.narrow( 
																								 orb.resolve_initial_references("POACurrent"));
	    System.out.println("ServerMessageInterceptor.pre for oid: " + poa_current.get_object_id());
	}
	catch ( Exception e )
	{
	    e.printStackTrace();
	}


	//	byte buf2[] = new byte[buf.length];

	Debug.output(1,"ServerMessageInterceptor.pre_invoke");
	return buf;

	// copy GIOP message header 
	//	System.arraycopy( buf, 0, buf2, 0, 12 );

	//	Environment.output(1,"decoding...");

	// reverse rest of message
	//	for( int i = 12; i < buf.length; i++ )
	//	    buf2[i] = buf[ buf.length+11-i ];

	//	return buf2;
    }
}


