1 /* 2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4127754 26 * 27 * @summary synopsis: need to modify registered ActivationDesc and 28 * ActivationGroupDesc 29 * @author Ann Wollrath 30 * 31 * @library ../../../testlibrary 32 * @build TestLibrary RMID ActivationLibrary 33 * ActivateMe ModifyDescriptor_Stub 34 * @run main/othervm/policy=security.policy/timeout=240 ModifyDescriptor 35 */ 36 37 import java.io.*; 38 import java.rmi.*; 39 import java.rmi.activation.*; 40 import java.rmi.server.*; 41 import java.rmi.registry.*; 42 import java.util.*; 43 44 public class ModifyDescriptor 45 implements ActivateMe, Runnable 46 { 47 48 private ActivationID id; 49 private String message; 50 51 private static final String MESSAGE1 = "hello"; 52 private static final String MESSAGE2 = "hello, again"; 53 54 55 public ModifyDescriptor(ActivationID id, MarshalledObject mobj) 56 throws ActivationException, RemoteException 57 { 58 this.id = id; 59 Activatable.exportObject(this, id, 0); 60 61 try { 62 message = (String) mobj.get(); 63 } catch (Exception e) { 64 System.err.println("unable to get message from marshalled object"); 65 } 66 } 67 68 public String getMessage() { 69 return message; 70 } 71 72 public String getProperty(String name) { 73 return TestLibrary.getProperty(name, null); 74 } 75 76 public ActivationID getID() { 77 return id; 78 } 79 80 /** 81 * Spawns a thread to deactivate the object. 82 */ 83 public void shutdown() throws Exception 84 { 85 (new Thread(this,"ModifyDescriptor")).start(); 86 } 87 88 /** 89 * Thread to deactivate object. First attempts to make object 90 * inactive (via the inactive method). If that fails (the 91 * object may still have pending/executing calls), then 92 * unexport the object forcibly. 93 */ 94 public void run() { 95 ActivationLibrary.deactivate(this, getID()); 96 } 97 98 public static void main(String[] args) { 99 100 System.out.println("\nRegression test for bug 4127754\n"); 101 102 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 103 104 RMID rmid = null; 105 106 try { 107 RMID.removeLog(); 108 rmid = RMID.createRMID(); 109 rmid.start(); 110 111 /* 112 * Create and register a group and activatable object 113 */ 114 115 System.err.println("Creating group descriptor"); 116 Properties props = new Properties(); 117 props.put("java.security.policy", 118 TestParams.defaultGroupPolicy); 119 props.put("java.security.manager", 120 TestParams.defaultSecurityManager); 121 props.put("test.message", MESSAGE1); 122 ActivationGroupDesc initialGroupDesc = 123 new ActivationGroupDesc(props, null); 124 System.err.println("Registering group"); 125 ActivationSystem system = ActivationGroup.getSystem(); 126 ActivationGroupID groupID = system.registerGroup(initialGroupDesc); 127 128 System.err.println("Creating descriptor"); 129 ActivationDesc initialDesc = 130 new ActivationDesc(groupID, "ModifyDescriptor", null, 131 new MarshalledObject(MESSAGE1), false); 132 133 System.err.println("Registering descriptor"); 134 ActivateMe obj = (ActivateMe) Activatable.register(initialDesc); 135 136 /* 137 * Ping object and verify that MarshalledObject is okay. 138 */ 139 System.err.println("Ping object"); 140 String message1 = obj.getMessage(); 141 System.err.println("message = " + message1); 142 143 if (message1.equals(MESSAGE1)) { 144 System.err.println("Test1a passed: initial MarshalledObject " + 145 "correct"); 146 } else { 147 TestLibrary.bomb("Test1 failed: unexpected MarshalledObject passed to " + 148 "constructor", null); 149 } 150 151 /* 152 * Get property from remote group and make sure it's okay 153 */ 154 message1 = obj.getProperty("test.message"); 155 if (message1.equals(MESSAGE1)) { 156 System.err.println("Test1b passed: initial group property " + 157 "correct"); 158 } else { 159 TestLibrary.bomb("Test1 failed: unexpected property passed to " + 160 "group", null); 161 } 162 163 /* 164 * Update activation descriptor for object and group 165 */ 166 System.err.println("Update activation descriptor"); 167 ActivationDesc newDesc = 168 new ActivationDesc(groupID, "ModifyDescriptor", null, 169 new MarshalledObject(MESSAGE2), false); 170 ActivationID id = obj.getID(); 171 ActivationDesc oldDesc = system.setActivationDesc(id, newDesc); 172 173 if (oldDesc.equals(initialDesc)) { 174 System.err.println("Test2a passed: desc returned from " + 175 "setActivationDesc is okay"); 176 } else { 177 TestLibrary.bomb("Test2a failed: desc returned from setActivationDesc " + 178 "is not the initial descriptor!", null); 179 } 180 181 182 Properties props2 = new Properties(); 183 props2.put("test.message", MESSAGE2); 184 props2.put("java.security.policy", 185 TestParams.defaultGroupPolicy); 186 props2.put("java.security.manager", 187 TestParams.defaultSecurityManager); 188 ActivationGroupDesc newGroupDesc = 189 new ActivationGroupDesc(props2, null); 190 191 ActivationGroupDesc oldGroupDesc = 192 system.setActivationGroupDesc(groupID, newGroupDesc); 193 194 if (oldGroupDesc.equals(initialGroupDesc)) { 195 System.err.println("Test2b passed: group desc returned from " + 196 "setActivationGroupDesc is okay"); 197 } else { 198 TestLibrary.bomb("Test2b failed: group desc returned from " + 199 "setActivationGroupDesc is not the initial descriptor!", 200 null); 201 } 202 203 /* 204 * Restart rmid; and ping object to make sure that it has 205 * new message. 206 */ 207 rmid.restart(); 208 209 System.err.println("Ping object after restart"); 210 String message2 = obj.getMessage(); 211 212 if (message2.equals(MESSAGE2)) { 213 System.err.println("Test3a passed: setActivationDesc takes " + 214 "effect after a restart"); 215 } else { 216 TestLibrary.bomb("Test3a failed: setActivationDesc did not take effect " + 217 "after a restart", null); 218 } 219 220 message2 = obj.getProperty("test.message"); 221 222 if (message2.equals(MESSAGE2)) { 223 System.err.println("Test3b passed: setActivationGroupDesc " + 224 "takes effect after a restart"); 225 } else { 226 TestLibrary.bomb("Test3b failed: setActivationGroupDesc did not take " + 227 "effect after a restart", null); 228 } 229 230 System.err.println("Get activation descriptor"); 231 ActivationDesc latestDesc = system.getActivationDesc(id); 232 233 if (latestDesc.equals(newDesc)) { 234 System.err.println("Test4a passed: desc is same as latest"); 235 } else { 236 TestLibrary.bomb("Test4a failed: there is no way this would happen", null); 237 } 238 239 System.err.println("Get activation group descriptor"); 240 ActivationGroupDesc latestGroupDesc = 241 system.getActivationGroupDesc(groupID); 242 243 if (latestGroupDesc.equals(newGroupDesc)) { 244 System.err.println("Test4b passed: group desc is same as " + 245 "latest"); 246 } else { 247 TestLibrary.bomb("Test4b failed: there is no way this would happen", null); 248 } 249 250 } catch (Exception e) { 251 TestLibrary.bomb("test failed", e); 252 } finally { 253 rmid.cleanup(); 254 } 255 } 256 }