is-registry/org/gcube/informationsystem/registry/test/RegistryTest.java

60 lines
2.3 KiB
Java

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.GHNContext;
import org.gcube.common.core.resources.GCUBEService;
import org.gcube.common.core.security.GCUBESecurityManager;
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
import org.gcube.informationsystem.registry.stubs.CreateResourceMessage;
import org.gcube.informationsystem.registry.stubs.RegistryFactoryPortType;
import org.gcube.informationsystem.registry.stubs.service.RegistryFactoryServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
public class RegistryTest {
public static void main (String[]args ) throws Exception {
RegistryFactoryServiceAddressingLocator registryLocator = new RegistryFactoryServiceAddressingLocator();
GCUBESecurityManagerImpl managerSec = new GCUBESecurityManagerImpl() { public boolean isSecurityEnabled() {return true;}};
ExtendedGSSCredential cred =org.diligentproject.dvos.authentication.util.ProxyUtil.loadProxyCredentials(args[2]);
FileReader fis = new FileReader (args[1]);
// GHNContext.getImplementation(GCUBEService.class);
GCUBEService resource =GHNContext.getImplementation(GCUBEService.class);
EndpointReferenceType factoryEPR = new EndpointReferenceType();
resource.load(fis);
//resource.store(fir);
RegistryFactoryPortType registryFactoryPortType= null;
try {
factoryEPR.setAddress(new Address(args[0]));
registryFactoryPortType = registryLocator.getRegistryFactoryPortTypePort(factoryEPR);
}catch(Exception e){
e.printStackTrace();
}
CreateResourceMessage message = new CreateResourceMessage();
String profile ="";
managerSec.useCredentials(cred);
managerSec.setSecurity(registryFactoryPortType, GCUBESecurityManager.AuthMode.INTEGRITY, GCUBESecurityManager.DelegationMode.NONE);
try {
StringWriter writer =new StringWriter();
resource.store(writer);
message.setProfile(writer.toString());
message.setType(resource.getType());
profile =registryFactoryPortType.createResource(message);
} catch(Exception e) {
e.printStackTrace();
}
System.out.println(profile);
}
}