1 /* |
1 /* |
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
26 package sun.rmi.server; |
26 package sun.rmi.server; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.io.ObjectInput; |
29 import java.io.ObjectInput; |
30 import java.io.ObjectOutput; |
30 import java.io.ObjectOutput; |
31 import java.io.PrintStream; |
31 import java.io.ObjectStreamClass; |
32 import java.lang.reflect.InvocationTargetException; |
32 import java.lang.reflect.InvocationTargetException; |
33 import java.lang.reflect.Method; |
33 import java.lang.reflect.Method; |
34 import java.rmi.MarshalException; |
34 import java.rmi.MarshalException; |
35 import java.rmi.Remote; |
35 import java.rmi.Remote; |
36 import java.rmi.RemoteException; |
36 import java.rmi.RemoteException; |
50 import java.util.Collections; |
50 import java.util.Collections; |
51 import java.util.Date; |
51 import java.util.Date; |
52 import java.util.HashMap; |
52 import java.util.HashMap; |
53 import java.util.Map; |
53 import java.util.Map; |
54 import java.util.WeakHashMap; |
54 import java.util.WeakHashMap; |
|
55 import java.util.concurrent.atomic.AtomicInteger; |
55 import sun.rmi.runtime.Log; |
56 import sun.rmi.runtime.Log; |
56 import sun.rmi.transport.LiveRef; |
57 import sun.rmi.transport.LiveRef; |
57 import sun.rmi.transport.Target; |
58 import sun.rmi.transport.Target; |
58 import sun.rmi.transport.tcp.TCPTransport; |
59 import sun.rmi.transport.tcp.TCPTransport; |
59 |
60 |
113 new HashToMethod_Maps(); |
114 new HashToMethod_Maps(); |
114 |
115 |
115 /** cache of impl classes that have no corresponding skeleton class */ |
116 /** cache of impl classes that have no corresponding skeleton class */ |
116 private static final Map<Class<?>,?> withoutSkeletons = |
117 private static final Map<Class<?>,?> withoutSkeletons = |
117 Collections.synchronizedMap(new WeakHashMap<Class<?>,Void>()); |
118 Collections.synchronizedMap(new WeakHashMap<Class<?>,Void>()); |
|
119 |
|
120 private final AtomicInteger methodCallIDCount = new AtomicInteger(0); |
118 |
121 |
119 /** |
122 /** |
120 * Create a new (empty) Unicast server remote reference. |
123 * Create a new (empty) Unicast server remote reference. |
121 */ |
124 */ |
122 public UnicastServerRef() { |
125 public UnicastServerRef() { |
295 |
298 |
296 // if calls are being logged, write out object id and operation |
299 // if calls are being logged, write out object id and operation |
297 logCall(obj, method); |
300 logCall(obj, method); |
298 |
301 |
299 // unmarshal parameters |
302 // unmarshal parameters |
300 Class<?>[] types = method.getParameterTypes(); |
303 Object[] params = null; |
301 Object[] params = new Object[types.length]; |
|
302 |
304 |
303 try { |
305 try { |
304 unmarshalCustomCallData(in); |
306 unmarshalCustomCallData(in); |
305 for (int i = 0; i < types.length; i++) { |
307 params = unmarshalParameters(obj, method, marshalStream); |
306 params[i] = unmarshalValue(types[i], in); |
|
307 } |
|
308 } catch (java.io.IOException e) { |
308 } catch (java.io.IOException e) { |
309 throw new UnmarshalException( |
309 throw new UnmarshalException( |
310 "error unmarshalling arguments", e); |
310 "error unmarshalling arguments", e); |
311 } catch (ClassNotFoundException e) { |
311 } catch (ClassNotFoundException e) { |
312 throw new UnmarshalException( |
312 throw new UnmarshalException( |
563 } |
563 } |
564 } |
564 } |
565 return map; |
565 return map; |
566 } |
566 } |
567 } |
567 } |
|
568 |
|
569 /** |
|
570 * Unmarshal parameters for the given method of the given instance over |
|
571 * the given marshalinputstream. Perform any necessary checks. |
|
572 */ |
|
573 private Object[] unmarshalParameters(Object obj, Method method, MarshalInputStream in) |
|
574 throws IOException, ClassNotFoundException { |
|
575 return (obj instanceof DeserializationChecker) ? |
|
576 unmarshalParametersChecked((DeserializationChecker)obj, method, in) : |
|
577 unmarshalParametersUnchecked(method, in); |
|
578 } |
|
579 |
|
580 /** |
|
581 * Unmarshal parameters for the given method of the given instance over |
|
582 * the given marshalinputstream. Do not perform any additional checks. |
|
583 */ |
|
584 private Object[] unmarshalParametersUnchecked(Method method, ObjectInput in) |
|
585 throws IOException, ClassNotFoundException { |
|
586 Class<?>[] types = method.getParameterTypes(); |
|
587 Object[] params = new Object[types.length]; |
|
588 for (int i = 0; i < types.length; i++) { |
|
589 params[i] = unmarshalValue(types[i], in); |
|
590 } |
|
591 return params; |
|
592 } |
|
593 |
|
594 /** |
|
595 * Unmarshal parameters for the given method of the given instance over |
|
596 * the given marshalinputstream. Do perform all additional checks. |
|
597 */ |
|
598 private Object[] unmarshalParametersChecked( |
|
599 DeserializationChecker checker, |
|
600 Method method, MarshalInputStream in) |
|
601 throws IOException, ClassNotFoundException { |
|
602 int callID = methodCallIDCount.getAndIncrement(); |
|
603 MyChecker myChecker = new MyChecker(checker, method, callID); |
|
604 in.setStreamChecker(myChecker); |
|
605 try { |
|
606 Class<?>[] types = method.getParameterTypes(); |
|
607 Object[] values = new Object[types.length]; |
|
608 for (int i = 0; i < types.length; i++) { |
|
609 myChecker.setIndex(i); |
|
610 values[i] = unmarshalValue(types[i], in); |
|
611 } |
|
612 myChecker.end(callID); |
|
613 return values; |
|
614 } finally { |
|
615 in.setStreamChecker(null); |
|
616 } |
|
617 } |
|
618 |
|
619 private static class MyChecker implements MarshalInputStream.StreamChecker { |
|
620 private final DeserializationChecker descriptorCheck; |
|
621 private final Method method; |
|
622 private final int callID; |
|
623 private int parameterIndex; |
|
624 |
|
625 MyChecker(DeserializationChecker descriptorCheck, Method method, int callID) { |
|
626 this.descriptorCheck = descriptorCheck; |
|
627 this.method = method; |
|
628 this.callID = callID; |
|
629 } |
|
630 |
|
631 @Override |
|
632 public void validateDescriptor(ObjectStreamClass descriptor) { |
|
633 descriptorCheck.check(method, descriptor, parameterIndex, callID); |
|
634 } |
|
635 |
|
636 @Override |
|
637 public void checkProxyInterfaceNames(String[] ifaces) { |
|
638 descriptorCheck.checkProxyClass(method, ifaces, parameterIndex, callID); |
|
639 } |
|
640 |
|
641 void setIndex(int parameterIndex) { |
|
642 this.parameterIndex = parameterIndex; |
|
643 } |
|
644 |
|
645 void end(int callId) { |
|
646 descriptorCheck.end(callId); |
|
647 } |
|
648 } |
568 } |
649 } |