我正在尝试学习如何使用 Tuscany 和 OSGi 捆绑包进行开发,以用作 SCA 组件的实现。我在 Eclipse IDE 上使用 java。我试图搜索在线教程以开始,但我没有找到任何人。
我在这里找到了一个链接http://tuscany.apache.org/sca-java-implementationosgi.html 这有助于总体思路,但没有提供详细信息。我决定在没有教程的情况下尝试,我做了一些事情,但没有奏效,并且出现错误。
所以这就是我所做的:我创建了一个包含以下接口的包:
package com.javaworld.sample.service;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface HelloService {
public String sayHello();
}
接口的实现工作正常,我在没有托斯卡纳的情况下单独检查了这个项目。
现在,这里是这个包的清单文件:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloService
Bundle-SymbolicName: com.javaworld.sample.HelloService
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.javaworld.sample.service.impl.HelloServiceActivator
Bundle-Vendor: JAVAWORLD
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: com.javaworld.sample.service
在一个单独的项目中,我有几个构建为 SCA 的组件,这是我的名为 store.composite 的复合文件,
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
xmlns:s="http://store"
targetNamespace="http://store"
name="store">
<component name="store">
<t:implementation.widget location="ufservices/store.html" />
<service name="Widget">
<t:binding.http uri="http://localhost:8080/store" />
</service>
<reference name="catalog" target="Catalog">
<t:binding.jsonrpc />
</reference>
<reference name="shoppingCart" target="ShoppingCart/Cart">
<t:binding.atom />
</reference>
<reference name="shoppingTotal" target="ShoppingCart/Total">
<t:binding.jsonrpc />
</reference>
<reference name="hellowService" target="HelloWorldService">
<t:binding.jsonrpc />
</reference>
</component>
<component name="Catalog">
<implementation.java class="services.CatalogImpl" />
<property name="currencyCode">USD</property>
<service name="Catalog">
<t:binding.jsonrpc uri="http://localhost:8080/Catalog"/>
</service>
<reference name="currencyConverter" target="CurrencyConverter" />
</component>
<component name="ShoppingCart">
<implementation.java class="services.ShoppingCartImpl" />
<service name="Cart">
<t:binding.atom uri="http://localhost:8080/ShoppingCart/Cart" />
</service>
<service name="Total">
<t:binding.jsonrpc uri="http://localhost:8080/Total"/>
</service>
</component>
<component name="CurrencyConverter">
<implementation.java class="services.CurrencyConverterImpl" />
</component>
<component name="HelloWorldService">
<implementation.osgi xmlns=http://tuscany.apache.org/xmlns/sca/1.0
bundleSymbolicName="com.javaworld.sample.HelloService"
bundleVersion="1.0.0.qualifier">
</implementation.osgi>
</component>
</composite>
您可以在此文件的末尾看到我创建了一个组件,该组件引用了 HelloWorldService 包的 osgi 实现。
下面是我的商店组件的一部分,它是一个 html 文件:
<html>
<head>
<title>Store</title>
<script type="text/javascript" src="store.js"></script>
<script language="JavaScript">
//@Reference
var hellowService= new tuscany.sca.Reference("hellowService");
function displayHellowService()
{
var h= hellowService.sayHello();
alert(h);
}
</script>
</head>
<body>
<h1>Store</h1>
<div id="store">
<form name="shoppingCartForm">
<input type="button" id="button1" onclick="displayHellowService()"/>
</form>
</div>
</body>
</html>
我还有一个包含主要方法并创建整个东西的启动 java 文件。最后,以下是我在运行项目时遇到的错误。
SEVERE: ContributionReadException occured due to : org.xml.sax.SAXParseException; lineNumber: 51; columnNumber: 36; Open quote is expected for attribute "xmlns" associated with an element type "implementation.osgi".
يول 14, 2013 1:37:52 ص org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor
SEVERE: ContributionReadException occured due to : com.ctc.wstx.exc.WstxIOException: Stream closed
Exception in thread "main" org.osoa.sca.ServiceRuntimeException: org.apache.tuscany.sca.contribution.service.ContributionException: org.apache.tuscany.sca.contribution.service.ContributionReadException: com.ctc.wstx.exc.WstxIOException: Stream closed
at org.apache.tuscany.sca.node.impl.NodeImpl.<init>(NodeImpl.java:204)
at org.apache.tuscany.sca.node.impl.NodeFactoryImpl.createSCANodeFromClassLoader(NodeFactoryImpl.java:37)
at org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain.init(DefaultSCADomain.java:178)
at org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain.<init>(DefaultSCADomain.java:100)
at org.apache.tuscany.sca.host.embedded.SCADomain.createNewInstance(SCADomain.java:182)
at org.apache.tuscany.sca.host.embedded.SCADomain.newInstance(SCADomain.java:63)
at launch.Launch.main(Launch.java:8)
Caused by: org.apache.tuscany.sca.contribution.service.ContributionException: org.apache.tuscany.sca.contribution.service.ContributionReadException: com.ctc.wstx.exc.WstxIOException: Stream closed
at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.addContribution(ContributionServiceImpl.java:421)
at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.contribute(ContributionServiceImpl.java:198)
at org.apache.tuscany.sca.node.impl.NodeImpl.configureNode(NodeImpl.java:524)
at org.apache.tuscany.sca.node.impl.NodeImpl.<init>(NodeImpl.java:200)
... 6 more
Caused by: org.apache.tuscany.sca.contribution.service.ContributionReadException: com.ctc.wstx.exc.WstxIOException: Stream closed
at org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.read(CompositeDocumentProcessor.java:214)
at org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.read(CompositeDocumentProcessor.java:137)
at org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.read(CompositeDocumentProcessor.java:59)
at org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor.read(ExtensibleURLArtifactProcessor.java:96)
at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.processReadPhase(ContributionServiceImpl.java:587)
at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.addContribution(ContributionServiceImpl.java:419)
... 9 more
Caused by: com.ctc.wstx.exc.WstxIOException: Stream closed
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:548)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:604)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:619)
at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:317)
at org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory.createXMLStreamReader(DefaultValidatingXMLInputFactory.java:226)
at org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor.read(CompositeDocumentProcessor.java:181)
... 14 more
Caused by: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.ctc.wstx.io.StreamBootstrapper.ensureLoaded(StreamBootstrapper.java:443)
at com.ctc.wstx.io.StreamBootstrapper.resolveStreamEncoding(StreamBootstrapper.java:267)
at com.ctc.wstx.io.StreamBootstrapper.bootstrapInput(StreamBootstrapper.java:131)
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:543)
... 19 more
有人可以给我一个教程指南或帮助我解决问题。谢谢。