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

Examples of org.wso2.carbon.governance.api.services.ServiceManager


        }
        GovernanceArtifact[] artifacts = wsdl.getDependents();
        // delete the wsdl
        wsdlManager.removeWsdl(wsdl.getId());

        ServiceManager serviceManager = new ServiceManager(registry);

        for (GovernanceArtifact artifact: artifacts) {
            if (artifact instanceof Service) {
                // getting the service.
                Service service2 = (Service)artifact;
                serviceManager.removeService(service2.getId());
            }
        }       

        // now try to remove the endpoint
        endpointManager.removeEndpoint(endpoints[0].getId());
View Full Code Here


        endpointManager.removeEndpoint(endpoints[0].getId());
        assertTrue(true);
    }

    public void testAddServiceWithEndpoints() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test/xxx", "myService"));

        service.addAttribute("endpoints_entry", ":http://endpoint1");
        service.addAttribute("endpoints_entry", "QA:http://endpoint2");

        serviceManager.addService(service);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        assertEquals("http://endpoint1", endpoints[0].getUrl());
        assertEquals(0, endpoints[0].getAttributeKeys().length);

        assertEquals("http://endpoint2", endpoints[1].getUrl());
        assertEquals(1, endpoints[1].getAttributeKeys().length);
        assertEquals("QA", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));

        // now update the endpoints in the service
        service.setAttributes("endpoints_entry", new String[] {
                "Dev:http://endpoint3",
                "Production:http://endpoint4",
                "QA:http://endpoint2",
        });
        serviceManager.updateService(service);

        endpoints = service.getAttachedEndpoints();
        assertEquals(3, endpoints.length);

View Full Code Here

        assertEquals("QA", endpoints[2].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));      
    }

    // add endpoints as attachments
    public void testAttachEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test234/xxxxx", "myServicxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("http://endpoint1xx");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("http://endpoint2xx");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        assertEquals("http://endpoint1xx", endpoints[0].getUrl());
        assertEquals(0, endpoints[0].getAttributeKeys().length);

        assertEquals("http://endpoint2xx", endpoints[1].getUrl());
        assertEquals(1, endpoints[1].getAttributeKeys().length);
        assertEquals("QA", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));

        service.detachEndpoint(ep1.getId());
        endpoints = service.getAttachedEndpoints();
        assertEquals(1, endpoints.length);
       
        assertEquals("http://endpoint2xx", endpoints[0].getUrl());
        assertEquals(1, endpoints[0].getAttributeKeys().length);
        assertEquals("QA", endpoints[0].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));


        // now update the endpoints in the service
        service.setAttributes("endpoints_entry", new String[] {
                "Dev:http://endpoint3",
                "Production:http://endpoint4",
                "QA:http://endpoint2xx",
        });
        serviceManager.updateService(service);

        endpoints = service.getAttachedEndpoints();
        assertEquals(3, endpoints.length);

View Full Code Here

        Endpoint ep5 = endpointManager.getEndpointByUrl("http://endpoint2");
        assertEquals("QA", ep5.getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
    }

    public void testAssociatingEndpoints() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://done.ding/dong/doodo", "bangService343"));

        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint endpoint = endpointManager.newEndpoint("http://dos.dis/doos/safdsf/ppeekk");
        endpointManager.addEndpoint(endpoint);
        service.attachEndpoint(endpoint);

        // retrieve the service
        Service service2 = serviceManager.getService(service.getId());
        Endpoint[] endpoints = service2.getAttachedEndpoints();
        assertEquals(1, endpoints.length);

        assertEquals(":" + endpoints[0].getUrl(), service2.getAttribute("endpoints_entry"));
    }
View Full Code Here

        byte[] fileContents = new byte[(int)file.length()];
        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("endpoints_entry"),
                ":http://localhost:8080/axis2/services/BizService");

        // now we just add an endpoints
View Full Code Here

        }
    }

    // detach endpoints
    public void testDetachEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/test234/xxxxx", "myServicxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("http://endpoint1");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("http://endpoint2");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        // get the updated service endpoints
        service = serviceManager.getService(service.getId());

        String[] endpointValues = service.getAttributes("endpoints_entry");

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

        assertEquals(2, endpointValues.length);
    }

    // add non http endpoints as attachments
    public void testNonHttpEndpointsToService() throws Exception {
        ServiceManager serviceManager = new ServiceManager(registry);
        Service service = serviceManager.newService(new QName("http://wso2.com/doadf/spidf", "myServisdfcxcde"));
        serviceManager.addService(service);

        EndpointManager endpointManager = new EndpointManager(registry);
        Endpoint ep1 = endpointManager.newEndpoint("jms:/Service1");
        endpointManager.addEndpoint(ep1);

        Endpoint ep2 = endpointManager.newEndpoint("jms:/Service2");
        ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
        endpointManager.addEndpoint(ep2);

        service.attachEndpoint(ep1);
        service.attachEndpoint(ep2);

        Endpoint[] endpoints = service.getAttachedEndpoints();
        assertEquals(2, endpoints.length);

        // get the updated service endpoints
        service = serviceManager.getService(service.getId());

        String[] endpointValues = service.getAttributes("endpoints_entry");

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

     *
     * @param service WS-D target service to be added to the registry
     * @throws Exception if an error occurs while saving the artifacts to the registry
     */
    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

        addService(service);
    }

    public static void remove(TargetService service) throws Exception {
        ServiceManager serviceManager = new ServiceManager(getRegistry());
        if (serviceManager.getService(service.getEpr().getAddress()) != null) {
            serviceManager.removeService(service.getEpr().getAddress());
        }
    }
View Full Code Here

     * @param epr WS-D service identifier
     * @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

TOP

Related Classes of org.wso2.carbon.governance.api.services.ServiceManager

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.