1 16 package org.jmanage.core.services; 17 18 import org.jmanage.core.auth.User; 19 import org.jmanage.core.remote.client.HttpServiceProxy; 20 import org.jmanage.core.data.OperationResultData; 21 22 51 public class RemoteServiceContextFactory { 52 53 static{ 54 ServiceFactory.init(ServiceFactory.MODE_REMOTE); 55 } 56 57 63 public static void setJManageURL(String jmanageURL){ 64 HttpServiceProxy.setRemoteURL(jmanageURL); 65 } 66 67 79 public static ServiceContext getServiceContext(String username, 80 String password, 81 String applicationName, 82 String mbeanName){ 83 ServiceContextImpl context = new ServiceContextImpl(); 84 85 User user = new User(username, 86 null, null, null, 0); 87 user.setPlaintextPassword(password); 88 context.setUser(user); 89 90 context.setApplicationName(applicationName); 91 92 context.setMBeanName(mbeanName); 93 return context; 94 } 95 96 99 public static void main(String [] args){ 100 RemoteServiceContextFactory.setJManageURL("http://localhost:9090"); 101 ServiceContext context = RemoteServiceContextFactory.getServiceContext( 102 "admin", "123456", 103 "testApp1", "jmanage:name=DataFormat,type=test"); 104 MBeanService mbeanService = ServiceFactory.getMBeanService(); 105 OperationResultData[] result = 106 mbeanService.invoke(context, "retrieveXMLData", new String []{}); 107 108 assert result.length == 1; 109 110 System.out.println(result[0].isError()?"Error": "OK"); 111 System.out.println(result[0].getDisplayOutput()); 112 } 113 } 114 | Popular Tags |