001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.cxf;
017:
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import javax.wsdl.Definition;
024: import javax.wsdl.Port;
025: import javax.wsdl.Service;
026: import javax.wsdl.extensions.ExtensibilityElement;
027: import javax.wsdl.extensions.schema.SchemaReference;
028: import javax.xml.namespace.QName;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.cxf.Bus;
033: import org.apache.cxf.service.model.EndpointInfo;
034: import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
035: import org.apache.cxf.tools.util.SOAPBindingUtil;
036: import org.apache.cxf.transport.http.WSDLQueryHandler;
037: import org.xmlsoap.schemas.wsdl.http.AddressType;
038:
039: public class GeronimoQueryHandler extends WSDLQueryHandler {
040:
041: private static final Log LOG = LogFactory
042: .getLog(GeronimoQueryHandler.class);
043:
044: public GeronimoQueryHandler(Bus bus) {
045: super (bus);
046: }
047:
048: protected void updateDefinition(Definition def,
049: Map<String, Definition> done,
050: Map<String, SchemaReference> doneSchemas, String base,
051: EndpointInfo ei) {
052: if (done.get("") == def) {
053: QName serviceName = ei.getService().getName();
054: String portName = ei.getName().getLocalPart();
055: updateServices(serviceName, portName, def, base);
056: }
057: super .updateDefinition(def, done, doneSchemas, base, ei);
058: }
059:
060: private void updateServices(QName serviceName, String portName,
061: Definition def, String baseUri) {
062: boolean updated = false;
063: Map services = def.getServices();
064: if (services != null) {
065: ArrayList<QName> servicesToRemove = new ArrayList<QName>();
066:
067: Iterator serviceIterator = services.entrySet().iterator();
068: while (serviceIterator.hasNext()) {
069: Map.Entry serviceEntry = (Map.Entry) serviceIterator
070: .next();
071: QName currServiceName = (QName) serviceEntry.getKey();
072: if (currServiceName.equals(serviceName)) {
073: Service service = (Service) serviceEntry.getValue();
074: updatePorts(portName, service, baseUri);
075: updated = true;
076: } else {
077: servicesToRemove.add(currServiceName);
078: }
079: }
080:
081: for (QName serviceToRemove : servicesToRemove) {
082: def.removeService(serviceToRemove);
083: }
084: }
085: if (!updated) {
086: LOG.warn("WSDL '" + serviceName.getLocalPart()
087: + "' service not found.");
088: }
089: }
090:
091: private void updatePorts(String portName, Service service,
092: String baseUri) {
093: boolean updated = false;
094: Map ports = service.getPorts();
095: if (ports != null) {
096: ArrayList<String> portsToRemove = new ArrayList<String>();
097:
098: Iterator portIterator = ports.entrySet().iterator();
099: while (portIterator.hasNext()) {
100: Map.Entry portEntry = (Map.Entry) portIterator.next();
101: String currPortName = (String) portEntry.getKey();
102: if (currPortName.equals(portName)) {
103: Port port = (Port) portEntry.getValue();
104: updatePortLocation(port, baseUri);
105: updated = true;
106: } else {
107: portsToRemove.add(currPortName);
108: }
109: }
110:
111: for (String portToRemove : portsToRemove) {
112: service.removePort(portToRemove);
113: }
114: }
115: if (!updated) {
116: LOG.warn("WSDL '" + portName + "' port not found.");
117: }
118: }
119:
120: private void updatePortLocation(Port port, String baseUri) {
121: List<?> exts = port.getExtensibilityElements();
122: if (exts != null && exts.size() > 0) {
123: ExtensibilityElement el = (ExtensibilityElement) exts
124: .get(0);
125: if (SOAPBindingUtil.isSOAPAddress(el)) {
126: SoapAddress add = SOAPBindingUtil.getSoapAddress(el);
127: add.setLocationURI(baseUri);
128: }
129: if (el instanceof AddressType) {
130: AddressType add = (AddressType) el;
131: add.setLocation(baseUri);
132: }
133: }
134: }
135:
136: }
|