You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/17 15:30:12 UTC
svn commit: r386642 [2/2] - in /incubator/servicemix/trunk/servicemix-sca:
./ src/main/java/org/apache/servicemix/sca/
src/main/java/org/apache/servicemix/sca/assembly/
src/main/java/org/apache/servicemix/sca/assembly/impl/
src/main/java/org/apache/ser...
Added: incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/java/org/apache/servicemix/sca/tuscany/TuscanyRuntime.java Fri Mar 17 06:30:08 2006
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.sca.tuscany;
+
+import java.util.List;
+
+import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
+import org.apache.tuscany.core.config.ConfigurationException;
+import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
+import org.apache.tuscany.core.context.AggregateContext;
+import org.apache.tuscany.core.context.CoreRuntimeException;
+import org.apache.tuscany.core.context.EventContext;
+import org.apache.tuscany.core.context.SystemAggregateContext;
+import org.apache.tuscany.core.runtime.RuntimeContext;
+import org.apache.tuscany.core.runtime.RuntimeContextImpl;
+import org.apache.tuscany.model.assembly.AssemblyModelContext;
+import org.apache.tuscany.model.assembly.ModuleComponent;
+import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
+import org.osoa.sca.ModuleContext;
+import org.osoa.sca.SCA;
+import org.osoa.sca.ServiceRuntimeException;
+
+public class TuscanyRuntime extends SCA {
+ private final TuscanyRuntime.Monitor monitor;
+ private final Object sessionKey = new Object();
+
+ private final RuntimeContext runtime;
+ private final AggregateContext moduleContext;
+
+ private final ModuleComponent moduleComponent;
+
+ private static final String SYSTEM_MODULE_COMPONENT = "org.apache.tuscany.core.system";
+
+ /**
+ * Construct a runtime using a null MonitorFactory.
+ *
+ * @param name the name of the module component
+ * @param uri the URI to assign to the module component
+ * @throws ConfigurationException if there was a problem loading the SCA configuration
+ * @see TuscanyRuntime#TuscanyRuntime(String, String, org.apache.tuscany.common.monitor.MonitorFactory)
+ */
+ public TuscanyRuntime(String name, String uri) throws ConfigurationException {
+ this(name, uri,
+ Thread.currentThread().getContextClassLoader(),
+ new NullMonitorFactory());
+ }
+
+ /**
+ * Construct a runtime containing a single module component with the
+ * specified name. The module definition is loaded from a "/sca.module"
+ * resource found on the classpath of the current Thread context classloader.
+ *
+ * @param name the name of the module component
+ * @param uri the URI to assign to the module component
+ * @param classLoader the class loader to use for the assembly
+ * @param monitorFactory the MonitorFactory for this runtime
+ * @throws ConfigurationException if there was a problem loading the SCA configuration
+ */
+ public TuscanyRuntime(String name, String uri, ClassLoader classLoader, MonitorFactory monitorFactory) throws ConfigurationException {
+ this.monitor = monitorFactory.getMonitor(TuscanyRuntime.Monitor.class);
+
+ // Create an assembly model context
+ AssemblyModelContext modelContext = BootstrapHelper.getModelContext(classLoader);
+
+ // Create a runtime context and start it
+ List<SCDLModelLoader> loaders = modelContext.getAssemblyLoader().getLoaders();
+ List<ContextFactoryBuilder> configBuilders = BootstrapHelper.getBuilders();
+ runtime = new RuntimeContextImpl(monitorFactory, loaders, configBuilders, new DefaultWireBuilder());
+ runtime.start();
+ monitor.started(runtime);
+
+ // Load and start the system configuration
+ SystemAggregateContext systemContext = runtime.getSystemContext();
+ ModuleComponentConfigurationLoader loader = BootstrapHelper.getConfigurationLoader(systemContext, modelContext);
+ ModuleComponent systemModuleComponent = loader.loadSystemModuleComponent(SYSTEM_MODULE_COMPONENT, SYSTEM_MODULE_COMPONENT);
+ AggregateContext context = BootstrapHelper.registerModule(systemContext, systemModuleComponent);
+ context.fireEvent(EventContext.MODULE_START, null);
+
+ // Load the SCDL configuration of the application module
+ AggregateContext rootContext = runtime.getRootContext();
+ moduleComponent = loader.loadModuleComponent(name, uri);
+ moduleContext = BootstrapHelper.registerModule(rootContext, moduleComponent);
+ }
+
+ public ModuleComponent getModuleComponent() {
+ return moduleComponent;
+ }
+
+ public AggregateContext getModuleContext() {
+ return moduleContext;
+ }
+
+ /**
+ * Start the runtime and associate the module context with the calling thread.
+ */
+ @Override
+ public void start() {
+ setModuleContext((ModuleContext) moduleContext);
+ try {
+ //moduleContext.start();
+ moduleContext.fireEvent(EventContext.MODULE_START, null);
+ moduleContext.fireEvent(EventContext.REQUEST_START, null);
+ moduleContext.fireEvent(EventContext.SESSION_NOTIFY, sessionKey);
+ monitor.started(moduleContext);
+ } catch (CoreRuntimeException e) {
+ setModuleContext(null);
+ monitor.startFailed(moduleContext, e);
+ //FIXME throw a better exception
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Disassociate the module context from the current thread and shut down the runtime.
+ */
+ @Override
+ public void stop() {
+ setModuleContext(null);
+ moduleContext.fireEvent(EventContext.REQUEST_END, null);
+ moduleContext.fireEvent(EventContext.SESSION_END, sessionKey);
+ moduleContext.fireEvent(EventContext.MODULE_STOP, null);
+ moduleContext.stop();
+ monitor.stopped(moduleContext);
+ runtime.stop();
+ monitor.stopped(runtime);
+ }
+
+ /**
+ * Monitor interface for a TuscanyRuntime.
+ */
+ public static interface Monitor {
+ /**
+ * Event emitted after the runtime has been started.
+ *
+ * @param ctx the runtime's module component context
+ */
+ void started(AggregateContext ctx);
+
+ /**
+ * Event emitted when an attempt to start the runtime failed.
+ *
+ * @param ctx the runtime's module component context
+ * @param e the exception that caused the failure
+ */
+ void startFailed(AggregateContext ctx, CoreRuntimeException e);
+
+ /**
+ * Event emitted after the runtime has been stopped.
+ *
+ * @param ctx the runtime's module component context
+ */
+ void stopped(AggregateContext ctx);
+ }
+
+}
\ No newline at end of file
Added: incubator/servicemix/trunk/servicemix-sca/src/main/resources/system.fragment
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/main/resources/system.fragment?rev=386642&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/main/resources/system.fragment (added)
+++ incubator/servicemix/trunk/servicemix-sca/src/main/resources/system.fragment Fri Mar 17 06:30:08 2006
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ Copyright (c) 2005 The Apache Software Foundation or its licensors, as applicable.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<moduleFragment xmlns="http://www.osoa.org/xmlns/sca/0.9" xmlns:v="http://www.osoa.org/xmlns/sca/values/0.9"
+ xmlns:system="http://org.apache.tuscany/xmlns/system/0.9"
+ name="org.apache.servicemix.sca">
+
+ <component name="org.apache.servicemix.sca.builder.ExternalJbiServiceBuilder">
+ <system:implementation.system class="org.apache.servicemix.sca.builder.ExternalJbiServiceBuilder"/>
+ </component>
+
+ <component name="org.apache.servicemix.sca.builder.ExternalJbiServiceWireBuilder">
+ <system:implementation.system class="org.apache.servicemix.sca.builder.ExternalJbiServiceWireBuilder"/>
+ </component>
+
+ <component name="org.apache.servicemix.sca.builder.JbiServiceEntryPointBuilder">
+ <system:implementation.system class="org.apache.servicemix.sca.builder.JbiServiceEntryPointBuilder"/>
+ </component>
+
+ <component name="org.apache.servicemix.sca.loader.JbiBindingLoader">
+ <system:implementation.system class="org.apache.servicemix.sca.loader.JbiBindingLoader"/>
+ </component>
+
+</moduleFragment>
Modified: incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/AssemblyLoaderTest.java Fri Mar 17 06:30:08 2006
@@ -15,38 +15,44 @@
*/
package org.apache.servicemix.sca;
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.servicemix.sca.assembly.JbiBinding;
-import org.apache.tuscany.model.assembly.AssemblyLoader;
-import org.apache.tuscany.model.assembly.AssemblyModelContext;
+import org.apache.servicemix.sca.tuscany.TuscanyRuntime;
+import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
import org.apache.tuscany.model.assembly.Binding;
import org.apache.tuscany.model.assembly.Component;
import org.apache.tuscany.model.assembly.EntryPoint;
import org.apache.tuscany.model.assembly.ExternalService;
import org.apache.tuscany.model.assembly.Module;
-import org.apache.tuscany.model.assembly.impl.AssemblyModelContextImpl;
/**
* @author delfinoj
*/
public class AssemblyLoaderTest extends TestCase {
- private AssemblyModelContext modelContext;
-
- /**
- *
- */
- public AssemblyLoaderTest() {
- super();
+ protected void setUp() throws Exception {
+ super.setUp();
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
}
- public void testLoader() {
-
- AssemblyLoader loader = modelContext.getAssemblyLoader();
- Module module = loader.getModule(getClass().getResource("bigbank/sca.module").toString());
- module.initialize(modelContext);
+ public void testLoader() throws Exception {
+ String name = "bigbank";
+ String uri = getClass().getResource("bigbank/sca.module").toString();
+
+ URL url = getClass().getResource("bigbank/sca.module");
+ URL parentUrl = new File(url.toURI()).getParentFile().toURL();
+ ClassLoader cl = new URLClassLoader(new URL[] { parentUrl }, getClass().getClassLoader());
+
+ TuscanyRuntime rt = new TuscanyRuntime(name, uri, cl, new NullMonitorFactory());
+ assertNotNull(rt);
+
+ Module module = rt.getModuleComponent().getModuleImplementation();
Assert.assertTrue(module.getName().equals("org.apache.servicemix.sca.bigbank"));
@@ -62,12 +68,4 @@
Binding binding = externalService.getBindings().get(0);
Assert.assertTrue(binding instanceof JbiBinding);
}
-
- protected void setUp() throws Exception {
- super.setUp();
-
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- modelContext = new AssemblyModelContextImpl();
- }
-
}
Modified: incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/ScaComponentTest.java Fri Mar 17 06:30:08 2006
@@ -67,15 +67,14 @@
container.activateComponent(component, "JSR181Component");
MockServiceComponent mock = new MockServiceComponent();
- mock.setService(new QName("StockQuoteService"));
- mock.setEndpoint("Mock");
+ mock.setService(new QName("http://www.quickstockquote.com", "StockQuoteService"));
+ mock.setEndpoint("StockQuoteServiceJBI");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StockQuoteResponse r = new StockQuoteResponse();
r.setResult(8.23f);
JAXBContext.newInstance(StockQuoteResponse.class).createMarshaller().marshal(r, baos);
mock.setResponseXml(baos.toString());
ActivationSpec as = new ActivationSpec();
- as.setInterfaceName(new QName("http://www.quickstockquote.com/StockQuoteService", "StockQuoteServiceJBI"));
as.setComponent(mock);
container.activateComponent(as);
@@ -90,7 +89,7 @@
ServiceMixClient client = new DefaultServiceMixClient(container);
Source req = new StringSource("<AccountReportRequest><CustomerID>id</CustomerID></AccountReportRequest>");
Object rep = client.request(new ServiceNameEndpointResolver(
- new QName("http://www.bigbank.com/AccountService/", "AccountService")),
+ new QName("http://sca.servicemix.apache.org/Bigbank/Account", "AccountService")),
null, null, req);
if (rep instanceof Node) {
rep = new DOMSource((Node) rep);
Modified: incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountServiceImpl.java Fri Mar 17 06:30:08 2006
@@ -26,7 +26,9 @@
import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteService;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+@Service(interfaces=AccountService.class)
public class AccountServiceImpl implements AccountService {
@Property
Copied: incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl (from r385380, incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl?p2=incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl&p1=incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl&r1=385380&r2=386642&rev=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/test/java/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/account/AccountService.wsdl Fri Mar 17 06:30:08 2006
@@ -15,15 +15,14 @@
* limitations under the License.
-->
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:tns="http://www.bigbank.com/AccountService/"
+ xmlns:tns="http://sca.servicemix.apache.org/Bigbank/Account"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://www.bigbank.com/AccountService/"
-
+ targetNamespace="http://sca.servicemix.apache.org/Bigbank/Account"
name="AccountService">
<wsdl:types>
- <xsd:schema targetNamespace="http://www.bigbank.com/AccountService/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:schema targetNamespace="http://sca.servicemix.apache.org/Bigbank/Account" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="getAccountReportRequest" type="tns:AccountReportRequest"/>
<xsd:complexType name="AccountReportRequest">
Modified: incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module?rev=386642&r1=386641&r2=386642&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module (original)
+++ incubator/servicemix/trunk/servicemix-sca/src/test/resources/org/apache/servicemix/sca/bigbank/sca.module Fri Mar 17 06:30:08 2006
@@ -20,8 +20,8 @@
<entryPoint name="AccountService">
<interface.java interface="org.apache.servicemix.sca.bigbank.account.AccountService"/>
- <interface.wsdl interface="http://www.bigbank.com/AccountService/#AccountService"/>
- <binding.jbi port="http://www.bigbank.com/AccountService/#AccountServiceJBI"/>
+ <interface.wsdl interface="http://sca.servicemix.apache.org/Bigbank/Account#AccountService"/>
+ <binding.jbi port="http://sca.servicemix.apache.org/Bigbank/Account/AccountService/AccountServiceJBI"/>
<reference>AccountServiceComponent</reference>
</entryPoint>
@@ -42,8 +42,12 @@
<externalService name="StockQuoteService">
<interface.java interface="org.apache.servicemix.sca.bigbank.stockquote.StockQuoteService"/>
- <binding.jbi port="http://www.quickstockquote.com/StockQuoteService#StockQuoteServiceJBI"/>
+ <binding.jbi port="http://www.quickstockquote.com/StockQuoteService/StockQuoteServiceJBI"/>
</externalService>
+
+ <import.wsdl
+ location="org/apache/servicemix/sca/bigbank/account/AccountService.wsdl"
+ namespace="http://sca.servicemix.apache.org/Bigbank/Account" />
</module>