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