diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-29 19:45:01 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-29 19:45:01 +0000 |
commit | e120e4227dae513c5d23bbfbf7b464e92c1a5dd6 (patch) | |
tree | bfa9cf0334d7ea7f398ff100d95b0552afa1cebc | |
parent | 40ced904cfdaf5fcd813112f7c72106fa77c4c46 (diff) |
Fix the uri calculation
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@939468 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java b/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java index bfc875edc1..96b1561d5c 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java +++ b/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java @@ -84,11 +84,11 @@ class WidgetImplementationProvider implements ImplementationProvider { } public void start() { - String contextRoot = getContextRoot(); + String baseURI = getBaseURI(); // get the ScaDomainScriptServlet, if it doesn't yet exist create one // this uses removeServletMapping / addServletMapping as there is no getServletMapping facility - scriptURI = URI.create(contextRoot + "/" + this.widgetName + ".js").toString(); + scriptURI = URI.create(baseURI + "/" + this.widgetName + ".js").toString(); Servlet servlet = servletHost.getServletMapping(scriptURI); if (servlet == null /*|| servlet instanceof HTTPGetListenerServlet*/) { WidgetComponentScriptServlet widgetScriptServlet; @@ -111,25 +111,34 @@ class WidgetImplementationProvider implements ImplementationProvider { * Get the contextRoot considering the HTTP Binding URI when in a embedded environment * @return */ - private String getContextRoot() { - String contextRoot = null; + private String getBaseURI() { + String baseURI = null; + String contextPath = "/"; if (servletHost != null) { - contextRoot = servletHost.getContextPath(); + contextPath = servletHost.getContextPath(); } - - if (contextRoot == null) { - for (ComponentService service : component.getServices()) { - if ("Widget".equals(service.getName())) { - for (Binding binding : service.getBindings()) { - if (binding.getType().equals(BINDING_HTTP)) { - contextRoot = binding.getURI(); - } + if (!contextPath.endsWith("/")) { + contextPath = contextPath + "/"; + } + + ComponentService service = component.getService("Widget"); + if (service != null) { + for (Binding binding : service.getBindings()) { + if (binding.getType().equals(BINDING_HTTP)) { + String bindingURI = binding.getURI(); + URI uri = URI.create(bindingURI); + if (uri.isAbsolute()) { + return bindingURI; + } + if (bindingURI.startsWith("/")) { + bindingURI = bindingURI.substring(1); } + baseURI = contextPath + bindingURI; } } } - - return contextRoot == null ? "" : contextRoot; - } + + return baseURI == null ? "" : baseURI; + } } |