You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/09/17 21:35:50 UTC
svn commit: r696411 - in /geronimo/server/branches/2.1/plugins:
axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/
cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/
jaxws/geronimo-jaxws/ jaxws/geronimo-jaxws/src/main/java/org/apache/ge...
Author: gawor
Date: Wed Sep 17 12:35:50 2008
New Revision: 696411
URL: http://svn.apache.org/viewvc?rev=696411&view=rev
Log:
update service address in WSDL on each request (GERONIMO-4308)
Added:
geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java (with props)
Modified:
geronimo/server/branches/2.1/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/WSDLQueryHandler.java
geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoQueryHandler.java
geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/pom.xml
Modified: geronimo/server/branches/2.1/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/WSDLQueryHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/WSDLQueryHandler.java?rev=696411&r1=696410&r2=696411&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/WSDLQueryHandler.java (original)
+++ geronimo/server/branches/2.1/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/WSDLQueryHandler.java Wed Sep 17 12:35:50 2008
@@ -22,31 +22,22 @@
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.wsdl.Definition;
import javax.wsdl.Import;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
import javax.wsdl.Types;
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.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.wsdl.xml.WSDLWriter;
-import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -56,6 +47,7 @@
import javax.xml.transform.stream.StreamResult;
import org.apache.axis2.description.AxisService;
+import org.apache.geronimo.jaxws.WSDLUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.webservices.WebServiceContainer.Request;
@@ -108,7 +100,8 @@
reader.setFeature("javax.wsdl.verbose", false);
Definition def = reader.readWSDL(wsdlUri);
updateDefinition(def, mp, smp, base);
- updateServices(this.service.getName(), this.service.getEndpointName(), def, base);
+ // remove other services and ports from wsdl
+ WSDLUtils.trimDefinition(def, this.service.getName(), this.service.getEndpointName());
mp.put("", def);
}
@@ -121,6 +114,11 @@
throw new FileNotFoundException("WSDL not found: " + wsdl);
}
+ // update service port location on each request
+ if (wsdl.equals("")) {
+ WSDLUtils.updateLocations(def, base);
+ }
+
WSDLFactory factory = WSDLFactory.newInstance();
WSDLWriter writer = factory.newWSDLWriter();
@@ -256,74 +254,4 @@
}
}
- private void updateServices(String serviceName, String portName, Definition def, String baseUri)
- throws Exception {
- boolean updated = false;
- Map services = def.getServices();
- if (services != null) {
- ArrayList<QName> servicesToRemove = new ArrayList<QName>();
-
- Iterator serviceIterator = services.entrySet().iterator();
- while (serviceIterator.hasNext()) {
- Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
- QName currServiceName = (QName) serviceEntry.getKey();
- if (currServiceName.getLocalPart().equals(serviceName)) {
- Service service = (Service) serviceEntry.getValue();
- updatePorts(portName, service, baseUri);
- updated = true;
- } else {
- servicesToRemove.add(currServiceName);
- }
- }
-
- for (QName serviceToRemove : servicesToRemove) {
- def.removeService(serviceToRemove);
- }
- }
- if (!updated) {
- LOG.warn("WSDL '" + serviceName + "' service not found.");
- }
- }
-
- private void updatePorts(String portName, Service service, String baseUri) throws Exception {
- boolean updated = false;
- Map ports = service.getPorts();
- if (ports != null) {
- ArrayList<String> portsToRemove = new ArrayList<String>();
-
- Iterator portIterator = ports.entrySet().iterator();
- while (portIterator.hasNext()) {
- Map.Entry portEntry = (Map.Entry) portIterator.next();
- String currPortName = (String) portEntry.getKey();
- if (currPortName.equals(portName)) {
- Port port = (Port) portEntry.getValue();
- updatePortLocation(port, baseUri);
- updated = true;
- } else {
- portsToRemove.add(currPortName);
- }
- }
-
- for (String portToRemove : portsToRemove) {
- service.removePort(portToRemove);
- }
- }
- if (!updated) {
- LOG.warn("WSDL '" + portName + "' port not found.");
- }
- }
-
- private void updatePortLocation(Port port, String baseUri) throws URISyntaxException {
- List<?> exts = port.getExtensibilityElements();
- if (exts != null && exts.size() > 0) {
- ExtensibilityElement el = (ExtensibilityElement) exts.get(0);
- if (el instanceof SOAP12Address) {
- SOAP12Address add = (SOAP12Address) el;
- add.setLocationURI(baseUri);
- } else if (el instanceof SOAPAddress) {
- SOAPAddress add = (SOAPAddress) el;
- add.setLocationURI(baseUri);
- }
- }
- }
}
Modified: geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java?rev=696411&r1=696410&r2=696411&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java (original)
+++ geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java Wed Sep 17 12:35:50 2008
@@ -29,6 +29,7 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.bus.extension.ExtensionManagerBus;
import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.geronimo.webservices.WebServiceContainer;
import org.apache.geronimo.webservices.saaj.SAAJUniverse;
@@ -76,6 +77,10 @@
destination = (GeronimoDestination) endpoint.getServer().getDestination();
}
+ static String getBaseUri(URI request) {
+ return request.getScheme() + "://" + request.getHost() + ":" + request.getPort() + request.getPath();
+ }
+
public void invoke(Request request, Response response) throws Exception {
if (request.getMethod() == Request.GET) {
processGET(request, response);
@@ -90,6 +95,9 @@
GeronimoQueryHandler queryHandler = new GeronimoQueryHandler(this.bus);
URI requestURI = request.getURI();
EndpointInfo ei = this.destination.getEndpointInfo();
+ // update service port location on each request
+ SoapAddress address = ei.getExtensor(SoapAddress.class);
+ address.setLocationURI(getBaseUri(requestURI));
OutputStream out = response.getOutputStream();
String baseUri = requestURI.toString();
response.setContentType("text/xml");
Modified: geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoQueryHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoQueryHandler.java?rev=696411&r1=696410&r2=696411&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoQueryHandler.java (original)
+++ geronimo/server/branches/2.1/plugins/cxf/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/GeronimoQueryHandler.java Wed Sep 17 12:35:50 2008
@@ -16,26 +16,17 @@
*/
package org.apache.geronimo.cxf;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.wsdl.Definition;
-import javax.wsdl.Port;
-import javax.wsdl.Service;
-import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.schema.SchemaReference;
-import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.Bus;
import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
-import org.apache.cxf.tools.util.SOAPBindingUtil;
import org.apache.cxf.transport.http.WSDLQueryHandler;
-import org.xmlsoap.schemas.wsdl.http.AddressType;
+import org.apache.geronimo.jaxws.WSDLUtils;
public class GeronimoQueryHandler extends WSDLQueryHandler {
@@ -51,88 +42,12 @@
String base,
EndpointInfo ei) {
if (done.get("") == def) {
- QName serviceName = ei.getService().getName();
+ String serviceName = ei.getService().getName().getLocalPart();
String portName = ei.getName().getLocalPart();
- updateServices(serviceName, portName, def, base);
+ // remove other services and ports from wsdl
+ WSDLUtils.trimDefinition(def, serviceName, portName);
}
super.updateDefinition(def, done, doneSchemas, base, ei);
}
- private void updateServices(QName serviceName,
- String portName,
- Definition def,
- String baseUri) {
- boolean updated = false;
- Map services = def.getServices();
- if (services != null) {
- ArrayList<QName> servicesToRemove = new ArrayList<QName>();
-
- Iterator serviceIterator = services.entrySet().iterator();
- while (serviceIterator.hasNext()) {
- Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
- QName currServiceName = (QName) serviceEntry.getKey();
- if (currServiceName.equals(serviceName)) {
- Service service = (Service) serviceEntry.getValue();
- updatePorts(portName, service, baseUri);
- updated = true;
- } else {
- servicesToRemove.add(currServiceName);
- }
- }
-
- for (QName serviceToRemove : servicesToRemove) {
- def.removeService(serviceToRemove);
- }
- }
- if (!updated) {
- LOG.warn("WSDL '" + serviceName.getLocalPart() + "' service not found.");
- }
- }
-
- private void updatePorts(String portName,
- Service service,
- String baseUri) {
- boolean updated = false;
- Map ports = service.getPorts();
- if (ports != null) {
- ArrayList<String> portsToRemove = new ArrayList<String>();
-
- Iterator portIterator = ports.entrySet().iterator();
- while (portIterator.hasNext()) {
- Map.Entry portEntry = (Map.Entry) portIterator.next();
- String currPortName = (String) portEntry.getKey();
- if (currPortName.equals(portName)) {
- Port port = (Port) portEntry.getValue();
- updatePortLocation(port, baseUri);
- updated = true;
- } else {
- portsToRemove.add(currPortName);
- }
- }
-
- for (String portToRemove : portsToRemove) {
- service.removePort(portToRemove);
- }
- }
- if (!updated) {
- LOG.warn("WSDL '" + portName + "' port not found.");
- }
- }
-
- private void updatePortLocation(Port port,
- String baseUri) {
- List<?> exts = port.getExtensibilityElements();
- if (exts != null && exts.size() > 0) {
- ExtensibilityElement el = (ExtensibilityElement) exts.get(0);
- if (SOAPBindingUtil.isSOAPAddress(el)) {
- SoapAddress add = SOAPBindingUtil.getSoapAddress(el);
- add.setLocationURI(baseUri);
- }
- if (el instanceof AddressType) {
- AddressType add = (AddressType) el;
- add.setLocation(baseUri);
- }
- }
- }
-
}
Modified: geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/pom.xml?rev=696411&r1=696410&r2=696411&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/pom.xml (original)
+++ geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/pom.xml Wed Sep 17 12:35:50 2008
@@ -80,6 +80,11 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ </dependency>
</dependencies>
</project>
Added: geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java?rev=696411&view=auto
==============================================================================
--- geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java (added)
+++ geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java Wed Sep 17 12:35:50 2008
@@ -0,0 +1,125 @@
+/**
+ * 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.geronimo.jaxws;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class WSDLUtils {
+
+ private static final Log LOG = LogFactory.getLog(WSDLUtils.class);
+
+ public static void trimDefinition(Definition def,
+ String serviceName,
+ String portName) {
+ Map services = def.getServices();
+ if (services != null) {
+ ArrayList<QName> servicesToRemove = new ArrayList<QName>(services.size());
+
+ Iterator serviceIterator = services.entrySet().iterator();
+ while (serviceIterator.hasNext()) {
+ Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
+ QName currServiceName = (QName) serviceEntry.getKey();
+ if (currServiceName.getLocalPart().equals(serviceName)) {
+ Service service = (Service) serviceEntry.getValue();
+ trimService(service, portName);
+ } else {
+ servicesToRemove.add(currServiceName);
+ }
+ }
+
+ for (QName serviceToRemove : servicesToRemove) {
+ def.removeService(serviceToRemove);
+ }
+ }
+ }
+
+ public static void trimService(Service service,
+ String portName) {
+ Map ports = service.getPorts();
+ if (ports != null) {
+ ArrayList<String> portsToRemove = new ArrayList<String>(ports.size());
+
+ Iterator portIterator = ports.entrySet().iterator();
+ while (portIterator.hasNext()) {
+ Map.Entry portEntry = (Map.Entry) portIterator.next();
+ String currPortName = (String) portEntry.getKey();
+ if (!currPortName.equals(portName)) {
+ portsToRemove.add(currPortName);
+ }
+ }
+
+ for (String portToRemove : portsToRemove) {
+ service.removePort(portToRemove);
+ }
+ }
+ }
+
+ public static void updateLocations(Definition def,
+ String location) {
+ Map services = def.getServices();
+ if (services != null) {
+ Iterator serviceIterator = services.entrySet().iterator();
+ while (serviceIterator.hasNext()) {
+ Map.Entry serviceEntry = (Map.Entry) serviceIterator.next();
+ Service service = (Service) serviceEntry.getValue();
+ updateLocations(service, location);
+ }
+ }
+ }
+
+ public static void updateLocations(Service service,
+ String location) {
+ boolean updated = false;
+ Map ports = service.getPorts();
+ if (ports != null) {
+ Iterator portIterator = ports.entrySet().iterator();
+ while (portIterator.hasNext()) {
+ Map.Entry portEntry = (Map.Entry) portIterator.next();
+ Port port = (Port) portEntry.getValue();
+ updateLocations(port, location);
+ }
+ }
+ }
+
+ public static void updateLocations(Port port,
+ String location) {
+ List<?> exts = port.getExtensibilityElements();
+ if (exts != null) {
+ for (Object extension : exts) {
+ if (extension instanceof SOAP12Address) {
+ ((SOAP12Address)extension).setLocationURI(location);
+ } else if (extension instanceof SOAPAddress) {
+ ((SOAPAddress)extension).setLocationURI(location);
+ }
+ }
+ }
+ }
+
+}
Propchange: geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/2.1/plugins/jaxws/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/WSDLUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain