diff --git a/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java b/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java index 2315e72a56..44d26926e4 100644 --- a/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java +++ b/modules/kernel/src/org/apache/axis2/dataretrieval/WSDLDataLocator.java @@ -116,7 +116,6 @@ protected Data[] outputInlineForm(MessageContext msgContext, ServiceData[] dataL if (msgContext != null) { theService = msgContext.getAxisService(); serviceURL = msgContext.getTo().getAddress(); - theService.setEndpointURL(serviceURL); } else { throw new DataRetrievalException("MessageContext was not set!"); } @@ -128,6 +127,7 @@ protected Data[] outputInlineForm(MessageContext msgContext, ServiceData[] dataL try { axisService2WOM = new AxisService2WSDL11(theService); + axisService2WOM.setRequestURL(serviceURL); wsdlElement = axisService2WOM.generateOM(); } catch (Exception e) { diff --git a/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java b/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java index 36420b901d..1d5765e165 100644 --- a/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java +++ b/modules/kernel/src/org/apache/axis2/description/AxisService2WSDL11.java @@ -99,6 +99,8 @@ public class AxisService2WSDL11 implements Java2WSDLConstants { private HashMap messagesMap; private boolean checkIfEndPointActive = true; + + private String requestURL; public AxisService2WSDL11() { } @@ -120,6 +122,19 @@ public void setCheckIfEndPointActive(boolean flag) { checkIfEndPointActive = flag; } + /** + * Sets the address the WSDL was requested at. Its host is used for the + * port addresses in the generated WSDL, unless the hostname parameter or + * modifyUserWSDLPortAddress says otherwise. It belongs to the request being + * answered, so it is kept here rather than on the shared AxisService. + * + * @param requestURL the address of the request, or null to use the + * endpoint URL set on the service + */ + public void setRequestURL(String requestURL) { + this.requestURL = requestURL; + } + protected void init() throws AxisFault { /* // the EPR list of AxisService contains REST EPRs as well. Those REST @@ -1337,7 +1352,8 @@ private String getEndpointURL(AxisEndpoint axisEndpoint) { //If it is not set extract the hostIP from the URL if (hostIP == null) { - hostIP = WSDLSerializationUtil.extractHostIP(axisService.getEndpointURL()); + hostIP = WSDLSerializationUtil.extractHostIP( + requestURL != null ? requestURL : axisService.getEndpointURL()); } //TODO This is to prevent problems when JAVA2WSDL tool is used where there is no diff --git a/modules/kernel/test/org/apache/axis2/dataretrieval/WSDLDataLocatorTest.java b/modules/kernel/test/org/apache/axis2/dataretrieval/WSDLDataLocatorTest.java new file mode 100644 index 0000000000..447206dbf3 --- /dev/null +++ b/modules/kernel/test/org/apache/axis2/dataretrieval/WSDLDataLocatorTest.java @@ -0,0 +1,101 @@ +/* + * 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.axis2.dataretrieval; + +import java.io.ByteArrayOutputStream; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.SessionContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.kernel.TransportListener; +import org.apache.axis2.util.Utils; + +public class WSDLDataLocatorTest extends TestCase { + private AxisService service; + + @Override + protected void setUp() throws Exception { + ConfigurationContext configContext = + ConfigurationContextFactory.createEmptyConfigurationContext(); + AxisConfiguration axisConfig = configContext.getAxisConfiguration(); + TransportInDescription httpIn = new TransportInDescription("http"); + httpIn.setReceiver(new HostEchoingListener()); + axisConfig.addTransportIn(httpIn); + service = Utils.createSimpleService(new QName("EchoService"), "", new QName("echo")); + axisConfig.addService(service); + org.apache.axis2.deployment.util.Utils.addEndpointsToService(service); + } + + @Override + protected void tearDown() throws Exception { + service = null; + super.tearDown(); + } + + public void testRequestHostIsUsedButNotStoredOnService() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + service.printWSDL(out, "requester.example"); + String wsdl = out.toString("UTF-8"); + assertTrue(wsdl, wsdl.contains( + "location=\"http://requester.example:8080/axis2/services/EchoService")); + assertNull(service.getEndpointURL()); + } + + /** + * Builds the EPRs the way the HTTP listeners do: from the host the request + * was made to. + */ + private static class HostEchoingListener implements TransportListener { + public void init(ConfigurationContext configContext, TransportInDescription transportIn) { + } + + public void start() { + } + + public void stop() { + } + + public void destroy() { + } + + public EndpointReference getEPRForService(String serviceName, String ip) throws AxisFault { + return getEPRsForService(serviceName, ip)[0]; + } + + public EndpointReference[] getEPRsForService(String serviceName, String ip) { + return new EndpointReference[] { + new EndpointReference("http://" + ip + ":8080/axis2/services/" + serviceName) }; + } + + public SessionContext getSessionContext(MessageContext messageContext) { + return null; + } + } +} diff --git a/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java b/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java index a63d2035a8..f12a204129 100644 --- a/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java +++ b/modules/mex/src/org/apache/axis2/mex/MexMessageReceiver.java @@ -77,7 +77,6 @@ public void invokeBusinessLogic(MessageContext msgContext, try { Metadata metadata = handleRequest(msgContext); - theService.setEndpointURL(msgContext.getTo().getAddress()); if (metadata != null) { SOAPEnvelope envelope = newmsgContext.getEnvelope();