Bug 399521 - SDK: Webservice could not be found in WSDL model after generation

https://bugs.eclipse.org/bugs/show_bug.cgi?id=399521

Adds different implementation for method PathNormalizer.toTargetNamespace().
Adds empty content check for WS listener.

Change-Id: I9ad3d22aad66f1fa14f111527b7888b20d062be7
Reviewed-on: https://git.eclipse.org/r/16953
Reviewed-by: Matthias Villiger <mvi@bsiag.com>
Tested-by: Hudson CI
Reviewed-by: Ken Lee <kle@bsiag.com>
IP-Clean: Ken Lee <kle@bsiag.com>
diff --git a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/operation/WsdlCreateOperation.java b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/operation/WsdlCreateOperation.java
index dd8f2b4..3a29a65 100644
--- a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/operation/WsdlCreateOperation.java
+++ b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/operation/WsdlCreateOperation.java
@@ -36,7 +36,6 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
 import org.eclipse.scout.commons.StringUtility;
 import org.eclipse.scout.sdk.operation.IOperation;
 import org.eclipse.scout.sdk.util.log.ScoutStatus;
@@ -149,7 +148,7 @@
       // Binding > Binding operation > Soap operation
       SOAPOperation soapOperation = (SOAPOperation) definition.getExtensionRegistry().createExtension(BindingOperation.class, new QName(definition.getNamespace("soap"), "operation"));
       bindingOperation.addExtensibilityElement(soapOperation);
-      soapOperation.setSoapActionURI(new Path(targetNamespace).append(m_serviceOperationName).removeTrailingSeparator().toString());
+      soapOperation.setSoapActionURI(PathNormalizer.removeTrailingSeparatorFromTargetNamespace(targetNamespace + m_serviceOperationName));
 
       // Binding > Binding operation > Binding input
       BindingInput bindingInput = definition.createBindingInput();
@@ -182,7 +181,7 @@
 
       // Port > Soap address
       SOAPAddress httpAddress = new SOAPAddressImpl();
-      httpAddress.setLocationURI(new Path(targetNamespace).removeTrailingSeparator().toString());
+      httpAddress.setLocationURI(PathNormalizer.removeTrailingSeparatorFromTargetNamespace(targetNamespace));
       httpAddress.setElementType(new QName(definition.getNamespace("soap"), "address"));
       port.addExtensibilityElement(httpAddress);
 
diff --git a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/swt/view/pages/WebServiceProviderTablePage.java b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/swt/view/pages/WebServiceProviderTablePage.java
index 0a7c8e4..c53c640 100644
--- a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/swt/view/pages/WebServiceProviderTablePage.java
+++ b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/swt/view/pages/WebServiceProviderTablePage.java
@@ -10,11 +10,13 @@
  ******************************************************************************/
 package org.eclipse.scout.sdk.ws.jaxws.swt.view.pages;
 
+import java.io.File;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.eclipse.core.resources.IFile;
 import org.eclipse.scout.commons.StringUtility;
 import org.eclipse.scout.commons.xmlparser.ScoutXmlDocument;
 import org.eclipse.scout.commons.xmlparser.ScoutXmlDocument.ScoutXmlElement;
@@ -118,9 +120,17 @@
   }
 
   private class P_SunJaxWsResourceListener implements IResourceListener {
+    private boolean isContentAvailable(IFile file) {
+      File osFile = file.getRawLocation().makeAbsolute().toFile();
+      return osFile.length() > 0;
+    }
 
     @Override
     public void changed(String element, int event) {
+      if (!isContentAvailable(getSunJaxWsResource().getFile())) {
+        return;
+      }
+
       m_sunJaxWsXml = getSunJaxWsResource().loadXml();
 
       // if endpoint was added or removed, mark structure dirty
diff --git a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/util/PathNormalizer.java b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/util/PathNormalizer.java
index ecb13f2..dc530a1 100644
--- a/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/util/PathNormalizer.java
+++ b/org.eclipse.scout.sdk.ws.jaxws/src/org/eclipse/scout/sdk/ws/jaxws/util/PathNormalizer.java
@@ -17,6 +17,7 @@
  * Ensures leading and trailing file separators for the given file type.
  */
 public class PathNormalizer {
+  public static final String SLASH_SUFFIX = "/";
 
   private PathNormalizer() {
   }
@@ -49,11 +50,38 @@
     return new Path(wsdlPath).makeRelative().removeTrailingSeparator().toString();
   }
 
+  /**
+   * Appends a "/" at the end of the given non-empty target namespace if it does not exist.
+   * 
+   * @param targetNamespace
+   *          name of the target namespace
+   * @return target namespace with a "/" at the end.
+   */
   public static String toTargetNamespace(String targetNamespace) {
     if (!StringUtility.hasText(targetNamespace)) {
       return null;
     }
-    return new Path(targetNamespace).addTrailingSeparator().toString();
+    if (!targetNamespace.endsWith(SLASH_SUFFIX)) {
+      return targetNamespace + SLASH_SUFFIX;
+    }
+    return targetNamespace;
+  }
+
+  /**
+   * Removes the "/" at the end of a non-empty target namespace if one exists.
+   * 
+   * @param targetNamespace
+   *          name of the target namespace
+   * @return target namespace without a trailing "/" at the end.
+   */
+  public static String removeTrailingSeparatorFromTargetNamespace(String targetNamespace) {
+    if (!StringUtility.hasText(targetNamespace)) {
+      return null;
+    }
+    if (targetNamespace.endsWith(SLASH_SUFFIX)) {
+      return targetNamespace.substring(0, targetNamespace.length() - 2);
+    }
+    return targetNamespace;
   }
 
   public static String toJarPath(String jarPath) {