1 package org.jacorb.orb.giop; 2 3 22 23 import java.io.*; 24 import java.util.*; 25 import org.jacorb.orb.CDROutputStream; 26 import org.jacorb.util.Time; 27 import org.omg.CONV_FRAME.*; 28 import org.omg.CORBA.MARSHAL ; 29 import org.omg.CORBA.PrincipalHelper; 30 import org.omg.GIOP.MsgType_1_1; 31 import org.omg.GIOP.TargetAddress; 32 import org.omg.GIOP.TargetAddressHelper; 33 import org.omg.IOP.INVOCATION_POLICIES; 34 import org.omg.IOP.ServiceContext ; 35 import org.omg.IOP.ServiceContextListHelper ; 36 import org.omg.Messaging.PolicyValue; 37 import org.omg.Messaging.PolicyValueSeqHelper; 38 import org.omg.Messaging.REPLY_END_TIME_POLICY_TYPE; 39 import org.omg.Messaging.REQUEST_END_TIME_POLICY_TYPE; 40 import org.omg.Messaging.REQUEST_START_TIME_POLICY_TYPE; 41 import org.omg.Messaging.SYNC_NONE; 42 import org.omg.Messaging.SYNC_WITH_SERVER; 43 import org.omg.Messaging.SYNC_WITH_TARGET; 44 import org.omg.Messaging.SYNC_WITH_TRANSPORT ; 45 import org.omg.TimeBase.UtcT; 46 47 52 public class RequestOutputStream 53 extends ServiceContextTransportingOutputStream 54 { 55 private static byte[] principal = new byte[ 0 ]; 56 private static byte[] reserved = new byte[ 3 ]; 57 58 private int request_id = -1; 59 private boolean response_expected = true; 60 private short syncScope = SYNC_WITH_SERVER.value; 61 private String operation = null; 62 63 67 private UtcT requestStartTime = null; 68 69 73 private UtcT requestEndTime = null; 74 75 79 private UtcT replyEndTime = null; 80 81 private org.jacorb.orb.dii.Request request = null; 82 83 private ClientConnection connection = null; 84 85 public RequestOutputStream( ClientConnection connection, 86 int request_id, 87 String operation, 88 boolean response_expected, 89 short syncScope, 90 UtcT requestStartTime, 91 UtcT requestEndTime, 92 UtcT replyEndTime, 93 byte[] object_key, 94 int giop_minor ) 95 { 96 super(); 97 98 setGIOPMinor( giop_minor ); 99 100 this.request_id = request_id; 101 this.response_expected = response_expected; 102 this.syncScope = syncScope; 103 this.operation = operation; 104 this.connection = connection; 105 106 this.requestStartTime = requestStartTime; 107 this.requestEndTime = requestEndTime; 108 this.replyEndTime = replyEndTime; 109 110 if (requestStartTime != null || 111 requestEndTime != null || 112 replyEndTime != null) 113 { 114 addServiceContext (createInvocationPolicies()); 115 } 116 117 writeGIOPMsgHeader( MsgType_1_1._Request, 118 giop_minor ); 119 120 switch( giop_minor ) 121 { 122 case 0 : 123 { 124 ServiceContextListHelper.write( this , Messages.service_context ); 126 write_ulong( request_id); 127 write_boolean( response_expected ); 128 write_long( object_key.length ); 129 write_octet_array( object_key, 0, object_key.length); 130 write_string( operation); 131 PrincipalHelper.write( this, principal); 132 133 break; 134 } 135 case 1 : 136 { 137 ServiceContextListHelper.write( this , Messages.service_context ); 139 write_ulong( request_id); 140 write_boolean( response_expected ); 141 write_long( object_key.length ); 142 write_octet_array( object_key, 0, object_key.length); 143 write_string( operation); 144 PrincipalHelper.write( this, principal); 145 146 break; 147 } 148 case 2 : 149 { 150 TargetAddress addr = new TargetAddress(); 152 addr.object_key( object_key ); 153 154 156 write_ulong( request_id); 157 if (response_expected) 158 { 159 write_octet ((byte)0x03); 160 } 161 else 162 { 163 switch (syncScope) 164 { 165 case SYNC_NONE.value: 166 case SYNC_WITH_TRANSPORT.value: 167 write_octet ((byte)0x00); 168 break; 169 case SYNC_WITH_SERVER.value: 170 write_octet ((byte)0x01); 171 break; 172 case SYNC_WITH_TARGET.value: 173 write_octet ((byte)0x03); 174 break; 175 default: 176 throw new MARSHAL ("Invalid SYNC_SCOPE: " + syncScope); 177 } 178 } 179 180 write_octet_array( reserved,0,3 ); 181 TargetAddressHelper.write( this, addr ); 182 write_string( operation ); 183 ServiceContextListHelper.write( this, Messages.service_context ); 184 185 markHeaderEnd(); 187 break; 188 } 189 default : 190 { 191 throw new MARSHAL ( "Unknown GIOP minor: " + giop_minor ); 192 } 193 } 194 } 195 196 public int requestId() 197 { 198 return request_id; 199 } 200 201 public boolean response_expected() 202 { 203 return response_expected; 204 } 205 206 public short syncScope() 207 { 208 return syncScope; 209 } 210 211 public String operation() 212 { 213 return operation; 214 } 215 216 public UtcT getReplyEndTime() 217 { 218 return replyEndTime; 219 } 220 221 public void setRequest(org.jacorb.orb.dii.Request request) 222 { 223 this.request = request; 224 } 225 226 public org.jacorb.orb.dii.Request getRequest() 227 { 228 return request; 229 } 230 231 public ClientConnection getConnection() 232 { 233 return connection; 234 } 235 236 240 public void write_to(GIOPConnection conn) throws IOException 241 { 242 if (!conn.isTCSNegotiated()) 243 { 244 CDROutputStream os = new CDROutputStream(); 246 os.beginEncapsulatedArray(); 247 CodeSetContextHelper.write 248 ( 249 os, 250 new CodeSetContext(conn.getTCS(), conn.getTCSW()) 251 ); 252 addServiceContext(new ServiceContext 253 ( 254 org.omg.IOP.CodeSets.value, 255 os.getBufferCopy() 256 )); 257 conn.markTCSNegotiated(); 258 } 259 super.write_to(conn); 260 } 261 262 266 private PolicyValue[] getTimingPolicyValues() 267 { 268 List l = new ArrayList(); 269 if (requestStartTime != null) 270 l.add (new PolicyValue (REQUEST_START_TIME_POLICY_TYPE.value, 271 Time.toCDR (requestStartTime))); 272 if (requestEndTime != null) 273 l.add (new PolicyValue (REQUEST_END_TIME_POLICY_TYPE.value, 274 Time.toCDR (requestEndTime))); 275 if (replyEndTime != null) 276 l.add (new PolicyValue (REPLY_END_TIME_POLICY_TYPE.value, 277 Time.toCDR (replyEndTime))); 278 return (PolicyValue[])l.toArray (new PolicyValue[0]); 279 } 280 281 private ServiceContext createInvocationPolicies() 282 { 283 CDROutputStream out = new CDROutputStream(); 284 out.beginEncapsulatedArray(); 285 PolicyValueSeqHelper.write(out, getTimingPolicyValues()); 286 return new ServiceContext (INVOCATION_POLICIES.value, 287 out.getBufferCopy()); 288 } 289 } 290 | Popular Tags |