Package org.apache.tuscany.sca.node.impl

Examples of org.apache.tuscany.sca.node.impl.NodeImpl


        }
        return getServletHost(node);
    }
   
    private static WebAppServletHost getServletHost(Node node) {
        NodeImpl nodeImpl = (NodeImpl) node;
        ExtensionPointRegistry eps = nodeImpl.getExtensionPoints();
        ServletHostExtensionPoint servletHosts = eps.getExtensionPoint(ServletHostExtensionPoint.class);
        List<ServletHost> hosts = servletHosts.getServletHosts();
        if (hosts == null || hosts.size() < 1) {
            throw new IllegalStateException("No ServletHost found");
        }
View Full Code Here


     * @throws Exception
     */
    @Test
    public void testInterfaceWriteRead() throws Exception {
        String [] contributions = {"./target/classes"};
        NodeImpl node1 = (NodeImpl)NodeFactory.newInstance().createNode(URI.create("uri:default"),
                                                                        "org/apache/tuscany/sca/itest/interfaces/missmatch/distributed/MissmatchDistributedService.composite",
                                                                        contributions);
        node1.start();
       
        Component serviceComponent = node1.getDomainComposite().getComponents().get(0);
        Service service = serviceComponent.getServices().get(0);
       
        InterfaceContractProcessor processor = new InterfaceContractProcessor(node1.getExtensionPointRegistry());
        ProcessorContext context = new ProcessorContext();
       
        FactoryExtensionPoint modelFactories = node1.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos);
        processor.write(service.getInterfaceContract(), writer, context);
        writer.close();
       
        String xml = bos.toString();
        System.out.println("Written ouput is:\n" + xml);
       
        ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
        XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
        XMLStreamReader reader = inputFactory.createXMLStreamReader(bis);
        InterfaceContract interfaceContract = processor.read(reader, context);
       
        bos = new ByteArrayOutputStream();
        writer = outputFactory.createXMLStreamWriter(bos);
        processor.write(interfaceContract, writer, context);
        writer.close();
       
        System.out.println("Read ouput is:\n" + bos);
       
        InterfaceContractMapper interfaceContractMapper = new InterfaceContractMapperImpl(node1.getExtensionPointRegistry());
       
        Audit matchAudit = new Audit();
        boolean match = false;
        match = interfaceContractMapper.isCompatibleSubset(service.getInterfaceContract(),
                                                           interfaceContract,
                                                           matchAudit);
       
        if (!match){
            System.out.println(matchAudit.toString());
        }
       
        Assert.assertTrue(match);
      
        node1.stop();
   
View Full Code Here

   
    public void testTuscanySerialization() throws Exception {        
       
        // read in WSDL
        String contributionLocation = "target/classes";
        NodeImpl node = (NodeImpl)NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/ws/axis2/wsdl-serialize.composite",
                                                                       new Contribution("test", contributionLocation));
        node.start();
       
        try {           
           
            RuntimeEndpointImpl endpoint = (RuntimeEndpointImpl)node.getDomainComposite().getComponents().get(0).getServices().get(0).getEndpoints().get(0);
            WSDLInterface wsdlInterface = (WSDLInterface)endpoint.getBindingInterfaceContract().getInterface();
           
            WSDLDefinition wsdlDefinition = wsdlInterface.getWsdlDefinition();
            Definition definition = wsdlDefinition.getDefinition();
           
            // write out a flattened WSDL along with XSD
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            try {
                WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
                String baseURI = null;
                if (wsdlDefinition.getLocation() != null) {
                    baseURI = wsdlDefinition.getLocation().toString();
                } else {
                    baseURI = "GeneratedWSDL";
                }
                outStream.write(baseURI.getBytes());
                outStream.write(separator);           
                writer.writeWSDL(definition, outStream);
                for (WSDLDefinition importedWSDLDefintion : wsdlDefinition.getImportedDefinitions()){
                    outStream.write(separator);
                    baseURI = importedWSDLDefintion.getLocation().toString();
                    outStream.write(baseURI.getBytes());
                    outStream.write(separator);
                    writer.writeWSDL(importedWSDLDefintion.getDefinition(), outStream);
                }
                for (XSDefinition xsdDefinition : wsdlDefinition.getXmlSchemas()){
                    // we store a reference to the schema schema. We don't need to write that out.
                    // also ignore schema that are extract from the original WSDL (have in their location)
                    if (!xsdDefinition.getNamespace().equals("http://www.w3.org/2001/XMLSchema") &&
                        xsdDefinition.getSchema() != null){
                        writeSchema(outStream, xsdDefinition.getSchema());
                    }
                }          
            } catch (Exception e){
                throw new RuntimeException(e);
            }
   
            String wsdlString = outStream.toString();
            //System.out.println(wsdlString);
           
            // Read the WSDL and XSD back in from the string
            String xmlArray[] = wsdlString.split("_X_");
            String topWSDLLocation = null;
            Map<String, XMLString> xmlMap = new HashMap<String, XMLString>();
           
            for (int i = 0; i < xmlArray.length; i = i + 2){
                String location = xmlArray[i];
                String xml = xmlArray[i+1];
                // strip the file name out of the location
                location = location.substring(location.lastIndexOf("/") + 1);
               
                if (location.endsWith(".wsdl")){
                    xmlMap.put(location,
                               new WSDLInfo(xmlArray[i],
                                              xml));
                   
                    if (topWSDLLocation == null){
                        topWSDLLocation = location;
                    }
                } else {
                    xmlMap.put(location,
                            new XSDInfo(xmlArray[i],
                                          xml));
                }
            }
           
            ExtensionPointRegistry registry = endpoint.getCompositeContext().getExtensionPointRegistry();
            FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
            org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory wsdlFactory = modelFactories.getFactory(org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory.class);
            XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class);
            XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
            schemaCollection.setSchemaResolver(new XSDURIResolverImpl(xmlMap));
            ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
            final org.apache.tuscany.sca.contribution.Contribution contribution = contributionFactory.createContribution();
            ProcessorContext processorContext = new ProcessorContext();
           
            ExtensibleModelResolver extensibleResolver = new ExtensibleModelResolver(contribution, registry.getExtensionPoint(ModelResolverExtensionPoint.class), modelFactories);
            WSDLModelResolver wsdlResolver = (WSDLModelResolver)extensibleResolver.getModelResolverInstance(WSDLDefinition.class);
            XSDModelResolver xsdResolver = (XSDModelResolver)extensibleResolver.getModelResolverInstance(XSDefinition.class);
            contribution.setURI("temp");
            contribution.setLocation(topWSDLLocation);
            contribution.setModelResolver(extensibleResolver);
   
            // read
            for (XMLString xmlString : xmlMap.values()){
                if (xmlString instanceof WSDLInfo){
                    WSDLReader reader =  WSDLFactory.newInstance().newWSDLReader();
                    reader.setFeature("javax.wsdl.verbose", false);
                    reader.setFeature("javax.wsdl.importDocuments", true);
                    WSDLLocatorImpl locator = new WSDLLocatorImpl(xmlString.getBaseURI(), xmlMap);
                    Definition readDefinition = reader.readWSDL(locator);
                   
                    wsdlDefinition = wsdlFactory.createWSDLDefinition();
                    wsdlDefinition.setDefinition(readDefinition);
                    wsdlDefinition.setLocation(new URI(xmlString.getBaseURI()));
                   
                    ((WSDLInfo)xmlString).setWsdlDefintion(wsdlDefinition);
                    wsdlResolver.addModel(wsdlDefinition, processorContext);
                   
                } else {
                    InputStream inputStream = new ByteArrayInputStream(xmlString.getXmlString().getBytes());
                    InputSource inputSource = new InputSource(inputStream);
                    inputSource.setSystemId(xmlString.getBaseURI());
                    XmlSchema schema = schemaCollection.read(inputSource, null);
                    inputStream.close();
                   
                    XSDefinition xsdDefinition = xsdFactory.createXSDefinition();
                    xsdDefinition.setSchema(schema);
                   
                    ((XSDInfo)xmlString).setXsdDefinition(xsdDefinition);
                    xsdResolver.addModel(xsdDefinition, processorContext);
                }
            }
           
            // resolve
            for (XMLString xmlString : xmlMap.values()){
                if (xmlString instanceof WSDLInfo){
                   wsdlDefinition = ((WSDLInfo)xmlString).getWsdlDefintion();
                  
                   // link to imports
                   for (Map.Entry<String, List<javax.wsdl.Import>> entry :
                       ((Map<String, List<javax.wsdl.Import>>)wsdlDefinition.getDefinition().getImports()).entrySet()) {
                       for (javax.wsdl.Import imp : entry.getValue()) {
                           String wsdlName = imp.getDefinition().getDocumentBaseURI();
                           WSDLInfo wsdlInfo = (WSDLInfo)xmlMap.get(getFilenameWithoutPath(wsdlName));
                           wsdlDefinition.getImportedDefinitions().add(wsdlInfo.getWsdlDefintion());
                       }
                   }
                  
                   // link to in-line types
                   Types types = wsdlDefinition.getDefinition().getTypes();
                   if ( types != null){
                       for (int i=0; i < types.getExtensibilityElements().size(); i++){
                           String schemaName = xmlString.getBaseURI() + "#" + i++;
                           XSDInfo xsdInfo = (XSDInfo)xmlMap.get(getFilenameWithoutPath(schemaName));
                           wsdlDefinition.getXmlSchemas().add(xsdInfo.getXsdDefinition());
                       }
                   }
   
                } else {
                   
                }
            }
           
            WSDLInfo topWSDL = (WSDLInfo)xmlMap.get(topWSDLLocation);
            WSDLDefinition topWSDLDefinition = topWSDL.getWsdlDefintion();
           
            PortType portType = (PortType)topWSDLDefinition.getDefinition().getAllPortTypes().values().iterator().next();
            WSDLInterface readWSDLInterface = wsdlFactory.createWSDLInterface(portType, topWSDLDefinition, extensibleResolver, null);
           
            // now check what we have just read with what we started out with to see if the compatibility test passes
            // in the real system have to check contracts not interfaces
            UtilityExtensionPoint utils = registry.getExtensionPoint(UtilityExtensionPoint.class);
            InterfaceContractMapper interfaceContractMapper = utils.getUtility(InterfaceContractMapper.class);
            boolean match = interfaceContractMapper.isCompatibleSubset(wsdlInterface, readWSDLInterface);
            Assert.assertTrue(match);
        } catch(Exception ex){
            System.out.println(ex.toString());
            ex.printStackTrace();
            node.stop();
            Assert.fail();
        }
       
        node.stop();       
    }
View Full Code Here

                    configuration.setDomainURI(domainURI);
                }
                configuration.setURI(contribution.getURI());
                // configuration.getExtensions().add(bundle);
                // FIXME: Configure the domain and node URI
                NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
                node.start();

                Component component = contribution.getDeployables().get(0).getComponents().get(0);
                ComponentReference componentReference = component.getReferences().get(0);
                ServiceReference serviceReference =
                    context.getServiceReference("(sca.reference=" + component.getURI()
View Full Code Here

               
                // create the org.osgi.sca.config.xml property 
                service.getExtensions().add(createSCAConfigXMLProperty(reference, properties, service));

                // FIXME: Configure the domain and node URI
                NodeImpl node = new NodeImpl(nodeFactory, configuration, Collections.singletonList(contribution));
                node.start();
                List<ExportRegistration> exportedServices = new ArrayList<ExportRegistration>();
                for (Endpoint endpoint : service.getEndpoints()) {
                    EndpointDescription endpointDescription = createEndpointDescription(context, endpoint);
                    synchronized (this) {
                        ExportReferenceImpl exportReference = exportReferences.get(endpointDescription);
View Full Code Here

        }
        return getServletHost(node);
    }

    private static WebAppServletHost getServletHost(Node node) {
        NodeImpl nodeImpl = (NodeImpl)node;
        ExtensionPointRegistry eps = nodeImpl.getExtensionPoints();
        ServletHostExtensionPoint servletHosts = eps.getExtensionPoint(ServletHostExtensionPoint.class);
        List<ServletHost> hosts = servletHosts.getServletHosts();
        if (hosts == null || hosts.size() < 1) {
            throw new IllegalStateException("No ServletHost found");
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.node.impl.NodeImpl

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.