1 26 27 package com.rift.coad.client.interceptor.iiop; 29 30 import java.io.ByteArrayInputStream ; 32 import java.io.ByteArrayOutputStream ; 33 import java.io.ObjectInputStream ; 34 import java.io.ObjectOutputStream ; 35 import java.util.MissingResourceException ; 36 import org.omg.CORBA.TIMEOUT ; 37 import org.omg.CORBA.LocalObject ; 38 import org.omg.IOP.ServiceContext ; 39 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 40 import org.omg.PortableInterceptor.ClientRequestInfo ; 41 import org.omg.PortableInterceptor.ForwardRequest ; 42 import org.omg.PortableInterceptor.ORBInitInfo ; 43 44 import org.apache.log4j.Logger; 46 47 import com.rift.coad.lib.interceptor.credentials.Login; 49 import com.rift.coad.client.naming.CoadunationInitialContextFactory; 50 51 57 public class ClientPasswordInterceptor extends LocalObject implements 58 ClientRequestInterceptor { 59 60 protected static Logger log = 62 Logger.getLogger(ClientPasswordInterceptor.class.getName()); 63 64 67 public ClientPasswordInterceptor() { 68 } 69 70 75 public String name() { 76 return "SessionClientInterceptor"; 77 } 78 79 80 83 public void destroy() { 84 } 86 87 88 91 public void receive_exception(ClientRequestInfo ri) throws ForwardRequest { 92 93 } 94 95 96 100 public void receive_other(ClientRequestInfo ri) throws ForwardRequest { 101 102 } 103 104 105 112 public void receive_reply(ClientRequestInfo ri) { 113 114 } 115 116 117 121 public void send_poll(ClientRequestInfo ri) throws TIMEOUT { 122 123 } 124 125 126 130 public void send_request(ClientRequestInfo ri) throws ForwardRequest { 131 try { 132 log.debug("Send a request on the client side"); 133 Login login = (Login)CoadunationInitialContextFactory.userLogin.get(); 134 if (login != null) { 135 ServiceContext securityContext = new ServiceContext ( 136 101,serialize((java.io.Serializable )login)); 137 ri.add_request_service_context(securityContext,true); 138 } 139 log.debug("After add the request to the context"); 140 } catch (Exception ex) { 141 log.error("Failed to set the service context : " + ex.getMessage(), 142 ex); 143 } 144 } 145 146 153 public byte[] serialize(Object ref) throws Exception { 154 try { 155 if (!(ref instanceof java.io.Serializable )) { 156 throw new Exception ("This object is not serializable. " + 157 "Must implement from java.io.Serializable."); 158 } 159 ByteArrayOutputStream byteOutput = new ByteArrayOutputStream (); 160 ObjectOutputStream objOutput = new ObjectOutputStream (byteOutput); 161 objOutput.writeObject(ref); 162 objOutput.flush(); 163 objOutput.close(); 164 return byteOutput.toByteArray(); 165 } catch (Exception ex) { 166 throw new Exception ("Failed to serialize the object : " + 167 ex.getMessage(),ex); 168 } 169 } 170 } 171 | Popular Tags |