diff --git a/core/src/main/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapter.java b/core/src/main/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapter.java index 0d82352b..8d74b6f7 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapter.java +++ b/core/src/main/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapter.java @@ -16,8 +16,6 @@ package org.springframework.ws.transport.http; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Iterator; import java.util.List; import java.util.Properties; @@ -160,25 +158,27 @@ public class WsdlDefinitionHandlerAdapter extends TransformerObjectSupport imple * This method is only called when the transformLocations property is true. */ protected String transformLocation(String location, HttpServletRequest request) { - try { - if (location.startsWith("/")) { - // a relative path, prepend the context path - URL newLocation = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), - request.getContextPath() + location); - return newLocation.toString(); - } - else { + StringBuffer url = new StringBuffer(request.getScheme()); + url.append("://").append(request.getServerName()).append(':').append(request.getServerPort()); + if (location.startsWith("/")) { + // a relative path, prepend the context path + url.append(request.getContextPath()).append(location); + return url.toString(); + } + else { + int idx = location.indexOf("://"); + if (idx != -1) { // a full url - URL oldLocation = new URL(location); - URL newLocation = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), - oldLocation.getFile()); - return newLocation.toString(); + idx = location.indexOf('/', idx + 3); + if (idx != -1) { + String path = location.substring(idx); + url.append(path); + return url.toString(); + } } } - catch (MalformedURLException e) { - return location; - // fall though to the default return value - } + // unknown location, return the original + return location; } /** @@ -198,7 +198,9 @@ public class WsdlDefinitionHandlerAdapter extends TransformerObjectSupport imple Attr location = (Attr) iterator.next(); if (location != null && StringUtils.hasLength(location.getValue())) { String newLocation = transformLocation(location.getValue(), request); - logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); + if (logger.isDebugEnabled()) { + logger.debug("Transforming [" + location.getValue() + "] to [" + newLocation + "]"); + } location.setValue(newLocation); } } diff --git a/core/src/test/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapterTest.java b/core/src/test/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapterTest.java index 9628b258..efe02fe6 100644 --- a/core/src/test/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapterTest.java +++ b/core/src/test/java/org/springframework/ws/transport/http/WsdlDefinitionHandlerAdapterTest.java @@ -16,7 +16,7 @@ package org.springframework.ws.transport.http; -import java.net.URL; +import java.net.URI; import javax.servlet.ServletException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -107,7 +107,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase { String result = adapter.transformLocation(oldLocation, request); assertNotNull("No result", result); - assertEquals("Invalid result", new URL("http://example.com:8080/context/service"), new URL(result)); + assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result)); } public void testTransformLocationEmptyContextFullUrl() throws Exception { @@ -120,7 +120,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase { String result = adapter.transformLocation(oldLocation, request); assertNotNull("No result", result); - assertEquals("Invalid result", new URL("http://example.com:8080/service"), new URL(result)); + assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result)); } public void testTransformLocationRelativeUrl() throws Exception { @@ -134,7 +134,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase { String result = adapter.transformLocation(oldLocation, request); assertNotNull("No result", result); - assertEquals("Invalid result", new URL("http://example.com:8080/context/service"), new URL(result)); + assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result)); } public void testTransformLocationEmptyContextRelativeUrl() throws Exception { @@ -147,6 +147,6 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase { String result = adapter.transformLocation(oldLocation, request); assertNotNull("No result", result); - assertEquals("Invalid result", new URL("http://example.com:8080/service"), new URL(result)); + assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result)); } } \ No newline at end of file