Code Search for Developers
 
 
  

JAXR.java from GridBlocks at Krugle


Show JAXR.java syntax highlighted

package fi.hip.gb.net.discovery;

import java.net.PasswordAuthentication;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessLifeCycleManager;
import javax.xml.registry.BusinessQueryManager;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.FindQualifier;
import javax.xml.registry.JAXRException;
import javax.xml.registry.JAXRResponse;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.Classification;
import javax.xml.registry.infomodel.ClassificationScheme;
import javax.xml.registry.infomodel.ExternalIdentifier;
import javax.xml.registry.infomodel.InternationalString;
import javax.xml.registry.infomodel.Key;
import javax.xml.registry.infomodel.Organization;
import javax.xml.registry.infomodel.Service;
import javax.xml.registry.infomodel.ServiceBinding;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import fi.hip.gb.core.Config;

public class JAXR {
    private Connection connection;

    private String userid = "jboss";

    private String passwd = "jboss";

    private BusinessLifeCycleManager blm = null;

    private RegistryService rs = null;

    private BusinessQueryManager bqm = null;

    private static Log log = LogFactory.getLog(JAXR.class);

    public JAXR() {
        String queryurl = System.getProperty("jaxr.query.url");
        String puburl = System.getProperty("jaxr.publish.url");

        // Standard JAXR ConnectionFactory properties
        Properties props = new Properties();
        props.setProperty("javax.xml.registry.queryManagerURL", queryurl);
        props.setProperty("javax.xml.registry.lifeCycleManagerURL", puburl);

        // JBoss JAXR property
        String transportClass = System.getProperty(
                "juddi.proxy.transportClass",
                "org.jboss.jaxr.juddi.transport.SaajTransport");
        System.setProperty("juddi.proxy.transportClass", transportClass);

        ConnectionFactory factory = null;
        try {
            // Create the connection, passing it the configuration properties
            factory = ConnectionFactory.newInstance();
            factory.setProperties(props);
            connection = factory.createConnection();
        } catch (JAXRException je) {
            log.error("Failed to connect to jUDDI registry", je);
        }
    }

    /**
     * Does authentication with the uddi registry
     */
    @SuppressWarnings("unchecked")
    private void login() {
        PasswordAuthentication passwdAuth = new PasswordAuthentication(userid,
                passwd.toCharArray());
        Set creds = new HashSet();
        creds.add(passwdAuth);

        try {
            //Set the credentials on the connection
            connection.setCredentials(creds);
        } catch (JAXRException e) {
            log.error("Failed to authenticate into jUDDI registry", e);
        }
    }

    protected BusinessQueryManager getBusinessQueryManager() throws JAXRException {
        if (rs == null)
            rs = connection.getRegistryService();
        return rs.getBusinessQueryManager();
    }

    protected BusinessLifeCycleManager getBusinessLifeCycleManager() throws JAXRException {
        if (rs == null)
            rs = connection.getRegistryService();
        return rs.getBusinessLifeCycleManager();
    }
    
    public InternationalString getIString(String str) throws JAXRException {
        return blm.createInternationalString(str);
    }

    //   Method that creates a Test JAXR Organization
    private Organization createOrganization(String orgname)
            throws JAXRException {
        Organization org = blm.createOrganization(orgname);
        org.setDescription(getIString("gridblocks.hip.fi"));
        
        Service service = blm.createService("GridBlocks Computing");
        service.setDescription(getIString("Distributed Computing Service"));

        // Create serviceBinding
        ServiceBinding serviceBinding = blm.createServiceBinding();
        serviceBinding.setDescription(getIString("Computing WS Service Binding"));

        //Turn validation of URI off
        serviceBinding.setValidateURI(false);
        serviceBinding.setAccessURI("http://pchip06.cern.ch:8080/gb-agent");

        // Add the serviceBinding to the service
        service.addServiceBinding(serviceBinding);

        ClassificationScheme cScheme = blm.createClassificationScheme("ntis-gov:naics", "");
        cScheme.setKey(blm.createKey("uuid:C0B9FE13-324F-413D-5A5B-2004DB8E5CC2"));
        Classification classification = blm.createClassification(cScheme, "Computer Systems Design and Related Services", "5415");
        org.addClassification(classification);
        
        ClassificationScheme cScheme1 = blm.createClassificationScheme("D-U-N-S", "");
        cScheme1.setKey(blm.createKey("uuid:3367C81E-FF1F-4D5A-B202-3EB13AD02423"));
        ExternalIdentifier ei = blm.createExternalIdentifier(cScheme1, "D-U-N-S number", "08-146-6849");
        org.addExternalIdentifier(ei);
        
        org.addService(service);
        return org;
    }

    /**Method that saves the JAXR Organization in the UDDI registry */
    public void saveTestBusiness() throws Exception {
        String keyid = "";
        login();
        try {
            rs = connection.getRegistryService();
            blm = rs.getBusinessLifeCycleManager();
            bqm = rs.getBusinessQueryManager();
            
            Collection orgs = new ArrayList();
            Organization org = createOrganization("GridBlocks");

            orgs.add(org);
            BulkResponse br = blm.saveOrganizations(orgs);
            if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
                Collection coll = br.getCollection();
                Iterator iter = coll.iterator();
                while (iter.hasNext()) {
                    Key key = (Key) iter.next();
                    keyid = key.getId();
                    System.out.println(keyid);
                }//end while
            } else {
                Collection exceptions = br.getExceptions();
                Iterator iter = exceptions.iterator();
                while (iter.hasNext()) {
                    Exception e = (Exception) iter.next();
                    System.out.println(e);
                }
            }
        } catch (JAXRException e) {
        }
    }

    /**
     * Delete an Organization with a given key
     *
     * @param orgkey
     * @throws Exception
     */
    protected void deleteOrganization(Key orgkey) throws Exception {
        if (blm == null) {
            blm = this.getBusinessLifeCycleManager();
            login();
        }
        if(orgkey == null)
            orgkey = blm.createKey("BE299250-8E8D-11DB-9250-8BC5AB6E457D");
        
        Collection keys = new ArrayList();
        keys.add(orgkey);

        BulkResponse response = blm.deleteOrganizations(keys);
        Collection exceptions = response.getExceptions();
    }

    public void searchServers(String bizname) throws JAXRException {
        // Get registry service and business query manager
        rs = connection.getRegistryService();
        bqm = rs.getBusinessQueryManager();

        // Define find qualifiers and name patterns
        Collection findQualifiers = new ArrayList();
        findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);

        Collection namePatterns = null;
        if(bizname != null) {
            namePatterns = new ArrayList();
            namePatterns.add("%" + bizname + "%");
        }

        // Find based upon qualifier type and values
        BulkResponse response = bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);

        // check how many organisation we have matched
        Collection orgs = response.getCollection();
        if (orgs == null) {
            System.out.println(" -- Matched 0 orgs");
        } else {
            System.out.println(" -- Matched " + orgs.size()
                    + " organizations -- ");

            // then step through them
            for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();) {
                Organization org = (Organization) orgIter.next();
                
                System.out.println("Org name: " + org.getName().getValue());
                System.out.println("Org description: " + org.getDescription().getValue());
                System.out.println("Org key id: " + org.getKey());
                
                for(Object serviceObject : org.getServices()) {
                    Service s = (Service) serviceObject;
                    System.out.println("Service: " + s.getName().getValue());
                    //System.out.println("Stat: " + s.getStatus());
                    System.out.println("Desc: " + s.getDescription().getValue());
                    
                    for(Object bindingObject : s.getServiceBindings()) {
                        ServiceBinding sb = (ServiceBinding) bindingObject;
                        System.out.println("Desc: " + sb.getDescription().getValue());
                        System.out.println("Access: " + sb.getAccessURI());
                    }
                }
                System.out.println("\n");
            }
        }
    }
    
    public static void main(String[] args) throws Exception {
        Config.getInstance();
        
        JAXR c = new JAXR();
        c.searchServers("GridBlocks");
        //c.deleteOrganization(null);
        //c.saveTestBusiness();
    }
}




See more files for this project here

GridBlocks

GridBlocks builds a grid application framework via easy-to-use building blocks in distributed environment. The framework offers components for Grid security, distributed storage, computing, and Portlet web interfaces.

Project homepage: http://sourceforge.net/projects/gridblocks
Programming language(s): Java,JSP,XML
License: other

  AgentPacket.java
  DiscoveryPacket.java
  DiscoveryService.java
  DiscoveryThread.java
  DiscoveryThreadMBean.java
  JAXR.java