You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2007/12/12 03:12:24 UTC
svn commit: r603438 - in /incubator/cxf/trunk:
rt/core/src/main/java/org/apache/cxf/endpoint/
rt/core/src/main/java/org/apache/cxf/transport/http/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/
rt/frontend/jaxws/src/main/resources/schemas/ rt/fr...
Author: ningjiang
Date: Tue Dec 11 18:12:22 2007
New Revision: 603438
URL: http://svn.apache.org/viewvc?rev=603438&view=rev
Log:
CXF-1279 applied the patch with thanks to Christian, also added a systest for the Servlet transport
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java (with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/resources/schemas/jaxws.xsd
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractWSDLBasedEndpointFactory.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring.xml
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java Tue Dec 11 18:12:22 2007
@@ -45,6 +45,7 @@
protected DataBinding dataBinding;
protected BindingFactory bindingFactory;
protected DestinationFactory destinationFactory;
+ protected String publishedEndpointUrl;
protected QName endpointName;
protected QName serviceName;
protected Map<String, Object> properties;
@@ -108,6 +109,14 @@
public void setDestinationFactory(DestinationFactory destinationFactory) {
this.destinationFactory = destinationFactory;
+ }
+
+ public String getPublishedEndpointUrl() {
+ return publishedEndpointUrl;
+ }
+
+ public void setPublishedEndpointUrl(String publishedEndpointUrl) {
+ this.publishedEndpointUrl = publishedEndpointUrl;
}
public QName getEndpointName() {
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/http/WSDLQueryHandler.java Tue Dec 11 18:12:22 2007
@@ -31,13 +31,18 @@
import javax.wsdl.Definition;
import javax.wsdl.Import;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
import javax.wsdl.Types;
import javax.wsdl.WSDLException;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.schema.Schema;
import javax.wsdl.extensions.schema.SchemaImport;
import javax.wsdl.extensions.schema.SchemaReference;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
@@ -47,7 +52,6 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-
import org.apache.cxf.Bus;
import org.apache.cxf.catalog.OASISCatalogManager;
import org.apache.cxf.common.i18n.Message;
@@ -146,6 +150,11 @@
base);
def = mp.get(wsdl2);
}
+
+ if (endpointInfo.getProperty("publishedEndpointUrl") != null) {
+ String publishingUrl = String.valueOf(endpointInfo.getProperty("publishedEndpointUrl"));
+ updatePublishedEndpointUrl(publishingUrl, def, endpointInfo.getName());
+ }
WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
.getWSDLFactory().newWSDLWriter();
@@ -224,7 +233,6 @@
baseUri), e);
}
}
-
static String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String base) {
String resolvedSchemaLocation = null;
@@ -282,6 +290,38 @@
Schema see = (Schema)el;
updateSchemaImports(see, doneSchemas, base);
}
+ }
+ }
+ }
+
+ protected void updatePublishedEndpointUrl(String publishingUrl, Definition def, QName name) {
+ Collection<Service> services = CastUtils.cast(def.getAllServices().values());
+ for (Service service : services) {
+ Collection<Port> ports = CastUtils.cast(service.getPorts().values());
+ if (ports.isEmpty()) {
+ continue;
+ }
+
+ if (name == null) {
+ setSoapAddressLocationOn(ports.iterator().next(), publishingUrl);
+ break; // only update the first port since we don't target any specific port
+ } else {
+ for (Port port : ports) {
+ if (name.getLocalPart().equals(port.getName())) {
+ setSoapAddressLocationOn(port, publishingUrl);
+ }
+ }
+ }
+ }
+ }
+
+ private void setSoapAddressLocationOn(Port port, String url) {
+ List extensions = port.getExtensibilityElements();
+ for (Object extension : extensions) {
+ if (extension instanceof SOAP12Address) {
+ ((SOAP12Address)extension).setLocationURI(url);
+ } else if (extension instanceof SOAPAddress) {
+ ((SOAPAddress)extension).setLocationURI(url);
}
}
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Tue Dec 11 18:12:22 2007
@@ -60,6 +60,7 @@
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.invoker.Invoker;
+import org.apache.cxf.service.model.EndpointInfo;
public class EndpointImpl extends javax.xml.ws.Endpoint
implements InterceptorProvider, Configurable {
@@ -88,6 +89,7 @@
private String bindingUri;
private String wsdlLocation;
private String address;
+ private String publishedEndpointUrl;
private QName endpointName;
private QName serviceName;
private Class implementorClass;
@@ -256,8 +258,13 @@
checkPublishPermission();
ServerImpl serv = getServer(addr);
- if (addr != null) {
- serv.getEndpoint().getEndpointInfo().setAddress(addr);
+ if (addr != null) {
+ EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
+ endpointInfo.setAddress(addr);
+ if (publishedEndpointUrl != null) {
+ // TODO is there a good place to put this key-string as a constant?
+ endpointInfo.setProperty("publishedEndpointUrl", publishedEndpointUrl);
+ }
this.address = addr;
}
serv.start();
@@ -387,6 +394,20 @@
public void setAddress(String address) {
this.address = address;
+ }
+
+ /**
+ * The published endpoint url is used for excplicitely specifying the url of the
+ * endpoint that would show up the generated wsdl definition, when the service is
+ * brought on line.
+ * @return
+ */
+ public String getPublishedEndpointUrl() {
+ return publishedEndpointUrl;
+ }
+
+ public void setPublishedEndpointUrl(String publishedEndpointUrl) {
+ this.publishedEndpointUrl = publishedEndpointUrl;
}
public QName getEndpointName() {
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/resources/schemas/jaxws.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/resources/schemas/jaxws.xsd?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/resources/schemas/jaxws.xsd (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/resources/schemas/jaxws.xsd Tue Dec 11 18:12:22 2007
@@ -55,6 +55,7 @@
<xsd:attribute name="implementor" type="xsd:string"/>
<xsd:attribute name="implementorClass" type="xsd:string"/>
<xsd:attribute name="publish" type="xsd:boolean" default="true"/>
+ <xsd:attribute name="publishedEndpointUrl" type="xsd:string"/>
<xsd:attribute name="endpointName" type="xsd:QName" />
<xsd:attribute name="serviceName" type="xsd:QName" />
<xsd:attribute name="wsdlLocation" type="xsd:string" />
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java Tue Dec 11 18:12:22 2007
@@ -22,6 +22,7 @@
import java.io.StringWriter;
import java.util.List;
+
import javax.xml.namespace.QName;
import junit.framework.Assert;
@@ -147,6 +148,12 @@
bean = ctx.getBean("wsdlLocation");
assertNotNull(bean);
+ bean = ctx.getBean("publishedEndpointUrl");
+ assertNotNull(bean);
+ String expectedEndpointUrl = "http://cxf.apache.org/Greeter";
+ ep = (EndpointImpl) bean;
+ assertEquals(expectedEndpointUrl, ep.getPublishedEndpointUrl());
+
// test for existence of Endpoint without an id element
boolean found = false;
String[] names = ctx.getBeanNamesForType(EndpointImpl.class);
@@ -160,6 +167,7 @@
testInterceptors(ctx);
}
+
private void testNamespaceMapping(ApplicationContext ctx) throws Exception {
AnonymousComplexType act = (AnonymousComplexType) ctx.getBean("bookClient");
Client client = ClientProxy.getClient(act);
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml Tue Dec 11 18:12:22 2007
@@ -120,4 +120,9 @@
implementor="java.lang.Object"
implementorClass="org.apache.cxf.jaxws.service.Hello"
address="http://localhost:8080/test"/>
+
+ <jaxws:endpoint id="publishedEndpointUrl"
+ implementor="#greeter"
+ address="http://localhost:8080/publishedEndpointUrl"
+ publishedEndpointUrl="http://cxf.apache.org/Greeter"/>
</beans>
Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractWSDLBasedEndpointFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractWSDLBasedEndpointFactory.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractWSDLBasedEndpointFactory.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/AbstractWSDLBasedEndpointFactory.java Tue Dec 11 18:12:22 2007
@@ -218,6 +218,10 @@
ei.setName(endpointName);
ei.setAddress(getAddress());
ei.setBinding(bindingInfo);
+
+ if (publishedEndpointUrl != null && !"".equals(publishedEndpointUrl)) {
+ ei.setProperty("publishedEndpointUrl", publishedEndpointUrl);
+ }
if (destinationFactory instanceof WSDLEndpointFactory) {
WSDLEndpointFactory we = (WSDLEndpointFactory) destinationFactory;
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java?rev=603438&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java Tue Dec 11 18:12:22 2007
@@ -0,0 +1,86 @@
+/**
+ * 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.cxf.systest.http;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+
+import junit.framework.Assert;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.hello_world_soap_http.Greeter;
+import org.junit.Test;
+
+
+public class PublishedEndpointUrlTest extends Assert {
+
+ @Test
+ public void testPublishedEndpointUrl() throws Exception {
+
+ Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
+ String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
+
+ JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
+ svrFactory.setServiceClass(Greeter.class);
+ svrFactory.setAddress("http://localhost:9000/publishedEndpointUrl");
+ svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
+ svrFactory.setServiceBean(implementor);
+
+ Server server = svrFactory.create();
+
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ wsdlReader.setFeature("javax.wsdl.verbose", false);
+ Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
+ assertNotNull(wsdl);
+
+ Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
+ final String failMesg = "WSDL provided incorrect soap:address location";
+
+ for (Service service : services) {
+ Collection<Port> ports = CastUtils.cast(service.getPorts().values());
+ for (Port port : ports) {
+ List extensions = port.getExtensibilityElements();
+ for (Object extension : extensions) {
+ String actualUrl = null;
+ if (extension instanceof SOAP12Address) {
+ actualUrl = ((SOAP12Address)extension).getLocationURI();
+ } else if (extension instanceof SOAPAddress) {
+ actualUrl = ((SOAPAddress)extension).getLocationURI();
+ }
+
+ //System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
+ assertEquals(failMesg, publishedEndpointUrl, actualUrl);
+ }
+ }
+ }
+
+ server.stop();
+ }
+
+
+}
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http/PublishedEndpointUrlTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java Tue Dec 11 18:12:22 2007
@@ -114,7 +114,15 @@
assertTrue("the soap address should changed",
res.getText().contains("<soap:address location=\"" + CONTEXT_URL + "/services/Greeter"));
-
+ req =
+ new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter2?wsdl");
+ res = client.getResponse(req);
+ assertEquals(200, res.getResponseCode());
+ assertEquals("text/xml", res.getContentType());
+ assertTrue("the wsdl should contain the opertion greetMe",
+ res.getText().contains("<wsdl:operation name=\"greetMe\">"));
+ assertTrue("the soap address should be updated",
+ res.getText().contains("<soap:address location=\"http://cxf.apache.org/Greeter"));
}
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring.xml?rev=603438&r1=603437&r2=603438&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring.xml (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring.xml Tue Dec 11 18:12:22 2007
@@ -50,6 +50,7 @@
<jaxws:endpoint id="endpoint2"
implementor="org.apache.hello_world_soap_http.GreeterImpl"
address="/services/Greeter2"
+ publishedEndpointUrl="http://cxf.apache.org/Greeter"
/>
</beans>