Package org.wso2.carbon.governance.api.services.dataobjects

Examples of org.wso2.carbon.governance.api.services.dataobjects.Service


    public static void addService(TargetService service) throws Exception {
        ServiceManager serviceManager = new ServiceManager(getRegistry());
        String serviceId = service.getEpr().getAddress();

        // Delete the existing stuff and start fresh
        Service oldService = serviceManager.getService(serviceId);
        String serviceName = null;
        if (oldService != null) {
            // TODO: Change this once the necessary improvements are in the governance API
            serviceName = oldService.getQName().getLocalPart();
            serviceManager.removeService(serviceId);
        }

        // Create a new service (Use the discovery namespace)
        if (serviceName == null) {
            serviceName = DiscoveryConstants.SERVICE_NAME_PREFIX +
                    new GregorianCalendar().getTimeInMillis();
        }

        Service newService = serviceManager.newService(new QName(
                DiscoveryConstants.WS_DISCOVERY_NAMESPACE, serviceName));
        newService.setId(serviceId);

        // Save the endpoint reference element as an attribute
        OMElement epr = EndpointReferenceHelper.toOM(OMAbstractFactory.getSOAP11Factory(),
                service.getEpr(),
                AddressingConstants.Final.WSA_ENDPOINT_REFERENCE,
                AddressingConstants.Final.WSA_NAMESPACE);
        newService.addAttribute(DiscoveryConstants.ATTR_EPR, epr.toString());

        // Set the version if provided
        if (service.getMetadataVersion() != -1) {
            newService.addAttribute(DiscoveryConstants.ATTR_METADATA_VERSION,
                    String.valueOf(service.getMetadataVersion()));
        }

         // Store other service metadata (scopes, types, x-addresses)
        QName[] types = service.getTypes();
        if (types != null && types.length > 0) {
            newService.setAttributes(DiscoveryConstants.ATTR_TYPES, Util.toStringArray(types));
        }

        URI[] scopes = service.getScopes();
        if (scopes != null && scopes.length > 0) {
            newService.setAttributes(DiscoveryConstants.ATTR_SCOPES, Util.toStringArray(scopes));
        }

        URI[] xAddresses = service.getXAddresses();
        boolean activate = false;
        if (xAddresses != null && xAddresses.length > 0) {
            newService.setAttributes(DiscoveryConstants.ATTR_XADDRESSES,
                    Util.toStringArray(xAddresses));
            activate = true;
        }

        // One hot discovered service coming thru....
        serviceManager.addService(newService);
        if (activate) {
            newService.activate();
        }
    }   
View Full Code Here


     * @return a TargetService instance with the given ID or null if no such service exists
     * @throws Exception if an error occurs while accessing the registry
     */
    public static TargetService getService(EndpointReference epr) throws Exception {
        ServiceManager serviceManager = new ServiceManager(getRegistry());
        Service service = serviceManager.getService(epr.getAddress());
        if (service == null) {
            return null;
        }

        return getTargetService(service);
View Full Code Here

     * @return the artifact added.
     * @throws GovernanceException if the operation failed.
     */
    public Service newService(QName qName) throws GovernanceException {
        String serviceId = UUID.randomUUID().toString();
        Service service = new Service(serviceId, qName);
        service.associateRegistry(registry);
        return service;
    }
View Full Code Here

     * @return the artifact added.
     * @throws GovernanceException if the operation failed.
     */
    public Service newService(OMElement content) throws GovernanceException {
        String serviceId = UUID.randomUUID().toString();
        Service service = new Service(serviceId, content);
        service.associateRegistry(registry);
        return service;
    }
View Full Code Here

     */
    public void updateService(Service service) throws GovernanceException {
        boolean succeeded = false;
        try {
            registry.beginTransaction();
            Service oldService = getService(service.getId());
            // first check for the old service and remove it.
            if (oldService != null) {
                QName oldQname = oldService.getQName();
                if (!oldQname.equals(service.getQName())) {
                    // then it is analogue to moving the resource for the new location
                    String oldPath = oldService.getPath();
                    // so just delete the old path
                    registry.delete(oldPath);
                }
            }
            addService(service);
View Full Code Here

public class ServiceTest extends BaseTestCase {
   
    public void testAddService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);

        Service service = serviceManager.newService(new QName("http://bang.boom.com/mnm/beep", "MyService"));
        service.addAttribute("testAttribute", "somevalue");
        serviceManager.addService(service);

        String serviceId = service.getId();
        Service newService = serviceManager.getService(serviceId);

        assertEquals(newService.getAttribute("testAttribute"), "somevalue");

        service.addAttribute("testAttribute", "somevalue2");
        serviceManager.updateService(service);

        newService = serviceManager.getService(serviceId);

        String[] values = newService.getAttributes("testAttribute");

        assertEquals(values.length, 2);
    }
View Full Code Here

        fileInputStream.read(fileContents);

        OMElement contentElement = GovernanceUtils.buildOMElement(fileContents);

        ServiceManager serviceManager = new ServiceManager(registry);                                      
        Service service = serviceManager.newService(contentElement);

        service.addAttribute("custom-attribute", "custom-value");
        serviceManager.addService(service);


        // so retrieve it back
        String serviceId = service.getId();
        Service newService = serviceManager.getService(serviceId);

        assertEquals(newService.getAttribute("custom-attribute")"custom-value");
        assertEquals(newService.getAttribute("interface_wsdlURL"),
                "/_system/governance/wsdls/com/foo/abc.wsdl");
        assertEquals(service.getQName(), newService.getQName());

        Service service2 = serviceManager.newService(new QName("http://baps.paps.mug/done", "meep"));
        service2.addAttribute("custom-attribute", "custom-value2");
        serviceManager.addService(service2);

        Service service3 =  serviceManager.newService(new QName("http://baps.paps.mug/jug", "peem"));
        service3.addAttribute("custom-attribute", "not-custom-value");
        serviceManager.addService(service3);

        Service service4 =  serviceManager.newService(new QName("http://baps.dadan.mug/jug", "doon"));
        service4.addAttribute("not-custom-attribute", "custom-value3");
        serviceManager.addService(service4);

        Service[] services = serviceManager.findServices(new ServiceFilter() {
            public boolean matches(Service service) throws GovernanceException {
                String attributeVal = service.getAttribute("custom-attribute");
View Full Code Here

        Wsdl wsdl = wsdlManager.newWsdl("http://svn.wso2.org/repos/wso2/trunk/carbon/components/governance/org.wso2.carbon.governance.api/src/test/resources/test-resources/wsdl/BizService.wsdl");
         wsdlManager.addWsdl(wsdl);

        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://test/org/bang", "myservice"));
        serviceManager.addService(service);

        service.attachWSDL(wsdl);

        Wsdl[] wsdls = service.getAttachedWsdls();

        assertEquals(wsdls.length, 1);
        assertEquals(wsdls[0].getQName(), new QName("http://foo.com", "BizService.wsdl"));

        Schema[] schemas = wsdls[0].getAttachedSchemas();

        assertEquals(schemas.length, 1);
        assertEquals(schemas[0].getQName(), new QName("http://bar.org/purchasing", "purchasing.xsd"));
        assertNotNull(schemas[0].getId());

        // now add a policy.
        PolicyManager policyManager = new PolicyManager(registry);

        Policy policy = policyManager.newPolicy(
                "http://svn.wso2.org/repos/wso2/tags/wsf/php/2.1.0/samples/security/" +
                        "complete/policy.xml");
        policy.setName("mypolicy.xml");
        policyManager.addPolicy(policy);

        service.attachPolicy(policy);

        Policy[] policies = service.getAttachedPolicies();
        assertEquals(policies.length, 1);
        assertEquals(policies[0].getQName(), new QName("mypolicy.xml"));

        File file = new File("src/test/resources/service.metadata.xml");
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] fileContents = new byte[(int)file.length()];
        fileInputStream.read(fileContents);

        OMElement contentElement = GovernanceUtils.buildOMElement(fileContents);

        service = serviceManager.newService(contentElement);
        //serviceManager.addService(service);

        String[] serviceIds = serviceManager.getAllServiceIds();
        for (String serviceId: serviceIds) {
            Service servicex = serviceManager.getService(serviceId);
            Policy[] policiesx = servicex.getAttachedPolicies();
            if (policiesx != null && policiesx.length != 0) {
                assertEquals(policiesx[0].getQName(), new QName("mypolicy.xml"));
            }
        }
View Full Code Here

    }

    public void testServiceRename() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);

        Service service = serviceManager.newService(new QName("http://banga.queek.queek/blaa", "sfosf"));
        serviceManager.addService(service);

        service.setQName(new QName("http://doc.x.ge/yong", "almdo"));
        serviceManager.updateService(service);

        Service exactServiceCopy = serviceManager.getService(service.getId());
        QName qname = exactServiceCopy.getQName();

        assertEquals(new QName("http://doc.x.ge/yong", "almdo"), qname);
        assertEquals(RegistryUtils.getRelativePathToOriginal(registry.getRegistryContext().getServicePath(),
                RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) +
                "/ge/x/doc/yong/almdo/1.0.0-SNAPSHOT/service", exactServiceCopy.getPath());


        // doing the same for a meta data service
        File file = new File("src/test/resources/service.metadata.xml");
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] fileContents = new byte[(int)file.length()];
        fileInputStream.read(fileContents);

        OMElement contentElement = GovernanceUtils.buildOMElement(fileContents);

        service = serviceManager.newService(contentElement);
        serviceManager.addService(service);

        service.setQName(new QName("http://doc.x.ge/yong", "almdo"));
        serviceManager.updateService(service);

        exactServiceCopy = serviceManager.getService(service.getId());
        qname = exactServiceCopy.getQName();

        assertEquals(new QName("http://doc.x.ge/yong", "almdo"), qname);
        assertEquals(RegistryUtils.getRelativePathToOriginal(registry.getRegistryContext().getServicePath(),
                RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) +
                "/ge/x/doc/yong/almdo/1.0.0-SNAPSHOT/service", exactServiceCopy.getPath());
               
    }
View Full Code Here

    }

    public void testServiceDelete() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);

        Service service = serviceManager.newService(new QName("http://banga.doom.queek/blaa", "lmnop"));
        serviceManager.addService(service);

        Service newService = serviceManager.getService(service.getId());
        assertNotNull(newService);

        serviceManager.removeService(newService.getId());
        newService = serviceManager.getService(service.getId());
        assertNull(newService);


        service = serviceManager.newService(new QName("http://banga.bang.queek/blaa", "basss"));
        serviceManager.addService(service);

        newService = serviceManager.getService(service.getId());
        assertNotNull(newService);

        registry.delete(newService.getPath());
        newService = serviceManager.getService(service.getId());
        assertNull(newService);
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.governance.api.services.dataobjects.Service

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.