1 21 package org.jacorb.orb; 22 23 import java.util.Enumeration ; 24 25 import org.apache.avalon.framework.logger.*; 26 27 import org.jacorb.orb.giop.*; 28 import org.jacorb.orb.portableInterceptor.*; 29 30 import org.omg.CORBA.portable.ApplicationException ; 31 import org.omg.CORBA.portable.RemarshalException ; 32 import org.omg.IOP.ServiceContext ; 33 import org.omg.GIOP.ReplyHeader_1_2; 34 import org.omg.GIOP.ReplyStatusType_1_2; 35 import org.omg.PortableInterceptor.*; 36 37 44 public class ClientInterceptorHandler 45 { 46 private ClientRequestInfoImpl info = null; 47 private Logger logger; 48 49 55 public ClientInterceptorHandler 56 ( org.jacorb.orb.ORB orb, 57 org.jacorb.orb.giop.RequestOutputStream ros, 58 org.omg.CORBA.Object self, 59 org.jacorb.orb.Delegate delegate, 60 org.jacorb.orb.ParsedIOR piorOriginal, 61 org.jacorb.orb.giop.ClientConnection connection ) 62 { 63 if ( orb.hasClientRequestInterceptors() ) 64 { 65 info = new ClientRequestInfoImpl ( orb, ros, self, delegate, 66 piorOriginal, connection ); 67 } 68 logger = 69 orb.getConfiguration().getNamedLogger("jacorb.orb.client_interceptors"); 70 } 71 72 public void handle_send_request() throws RemarshalException 73 { 74 if ( info != null ) 75 { 76 invokeInterceptors ( info, ClientInterceptorIterator.SEND_REQUEST ); 77 78 Enumeration ctx = info.getRequestServiceContexts(); 80 81 while ( ctx.hasMoreElements() ) 82 { 83 info.request_os.addServiceContext 84 ( ( ServiceContext ) ctx.nextElement() ); 85 } 86 } 87 } 88 89 public void handle_location_forward ( ReplyInputStream reply, 90 org.omg.CORBA.Object forward_reference ) 91 throws RemarshalException 92 { 93 if ( info != null ) 94 { 95 info.setReplyStatus (LOCATION_FORWARD.value); 96 info.setReplyServiceContexts( reply.rep_hdr.service_context ); 97 98 info.setForwardReference (forward_reference); 99 100 info.reply_is = reply; 102 103 invokeInterceptors( info, 104 ClientInterceptorIterator.RECEIVE_OTHER ); 105 } 106 } 107 108 public void handle_receive_reply ( ReplyInputStream reply ) 109 throws RemarshalException 110 { 111 if ( info != null ) 112 { 113 ReplyHeader_1_2 header = reply.rep_hdr; 114 115 if ( header.reply_status.value() == ReplyStatusType_1_2._NO_EXCEPTION ) 116 { 117 info.setReplyStatus (SUCCESSFUL.value); 118 119 info.setReplyServiceContexts( header.service_context ); 120 121 if ( info.request_os.getRequest() == null ) 126 { 127 InterceptorManager manager = info.orb.getInterceptorManager(); 128 info.setCurrent (manager.getCurrent()); 129 130 info.reply_is = reply; 132 133 invokeInterceptors( info, 134 ClientInterceptorIterator.RECEIVE_REPLY ); 135 } 136 else 137 info.request_os.getRequest().setInfo( info ); 138 } 139 } 140 } 141 142 public void handle_receive_other ( short reply_status ) 143 throws RemarshalException 144 { 145 if ( info != null ) 146 { 147 info.setReplyStatus (reply_status); 148 invokeInterceptors ( info, ClientInterceptorIterator.RECEIVE_OTHER ); 149 } 150 } 151 152 public void handle_receive_exception ( org.omg.CORBA.SystemException ex ) 153 throws RemarshalException 154 { 155 handle_receive_exception ( ex, null ); 156 } 157 158 public void handle_receive_exception ( org.omg.CORBA.SystemException ex, 159 ReplyInputStream reply ) 160 throws RemarshalException 161 { 162 if ( info != null ) 163 { 164 SystemExceptionHelper.insert ( info.received_exception, ex ); 165 try 166 { 167 info.received_exception_id = 168 SystemExceptionHelper.type ( ex ).id(); 169 } 170 catch ( org.omg.CORBA.TypeCodePackage.BadKind bk ) 171 { 172 if (logger.isDebugEnabled()) 173 logger.debug("BadKind: " + bk.getMessage()); 174 } 175 info.setReplyStatus (SYSTEM_EXCEPTION.value); 176 177 if ( reply != null ) 178 { 179 info.setReplyServiceContexts ( reply.rep_hdr.service_context ); 180 info.reply_is = reply; 181 } 182 183 invokeInterceptors ( info, 184 ClientInterceptorIterator.RECEIVE_EXCEPTION ); 185 } 186 } 187 188 public void handle_receive_exception ( ApplicationException ex, 189 ReplyInputStream reply ) 190 throws RemarshalException 191 { 192 if ( info != null ) 193 { 194 info.received_exception_id = ex.getId(); 195 try 196 { 197 ApplicationExceptionHelper.insert( info.received_exception, 198 ex ); 199 } 200 catch ( Exception e ) 201 { 202 if (logger.isDebugEnabled()) 203 logger.debug(e.getMessage()); 204 SystemExceptionHelper.insert ( info.received_exception, 205 new org.omg.CORBA.UNKNOWN 206 ( e.getMessage() ) ); 207 } 208 info.setReplyStatus (USER_EXCEPTION.value); 209 210 try 211 { 212 reply.reset(); 213 } 214 catch ( Exception e ) 215 { 216 if (logger.isWarnEnabled()) 218 logger.warn(e.getMessage()); 219 } 220 221 info.setReplyServiceContexts ( reply.rep_hdr.service_context ); 222 info.reply_is = reply; 223 224 invokeInterceptors ( info, 225 ClientInterceptorIterator.RECEIVE_EXCEPTION ); 226 } 227 } 228 229 private void invokeInterceptors( ClientRequestInfoImpl info, short op ) 230 throws RemarshalException 231 { 232 ClientInterceptorIterator intercept_iter = 233 info.orb.getInterceptorManager().getClientIterator(); 234 235 try 236 { 237 intercept_iter.iterate( info, op ); 238 } 239 catch ( org.omg.PortableInterceptor.ForwardRequest fwd ) 240 { 241 info.delegate.rebind( info.orb.object_to_string( fwd.forward ) ); 242 throw new RemarshalException (); 243 } 244 catch ( org.omg.CORBA.UserException ue ) 245 { 246 if (logger.isWarnEnabled()) 247 logger.warn("UserException: " + ue.getMessage()); 248 } 249 } 250 251 252 } 253 | Popular Tags |