KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > remoting > jmx > RequestChannelInterceptorInvoker


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.security.remoting.jmx;
19
20 import java.io.IOException JavaDoc;
21 import java.io.Serializable JavaDoc;
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 /**
34  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
35  */

36 public class RequestChannelInterceptorInvoker implements RequestListener {
37
38     private static final Log log = LogFactory.getLog(RequestChannelInterceptorInvoker.class);
39
40     private ClassLoader JavaDoc classloader;
41     private Interceptor next;
42
43     public RequestChannelInterceptorInvoker(Interceptor next, ClassLoader JavaDoc classloader) {
44         this.next = next;
45         this.classloader = classloader;
46     }
47
48     public static class ThrowableWrapper implements Serializable JavaDoc {
49         private static final long serialVersionUID = 3905243428970182455L;
50         ThrowableWrapper(Throwable JavaDoc exception) {
51             this.exception = exception;
52         }
53         public Throwable JavaDoc exception;
54     }
55
56     public ClassLoader JavaDoc getClassloader() {
57         return classloader;
58     }
59
60     public void setClassloader(ClassLoader JavaDoc classloader) {
61         this.classloader = classloader;
62     }
63
64     public Packet onRequest(Packet request) {
65         Thread JavaDoc currentThread = Thread.currentThread();
66         ClassLoader JavaDoc 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 JavaDoc e) {
75                 // Could not deserialize the invocation...
76
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 JavaDoc e) {
84                 return RequestChannelInterceptor.serialize(new ThrowableWrapper(e));
85             }
86
87
88         } catch (IOException JavaDoc e) {
89             // TODO: handle this.
90
return EmptyPacket.EMPTY_PACKET;
91         } finally {
92             currentThread.setContextClassLoader(orig);
93         }
94     }
95
96     public void onRquestError(IOException JavaDoc error) {
97         log.error("Request Error", error);
98     }
99
100 }
101
Popular Tags