More work on AXIS-2882.
diff --git a/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java b/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java
index 1bfaa7b..43266b7 100644
--- a/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java
+++ b/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java
@@ -256,6 +256,8 @@
writeGetPortName(pw, bindingType, portName);
writeGetPortNameURL(pw, bindingType, portName, stubClass,
wsddServiceName);
+ writeGetPortNameString(pw, bindingType, portName, stubClass,
+ wsddServiceName);
writeSetPortEndpointAddress(pw, portName);
}
@@ -410,6 +412,36 @@
} // writeGetPortNameURL
/**
+ * Write the get<portName>(String) method.
+ *
+ * @param pw
+ * @param bindingType
+ * @param portName
+ * @param stubClass
+ * @param wsddServiceName
+ */
+ protected void writeGetPortNameString(PrintWriter pw, String bindingType,
+ String portName, String stubClass,
+ String wsddServiceName) {
+
+ pw.println(" public " + bindingType + " get" + portName
+ + "(java.lang.String portAddress) throws "
+ + javax.xml.rpc.ServiceException.class.getName() + " {");
+ pw.println(" try {");
+ pw.println(" " + stubClass + " _stub = new " + stubClass
+ + "(portAddress, this);");
+ pw.println(" _stub.setPortName(get" + wsddServiceName
+ + "());");
+ pw.println(" return _stub;");
+ pw.println(" }");
+ pw.println(" catch (org.apache.axis.AxisFault e) {");
+ pw.println(" return null;");
+ pw.println(" }");
+ pw.println(" }");
+ pw.println();
+ } // writeGetPortNameURL
+
+ /**
* Write the set<portName>EndpointAddress(String) method.
*
* @param pw
diff --git a/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaStubWriter.java b/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaStubWriter.java
index a93cd98..83666a1 100644
--- a/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaStubWriter.java
+++ b/axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaStubWriter.java
@@ -189,6 +189,17 @@
pw.println();
pw.println(
" public " + className
+ + "(java.lang.String endpoint, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
+ pw.println(" this(service);");
+ pw.println(" try {");
+ pw.println(" super.cachedEndpoint = org.apache.axis.utils.IOUtils.toURL(endpoint);");
+ pw.println(" } catch (java.net.MalformedURLException ex) {");
+ pw.println(" throw org.apache.axis.AxisFault.makeFault(ex);");
+ pw.println(" }");
+ pw.println(" }");
+ pw.println();
+ pw.println(
+ " public " + className
+ "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
pw.println(" if (service == null) {");
pw.println(
diff --git a/axis-rt-core/src/main/java/org/apache/axis/utils/DummyURLStreamHandler.java b/axis-rt-core/src/main/java/org/apache/axis/utils/DummyURLStreamHandler.java
new file mode 100644
index 0000000..328629e
--- /dev/null
+++ b/axis-rt-core/src/main/java/org/apache/axis/utils/DummyURLStreamHandler.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axis.utils;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+final class DummyURLStreamHandler extends URLStreamHandler {
+ static final DummyURLStreamHandler INSTANCE = new DummyURLStreamHandler();
+
+ protected URLConnection openConnection(URL u) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/axis-rt-core/src/main/java/org/apache/axis/utils/IOUtils.java b/axis-rt-core/src/main/java/org/apache/axis/utils/IOUtils.java
index deac1c1..cb9d77a 100644
--- a/axis-rt-core/src/main/java/org/apache/axis/utils/IOUtils.java
+++ b/axis-rt-core/src/main/java/org/apache/axis/utils/IOUtils.java
@@ -18,9 +18,11 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLStreamHandler;
/**
* Utility class containing IO helper methods
@@ -86,4 +88,20 @@
}
return new URI(str);
}
+
+ /**
+ * Constructs a {@link URL} by parsing the given string. This method does the same as
+ * {@link URL#URL(String)}, except that it configures the URL with a dummy
+ * {@link URLStreamHandler}. This means that the method works for URIs with any protocol, not
+ * just protocols for which a {@link URLStreamHandler} is registered.
+ *
+ * @param str
+ * the string to be parsed into a URL
+ * @return the URL
+ * @throws MalformedURLException
+ * if the given string is not a valid URL
+ */
+ public static URL toURL(String str) throws MalformedURLException {
+ return new URL(null, str, DummyURLStreamHandler.INSTANCE);
+ }
}
\ No newline at end of file
diff --git a/axis-rt-core/src/test/java/org/apache/axis/utils/IOUtilsTest.java b/axis-rt-core/src/test/java/org/apache/axis/utils/IOUtilsTest.java
new file mode 100644
index 0000000..db6cee0
--- /dev/null
+++ b/axis-rt-core/src/test/java/org/apache/axis/utils/IOUtilsTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.axis.utils;
+
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class IOUtilsTest extends TestCase {
+ public void testToURIParticularCase() throws Exception {
+ URI uri = IOUtils.toURI("local:");
+ assertEquals("local", uri.getScheme());
+ assertEquals("/", uri.getPath());
+ }
+
+ public void testToURL() throws Exception {
+ String s = "fancyp://user:password@localhost:8888/dest?prop=value";
+ URL url = IOUtils.toURL(s);
+ assertEquals(s, url.toString());
+ }
+}
diff --git a/samples/jms-sample/src/main/java/samples/jms/stub/JMSURLStubTest.java b/samples/jms-sample/src/main/java/samples/jms/stub/JMSURLStubTest.java
index be4402d..806c6cc 100644
--- a/samples/jms-sample/src/main/java/samples/jms/stub/JMSURLStubTest.java
+++ b/samples/jms-sample/src/main/java/samples/jms/stub/JMSURLStubTest.java
@@ -25,8 +25,6 @@
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
@@ -57,12 +55,10 @@
}
try {
- getQuote = locator.getGetQuote(new URL(endptAddr));
+ getQuote = locator.getGetQuote(endptAddr);
}
catch (ServiceException e) {
throw new AxisFault("JAX-RPC ServiceException caught: ", e);
- } catch (MalformedURLException e) {
- throw new AxisFault("MalformedURLException caught: ", e);
}
assertTrue("getQuote is null", getQuote != null);