1 17 18 package org.apache.geronimo.security.remoting.jmx; 19 20 import java.io.IOException ; 21 import java.io.Serializable ; 22 23 import org.activeio.Packet; 24 import org.activeio.RequestListener; 25 import org.activeio.packet.EmptyPacket; 26 27 import org.apache.geronimo.interceptor.Interceptor; 28 import org.apache.geronimo.interceptor.Invocation; 29 import org.apache.geronimo.interceptor.InvocationResult; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 36 public class RequestChannelInterceptorInvoker implements RequestListener { 37 38 private static final Log log = LogFactory.getLog(RequestChannelInterceptorInvoker.class); 39 40 private ClassLoader classloader; 41 private Interceptor next; 42 43 public RequestChannelInterceptorInvoker(Interceptor next, ClassLoader classloader) { 44 this.next = next; 45 this.classloader = classloader; 46 } 47 48 public static class ThrowableWrapper implements Serializable { 49 private static final long serialVersionUID = 3905243428970182455L; 50 ThrowableWrapper(Throwable exception) { 51 this.exception = exception; 52 } 53 public Throwable exception; 54 } 55 56 public ClassLoader getClassloader() { 57 return classloader; 58 } 59 60 public void setClassloader(ClassLoader classloader) { 61 this.classloader = classloader; 62 } 63 64 public Packet onRequest(Packet request) { 65 Thread currentThread = Thread.currentThread(); 66 ClassLoader orig = currentThread.getContextClassLoader(); 67 try { 68 69 Invocation marshalledInvocation; 70 71 try { 72 currentThread.setContextClassLoader(classloader); 73 marshalledInvocation = (Invocation) RequestChannelInterceptor.deserialize(request,classloader); 74 } catch (Throwable e) { 75 log.error("Could not deserialize the invocation", e); 77 return RequestChannelInterceptor.serialize(new ThrowableWrapper(e)); 78 } 79 80 try { 81 InvocationResult rc = next.invoke(marshalledInvocation); 82 return RequestChannelInterceptor.serialize(rc); 83 } catch (Throwable e) { 84 return RequestChannelInterceptor.serialize(new ThrowableWrapper(e)); 85 } 86 87 88 } catch (IOException e) { 89 return EmptyPacket.EMPTY_PACKET; 91 } finally { 92 currentThread.setContextClassLoader(orig); 93 } 94 } 95 96 public void onRquestError(IOException error) { 97 log.error("Request Error", error); 98 } 99 100 } 101 | Popular Tags |