diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-14 00:50:38 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-03-14 00:50:38 +0000 |
commit | b4f48f407a8fefba16395eceb34de6bd48e74d12 (patch) | |
tree | 7e1bcf4456ef1dfd3b4d337ed7ea262f1259ffef | |
parent | 014971ccb5b2041147cf9d84d498cce64ea0493e (diff) |
Improve the IP address binding to be based on the host from the uri
Having servlet host to return deployed uri
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@922701 13f79535-47bb-0310-9956-ffa450edef68
32 files changed, 292 insertions, 240 deletions
diff --git a/sca-java-2.x/trunk/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java b/sca-java-2.x/trunk/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java index 27768f3799..897cd21e8a 100644 --- a/sca-java-2.x/trunk/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java +++ b/sca-java-2.x/trunk/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java @@ -52,7 +52,7 @@ public class CustomCompositeBuilder { node.start(); // get some things out of the extension registry - extensionPoints = ((NodeImpl)node).getExtensionPoints(); + extensionPoints = ((NodeImpl)node).getExtensionPointRegistry(); UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); diff --git a/sca-java-2.x/trunk/itest/ws/http-ssl/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite b/sca-java-2.x/trunk/itest/ws/http-ssl/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite index a56dfb6212..b50be10f83 100644 --- a/sca-java-2.x/trunk/itest/ws/http-ssl/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite +++ b/sca-java-2.x/trunk/itest/ws/http-ssl/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/helloworld/helloworld.composite @@ -32,7 +32,7 @@ <component name="HelloWorldService"> <implementation.java class="org.apache.tuscany.sca.binding.ws.axis2.helloworld.HelloWorldService"/> <service name="HelloWorld" requires="confidentiality"> - <binding.ws uri="https://localhost:8443/HelloWorldService/HelloWorld" /> + <binding.ws uri="https://0.0.0.0:8443/HelloWorldService/HelloWorld" /> </service> </component> diff --git a/sca-java-2.x/trunk/modules/binding-ws-axis2/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-ws-axis2/META-INF/MANIFEST.MF index 650dfc7e7d..04cfcba69e 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-axis2/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-ws-axis2/META-INF/MANIFEST.MF @@ -105,6 +105,7 @@ Import-Package: javax.activation;resolution:=optional, org.apache.axis2.i18n,
org.apache.axis2.receivers,
org.apache.axis2.transport,
+ org.apache.axis2.transport.base,
org.apache.axis2.transport.http,
org.apache.axis2.transport.http.server,
org.apache.axis2.transport.jms,
diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java index 589d3881c0..ec6c610d76 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -67,6 +67,7 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem private WebServiceBinding wsBinding; private Port wsdlPort; private String endpointURI; + private String deployedURI; private InterfaceContract contract; // The Axis2 configuration that the binding creates @@ -140,15 +141,16 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem endpointURI = Axis2EngineIntegration.getPortAddress(wsdlPort); if (endpointURI.startsWith("jms:")) { + deployedURI = endpointURI; isJMSRequired = true; } else { if (servletHost == null) { throw new ServiceRuntimeException("No Servlet host is avaible for HTTP web services"); } - endpointURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); + deployedURI = servletHost.getURLMapping(endpointURI, httpSecurityContext).toString(); } - Axis2EngineIntegration.setPortAddress(wsdlPort, endpointURI); + Axis2EngineIntegration.setPortAddress(wsdlPort, deployedURI); // Apply the configuration from the mayProvides intents @@ -163,28 +165,28 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem if (isJMSRequired){ // TODO - do we need to go back to configurator? } - wsBinding.setURI(endpointURI); + wsBinding.setURI(deployedURI); } private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; public void start() { try { - createAxisService(endpointURI, wsdlPort); + createAxisService(deployedURI, wsdlPort); - if (endpointURI.startsWith("http://") || - endpointURI.startsWith("https://") || - endpointURI.startsWith("/")) { + if (deployedURI.startsWith("http://") || + deployedURI.startsWith("https://") || + deployedURI.startsWith("/")) { Axis2ServiceServlet servlet = new Axis2ServiceServlet(); servlet.init(configContext); if (httpSecurityContext.isSSLEnabled()){ - servletHost.addServletMapping(endpointURI, servlet, httpSecurityContext); + deployedURI = servletHost.addServletMapping(endpointURI, servlet, httpSecurityContext); } else { - servletHost.addServletMapping(endpointURI, servlet); + deployedURI = servletHost.addServletMapping(endpointURI, servlet); } - } else if (endpointURI.startsWith("jms")) { - logger.log(Level.INFO, "Axis2 JMS URL=" + endpointURI); + } else if (deployedURI.startsWith("jms")) { + logger.log(Level.INFO, "Axis2 JMS URL=" + deployedURI); jmsListener = new JMSListener(); jmsSender = new JMSSender(); @@ -249,7 +251,7 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem // get the path to the service // [nash] Need a leading slash for WSDL imports to work with ?wsdl - URI uriPath = new URI(endpointURI); + URI uriPath = new URI(deployedURI); String stringURIPath = uriPath.getPath(); configContext.getAxisConfiguration().removeService(stringURIPath); } catch (URISyntaxException e) { diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index fc2c6bbdfb..4829bab095 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -43,7 +43,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; @@ -92,7 +91,7 @@ public class ComponentContextImpl implements RuntimeComponentContext { this.requestContextFactory = registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class); - this.proxyFactory = new ExtensibleProxyFactory(registry.getExtensionPoint(ProxyFactoryExtensionPoint.class)); + this.proxyFactory = ExtensibleProxyFactory.getInstance(registry); this.propertyFactory = factories.getFactory(PropertyValueFactory.class); this.eprBinder = utilities.getUtility(EndpointReferenceBinder.class); diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java index c6a6ecd9c0..cdb510f7ec 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java @@ -25,10 +25,6 @@ import javax.security.auth.Subject; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.context.ThreadMessageContext; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -43,11 +39,7 @@ import org.oasisopen.sca.ServiceReference; */ public class RequestContextImpl implements RequestContext { - private ProxyFactoryExtensionPoint proxyFactoryExtensionPoint; - public RequestContextImpl(RuntimeComponent component) { - ExtensionPointRegistry registry = component.getComponentContext().getExtensionPointRegistry(); - proxyFactoryExtensionPoint = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); } public Subject getSecuritySubject() { @@ -97,7 +89,6 @@ public class RequestContextImpl implements RequestContext { JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface(); Class<CB> javaClass = (Class<CB>)javaInterface.getJavaClass(); List<EndpointReference> wires = callbackReference.getEndpointReferences(); - ProxyFactory proxyFactory = new ExtensibleProxyFactory(proxyFactoryExtensionPoint); ServiceReferenceImpl ref = new CallbackServiceReferenceImpl(javaClass, wires); return ref; diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java index 5edf357e60..5d6719bc81 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java @@ -51,7 +51,6 @@ import org.apache.tuscany.sca.core.context.ServiceReferenceExt; import org.apache.tuscany.sca.core.factory.ObjectCreationException; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; @@ -126,7 +125,7 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> { this.staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); this.staxProcessor = staxProcessors.getProcessor(EndpointReference.class); this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - this.proxyFactory = new ExtensibleProxyFactory(registry.getExtensionPoint(ProxyFactoryExtensionPoint.class)); + this.proxyFactory = ExtensibleProxyFactory.getInstance(registry); } public RuntimeEndpointReference getEndpointReference() { @@ -412,9 +411,7 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> { private ProxyFactory getProxyFactory(CompositeContext compositeContext) { ExtensionPointRegistry extensionPointRegistry = compositeContext.getExtensionPointRegistry(); - ProxyFactoryExtensionPoint proxyFactories = - extensionPointRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class); - return new ExtensibleProxyFactory(proxyFactories); + return ExtensibleProxyFactory.getInstance(extensionPointRegistry); } // ================================================================================== diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java index 7f476b2fa5..bbbd3a9391 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.core.invocation; import java.util.List; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.runtime.Invocable; import org.oasisopen.sca.ServiceReference; @@ -37,6 +39,15 @@ public class ExtensibleProxyFactory implements ProxyFactory { this.proxyFactories = proxyFactories; } + public ExtensibleProxyFactory(ExtensionPointRegistry registry) { + this.proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); + } + + public static ExtensibleProxyFactory getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilities.getUtility(ExtensibleProxyFactory.class); + } + /** * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#cast(java.lang.Object) */ diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java index caf3caf00a..e538ea9f53 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/domain/node/DomainNode.java @@ -115,7 +115,7 @@ public class DomainNode { public List<String> getServiceNames() {
List<String> serviceNames = new ArrayList<String>();
if (nodes.size() > 0) {
- ExtensionPointRegistry extensionsRegistry = ((NodeImpl)nodes.values().iterator().next()).getExtensionPoints();
+ ExtensionPointRegistry extensionsRegistry = ((NodeImpl)nodes.values().iterator().next()).getExtensionPointRegistry();
DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(extensionsRegistry);
EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry(getDomainConfigURI(), getDomainName());
for (Endpoint endpoint : endpointRegistry.getEndpoints()) {
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java index 6cee3142ca..4c868f73e4 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java @@ -32,7 +32,6 @@ import javax.servlet.Servlet; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.LifeCycleListener; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; /** * Default implementation of a Servlet host extension point. @@ -43,6 +42,7 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi private List<ServletHost> servletHosts = new ArrayList<ServletHost>(); private boolean loaded; + private boolean webApp; private ExtensionPointRegistry registry; @@ -129,12 +129,12 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi return host; } - public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException { - getServletHost().addServletMapping(uri, servlet); + public String addServletMapping(String uri, Servlet servlet) throws ServletMappingException { + return getServletHost().addServletMapping(uri, servlet); } - public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { - getServletHost().addServletMapping(uri, servlet, securityContext); + public String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { + return getServletHost().addServletMapping(uri, servlet, securityContext); } public String getContextPath() { @@ -199,4 +199,12 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi servletHosts.clear(); registry = null; } + + public boolean isWebApp() { + return webApp; + } + + public void setWebApp(boolean webApp) { + this.webApp = webApp; + } } diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java index 776de4a361..1b639041f7 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java @@ -20,10 +20,14 @@ package org.apache.tuscany.sca.host.http; import java.net.URL; +import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; + /** * Default implementation of an extensible Servlet host. * @@ -32,98 +36,87 @@ import javax.servlet.Servlet; public class ExtensibleServletHost implements ServletHost { private ServletHostExtensionPoint servletHosts; + + public ExtensibleServletHost(ExtensionPointRegistry registry) { + this.servletHosts = registry.getExtensionPoint(ServletHostExtensionPoint.class); + } + public static ExtensibleServletHost getInstance(ExtensionPointRegistry registry) { + UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class); + return utilityExtensionPoint.getUtility(ExtensibleServletHost.class); + } + public ExtensibleServletHost(ServletHostExtensionPoint servletHosts) { this.servletHosts = servletHosts; } public void setDefaultPort(int port) { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - for (ServletHost servletHost: servletHosts.getServletHosts()) { servletHost.setDefaultPort(port); } } - private ServletHost getDefaultServletHost() { - return servletHosts.getServletHosts().get(0); + public ServletHost getDefaultServletHost() { + List<ServletHost> hosts = servletHosts.getServletHosts(); + if (hosts.isEmpty()) { + throw new ServletMappingException("No servlet host is available."); + } + if (servletHosts.isWebApp()) { + for (ServletHost servletHost : hosts) { + if (!"webapp".equals(servletHost.getName())) { + continue; + } + if (servletHost instanceof DefaultServletHostExtensionPoint.LazyServletHost) { + return ((DefaultServletHostExtensionPoint.LazyServletHost)servletHost).getServletHost(); + } else { + return servletHost; + } + } + } + return hosts.get(0); } public int getDefaultPort() { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - return getDefaultServletHost().getDefaultPort(); } - public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - + public String addServletMapping(String uri, Servlet servlet) throws ServletMappingException { // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one - getDefaultServletHost().addServletMapping(uri, servlet); + return getDefaultServletHost().addServletMapping(uri, servlet); } - public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - + public String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one - getDefaultServletHost().addServletMapping(uri, servlet, securityContext); + return getDefaultServletHost().addServletMapping(uri, servlet, securityContext); } public Servlet getServletMapping(String uri) throws ServletMappingException { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one return getDefaultServletHost().getServletMapping(uri); } public Servlet removeServletMapping(String uri) throws ServletMappingException { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one return getDefaultServletHost().removeServletMapping(uri); } public RequestDispatcher getRequestDispatcher(String uri) throws ServletMappingException { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one return getDefaultServletHost().getRequestDispatcher(uri); } public String getContextPath() { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - // TODO implement selection of the correct Servlet host based on the mapping // For now just select the first one return getDefaultServletHost().getContextPath(); } public URL getURLMapping(String uri, SecurityContext securityContext) { - if (servletHosts.getServletHosts().isEmpty()) { - throw new ServletMappingException("No servlet host available"); - } - return getDefaultServletHost().getURLMapping(uri, securityContext); } diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java index f5e375a2ed..eee223e9a9 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java @@ -55,9 +55,10 @@ public interface ServletHost { * * @param uri the URI-mapping for the Servlet * @param servlet the Servlet that should be invoked + * @return The deployed URI * @throws ServletMappingException */ - void addServletMapping(String uri, Servlet servlet) throws ServletMappingException; + String addServletMapping(String uri, Servlet servlet) throws ServletMappingException; /** * Add a mapping for an instance of a Servlet. This requests that the @@ -68,9 +69,10 @@ public interface ServletHost { * @param uri the URI-mapping for the Servlet * @param servlet the Servlet that should be invoked * @param securityContext the SecurityContext to enable QoS services + * @return The deployed URI * @throws ServletMappingException */ - void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException; + String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException; /** * Remove a Servlet mapping. This directs the Servlet container not to direct diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java index fbd085ba2b..8ef48e4949 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java @@ -26,6 +26,17 @@ import java.util.List; * @version $Rev$ $Date$ */ public interface ServletHostExtensionPoint { + /** + * Test if it's inside a web application + * @return + */ + boolean isWebApp(); + + /** + * Set the flag to indicate it's inside a web application + * @param webApp + */ + void setWebApp(boolean webApp); /** * Adds a Servlet host extension. diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java index 946eb54ed6..84caa29237 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java @@ -19,34 +19,12 @@ package org.apache.tuscany.sca.host.http;
-import java.util.List;
-
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
public class ServletHostHelper {
-
- private static boolean webappHost;
-
+
public static ServletHost getServletHost(ExtensionPointRegistry extensionPoints) {
- ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
- List<ServletHost> hosts = servletHosts.getServletHosts();
- for (ServletHost servletHost : hosts) {
- if (webappHost && !"webapp".equals(servletHost.getName())) {
- continue;
- }
- if (!webappHost && "webapp".equals(servletHost.getName())) {
- continue;
- }
- if(servletHost instanceof DefaultServletHostExtensionPoint.LazyServletHost) {
- return ((DefaultServletHostExtensionPoint.LazyServletHost) servletHost).getServletHost();
- } else {
- return servletHost;
- }
- }
- throw new IllegalStateException("No ServletHost found");
- }
-
- public static void setWebappHost(boolean b) {
- ServletHostHelper.webappHost = b;
+ ExtensibleServletHost host = ExtensibleServletHost.getInstance(extensionPoints);
+ return host.getDefaultServletHost();
}
}
diff --git a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java index 5b722528e5..ba131e0e94 100644 --- a/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java +++ b/sca-java-2.x/trunk/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java @@ -118,6 +118,7 @@ public class JettyServer implements ServletHost, LifeCycleListener { } protected JettyServer(WorkScheduler workScheduler) { + this.defaultPort = portDefault; this.workScheduler = workScheduler; AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { @@ -203,11 +204,11 @@ public class JettyServer implements ServletHost, LifeCycleListener { } - public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException { - addServletMapping(suri, servlet, null); + public String addServletMapping(String suri, Servlet servlet) throws ServletMappingException { + return addServletMapping(suri, servlet, null); } - public void addServletMapping(String suri, Servlet servlet, final SecurityContext securityContext) throws ServletMappingException { + public String addServletMapping(String suri, Servlet servlet, final SecurityContext securityContext) throws ServletMappingException { URI uri = URI.create(suri); // Get the URI scheme and port @@ -221,6 +222,11 @@ public class JettyServer implements ServletHost, LifeCycleListener { } } + String host = uri.getHost(); + if ("0.0.0.0".equals(host)) { + host = null; + } + int portNumber = uri.getPort(); if (portNumber == -1) { if ("http".equals(scheme)) { @@ -243,11 +249,17 @@ public class JettyServer implements ServletHost, LifeCycleListener { // httpConnector.setPort(portNumber); SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setPort(portNumber); + // FIXME: [rfeng] We should set the host to be bound but binding-ws-axis2 is passing + // in an absolute URI with host set to one of the ip addresses + sslConnector.setHost(host); configureSSL(sslConnector, securityContext); server.setConnectors(new Connector[] {sslConnector}); } else { SelectChannelConnector selectConnector = new SelectChannelConnector(); selectConnector.setPort(portNumber); + // FIXME: [rfeng] We should set the host to be bound but binding-ws-axis2 is passing + // in an absolute URI with host set to one of the ip addresses + selectConnector.setHost(host); server.setConnectors(new Connector[] {selectConnector}); } @@ -318,11 +330,12 @@ public class JettyServer implements ServletHost, LifeCycleListener { servletHandler.addServletMapping(mapping); // Compute the complete URL - String host; - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - host = "localhost"; + if (host == null) { + try { + host = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + host = "localhost"; + } } URL addedURL; try { @@ -331,9 +344,14 @@ public class JettyServer implements ServletHost, LifeCycleListener { throw new ServletMappingException(e); } logger.info("Added Servlet mapping: " + addedURL); + return addedURL.toString(); } public URL getURLMapping(String suri, SecurityContext securityContext) throws ServletMappingException { + return map(suri, securityContext, true); + } + + private URL map(String suri, SecurityContext securityContext, boolean resolve) throws ServletMappingException { URI uri = URI.create(suri); // Get the URI scheme and port @@ -357,11 +375,16 @@ public class JettyServer implements ServletHost, LifeCycleListener { } // Get the host - String host; - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - host = "localhost"; + String host = uri.getHost(); + if (host == null) { + host = "0.0.0.0"; + if (resolve) { + try { + host = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + host = "localhost"; + } + } } // Construct the URL diff --git a/sca-java-2.x/trunk/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java b/sca-java-2.x/trunk/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java index 2ab9e46b10..a3199cf4d1 100644 --- a/sca-java-2.x/trunk/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java +++ b/sca-java-2.x/trunk/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.ConnectException; +import java.net.InetAddress; import java.net.Socket; import java.net.URL; @@ -41,6 +42,7 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.host.http.DefaultResourceServlet; import org.apache.tuscany.sca.work.NotificationListener; import org.apache.tuscany.sca.work.WorkScheduler; +import org.junit.Assert; /** * @version $Rev$ $Date$ @@ -98,6 +100,30 @@ public class JettyServerTestCase extends TestCase { service.stop(); assertTrue(servlet.invoked); } + + /** + * Verifies requests are properly routed according to the Servlet mapping + */ + public void testDeployedURI() throws Exception { + JettyServer service = new JettyServer(workScheduler); + service.setDefaultPort(8085); + service.start(); + TestServlet servlet = new TestServlet(); + String host = InetAddress.getLocalHost().getHostAddress(); + String hostName = InetAddress.getLocalHost().getHostName(); + String url1 = service.addServletMapping("/MyService", servlet); + Assert.assertEquals("http://" + host + ":8085/MyService", url1); + String url2 = service.addServletMapping("http://localhost:8086/MyService", servlet); + Assert.assertEquals("http://localhost:8086/MyService", url2); + String url3 = service.addServletMapping("http://" + host + ":8087/MyService", servlet); + Assert.assertEquals("http://" + host + ":8087/MyService", url3); + String url4 = service.addServletMapping("http://0.0.0.0:8088/MyService", servlet); + Assert.assertEquals("http://" + host + ":8088/MyService", url4); + String url5 = service.addServletMapping("http://" + hostName + ":8089/MyService", servlet); + Assert.assertEquals("http://" + hostName + ":8089/MyService", url5); + + service.stop(); + } public void testRegisterServletMappingSSL() throws Exception { System.setProperty("javax.net.ssl.keyStore", "target/test-classes/tuscany.keyStore"); diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java index 62c238e135..45c1bbf3da 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java @@ -36,7 +36,7 @@ public class TuscanyContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { logger.info(event.getServletContext().getServletContextName() + " is starting."); try { - ServletHostHelper.init(event.getServletContext()); + WebAppHelper.init(event.getServletContext()); } catch (Throwable e) { logger.log(Level.SEVERE, e.getMessage(), e); } @@ -49,7 +49,7 @@ public class TuscanyContextListener implements ServletContextListener { return; } try { - ServletHostHelper.stop(event.getServletContext()); + WebAppHelper.stop(event.getServletContext()); } catch (Throwable e) { logger.log(Level.SEVERE, e.getMessage(), e); } diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java index 72a76a789e..a12466a9fd 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java @@ -60,7 +60,7 @@ public class TuscanyServletFilter implements Filter { String value = config.getInitParameter(name); context.setAttribute(name, value); } - servletHost = ServletHostHelper.init(context); + servletHost = WebAppHelper.init(context); } catch (Throwable e) { logger.log(Level.SEVERE, e.getMessage(), e); context.log(e.getMessage(), e); @@ -69,7 +69,7 @@ public class TuscanyServletFilter implements Filter { } public void destroy() { - ServletHostHelper.stop(context); + WebAppHelper.stop(context); servletHost = null; } diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java index d157b5f565..7d086cd0f3 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppHelper.java @@ -29,16 +29,18 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; -import org.apache.tuscany.sca.node.impl.NodeImpl; -public class ServletHostHelper { +public class WebAppHelper { public static final String DOMAIN_NAME_ATTR = "org.apache.tuscany.sca.domain.name"; public static final String SCA_NODE_ATTRIBUTE = Node.class.getName(); private static NodeFactory factory; + private static WebAppServletHost host; private static URL getResource(ServletContext servletContext, String location) throws IOException { URI uri = URI.create(location); @@ -125,50 +127,57 @@ public class ServletHostHelper { return domainName; } - public static ServletHost init(final ServletContext servletContext) { - Node node = (Node)servletContext.getAttribute(SCA_NODE_ATTRIBUTE); - if (node == null) { - org.apache.tuscany.sca.host.http.ServletHostHelper.setWebappHost(true); + public synchronized static ServletHost init(final ServletContext servletContext) { + if (host == null) { try { - String domainName = (String)servletContext.getAttribute(DOMAIN_NAME_ATTR); factory = NodeFactory.getInstance(); + ExtensionPointRegistry registry = factory.getExtensionPointRegistry(); + ServletHostExtensionPoint servletHosts = registry.getExtensionPoint(ServletHostExtensionPoint.class); + servletHosts.setWebApp(true); for (Enumeration<String> e = servletContext.getInitParameterNames(); e.hasMoreElements();) { String name = e.nextElement(); String value = servletContext.getInitParameter(name); servletContext.setAttribute(name, value); } - node = createNode(servletContext); + host = getServletHost(servletContext); + Node node = createAndStartNode(servletContext); servletContext.setAttribute(SCA_NODE_ATTRIBUTE, node); - getServletHost(node).init(new ServletConfig() { - public String getInitParameter(String name) { - return servletContext.getInitParameter(name); - } - - public Enumeration<?> getInitParameterNames() { - return servletContext.getInitParameterNames(); - } - - public ServletContext getServletContext() { - return servletContext; - } - - public String getServletName() { - return servletContext.getServletContextName(); - } - }); + return host; } catch (ServletException e) { throw new RuntimeException(e); } } - return getServletHost(node); + return host; + } + + private static WebAppServletHost getServletHost(final ServletContext servletContext) throws ServletException { + WebAppServletHost host = (WebAppServletHost) getServletHost(factory); + host.init(new ServletConfig() { + public String getInitParameter(String name) { + return servletContext.getInitParameter(name); + } + + public Enumeration<?> getInitParameterNames() { + return servletContext.getInitParameterNames(); + } + + public ServletContext getServletContext() { + return servletContext; + } + + public String getServletName() { + return servletContext.getServletContextName(); + } + }); + return host; } - private static WebAppServletHost getServletHost(Node node) { - NodeImpl nodeImpl = (NodeImpl)node; - return (WebAppServletHost) org.apache.tuscany.sca.host.http.ServletHostHelper.getServletHost(nodeImpl.getExtensionPoints()); + private static WebAppServletHost getServletHost(NodeFactory factory) { + ExtensionPointRegistry registry = factory.getExtensionPointRegistry(); + return (WebAppServletHost) org.apache.tuscany.sca.host.http.ServletHostHelper.getServletHost(registry); } - private static Node createNode(final ServletContext servletContext) throws ServletException { + private static Node createAndStartNode(final ServletContext servletContext) throws ServletException { NodeConfiguration configuration; try { configuration = getNodeConfiguration(servletContext); @@ -180,10 +189,10 @@ public class ServletHostHelper { } public static void stop(ServletContext servletContext) { - Node node = (Node)servletContext.getAttribute(ServletHostHelper.SCA_NODE_ATTRIBUTE); + Node node = (Node)servletContext.getAttribute(WebAppHelper.SCA_NODE_ATTRIBUTE); if (node != null) { node.stop(); - servletContext.setAttribute(ServletHostHelper.SCA_NODE_ATTRIBUTE, null); + servletContext.setAttribute(WebAppHelper.SCA_NODE_ATTRIBUTE, null); } } } diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java index f1d485b6c2..0c5431a7d8 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java @@ -58,6 +58,7 @@ public class WebAppServletHost implements ServletHost { private int defaultPortNumber = 8080; private String contributionRoot; + private ServletConfig servletConfig; private ServletContext servletContext; private Map<String, Object> tempAttributes = new HashMap<String, Object>(); @@ -77,11 +78,11 @@ public class WebAppServletHost implements ServletHost { return "webapp"; } - public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException { - addServletMapping(suri, servlet, null); + public String addServletMapping(String suri, Servlet servlet) throws ServletMappingException { + return addServletMapping(suri, servlet, null); } - public void addServletMapping(String suri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { + public String addServletMapping(String suri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException { URI pathURI = URI.create(suri); // Make sure that the path starts with a / @@ -90,15 +91,27 @@ public class WebAppServletHost implements ServletHost { suri = '/' + suri; } - if (!suri.startsWith(contextPath)) { + // String relativeURI = suri; + if (!suri.startsWith(contextPath + "/")) { suri = contextPath + suri; - } + } + if (!servlets.values().contains(servlet)) { + // The same servlet can be registred more than once + try { + servlet.init(servletConfig); + } catch (ServletException e) { + throw new ServletMappingException(e); + } + } + // In a webapp just use the given path and ignore the host and port // as they are fixed by the Web container servlets.put(suri, servlet); - logger.info("Added Servlet mapping: " + suri); + URL url = getURLMapping(suri, securityContext); + logger.info("Added Servlet mapping: " + url); + return url.toString(); } public Servlet removeServletMapping(String suri) throws ServletMappingException { @@ -116,7 +129,13 @@ public class WebAppServletHost implements ServletHost { // In a webapp just use the given path and ignore the host and port // as they are fixed by the Web container - return servlets.remove(suri); + Servlet servlet = servlets.remove(suri); + /* + if (servlet != null) { + servlet.destroy(); + } + */ + return servlet; } public Servlet getServletMapping(String suri) throws ServletMappingException { @@ -147,11 +166,13 @@ public class WebAppServletHost implements ServletHost { } // Get the host - String host; - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - host = "localhost"; + String host = uri.getHost(); + if (host == null) { + try { + host = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + host = "localhost"; + } } // Construct the URL @@ -210,14 +231,14 @@ public class WebAppServletHost implements ServletHost { } public void init(ServletConfig config) throws ServletException { - + this.servletConfig = config; servletContext = config.getServletContext(); for (String name : tempAttributes.keySet()) { servletContext.setAttribute(name, tempAttributes.get(name)); } - ServletHostHelper.init(servletContext); + // WebAppHelper.init(servletContext); initContextPath(config); @@ -282,7 +303,7 @@ public class WebAppServletHost implements ServletHost { } // Close the SCA domain - ServletHostHelper.stop(servletContext); + WebAppHelper.stop(servletContext); } public String getContextPath() { diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java index 36d9878fd9..b59966a39e 100644 --- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java +++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java @@ -73,7 +73,7 @@ public class JavaImplementationProviderFactory implements ImplementationProvider componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class); requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); - proxyFactory = new ExtensibleProxyFactory(proxyFactories); + proxyFactory = ExtensibleProxyFactory.getInstance(registry); } /* diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java index 5dfdbffd84..01b458d1f5 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java @@ -21,7 +21,6 @@ package org.apache.tuscany.sca.implementation.spring.invocation; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.databinding.impl.MediatorImpl; import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory; import org.apache.tuscany.sca.implementation.spring.SpringImplementation; @@ -46,8 +45,7 @@ public class SpringImplementationProviderFactory implements ImplementationProvid public SpringImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { super(); - ProxyFactoryExtensionPoint proxyFactories = extensionPoints.getExtensionPoint(ProxyFactoryExtensionPoint.class); - proxyFactory = new ExtensibleProxyFactory(proxyFactories); + proxyFactory = ExtensibleProxyFactory.getInstance(extensionPoints); // TODO: could the runtime have a default PropertyValueObjectFactory? propertyFactory = new JavaPropertyValueObjectFactory(new MediatorImpl(extensionPoints)); diff --git a/sca-java-2.x/trunk/modules/implementation-web-client/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/implementation-web-client/META-INF/MANIFEST.MF index 246ec6e78e..6690eac03d 100644 --- a/sca-java-2.x/trunk/modules/implementation-web-client/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/implementation-web-client/META-INF/MANIFEST.MF @@ -11,6 +11,7 @@ Bundle-DocURL: http://www.apache.org/ Import-Package: javax.servlet,
javax.servlet.http,
org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.context;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.host.http;version="2.0.0",
org.apache.tuscany.sca.implementation.web;version="2.0.0",
@@ -25,6 +26,6 @@ Import-Package: javax.servlet, org.directwebremoting.create;version="2.0.3",
org.directwebremoting.extend;version="2.0.3",
org.directwebremoting.servlet;version="2.0.3",
- org.oasisopen.sca.annotation;version="2.0.0",
- org.oasisopen.sca;version="2.0.0"
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/ClientServlet.java b/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/ClientServlet.java index 0917804d65..5316efeef0 100644 --- a/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/ClientServlet.java +++ b/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/ClientServlet.java @@ -36,9 +36,10 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
import org.directwebremoting.Container;
import org.directwebremoting.create.AbstractCreator;
import org.directwebremoting.extend.CreatorManager;
@@ -57,7 +58,7 @@ import org.directwebremoting.servlet.UrlProcessor; public class ClientServlet extends DwrServlet {
private static final long serialVersionUID = 1L;
- private transient Map<String, ServiceHolder> services;
+ private transient Map<String, RuntimeEndpointReference> serviceRefs;
// private transient List<String> referenceNames;
private transient boolean initialized;
private transient Map<String, String> initParams;
@@ -65,7 +66,7 @@ public class ClientServlet extends DwrServlet { public static final String SCRIPT_PATH = "/org.oasisopen.sca.componentContext.js";
public ClientServlet() {
- this.services = new HashMap<String, ServiceHolder>();
+ this.serviceRefs = new HashMap<String, RuntimeEndpointReference>();
// this.referenceNames = new ArrayList<String>();
this.initParams = new HashMap<String, String>();
@@ -88,7 +89,7 @@ public class ClientServlet extends DwrServlet { if (!initialized) {
super.init(patchConfig(servletConfig));
addScriptHandler();
- initServices();
+ // initServices();
initialized = true;
}
}
@@ -159,8 +160,8 @@ public class ClientServlet extends DwrServlet { Remoter remoter = (Remoter)getContainer().getBean(Remoter.class.getName());
- for (String serviceName : services.keySet()) {
- String path = request.getServletPath() + "/" + services.get(serviceName).c.getName();
+ for (String serviceName : serviceRefs.keySet()) {
+ String path = request.getServletPath() + "/" + serviceName;
String serviceScript = remoter.generateInterfaceScript(serviceName, path);
out.println(serviceScript);
out.println("SCA.componentContext.serviceNames.push('" + serviceName + "');");
@@ -210,42 +211,27 @@ public class ClientServlet extends DwrServlet { /**
* Add an SCA service to be added to the DWR runtime
*/
- public void addService(ComponentReference cr, RuntimeComponent c) {
- ServiceHolder holder = new ServiceHolder();
- holder.name = cr.getName();
- holder.cr = cr;
- holder.c = c;
- services.put(cr.getName(), holder);
- }
-
- /**
- * Defines each SCA service proxy instance to DWR
- */
- private void initServices() {
+ public void addService(RuntimeEndpointReference epr) {
+
CreatorManager creatorManager = (CreatorManager)getContainer().getBean(CreatorManager.class.getName());
-
- for (final ServiceHolder service : services.values()) {
-
- final Class<?> iface = ((JavaInterface)service.cr.getInterfaceContract().getInterface()).getJavaClass();
- final Object instance = service.c.getComponentContext().getServiceReference(iface, service.cr.getName()).getService();
-
- creatorManager.addCreator(service.cr.getName(), new AbstractCreator() {
- public Class<?> getType() {
- return iface;
- }
-
- public Object getInstance() throws InstantiationException {
- return instance;
- }
- });
- }
+ addService(creatorManager, epr);
+ serviceRefs.put(epr.getReference().getName(), epr);
}
- // utility class to aid passing around services
- private class ServiceHolder {
- String name;
- ComponentReference cr;
- RuntimeComponent c;
+ private void addService(CreatorManager creatorManager, final RuntimeEndpointReference epr) {
+ final Class<?> iface = ((JavaInterface)epr.getComponentTypeReferenceInterfaceContract().getInterface()).getJavaClass();
+
+ creatorManager.addCreator(epr.getReference().getName(), new AbstractCreator() {
+ public Class<?> getType() {
+ return iface;
+ }
+
+ public Object getInstance() throws InstantiationException {
+ ExtensionPointRegistry registry = epr.getCompositeContext().getExtensionPointRegistry();
+ ExtensibleProxyFactory proxyFactory = ExtensibleProxyFactory.getInstance(registry);
+ return proxyFactory.createProxy(iface, epr);
+ }
+ });
}
/**
diff --git a/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/JSClientExtensionPointImpl.java b/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/JSClientExtensionPointImpl.java index e57d751048..049cda2eb8 100644 --- a/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/JSClientExtensionPointImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-web-client/src/main/java/org/apache/tuscany/sca/implementation/web/client/JSClientExtensionPointImpl.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.implementation.web.client;
import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.host.http.ServletHost;
import org.apache.tuscany.sca.host.http.ServletHostHelper;
@@ -30,6 +31,7 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.provider.ImplementationProvider;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
public class JSClientExtensionPointImpl implements ClientExtensionPoint {
@@ -46,7 +48,9 @@ public class JSClientExtensionPointImpl implements ClientExtensionPoint { if (component.getReferences().size() > 0) {
for (ComponentReference cr : component.getReferences()) {
- clientServlet.addService(cr, component);
+ for (EndpointReference epr : cr.getEndpointReferences()) {
+ clientServlet.addService((RuntimeEndpointReference)epr);
+ }
}
}
diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java index 811799e239..5efaa97841 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java @@ -490,5 +490,5 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { */ public abstract NodeConfiguration loadConfiguration(InputStream xml, URL base); - + public abstract <T> T getExtensionPointRegistry(); } diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java index 30d61b51bf..e0691ab11b 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -65,7 +65,6 @@ import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.deployment.Deployer; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.monitor.Monitor; @@ -210,7 +209,7 @@ public class NodeFactoryImpl extends NodeFactory { return attached; } - public ExtensionPointRegistry getExtensionPoints() { + public ExtensionPointRegistry getExtensionPointRegistry() { if (registry == null) { // Create extension point registry registry = createExtensionPointRegistry(); @@ -225,7 +224,7 @@ public class NodeFactoryImpl extends NodeFactory { } long start = currentTimeMillis(); - getExtensionPoints(); + getExtensionPointRegistry(); // Use the runtime-enabled assembly factory FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); @@ -248,8 +247,7 @@ public class NodeFactoryImpl extends NodeFactory { // Initialize runtime // Get proxy factory - ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class); - proxyFactory = new ExtensibleProxyFactory(proxyFactories); + proxyFactory = ExtensibleProxyFactory.getInstance(registry); utilities.getUtility(WorkScheduler.class); @@ -466,7 +464,7 @@ public class NodeFactoryImpl extends NodeFactory { @Override public void configure(Map<String, Map<String, String>> attributes) { - ServiceDiscovery discovery = getExtensionPoints().getServiceDiscovery(); + ServiceDiscovery discovery = getExtensionPointRegistry().getServiceDiscovery(); for (Map.Entry<String, Map<String, String>> e : attributes.entrySet()) { discovery.setAttribute(e.getKey(), e.getValue()); } diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 57cbd200fe..eef9f39009 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -292,8 +292,8 @@ public class NodeImpl implements Node { return configuration; } - public ExtensionPointRegistry getExtensionPoints() { - return manager.getExtensionPoints(); + public ExtensionPointRegistry getExtensionPointRegistry() { + return manager.getExtensionPointRegistry(); } /** @@ -326,7 +326,7 @@ public class NodeImpl implements Node { public String dumpDomainComposite() { StAXArtifactProcessorExtensionPoint xmlProcessors = - getExtensionPoints().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + getExtensionPointRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class); @@ -336,7 +336,7 @@ public class NodeImpl implements Node { private String writeComposite(Composite composite, StAXArtifactProcessor<Composite> compositeProcessor){ ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLOutputFactory outputFactory = - manager.getExtensionPoints().getExtensionPoint(FactoryExtensionPoint.class) + manager.getExtensionPointRegistry().getExtensionPoint(FactoryExtensionPoint.class) .getFactory(XMLOutputFactory.class); try { diff --git a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java index 56b13b78bb..126340891e 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -135,11 +135,11 @@ public class NodeImplTestCase { attrs.put(DomainRegistryFactoryExtensionPoint.class.getName(), map2); NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance(attrs); - Assert.assertFalse(factory.getExtensionPoints().getExtensionPoint(ValidationSchemaExtensionPoint.class) + Assert.assertFalse(factory.getExtensionPointRegistry().getExtensionPoint(ValidationSchemaExtensionPoint.class) .isEnabled()); DomainRegistryFactoryExtensionPoint domainRegistryFactoryExtensionPoint = - factory.getExtensionPoints().getExtensionPoint(DomainRegistryFactoryExtensionPoint.class); + factory.getExtensionPointRegistry().getExtensionPoint(DomainRegistryFactoryExtensionPoint.class); Map<String, String> mapping = domainRegistryFactoryExtensionPoint.getDomainRegistryMapping(); Assert.assertEquals(1, mapping.size()); Assert.assertEquals("multicast://200.0.0.100:50000/MyDomain", mapping.get("urn:MyDomain")); diff --git a/sca-java-2.x/trunk/modules/pom.xml b/sca-java-2.x/trunk/modules/pom.xml index 5f97e96095..8cbfa9e6d7 100644 --- a/sca-java-2.x/trunk/modules/pom.xml +++ b/sca-java-2.x/trunk/modules/pom.xml @@ -131,7 +131,7 @@ <plugin> <groupId>org.apache.tuscany.maven.plugins</groupId> <artifactId>maven-bundle-plugin</artifactId> - <version>1.0.4</version> + <version>1.0.6</version> <extensions>true</extensions> <executions> <execution> diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java index 762c97bef9..c3cfdc791c 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java @@ -36,7 +36,6 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; @@ -75,7 +74,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory { this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance(); this.nodeFactory.init(); - this.extensionsRegistry = nodeFactory.getExtensionPoints(); + this.extensionsRegistry = nodeFactory.getExtensionPointRegistry(); DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(extensionsRegistry); String registryURI = getDomainURI().toString(); @@ -91,7 +90,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory { FactoryExtensionPoint factories = extensionsRegistry.getExtensionPoint(FactoryExtensionPoint.class); this.assemblyFactory = factories.getFactory(AssemblyFactory.class); this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class); - this.proxyFactory = new ExtensibleProxyFactory(extensionsRegistry.getExtensionPoint(ProxyFactoryExtensionPoint.class)); + this.proxyFactory = ExtensibleProxyFactory.getInstance(extensionsRegistry); String client = "sca.client." + UUID.randomUUID(); this.compositeContext = diff --git a/sca-java-2.x/trunk/shades/json-nodep/pom.xml b/sca-java-2.x/trunk/shades/json-nodep/pom.xml index 13d4f72f13..f90e6204a9 100644 --- a/sca-java-2.x/trunk/shades/json-nodep/pom.xml +++ b/sca-java-2.x/trunk/shades/json-nodep/pom.xml @@ -36,13 +36,7 @@ <groupId>org.apache.tuscany.sca.shades</groupId>
<artifactId>tuscany-json</artifactId>
<version>${pom.version}</version>
- <exclusions>
- <exclusion>
- <!-- commpons logging is in the tuscany-base-nodep jar -->
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
+
</dependency>
<dependency>
|