38 |
|
|
39 |
package gnu.CORBA; |
package gnu.CORBA; |
40 |
|
|
41 |
import gnu.CORBA.CDR.cdrBufInput; |
import gnu.CORBA.CDR.BufferredCdrInput; |
42 |
import gnu.CORBA.CDR.cdrBufOutput; |
import gnu.CORBA.CDR.BufferedCdrOutput; |
43 |
import gnu.CORBA.GIOP.MessageHeader; |
import gnu.CORBA.GIOP.MessageHeader; |
44 |
import gnu.CORBA.GIOP.ReplyHeader; |
import gnu.CORBA.GIOP.ReplyHeader; |
45 |
import gnu.CORBA.GIOP.RequestHeader; |
import gnu.CORBA.GIOP.RequestHeader; |
46 |
import gnu.CORBA.GIOP.cxCodeSet; |
import gnu.CORBA.GIOP.CodeSetServiceContext; |
47 |
import gnu.CORBA.Interceptor.gnuClientRequestInfo; |
import gnu.CORBA.Interceptor.gnuClientRequestInfo; |
48 |
import gnu.CORBA.Poa.ORB_1_4; |
import gnu.CORBA.Poa.ORB_1_4; |
49 |
|
|
54 |
import org.omg.CORBA.BAD_INV_ORDER; |
import org.omg.CORBA.BAD_INV_ORDER; |
55 |
import org.omg.CORBA.BAD_PARAM; |
import org.omg.CORBA.BAD_PARAM; |
56 |
import org.omg.CORBA.Bounds; |
import org.omg.CORBA.Bounds; |
57 |
|
import org.omg.CORBA.COMM_FAILURE; |
58 |
import org.omg.CORBA.CompletionStatus; |
import org.omg.CORBA.CompletionStatus; |
59 |
import org.omg.CORBA.Context; |
import org.omg.CORBA.Context; |
60 |
import org.omg.CORBA.ContextList; |
import org.omg.CORBA.ContextList; |
135 |
/** |
/** |
136 |
* The empty byte array. |
* The empty byte array. |
137 |
*/ |
*/ |
138 |
private static final binaryReply EMPTY = |
private static final RawReply EMPTY = |
139 |
new binaryReply(null, new MessageHeader(), new byte[ 0 ]); |
new RawReply(null, new MessageHeader(), new byte[ 0 ]); |
140 |
|
|
141 |
/** |
/** |
142 |
* The context holder for methods ctx(Context) and ctx(). |
* The context holder for methods ctx(Context) and ctx(). |
223 |
* The request arguments in the case when they are directly written into the |
* The request arguments in the case when they are directly written into the |
224 |
* parameter buffer. |
* parameter buffer. |
225 |
*/ |
*/ |
226 |
protected streamRequest m_parameter_buffer; |
protected StreamBasedRequest m_parameter_buffer; |
227 |
|
|
228 |
/** |
/** |
229 |
* The array of slots. |
* The array of slots. |
295 |
orb = an_orb; |
orb = an_orb; |
296 |
|
|
297 |
// Take the interceptor from the ORB. |
// Take the interceptor from the ORB. |
298 |
if (orb instanceof Restricted_ORB) |
if (orb instanceof OrbRestricted) |
299 |
m_interceptor = ((Restricted_ORB) orb).iClient; |
m_interceptor = ((OrbRestricted) orb).iClient; |
300 |
|
|
301 |
if (m_interceptor != null && orb instanceof ORB_1_4) |
if (m_interceptor != null && orb instanceof ORB_1_4) |
302 |
{ |
{ |
333 |
* Get the parameter stream, where the invocation arguments should be written |
* Get the parameter stream, where the invocation arguments should be written |
334 |
* if they are written into the stream directly. |
* if they are written into the stream directly. |
335 |
*/ |
*/ |
336 |
public streamRequest getParameterStream() |
public StreamBasedRequest getParameterStream() |
337 |
{ |
{ |
338 |
m_parameter_buffer = new streamRequest(); |
m_parameter_buffer = new StreamBasedRequest(); |
339 |
m_parameter_buffer.request = this; |
m_parameter_buffer.request = this; |
340 |
m_parameter_buffer.setVersion(ior.Internet.version); |
m_parameter_buffer.setVersion(ior.Internet.version); |
341 |
m_parameter_buffer.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets)); |
m_parameter_buffer.setCodeSet(CodeSetServiceContext.negotiate(ior.Internet.CodeSets)); |
342 |
m_parameter_buffer.setOrb(orb); |
m_parameter_buffer.setOrb(orb); |
343 |
m_parameter_buffer.setBigEndian(Big_endian); |
m_parameter_buffer.setBigEndian(Big_endian); |
344 |
|
|
346 |
// correctly. |
// correctly. |
347 |
if (ior.Internet.version.until_inclusive(1, 1)) |
if (ior.Internet.version.until_inclusive(1, 1)) |
348 |
{ |
{ |
349 |
cdrBufOutput measure = new cdrBufOutput(); |
BufferedCdrOutput measure = new BufferedCdrOutput(); |
350 |
measure.setOffset(12); |
measure.setOffset(12); |
351 |
if (m_rqh == null) |
if (m_rqh == null) |
352 |
m_rqh = new gnu.CORBA.GIOP.v1_0.RequestHeader(); |
m_rqh = new gnu.CORBA.GIOP.v1_0.RequestHeader(); |
514 |
try |
try |
515 |
{ |
{ |
516 |
ObjectImpl impl = (ObjectImpl) e.forward; |
ObjectImpl impl = (ObjectImpl) e.forward; |
517 |
Simple_delegate delegate = |
SimpleDelegate delegate = |
518 |
(Simple_delegate) impl._get_delegate(); |
(SimpleDelegate) impl._get_delegate(); |
519 |
ior = delegate.getIor(); |
ior = delegate.getIor(); |
520 |
} |
} |
521 |
catch (Exception ex) |
catch (Exception ex) |
715 |
/** |
/** |
716 |
* Do the actual invocation. This implementation requires to set the IOR |
* Do the actual invocation. This implementation requires to set the IOR |
717 |
* property ({@link #setIOR(IOR)} before calling this method. |
* property ({@link #setIOR(IOR)} before calling this method. |
718 |
* |
* |
719 |
* @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously set |
* @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously set |
720 |
* or if the direct argument addition is mixed with the direct argument |
* or if the direct argument addition is mixed with the direct argument |
721 |
* writing into the output stream. |
* writing into the output stream. |
722 |
* |
* |
723 |
* @return the server response in binary form. |
* @return the server response in binary form. |
724 |
*/ |
*/ |
725 |
public synchronized binaryReply submit() throws ForwardRequest |
public synchronized RawReply submit() |
726 |
|
throws ForwardRequest |
727 |
{ |
{ |
728 |
gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader(); |
gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader(); |
729 |
|
|
744 |
m_interceptor.send_request(m_info); |
m_interceptor.send_request(m_info); |
745 |
|
|
746 |
// Prepare the submission. |
// Prepare the submission. |
747 |
cdrBufOutput request_part = new cdrBufOutput(); |
BufferedCdrOutput request_part = new BufferedCdrOutput(); |
748 |
|
|
749 |
request_part.setOffset(header.getHeaderSize()); |
request_part.setOffset(header.getHeaderSize()); |
750 |
request_part.setVersion(header.version); |
request_part.setVersion(header.version); |
751 |
request_part.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets)); |
request_part.setCodeSet(CodeSetServiceContext.negotiate(ior.Internet.CodeSets)); |
752 |
request_part.setOrb(orb); |
request_part.setOrb(orb); |
753 |
request_part.setBigEndian(header.isBigEndian()); |
request_part.setBigEndian(header.isBigEndian()); |
754 |
|
|
755 |
// This also sets the stream encoding to the encoding, specified |
// This also sets the stream encoding to the encoding, specified |
756 |
// in the header. |
// in the header. |
757 |
rh.write(request_part); |
rh.write(request_part); |
758 |
|
|
759 |
if (m_args != null && m_args.count() > 0) |
if (m_args != null && m_args.count() > 0) |
760 |
{ |
{ |
761 |
write_parameters(header, request_part); |
write_parameters(header, request_part); |
762 |
|
|
763 |
if (m_parameter_buffer != null) |
if (m_parameter_buffer != null) |
764 |
throw new BAD_INV_ORDER("Please either add parameters or " + |
throw new BAD_INV_ORDER("Please either add parameters or " |
765 |
"write them into stream, but not both " + "at once." |
+ "write them into stream, but not both " + "at once."); |
|
); |
|
766 |
} |
} |
767 |
|
|
768 |
if (m_parameter_buffer != null) |
if (m_parameter_buffer != null) |
790 |
{ |
{ |
791 |
// The BindException may be thrown under very heavy parallel |
// The BindException may be thrown under very heavy parallel |
792 |
// load. For some time, just wait, exceptiong the socket to free. |
// load. For some time, just wait, exceptiong the socket to free. |
793 |
Open: |
Open: for (int i = 0; i < PAUSE_STEPS; i++) |
|
for (int i = 0; i < PAUSE_STEPS; i++) |
|
794 |
{ |
{ |
795 |
try |
try |
796 |
{ |
{ |
797 |
socket = new Socket(ior.Internet.host, ior.Internet.port); |
if (orb instanceof OrbFunctional) |
798 |
|
socket = ((OrbFunctional) orb).socketFactory.createClientSocket( |
799 |
|
ior.Internet.host, ior.Internet.port); |
800 |
|
else |
801 |
|
socket = new Socket(ior.Internet.host, ior.Internet.port); |
802 |
break Open; |
break Open; |
803 |
} |
} |
804 |
catch (BindException ex) |
catch (BindException ex) |
820 |
} |
} |
821 |
|
|
822 |
if (socket == null) |
if (socket == null) |
823 |
throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port + |
throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port |
824 |
" in use" |
+ " in use"); |
|
); |
|
825 |
socket.setKeepAlive(true); |
socket.setKeepAlive(true); |
826 |
|
|
827 |
OutputStream socketOutput = socket.getOutputStream(); |
OutputStream socketOutput = socket.getOutputStream(); |
839 |
InputStream socketInput = socket.getInputStream(); |
InputStream socketInput = socket.getInputStream(); |
840 |
response_header.read(socketInput); |
response_header.read(socketInput); |
841 |
|
|
842 |
byte[] r = new byte[ response_header.message_size ]; |
byte[] r; |
843 |
int n = 0; |
if (orb instanceof OrbFunctional) |
|
reading: |
|
|
while (n < r.length) |
|
844 |
{ |
{ |
845 |
n += socketInput.read(r, n, r.length - n); |
OrbFunctional fo = (OrbFunctional) orb; |
846 |
|
r = response_header.readMessage(socketInput, socket, |
847 |
|
fo.TOUT_WHILE_READING, fo.TOUT_AFTER_RECEIVING); |
848 |
} |
} |
849 |
return new binaryReply(orb, response_header, r); |
else |
850 |
|
r = response_header.readMessage(socketInput, null, 0, 0); |
851 |
|
|
852 |
|
return new RawReply(orb, response_header, r); |
853 |
} |
} |
854 |
else |
else |
855 |
return EMPTY; |
return EMPTY; |
856 |
} |
} |
857 |
catch (IOException io_ex) |
catch (IOException io_ex) |
858 |
{ |
{ |
859 |
MARSHAL m = |
COMM_FAILURE m = new COMM_FAILURE("Unable to open a socket at " |
860 |
new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" + |
+ ior.Internet.host + ":" + ior.Internet.port, 0xC9, |
861 |
ior.Internet.port, 10000 + ior.Internet.port, |
CompletionStatus.COMPLETED_NO); |
|
CompletionStatus.COMPLETED_NO |
|
|
); |
|
862 |
m.initCause(io_ex); |
m.initCause(io_ex); |
863 |
throw m; |
throw m; |
864 |
} |
} |
868 |
{ |
{ |
869 |
if (socket != null && !socket.isClosed()) |
if (socket != null && !socket.isClosed()) |
870 |
{ |
{ |
871 |
socket.setSoTimeout(Functional_ORB.TANDEM_REQUESTS); |
socket.setSoTimeout(OrbFunctional.TANDEM_REQUESTS); |
872 |
SocketRepository.put_socket(key, socket); |
SocketRepository.put_socket(key, socket); |
873 |
} |
} |
874 |
} |
} |
933 |
* Do actual invocation. This method recursively calls itself if the |
* Do actual invocation. This method recursively calls itself if the |
934 |
* redirection is detected. |
* redirection is detected. |
935 |
*/ |
*/ |
936 |
private void p_invoke() throws SystemException, ForwardRequest |
private void p_invoke() |
937 |
|
throws SystemException, ForwardRequest |
938 |
{ |
{ |
939 |
binaryReply response = submit(); |
RawReply response = submit(); |
940 |
|
|
941 |
if (m_rph == null) |
if (m_rph == null) |
942 |
m_rph = response.header.create_reply_header(); |
m_rph = response.header.create_reply_header(); |
943 |
|
|
944 |
cdrBufInput input = response.getStream(); |
BufferredCdrInput input = response.getStream(); |
945 |
input.setOrb(orb); |
input.setOrb(orb); |
946 |
|
|
947 |
m_rph.read(input); |
m_rph.read(input); |
951 |
|
|
952 |
switch (m_rph.reply_status) |
switch (m_rph.reply_status) |
953 |
{ |
{ |
954 |
case ReplyHeader.NO_EXCEPTION : |
case ReplyHeader.NO_EXCEPTION: |
955 |
|
|
956 |
NamedValue arg; |
NamedValue arg; |
957 |
|
|
997 |
|
|
998 |
break; |
break; |
999 |
|
|
1000 |
case ReplyHeader.SYSTEM_EXCEPTION : |
case ReplyHeader.SYSTEM_EXCEPTION: |
1001 |
if (align) |
if (align) |
1002 |
{ |
{ |
1003 |
input.align(8); |
input.align(8); |
1005 |
} |
} |
1006 |
readExceptionId(input); |
readExceptionId(input); |
1007 |
|
|
1008 |
m_sys_ex = ObjectCreator.readSystemException(input); |
m_sys_ex = ObjectCreator.readSystemException(input, |
1009 |
|
m_rph.service_context); |
1010 |
m_environment.exception(m_sys_ex); |
m_environment.exception(m_sys_ex); |
1011 |
|
|
1012 |
if (m_interceptor != null) |
if (m_interceptor != null) |
1014 |
|
|
1015 |
throw m_sys_ex; |
throw m_sys_ex; |
1016 |
|
|
1017 |
case ReplyHeader.USER_EXCEPTION : |
case ReplyHeader.USER_EXCEPTION: |
1018 |
if (align) |
if (align) |
1019 |
{ |
{ |
1020 |
input.align(8); |
input.align(8); |
1026 |
gnuAny exc = new gnuAny(); |
gnuAny exc = new gnuAny(); |
1027 |
exc.setOrb(orb); |
exc.setOrb(orb); |
1028 |
|
|
1029 |
exc.insert_Streamable(new streamReadyHolder(input)); |
exc.insert_Streamable(new StreamHolder(input)); |
1030 |
|
|
1031 |
UnknownUserException unuex = new UnknownUserException(exc); |
UnknownUserException unuex = new UnknownUserException(exc); |
1032 |
m_environment.exception(unuex); |
m_environment.exception(unuex); |
1036 |
|
|
1037 |
break; |
break; |
1038 |
|
|
1039 |
case ReplyHeader.LOCATION_FORWARD_PERM : |
case ReplyHeader.LOCATION_FORWARD_PERM: |
1040 |
case ReplyHeader.LOCATION_FORWARD : |
case ReplyHeader.LOCATION_FORWARD: |
1041 |
if (response.header.version.since_inclusive(1, 2)) |
if (response.header.version.since_inclusive(1, 2)) |
1042 |
input.align(8); |
input.align(8); |
1043 |
|
|
1049 |
catch (IOException ex) |
catch (IOException ex) |
1050 |
{ |
{ |
1051 |
new MARSHAL("Cant read forwarding info", 5103, |
new MARSHAL("Cant read forwarding info", 5103, |
1052 |
CompletionStatus.COMPLETED_NO |
CompletionStatus.COMPLETED_NO); |
|
); |
|
1053 |
} |
} |
1054 |
|
|
1055 |
setIor(forwarded); |
setIor(forwarded); |
1063 |
p_invoke(); |
p_invoke(); |
1064 |
return; |
return; |
1065 |
|
|
1066 |
default : |
default: |
1067 |
throw new MARSHAL("Unknow reply status", 8100 + m_rph.reply_status, |
throw new MARSHAL("Unknow reply status", 8100 + m_rph.reply_status, |
1068 |
CompletionStatus.COMPLETED_NO |
CompletionStatus.COMPLETED_NO); |
|
); |
|
1069 |
} |
} |
1070 |
} |
} |
1071 |
|
|
1072 |
/** |
/** |
1073 |
* Read exception id without changing the stream pointer position. |
* Read exception id without changing the stream pointer position. |
1074 |
*/ |
*/ |
1075 |
void readExceptionId(cdrBufInput input) |
void readExceptionId(BufferredCdrInput input) |
1076 |
{ |
{ |
1077 |
input.mark(2048); |
input.mark(2048); |
1078 |
m_exception_id = input.read_string(); |
m_exception_id = input.read_string(); |
1088 |
* @throws MARSHAL if the attempt to write the parameters has failde. |
* @throws MARSHAL if the attempt to write the parameters has failde. |
1089 |
*/ |
*/ |
1090 |
protected void write_parameter_buffer(MessageHeader header, |
protected void write_parameter_buffer(MessageHeader header, |
1091 |
cdrBufOutput request_part |
BufferedCdrOutput request_part |
1092 |
) throws MARSHAL |
) throws MARSHAL |
1093 |
{ |
{ |
1094 |
try |
try |
1101 |
} |
} |
1102 |
catch (IOException ex) |
catch (IOException ex) |
1103 |
{ |
{ |
1104 |
throw new MARSHAL("Unable to write method arguments to CDR output."); |
MARSHAL m = new MARSHAL("Unable to write method arguments to CDR output."); |
1105 |
|
m.minor = Minor.CDR; |
1106 |
|
throw m; |
1107 |
} |
} |
1108 |
} |
} |
1109 |
|
|
1116 |
* @throws MARSHAL if the attempt to write the parameters has failde. |
* @throws MARSHAL if the attempt to write the parameters has failde. |
1117 |
*/ |
*/ |
1118 |
protected void write_parameters(MessageHeader header, |
protected void write_parameters(MessageHeader header, |
1119 |
cdrBufOutput request_part |
BufferedCdrOutput request_part |
1120 |
) throws MARSHAL |
) throws MARSHAL |
1121 |
{ |
{ |
1122 |
// Align after 1.2, but only once. |
// Align after 1.2, but only once. |
1167 |
*/ |
*/ |
1168 |
public TaggedProfile effective_profile() |
public TaggedProfile effective_profile() |
1169 |
{ |
{ |
1170 |
cdrBufOutput buf = new cdrBufOutput(512); |
BufferedCdrOutput buf = new BufferedCdrOutput(512); |
1171 |
buf.setOrb(orb); |
buf.setOrb(orb); |
1172 |
ior.Internet.write(buf); |
ior.Internet.write(buf); |
1173 |
|
|
1182 |
*/ |
*/ |
1183 |
public org.omg.CORBA.Object effective_target() |
public org.omg.CORBA.Object effective_target() |
1184 |
{ |
{ |
1185 |
return new IOR_contructed_object(orb, ior); |
return new IorObject(orb, ior); |
1186 |
} |
} |
1187 |
|
|
1188 |
/** |
/** |
1194 |
if (id == TAG_CODE_SETS.value) |
if (id == TAG_CODE_SETS.value) |
1195 |
{ |
{ |
1196 |
// Codesets are encoded separately. |
// Codesets are encoded separately. |
1197 |
cdrBufOutput buf = new cdrBufOutput(512); |
BufferedCdrOutput buf = new BufferedCdrOutput(512); |
1198 |
buf.setOrb(orb); |
buf.setOrb(orb); |
1199 |
ior.Internet.CodeSets.write(buf); |
ior.Internet.CodeSets.write(buf); |
1200 |
|
|
1295 |
return m_forwarding_target; |
return m_forwarding_target; |
1296 |
|
|
1297 |
if (m_forward_ior != null) |
if (m_forward_ior != null) |
1298 |
return new IOR_contructed_object(orb, m_forward_ior); |
return new IorObject(orb, m_forward_ior); |
1299 |
else |
else |
1300 |
return null; |
return null; |
1301 |
} |
} |