This commit is contained in:
Manuele Simi 2008-06-30 22:55:31 +00:00
parent ffd9cda8f9
commit 7c0839a979
2 changed files with 85 additions and 44 deletions

View File

@ -3,11 +3,13 @@ package org.gcube.informationsystem.registry.test;
import java.io.FileReader;
import java.io.StringWriter;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
import org.gcube.common.core.contexts.GHNContext;
import org.gcube.common.core.resources.GCUBEGenericResource;
import org.gcube.common.core.resources.GCUBEHostingNode;
import org.gcube.common.core.resources.GCUBEResource;
import org.gcube.common.core.resources.GCUBERunningInstance;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.scope.ServiceMap.ServiceType;
@ -17,59 +19,98 @@ import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
/**
* GCUBE resource registration tester
*
* @author Manuele Simi (CNR-ISTI)
*
*/
public class RegistryRegistrationTest {
public static void main (String[]args ) throws Exception {
public static void main(String[] args) throws Exception {
if (args.length != 3) {
printUsage();
}
//get the scope and the factory URI
// get the scope and the factory URI
GCUBEScope scope = GCUBEScope.getScope(args[2]);
EndpointReferenceType factoryEPR = scope.getServiceMap().getEndpoint(ServiceType.ISRegistry);
EndpointReferenceType factoryEPR = scope.getServiceMap().getEndpoint(
ServiceType.ISRegistry);
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() { public boolean isSecurityEnabled() {return false;}};
//ExtendedGSSCredential cred =org.diligentproject.dvos.authentication.util.ProxyUtil.loadProxyCredentials(args[2]);
//managerSec.useCredentials(cred);
//load the resource
GCUBEResource resource = null;
if (args[1].compareTo("Service") == 0) {
GCUBEService service =GHNContext.getImplementation(GCUBEService.class);
service.load(new FileReader (args[0]));
resource = (GCUBEResource)service;
}
RegistryFactoryPortType registryFactoryPortType= null;
try {
registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR);
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
CreateResourceMessage message = new CreateResourceMessage();
registryFactoryPortType = GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,scope,managerSec);
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() {
public boolean isSecurityEnabled() {
return false;
}
};
// ExtendedGSSCredential cred = org.diligentproject.dvos.authentication.util.ProxyUtil.loadProxyCredentials(args[2]);
// managerSec.useCredentials(cred);
// load the resource
GCUBEResource resource = getResource(args[1], new FileReader(args[0]));
RegistryFactoryPortType registryFactoryPortType = null;
try {
StringWriter writer =new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
System.out.println(registryFactoryPortType.createResource(message));
} catch(Exception e) {
e.printStackTrace();
registryFactoryPortType = registryLocator
.getRegistryFactoryPortTypePort(factoryEPR);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
CreateResourceMessage message = new CreateResourceMessage();
registryFactoryPortType = GCUBERemotePortTypeContext.getProxy(
registryFactoryPortType, scope, managerSec);
try {
StringWriter writer = new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
System.out.println(registryFactoryPortType.createResource(message));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Loads the specific GCUBEResource class
* @param type the resource type
* @param file the file representation of the profile
* @return the resource class
* @throws Exception if the loading fails
*/
static GCUBEResource getResource(String type, FileReader file) throws Exception {
if (type.compareTo("Service") == 0) {
GCUBEService service = GHNContext.getImplementation(GCUBEService.class);
service.load(file);
return (GCUBEResource) service;
}
else if (type.compareTo("RunningInstance") == 0) {
GCUBERunningInstance instance = GHNContext.getImplementation(GCUBERunningInstance.class);
instance.load(file);
return (GCUBEResource) instance;
} else if (type.compareTo("GHN") == 0) {
GCUBEHostingNode node = GHNContext.getImplementation(GCUBEHostingNode.class);
node.load(file);
return (GCUBEResource) node;
} else if (type.compareTo("GenericResource") == 0) {
GCUBEGenericResource generic = GHNContext.getImplementation(GCUBEGenericResource.class);
generic.load(file);
return (GCUBEResource) generic;
}
throw new Exception( type + " is an invalid resource type");
}
/**
* Prints tester usage syntax
*/
static void printUsage() {
System.out.println("RegistryRegistrationTest <resource file> <resource type> <caller scope>");
System.out.println("allowed types are: RunningInstance/Service/GHN/GenericResource");

View File

@ -42,7 +42,7 @@ public static void main (String[]args ) throws Exception {
managerSec.useCredentials(cred);
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope("/gcube/devsec"),managerSec);
registryFactoryPortType =GCUBERemotePortTypeContext.getProxy(registryFactoryPortType,GCUBEScope.getScope(args[3]),managerSec);
try {
StringWriter writer =new StringWriter();
resource.store(writer);