This is an automated email from the ASF dual-hosted git repository. billblough pushed a commit to branch AXIS-2882 in repository https://gitbox.apache.org/repos/asf/axis-axis1-java.git
commit 985dac4296711ebc81ff789c90dbaa97db5986d6 Author: Andreas Veithen <veit...@apache.org> AuthorDate: Fri Dec 7 20:24:34 2012 +0000 More work on AXIS-2882. --- .../java/org/apache/axis/client/AdminClient.java | 13 +++++++- .../src/main/java/org/apache/axis/client/Call.java | 15 ++++------ .../main/java/org/apache/axis/client/Service.java | 4 +-- .../main/java/org/apache/axis/utils/IOUtils.java | 24 +++++++++++++++ .../main/java/org/apache/axis/utils/Options.java | 17 ++++++----- .../java/samples/transport/tcp/AdminClient.java | 1 - .../main/java/samples/transport/tcp/GetQuote.java | 4 +-- .../main/java/samples/transport/tcp/Handler.java | 35 ---------------------- .../java/samples/transport/tcp/TCPTransport.java | 12 ++++---- .../test/functional/TestTCPTransportSample.java | 3 +- 10 files changed, 62 insertions(+), 66 deletions(-) diff --git a/axis-rt-core/src/main/java/org/apache/axis/client/AdminClient.java b/axis-rt-core/src/main/java/org/apache/axis/client/AdminClient.java index 319d145..d06b890 100644 --- a/axis-rt-core/src/main/java/org/apache/axis/client/AdminClient.java +++ b/axis-rt-core/src/main/java/org/apache/axis/client/AdminClient.java @@ -21,6 +21,7 @@ import org.apache.axis.EngineConfiguration; import org.apache.axis.components.logger.LogFactory; import org.apache.axis.deployment.wsdd.WSDDConstants; import org.apache.axis.message.SOAPBodyElement; +import org.apache.axis.utils.IOUtils; import org.apache.axis.utils.Messages; import org.apache.axis.utils.Options; import org.apache.axis.utils.StringUtils; @@ -30,6 +31,7 @@ import javax.xml.rpc.ServiceException; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.util.Vector; @@ -346,7 +348,7 @@ public class AdminClient throw new Exception(Messages.getMessage("nullCall00")); } - URL address = new URL(opts.getURL()); + URI address = IOUtils.toURI(opts.getURL()); setTargetEndpointAddress(address); setLogin(opts.getUser(), opts.getPassword()); @@ -375,6 +377,15 @@ public class AdminClient } /** + * set the URL to deploy to + * requires that call!=null + * @param address + */ + public void setTargetEndpointAddress(URI address) { + call.setTargetEndpointAddress( address ); + } + + /** * set the transport to deploy with. * requires that call!=null * @param transportName a null or empty value does not trigger a setting diff --git a/axis-rt-core/src/main/java/org/apache/axis/client/Call.java b/axis-rt-core/src/main/java/org/apache/axis/client/Call.java index aaadedc..80702ff 100644 --- a/axis-rt-core/src/main/java/org/apache/axis/client/Call.java +++ b/axis-rt-core/src/main/java/org/apache/axis/client/Call.java @@ -51,6 +51,7 @@ import org.apache.axis.message.SOAPHeaderElement; import org.apache.axis.soap.SOAPConstants; import org.apache.axis.transport.http.HTTPTransport; import org.apache.axis.utils.ClassUtils; +import org.apache.axis.utils.IOUtils; import org.apache.axis.utils.JavaUtils; import org.apache.axis.utils.Messages; import org.apache.axis.utils.LockableHashtable; @@ -340,7 +341,7 @@ public class Call implements javax.xml.rpc.Call { public Call(String url) throws MalformedURLException { this(new Service()); try { - setTargetEndpointAddress(new URI(url)); + setTargetEndpointAddress(IOUtils.toURI(url)); } catch (URISyntaxException ex) { // The method used to use new URL(...). Need this to ensure source code compatibility: throw new MalformedURLException(ex.getMessage()); @@ -805,14 +806,8 @@ public class Call implements javax.xml.rpc.Call { * as URI */ public void setTargetEndpointAddress(String address) { - // Special case: Since Axis 1.4 used java.net.URL, it accepted "<scheme>:" (e.g. "local:") - // as a valid URL. However this is not a valid URI. If we encounter this case, we add a - // slash to make it a valid URI: "<scheme>:/". - if (address.indexOf(':') == address.length() - 1) { - address += '/'; - } try { - setTargetEndpointAddress(new URI(address)); + setTargetEndpointAddress(IOUtils.toURI(address)); } catch (URISyntaxException mue) { throw new JAXRPCException(mue); @@ -858,7 +853,7 @@ public class Call implements javax.xml.rpc.Call { if ( this.transport != null ) { String oldAddr = this.transport.getUrl(); if ( oldAddr != null && !oldAddr.equals("") ) { - URI tmpURL = new URI( oldAddr ); + URI tmpURL = IOUtils.toURI( oldAddr ); String oldProto = tmpURL.getScheme(); if ( protocol.equals(oldProto) ) { this.transport.setUrl( address.toString() ); @@ -1657,7 +1652,7 @@ public class Call implements javax.xml.rpc.Call { if ( obj instanceof SOAPAddress ) { try { SOAPAddress addr = (SOAPAddress) obj ; - this.setTargetEndpointAddress(new URI(addr.getLocationURI())); + this.setTargetEndpointAddress(addr.getLocationURI()); } catch(Exception exp) { throw new JAXRPCException( diff --git a/axis-rt-core/src/main/java/org/apache/axis/client/Service.java b/axis-rt-core/src/main/java/org/apache/axis/client/Service.java index 5f93c74..0aececa 100644 --- a/axis-rt-core/src/main/java/org/apache/axis/client/Service.java +++ b/axis-rt-core/src/main/java/org/apache/axis/client/Service.java @@ -440,7 +440,7 @@ public class Service implements javax.xml.rpc.Service, Serializable, Referenceab if (portName == null) { call = (org.apache.axis.client.Call) createCall(); if (endpoint != null) { - call.setTargetEndpointAddress(new URI(endpoint)); + call.setTargetEndpointAddress(endpoint); } } else { call = (org.apache.axis.client.Call) createCall(portName); @@ -495,7 +495,7 @@ public class Service implements javax.xml.rpc.Service, Serializable, Referenceab if (obj instanceof SOAPAddress) { try { SOAPAddress addr = (SOAPAddress) obj; - call.setTargetEndpointAddress(new URI(addr.getLocationURI())); + call.setTargetEndpointAddress(addr.getLocationURI()); } catch (Exception exp) { throw new ServiceException( Messages.getMessage("cantSetURI00", "" + exp)); 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 411b1f9..deac1c1 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,6 +18,9 @@ package org.apache.axis.utils; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; /** * Utility class containing IO helper methods @@ -62,4 +65,25 @@ public class IOUtils } } } + + /** + * Constructs a {@link URI} by parsing the given string. This method basically does the same as + * {@link URI#URI(String)}, with one exception: it accepts URIs of the form + * <tt><scheme>:</tt> (e.g. <tt>local:</tt>). They are accepted by {@link URL}, but they are + * not valid URIs. If the passed string is of that form, the method adds a slash to make it a + * valid URI, i.e. it transforms <tt><scheme>:</tt> into <tt><scheme>:/</tt>. This ensures + * compatibility with Axis 1.4 (which used {@link URL} internally). + * + * @param str + * the string to be parsed into a URI + * @return the URI + * @throws URISyntaxException + * if the given string is not a valid URI + */ + public static URI toURI(String str) throws URISyntaxException { + if (str.indexOf(':') == str.length() - 1) { + str += '/'; + } + return new URI(str); + } } \ No newline at end of file diff --git a/axis-rt-core/src/main/java/org/apache/axis/utils/Options.java b/axis-rt-core/src/main/java/org/apache/axis/utils/Options.java index 7d0f388..6789ff1 100644 --- a/axis-rt-core/src/main/java/org/apache/axis/utils/Options.java +++ b/axis-rt-core/src/main/java/org/apache/axis/utils/Options.java @@ -27,6 +27,8 @@ import org.apache.axis.components.logger.LogFactory; import org.apache.commons.logging.Log; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Vector; @@ -228,17 +230,18 @@ public class Options { String servlet = null ; // -s also -f (file) String protocol = null ; - URL url = null ; + URI url = null ; - // Just in case... - org.apache.axis.client.Call.initialize(); - if ( (tmp = isValueSet( 'l' )) != null ) { - url = new URL( tmp ); + try { + url = IOUtils.toURI( tmp ); + } catch (URISyntaxException ex) { + throw new MalformedURLException(ex.getMessage()); + } host = url.getHost(); port = "" + url.getPort(); - servlet = url.getFile(); - protocol = url.getProtocol(); + servlet = url.getPath(); + protocol = url.getScheme(); } if ( (tmp = isValueSet( 'f' )) != null ) { diff --git a/samples/transport-sample/src/main/java/samples/transport/tcp/AdminClient.java b/samples/transport-sample/src/main/java/samples/transport/tcp/AdminClient.java index 348c2aa..bfc3a45 100644 --- a/samples/transport-sample/src/main/java/samples/transport/tcp/AdminClient.java +++ b/samples/transport-sample/src/main/java/samples/transport/tcp/AdminClient.java @@ -33,7 +33,6 @@ import org.apache.axis.configuration.SimpleProvider; public class AdminClient extends org.apache.axis.client.AdminClient { public static void main(String args[]) { - Call.addTransportPackage("samples.transport"); Call.setTransportForProtocol("tcp", TCPTransport.class); // Deploy the transport on top of the default client configuration. diff --git a/samples/transport-sample/src/main/java/samples/transport/tcp/GetQuote.java b/samples/transport-sample/src/main/java/samples/transport/tcp/GetQuote.java index 209dc7b..a5fa397 100644 --- a/samples/transport-sample/src/main/java/samples/transport/tcp/GetQuote.java +++ b/samples/transport-sample/src/main/java/samples/transport/tcp/GetQuote.java @@ -28,7 +28,6 @@ import org.apache.axis.utils.Options; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; -import java.net.URL; /** * @@ -39,7 +38,6 @@ public class GetQuote { // helper function; does all the real work public float getQuote (String args[]) throws Exception { - Call.addTransportPackage("samples.transport"); Call.setTransportForProtocol("tcp", TCPTransport.class); Options opts = new Options( args ); @@ -65,7 +63,7 @@ public class GetQuote { call.setTransport(new TCPTransport()); - call.setTargetEndpointAddress( new URL(opts.getURL()) ); + call.setTargetEndpointAddress(opts.getURL()); call.setOperationName( new QName("urn:xmltoday-delayed-quotes", "getQuote") ); call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); call.setReturnType( XMLType.XSD_FLOAT ); diff --git a/samples/transport-sample/src/main/java/samples/transport/tcp/Handler.java b/samples/transport-sample/src/main/java/samples/transport/tcp/Handler.java deleted file mode 100644 index ad4e6c6..0000000 --- a/samples/transport-sample/src/main/java/samples/transport/tcp/Handler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2001-2004 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 samples.transport.tcp; - -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * A stub URLStreamHandler, so the system will recognize our - * custom URLs as valid. - * - * @author Glen Daniels (gdani...@apache.org) - */ -public class Handler extends URLStreamHandler -{ - protected URLConnection openConnection(URL u) - { - return null; - } -} diff --git a/samples/transport-sample/src/main/java/samples/transport/tcp/TCPTransport.java b/samples/transport-sample/src/main/java/samples/transport/tcp/TCPTransport.java index b641ff3..384c278 100644 --- a/samples/transport-sample/src/main/java/samples/transport/tcp/TCPTransport.java +++ b/samples/transport-sample/src/main/java/samples/transport/tcp/TCPTransport.java @@ -17,13 +17,15 @@ package samples.transport.tcp; import org.apache.axis.AxisEngine; +import org.apache.axis.AxisFault; import org.apache.axis.MessageContext; import org.apache.axis.client.Call; import org.apache.axis.client.Transport; import org.apache.axis.components.logger.LogFactory; import org.apache.commons.logging.Log; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; /** * @@ -63,17 +65,17 @@ public class TCPTransport extends Transport */ public void setupMessageContextImpl(MessageContext mc, Call call, - AxisEngine engine) + AxisEngine engine) throws AxisFault { try { String urlString = mc.getStrProp(MessageContext.TRANS_URL); if (urlString != null) { - URL url = new URL(urlString); + URI url = new URI(urlString); host = url.getHost(); port = new Integer(url.getPort()).toString(); } - } catch (java.net.MalformedURLException e) { - // Do nothing here? + } catch (URISyntaxException ex) { + throw AxisFault.makeFault(ex); } if (host != null) mc.setProperty(HOST, host); diff --git a/samples/transport-sample/src/test/java/test/functional/TestTCPTransportSample.java b/samples/transport-sample/src/test/java/test/functional/TestTCPTransportSample.java index da7c322..0c1acbc 100644 --- a/samples/transport-sample/src/test/java/test/functional/TestTCPTransportSample.java +++ b/samples/transport-sample/src/test/java/test/functional/TestTCPTransportSample.java @@ -33,7 +33,6 @@ import samples.transport.tcp.TCPSender; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; -import java.net.URL; /** Test the stock sample code. */ @@ -74,7 +73,7 @@ public class TestTCPTransportSample extends TestCase { Call call = (Call) service.createCall(); - call.setTargetEndpointAddress( new URL(uri) ); + call.setTargetEndpointAddress(uri); call.setOperationName( new QName("urn:xmltoday-delayed-quotes", "getQuote") ); call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); call.setReturnType( XMLType.XSD_FLOAT );