gt:                     uri = si.getReferencedSchema().getDocumentBaseURI();
context: /**
   * 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.frontend;
  
  import java.io.UnsupportedEncodingException;
  import java.net.MalformedURLException;
  import java.net.URI;
  import java.net.URL;
  import java.net.URLDecoder;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.concurrent.ConcurrentHashMap;
  import java.util.logging.Logger;
  
  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.xml.WSDLWriter;
  import javax.xml.namespace.QName;
  import javax.xml.transform.dom.DOMSource;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  import org.xml.sax.InputSource;
  
  import org.apache.cxf.Bus;
  import org.apache.cxf.catalog.OASISCatalogManager;
  import org.apache.cxf.catalog.OASISCatalogManagerHelper;
  import org.apache.cxf.common.logging.LogUtils;
  import org.apache.cxf.helpers.CastUtils;
  import org.apache.cxf.helpers.DOMUtils;
  import org.apache.cxf.message.Message;
  import org.apache.cxf.message.MessageUtils;
  import org.apache.cxf.service.model.EndpointInfo;
  import org.apache.cxf.service.model.SchemaInfo;
  import org.apache.cxf.staxutils.StaxUtils;
  import org.apache.cxf.wsdl.WSDLManager;
  import org.apache.cxf.wsdl11.ResourceManagerWSDLLocator;
  import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
  
  /**
   * 
   */
  public class WSDLGetUtils {
      
      public static final String AUTO_REWRITE_ADDRESS = "autoRewriteSoapAddress";
      public static final String AUTO_REWRITE_ADDRESS_ALL = "autoRewriteSoapAddressForAllServices";
      public static final String PUBLISHED_ENDPOINT_URL = "publishedEndpointUrl";
      public static final String WSDL_CREATE_IMPORTS = "org.apache.cxf.wsdl.create.imports";
      
      private static final String WSDLS_KEY = WSDLGetUtils.class.getName() + ".WSDLs";
      private static final String SCHEMAS_KEY = WSDLGetUtils.class.getName() + ".Schemas";
      
      private static final Logger LOG = LogUtils.getL7dLogger(WSDLGetInterceptor.class);
      
      public WSDLGetUtils() {
          //never constructed
      }
  
  
      public Set<String> getWSDLIds(Message message,
                              String base,
                              String ctxUri,
                              EndpointInfo endpointInfo) {
          Map<String, String> params = new HashMap<String, String>();
          params.put("wsdl", "");
          new WSDLGetUtils().getDocument(message, base, 
                                         params, ctxUri, 
                                         endpointInfo);
          
          Map<String, Definition> mp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                                      .getProperty(WSDLS_KEY));
          return mp.keySet();
      }
      private String buildUrl(String base, String ctxUri, String s) {
          return base + ctxUri + "?" + s;
      }
      public Map<String, String> getSchemaLocations(Message message,
                                                    String base,
                                                    String ctxUri,
                                                    EndpointInfo endpointInfo) {
          Map<String, String> params = new HashMap<String, String>();
          params.put("wsdl", "");
          new WSDLGetUtils().getDocument(message, base, 
                                         params, ctxUri, 
                                         endpointInfo);
        
          Map<String, SchemaReference> mp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                                           .getProperty(SCHEMAS_KEY));
          
          Map<String, String> schemas = new HashMap<String, String>();
          for (Map.Entry<String, SchemaReference> ent : mp.entrySet()) {
              params.clear();
              params.put("xsd", ent.getKey());
              Document doc = getDocument(message, base, params, ctxUri, endpointInfo);
              schemas.put(doc.getDocumentElement().getAttribute("targetNamespace"), 
                          buildUrl(base, ctxUri, "xsd=" + ent.getKey()));
          }
          return schemas;
      }
  
      public Document getDocument(Message message,
                              String base,
                              Map<String, String> params,
                              String ctxUri,
                              EndpointInfo endpointInfo) {
          try {
              Bus bus = message.getExchange().getBus();
              Object prop = message.getContextualProperty(PUBLISHED_ENDPOINT_URL);
              if (prop == null) {
                  prop = endpointInfo.getProperty(PUBLISHED_ENDPOINT_URL);
              }
              if (prop != null) {
                  base = String.valueOf(prop);
              }
  
              String wsdl = params.get("wsdl");
              if (wsdl != null) {
                  // Always use the URL decoded version to ensure that we have a
                  // canonical representation of the import URL for lookup.
                  wsdl = URLDecoder.decode(wsdl, "utf-8");
              }
              
              String xsd =  params.get("xsd");
              if (xsd != null) {
                  // Always use the URL decoded version to ensure that we have a
                  // canonical representation of the import URL for lookup.
                  xsd = URLDecoder.decode(xsd, "utf-8");
              }
              
              Map<String, Definition> mp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                                          .getProperty(WSDLS_KEY));
              Map<String, SchemaReference> smp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                                          .getProperty(SCHEMAS_KEY));
  
              if (mp == null) {
                  endpointInfo.getService().setProperty(WSDLS_KEY,
                                                        new ConcurrentHashMap<String, Definition>(8, 0.75f, 4));
                  mp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                      .getProperty(WSDLS_KEY));
              }
              if (smp == null) {
                  endpointInfo.getService().setProperty(SCHEMAS_KEY,
                                                        new ConcurrentHashMap<String, SchemaReference>(8, 0.75f, 4));
                  smp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                      .getProperty(SCHEMAS_KEY));
              }
              
              if (!mp.containsKey("")) {
                  ServiceWSDLBuilder builder = 
                      new ServiceWSDLBuilder(bus, endpointInfo.getService());
  
                  builder.setUseSchemaImports(
                       MessageUtils.getContextualBoolean(message, WSDL_CREATE_IMPORTS, false));
                  
                  // base file name is ignored if createSchemaImports == false!
                  builder.setBaseFileName(endpointInfo.getService().getName().getLocalPart());
                  
                  Definition def = builder.build(new HashMap<String, SchemaInfo>());
  
                  mp.put("", def);
                  updateDefinition(bus, def, mp, smp, base, endpointInfo);
              }
              
              
              Document doc;
              if (xsd == null) {
                  Definition def = mp.get(wsdl);
                  if (def == null) {
                      String wsdl2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                         wsdl,
                                                         base);
                      if (wsdl2 != null) {
                          def = mp.get(wsdl2);
                      }
                  }
                  if (def == null) {
                      throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("WSDL_NOT_FOUND",
                                                                                          LOG, wsdl), null);
                  }
                  
                  synchronized (def) {
                      //writing a def is not threadsafe.  Sync on it to make sure
                      //we don't get any ConcurrentModificationExceptions
                      if (endpointInfo.getProperty(PUBLISHED_ENDPOINT_URL) != null) {
                          String epurl = 
                              String.valueOf(endpointInfo.getProperty(PUBLISHED_ENDPOINT_URL));
                          updatePublishedEndpointUrl(epurl, def, endpointInfo.getName());
                          base = epurl;
                      }
          
                      WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
                          .getWSDLFactory().newWSDLWriter();
                      def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
                      doc = wsdlWriter.getDocument(def);
                  }
              } else {
                  SchemaReference si = smp.get(xsd);
                  if (si == null) {
                      String xsd2 = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                                         xsd,
                                                         base);
                      if (xsd2 != null) { 
                          si = smp.get(xsd2);
                      }
                  }
                  if (si == null) {
                      throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("SCHEMA_NOT_FOUND", 
                                                                                          LOG, wsdl), null);
                  }
                  
                  String uri = si.getReferencedSchema().getDocumentBaseURI();
                  uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus),
                                            uri,
                                            si.getReferencedSchema().getDocumentBaseURI());
                  if (uri == null) {
  