KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > interceptor > iiop > SessionClientInterceptor


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * SessionClientInterceptor.java
20  *
21  * This interceptor is responsible for setting up the client side of the
22  * connection so that a session can be setup on the server side appropriatly.
23  */

24
25 // package path
26
package com.rift.coad.lib.interceptor.iiop;
27
28 // java imports
29
import java.util.MissingResourceException JavaDoc;
30 import org.omg.CORBA.TIMEOUT JavaDoc;
31 import org.omg.IOP.ServiceContext JavaDoc;
32 import org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc;
33 import org.omg.PortableInterceptor.ClientRequestInfo JavaDoc;
34 import org.omg.PortableInterceptor.ForwardRequest JavaDoc;
35 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
36
37 // logging import
38
import org.apache.log4j.Logger;
39
40 // coadunation imports
41
import com.rift.coad.lib.common.ObjectSerializer;
42 import com.rift.coad.lib.interceptor.credentials.Credential;
43 import com.rift.coad.lib.interceptor.InterceptorWrapper;
44 import com.rift.coad.lib.interceptor.ClientInterceptor;
45
46
47 /**
48  * This interceptor is responsible for setting up the client side of the
49  * connection so that a session can be setup on the server side appropriatly.
50  *
51  * @author Brett Chaldecott
52  */

53 public class SessionClientInterceptor extends InterceptorWrapper implements
54         ClientRequestInterceptor JavaDoc {
55     
56     // the class log variable
57
protected static Logger log =
58             Logger.getLogger(SessionClientInterceptor.class.getName());
59     /**
60      * Creates a new instance of SessionClientInterceptor
61      */

62     public SessionClientInterceptor(ORBInitInfo JavaDoc info) {
63     }
64     
65     
66     /**
67      * This method returns the name of this interceptor.
68      *
69      * @return A string containing the name of this interceptor.
70      */

71     public String JavaDoc name() {
72         return "SessionClientInterceptor";
73     }
74     
75     
76     /**
77      * This method is called to distory this object.
78      */

79     public void destroy() {
80         // do nothing for time being
81
}
82     
83     
84     /**
85      * Indicates to the interceptor that an exception occurred.
86      */

87     public void receive_exception(ClientRequestInfo JavaDoc ri) throws ForwardRequest JavaDoc {
88         
89     }
90     
91     
92     /**
93      * Allows an Interceptor to query the information available when a request
94      * results in something other than a normal reply or an exception.
95      */

96     public void receive_other(ClientRequestInfo JavaDoc ri) throws ForwardRequest JavaDoc {
97         
98     }
99     
100     
101     /**
102      * Allows an Interceptor to query the information on a reply after it is
103      * returned from the server and before control is returned to the client.
104      *
105      * @param ri The client request information.
106      * @exception ForwardRequest
107      */

108     public void receive_reply(ClientRequestInfo JavaDoc ri) {
109         
110     }
111     
112     
113     /**
114      * Allows an Interceptor to query information during a Time-Independent
115      * Invocation(TII) polling get reply sequence.
116      */

117     public void send_poll(ClientRequestInfo JavaDoc ri) throws TIMEOUT JavaDoc {
118         
119     }
120     
121     
122     /**
123      * Allows an Interceptor to query request information and modify the service
124      * context before the request is sent to the server.
125      */

126     public void send_request(ClientRequestInfo JavaDoc ri) throws ForwardRequest JavaDoc {
127         try {
128             log.debug("Send a request on the client side");
129             ClientInterceptor clientInterceptor = this.getClientInterceptor();
130             Credential credential = clientInterceptor.getSessionCredential();
131             ServiceContext JavaDoc securityContext = new ServiceContext JavaDoc(
132                     Constants.STANDARD_SECURITY_CONTEXT_ID,ObjectSerializer.
133                     serialize(credential));
134             ri.add_request_service_context(securityContext,true);
135         } catch (Exception JavaDoc ex) {
136             throw new SecurityInterceptorException(
137                     "Failed to setup the context for the call to the server : " +
138                     ex.getMessage(),ex);
139         }
140     }
141     
142 }
143
Popular Tags