001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.support.soap;
014:
015: import java.text.Collator;
016: import java.util.Collections;
017: import java.util.Comparator;
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import javax.wsdl.Binding;
022: import javax.wsdl.BindingOperation;
023: import javax.wsdl.extensions.soap12.SOAP12Binding;
024:
025: import org.apache.log4j.Logger;
026:
027: import com.eviware.soapui.impl.wsdl.WsdlInterface;
028: import com.eviware.soapui.impl.wsdl.WsdlOperation;
029: import com.eviware.soapui.impl.wsdl.WsdlProject;
030: import com.eviware.soapui.impl.wsdl.support.BindingImporter;
031: import com.eviware.soapui.impl.wsdl.support.Constants;
032: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
033: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
034: import com.eviware.soapui.settings.WsdlSettings;
035:
036: /**
037: * BindingImporter that can import a WsdlInterface from an SOAP 1.2/HTTP binding
038: *
039: * @author Ole.Matzura
040: */
041:
042: public class Soap12HttpBindingImporter implements BindingImporter {
043: private final static Logger log = Logger
044: .getLogger(Soap12HttpBindingImporter.class);
045:
046: public boolean canImport(Binding binding) {
047: List list = binding.getExtensibilityElements();
048: SOAP12Binding soapBinding = WsdlUtils.getExtensiblityElement(
049: list, SOAP12Binding.class);
050: return soapBinding == null ? false : soapBinding
051: .getTransportURI().startsWith(
052: Constants.SOAP_HTTP_BINDING_NS);
053: }
054:
055: public WsdlInterface importBinding(WsdlProject project,
056: WsdlContext wsdlContext, Binding binding) throws Exception {
057: String name = project.getSettings().getBoolean(
058: WsdlSettings.NAME_WITH_BINDING) ? binding.getQName()
059: .getLocalPart() : binding.getPortType().getQName()
060: .getLocalPart();
061:
062: WsdlInterface iface = project.addNewInterface(name);
063: iface.setBindingName(binding.getQName());
064: iface.setSoapVersion(SoapVersion.Soap12);
065:
066: String[] endpoints = WsdlUtils.getEndpointsForBinding(
067: wsdlContext.getDefinition(), binding);
068: for (int i = 0; i < endpoints.length; i++) {
069: log.info("importing endpoint " + endpoints[i]);
070: iface.addEndpoint(endpoints[i]);
071: }
072:
073: List<BindingOperation> list = binding.getBindingOperations();
074: Collections.sort(list, new BindingOperationComparator());
075:
076: for (Iterator iter = list.iterator(); iter.hasNext();) {
077: BindingOperation operation = (BindingOperation) iter.next();
078:
079: // sanity check
080: if (operation.getOperation() == null
081: || operation.getOperation().isUndefined()) {
082: log
083: .error("BindingOperation ["
084: + operation.getName()
085: + "] is missing or referring to an invalid operation");
086: } else {
087: log.info("importing operation " + operation.getName());
088: WsdlOperation op = iface.addNewOperation(operation);
089: }
090: }
091:
092: return iface;
093: }
094:
095: private static final class BindingOperationComparator implements
096: Comparator<BindingOperation> {
097: public int compare(BindingOperation o1, BindingOperation o2) {
098: return Collator.getInstance().compare(
099: o1.getOperation().getName(),
100: o2.getOperation().getName());
101: }
102: }
103: }
|