RegistryService rs = connection.getRegistryService();
blm = rs.getBusinessLifeCycleManager();
Creator creator = new Creator(blm);
Collection<Organization> organizations = new ArrayList<Organization>();
Organization organization = creator.createOrganization("Red Hat/JBossESB");
organizations.add(organization);
BulkResponse br = blm.saveOrganizations(organizations);
assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
} catch (JAXRException je) {
je.printStackTrace();
assertTrue(false);
}
//find organization
try
{
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
Finder finder = new Finder(bqm, uddiversion);
Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
Organization org = orgs.iterator().next();
assertEquals("Red Hat/JBossESB", org.getName().getValue());
} catch (JAXRException je) {
fail(je.getMessage());
}
try {
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
Finder finder = new Finder(bqm, uddiversion);
Collection<Organization> orgs = finder.findOrganizationsByName("Not Existing Org");
assertEquals(0, orgs.size());
} catch (JAXRException je) {
fail(je.getMessage());
}
//Publish a service
try {
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
Finder finder = new Finder(bqm, uddiversion);
Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
Organization organization = orgs.iterator().next();
blm = rs.getBusinessLifeCycleManager();
//Adding the category as prefix for the name
Service service = blm.createService(blm.createInternationalString("Registry Test ServiceName"));
service.setDescription(blm.createInternationalString("Registry Test Service Description"));
Collection<String> findQualifiers = new ArrayList<String>();
findQualifiers.add(FindQualifier.AND_ALL_KEYS);
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
Classification classification = blm.createClassification(cScheme, "category", "registry");
service.addClassification(classification);
organization.addService(service);
Collection<Service> services = new ArrayList<Service>();
services.add(service);
BulkResponse br = blm.saveServices(services);
assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
} catch (JAXRException je) {
fail(je.getMessage());
}
//find Service
try
{
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
blm = rs.getBusinessLifeCycleManager();
Finder finder = new Finder(bqm, uddiversion);
//Find the service
Service service = finder.findService("registry","Registry Test ServiceName", blm);
assertEquals("Registry Test ServiceName", service.getName().getValue());
} catch (JAXRException je) {
fail(je.getMessage());
}
//publish serviceBinding
try {
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
blm = rs.getBusinessLifeCycleManager();
Finder finder = new Finder(bqm, uddiversion);
//Find the service
Service service = finder.findService("registry","Registry Test ServiceName", blm);
ServiceBinding serviceBinding = blm.createServiceBinding();
serviceBinding.setDescription(blm.createInternationalString("eprDescription"));
String xml = "<epr>epr uri</epr>";
serviceBinding.setAccessURI(xml);
ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
serviceBindings.add(serviceBinding);
service.addServiceBindings(serviceBindings);
Collection<String> findQualifiers = new ArrayList<String>();
findQualifiers.add(FindQualifier.AND_ALL_KEYS);
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
Classification classification = blm.createClassification(cScheme, "category", "registry");
service.addClassification(classification);
BulkResponse br = blm.saveServiceBindings(serviceBindings);
assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus());
BulkResponse br2 = blm.saveServiceBindings(serviceBindings); //Save one more
assertEquals(BulkResponse.STATUS_SUCCESS, br2.getStatus());
//Delete one binding
Collection<ServiceBinding> serviceBindings2 = finder.findServiceBindings(service.getKey(),classification);
if ((serviceBindings2 != null) && (serviceBindings2.iterator() != null)
&& (serviceBindings2.iterator().hasNext())) {
ServiceBinding serviceBinding2 = serviceBindings2.iterator().next();
Remover remover = new Remover(blm);
remover.removeServiceBinding(serviceBinding2);
}
} catch (JAXRException re) {
fail(re.getMessage());
}
//find all services for this organization
try
{
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
Finder finder = new Finder(bqm, uddiversion);
Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
Organization org = orgs.iterator().next();
//Listing out the services and their Bindings
System.out.println("-------------------------------------------------");
System.out.println("Organization name: " + org.getName().getValue());
System.out.println("Description: " + org.getDescription().getValue());
System.out.println("Key id: " + org.getKey().getId());
User primaryContact = org.getPrimaryContact();
System.out.println("Primary Contact: " + primaryContact.getPersonName().getFullName());
Collection services = org.getServices();
for (Iterator serviceIter = services.iterator();serviceIter.hasNext();) {
Service service = (Service) serviceIter.next();
System.out.println("- Service Name: " + service.getName().getValue());
System.out.println(" Service Key : " + service.getKey().getId());
Collection serviceBindings = service.getServiceBindings();
for (Iterator serviceBindingIter = serviceBindings.iterator();serviceBindingIter.hasNext();){
ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
System.out.println(" ServiceBinding Description: " + serviceBinding.getDescription().getValue());
String xml = serviceBinding.getAccessURI();
System.out.println(" ServiceBinding URI: " + xml);
assertEquals("<epr>epr uri</epr>",xml);
}
}
System.out.println("-------------------------------------------------");
} catch (Exception je) {
fail(je.getMessage());
}
//delete the service
try
{
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
blm = rs.getBusinessLifeCycleManager();
Finder finder = new Finder(bqm, uddiversion);
//Find the service
Service service = finder.findService("registry","Registry Test ServiceName", blm);
Remover remover = new Remover(blm);
remover.removeService(service);
} catch (JAXRException je) {
fail(je.getMessage());
}
//delete the organization
try
{
RegistryService rs = connection.getRegistryService();
bqm = rs.getBusinessQueryManager();
blm = rs.getBusinessLifeCycleManager();
Finder finder = new Finder(bqm, uddiversion);
Collection<Organization> orgs = finder.findOrganizationsByName("Red Hat/JBossESB");
Organization org = orgs.iterator().next();
Remover remover = new Remover(blm);
remover.removeOrganization(org);
} catch (JAXRException je) {
fail(je.getMessage());
}