Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/activation/ActivationGroup/downloadActivationGroup/DownloadActivationGroup.java
38889 views
/*1* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 451035526* @summary ActivationGroup implementations cannot be downloaded by default;27* Creates a custom activation group without setting a security manager28* in activation group's descriptor. The custom activation group29* implementation should be downloaded when first object within that group30* is activated.31* @author Ann Wollrath32*33* @library ../../../testlibrary34* @build TestLibrary RMID ActivationLibrary35* DownloadActivationGroup MyActivationGroupImpl DownloadActivationGroup_Stub36* @run main/othervm/policy=security.policy/timeout=240 DownloadActivationGroup37*/3839import java.io.*;40import java.rmi.*;41import java.net.*;42import java.rmi.activation.*;43import java.rmi.server.*;44import java.rmi.registry.*;45import java.util.Vector;46import java.util.Properties;4748public class DownloadActivationGroup49implements Ping, Runnable50{5152private ActivationID id;5354public DownloadActivationGroup(ActivationID id, MarshalledObject mobj)55throws ActivationException, RemoteException56{57this.id = id;58Activatable.exportObject(this, id, 0);59System.err.println("object activated in group");60}6162public DownloadActivationGroup() throws RemoteException {63UnicastRemoteObject.exportObject(this, 0);64}6566/**67* Used to activate object.68*/69public void ping() {70System.err.println("received ping");71}7273/**74* Spawns a thread to deactivate the object (and thus, shuts down the75* activation group).76*/77public void shutdown() throws Exception78{79(new Thread(this,"DownloadActivationGroup")).start();80}8182/**83* Thread to deactivate object.84*/85public void run() {86ActivationLibrary.deactivate(this, getID());87}8889public ActivationID getID() {90return id;91}929394public static void main(String[] args) {9596RMID rmid = null;9798System.out.println("\nRegression test for bug 4510355\n");99100try {101TestLibrary.suggestSecurityManager("java.lang.SecurityManager");102103/*104* Install group class file in codebase.105*/106System.err.println("install class file in codebase");107URL groupURL = TestLibrary.installClassInCodebase(108"MyActivationGroupImpl", "group");109System.err.println("class file installed");110111/*112* Start rmid.113*/114RMID.removeLog();115rmid = RMID.createRMID();116String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none";117rmid.addOptions(new String[] { execPolicyOption });118rmid.start();119120/*121* Create and register descriptors for custom group and an122* activatable object in that group.123*/124System.err.println("register group");125126Properties p = new Properties();127p.put("java.security.policy", TestParams.defaultGroupPolicy);128129ActivationGroupDesc groupDesc =130new ActivationGroupDesc("MyActivationGroupImpl",131groupURL.toExternalForm(),132null, p, null);133ActivationGroupID groupID =134ActivationGroup.getSystem().registerGroup(groupDesc);135136137System.err.println("register activatable object");138ActivationDesc desc =139new ActivationDesc(groupID, "DownloadActivationGroup",140null, null);141Ping obj = (Ping) Activatable.register(desc);142143/*144* Start group (by calling ping).145*/146System.err.println(147"ping object (forces download of group's class)");148obj.ping();149System.err.println(150"TEST PASSED: group's class downloaded successfully");151System.err.println("shutdown object");152obj.shutdown();153System.err.println("TEST PASSED");154155} catch (Exception e) {156TestLibrary.bomb(e);157} finally {158ActivationLibrary.rmidCleanup(rmid);159}160}161}162163interface Ping extends Remote {164public void ping() throws RemoteException;165public void shutdown() throws Exception;166}167168169