예제 #1
0
  protected void updateDefinition(
      Definition def,
      Map<String, Definition> done,
      Map<String, SchemaReference> doneSchemas,
      String base,
      EndpointInfo ei) {
    OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);

    Collection<List<?>> imports = CastUtils.cast((Collection<?>) def.getImports().values());
    for (List<?> lst : imports) {
      List<Import> impLst = CastUtils.cast(lst);
      for (Import imp : impLst) {

        String start = imp.getLocationURI();
        String decodedStart = null;
        // Always use the URL decoded version to ensure that we have a
        // canonical representation of the import URL for lookup.
        try {
          decodedStart = URLDecoder.decode(start, "utf-8");
        } catch (UnsupportedEncodingException e) {
          throw new WSDLQueryException(
              new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e);
        }

        String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);

        if (resolvedSchemaLocation == null) {
          try {
            // check to see if it's already in a URL format.  If so, leave it.
            new URL(start);
          } catch (MalformedURLException e) {
            if (done.put(decodedStart, imp.getDefinition()) == null) {
              updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
            }
          }
        } else {
          if (done.put(decodedStart, imp.getDefinition()) == null) {
            done.put(resolvedSchemaLocation, imp.getDefinition());
            updateDefinition(imp.getDefinition(), done, doneSchemas, base, ei);
          }
        }
      }
    }

    /* This doesn't actually work.   Setting setSchemaLocationURI on the import
     * for some reason doesn't actually result in the new URI being written
     * */
    Types types = def.getTypes();
    if (types != null) {
      for (ExtensibilityElement el :
          CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class)) {
        if (el instanceof Schema) {
          Schema see = (Schema) el;
          updateSchemaImports(see, doneSchemas, base);
        }
      }
    }
  }
예제 #2
0
 static String resolveWithCatalogs(OASISCatalogManager catalogs, String start, String base) {
   if (catalogs == null) {
     return null;
   }
   String resolvedSchemaLocation = null;
   try {
     resolvedSchemaLocation = catalogs.resolveSystem(start);
     if (resolvedSchemaLocation == null) {
       resolvedSchemaLocation = catalogs.resolveURI(start);
     }
     if (resolvedSchemaLocation == null) {
       resolvedSchemaLocation = catalogs.resolvePublic(start, base);
     }
   } catch (Exception ex) {
     // ignore
   }
   return resolvedSchemaLocation;
 }
예제 #3
0
  @Test
  public void testWSDLLocatorWithDefaultCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);

    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();

    CatalogWSDLLocator wsdlLocator =
        new CatalogWSDLLocator(wsdl.toString(), OASISCatalogManager.getCatalogManager(null));
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    wsdlReader.readWSDL(wsdlLocator);
  }
예제 #4
0
  @Test
  public void testClientWithoutCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);

    // set Catalog on the Bus
    Bus bus = BusFactory.getDefaultBus();
    OASISCatalogManager catalog = new OASISCatalogManager();
    bus.setExtension(catalog, OASISCatalogManager.class);
    // prevent cache from papering over the lack of a schema.
    WSDLManagerImpl mgr = (WSDLManagerImpl) bus.getExtension(WSDLManager.class);
    mgr.setDisableSchemaCache(true);

    try {
      SOAPService service = new SOAPService(wsdl, serviceName);
      service.getPort(portName, Greeter.class);
      fail("Test did not fail as expected");
    } catch (WebServiceException e) {
      // ignore
    }

    // update catalog dynamically now
    Enumeration<URL> jaxwscatalog =
        getClass().getClassLoader().getResources("META-INF/jax-ws-catalog.xml");
    assertNotNull(jaxwscatalog);

    while (jaxwscatalog.hasMoreElements()) {
      URL url = jaxwscatalog.nextElement();
      catalog.loadCatalog(url);
    }

    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    assertNotNull(greeter);
    bus.shutdown(true);
  }
예제 #5
0
  @Override
  public void writeResponse(
      String baseUri, String ctxUri, EndpointInfo endpointInfo, OutputStream os) {
    try {
      int idx = baseUri.toLowerCase().indexOf("?");
      Map<String, String> params = UrlUtils.parseQueryString(baseUri.substring(idx + 1));

      String base;

      if (endpointInfo.getProperty("publishedEndpointUrl") != null) {
        base = String.valueOf(endpointInfo.getProperty("publishedEndpointUrl"));
      } else {
        base = baseUri.substring(0, baseUri.toLowerCase().indexOf("?"));
      }

      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(WSDLQueryHandler.class.getName()));
      Map<String, SchemaReference> smp =
          CastUtils.cast(
              (Map)
                  endpointInfo
                      .getService()
                      .getProperty(WSDLQueryHandler.class.getName() + ".Schemas"));

      if (mp == null) {
        endpointInfo
            .getService()
            .setProperty(WSDLQueryHandler.class.getName(), new ConcurrentHashMap());
        mp =
            CastUtils.cast(
                (Map) endpointInfo.getService().getProperty(WSDLQueryHandler.class.getName()));
      }
      if (smp == null) {
        endpointInfo
            .getService()
            .setProperty(WSDLQueryHandler.class.getName() + ".Schemas", new ConcurrentHashMap());
        smp =
            CastUtils.cast(
                (Map)
                    endpointInfo
                        .getService()
                        .getProperty(WSDLQueryHandler.class.getName() + ".Schemas"));
      }

      if (!mp.containsKey("")) {
        Definition def = getDefinition(endpointInfo);

        mp.put("", def);
        updateDefinition(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("publishedEndpointUrl") != null) {
            String publishingUrl = String.valueOf(endpointInfo.getProperty("publishedEndpointUrl"));
            updatePublishedEndpointUrl(publishingUrl, def, endpointInfo.getName());
          }

          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) {
          uri = si.getReferencedSchema().getDocumentBaseURI();
        }
        ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri, bus);

        InputSource src = rml.getBaseInputSource();
        doc = XMLUtils.getParser().parse(src);
      }

      updateDoc(doc, base, mp, smp, endpointInfo);
      String enc = null;
      try {
        enc = doc.getXmlEncoding();
      } catch (Exception ex) {
        // ignore - not dom level 3
      }
      if (enc == null) {
        enc = "utf-8";
      }

      XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, enc);
      StaxUtils.writeNode(doc, writer, true);
      writer.flush();
    } catch (WSDLQueryException wex) {
      throw wex;
    } catch (Exception wex) {
      throw new WSDLQueryException(
          new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, baseUri), wex);
    }
  }
예제 #6
0
  protected void updateSchemaImports(
      Schema schema, Map<String, SchemaReference> doneSchemas, String base) {
    OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);
    Collection<List<?>> imports = CastUtils.cast((Collection<?>) schema.getImports().values());
    for (List<?> lst : imports) {
      List<SchemaImport> impLst = CastUtils.cast(lst);
      for (SchemaImport imp : impLst) {
        String start = imp.getSchemaLocationURI();

        if (start != null) {
          String decodedStart = null;
          // Always use the URL decoded version to ensure that we have a
          // canonical representation of the import URL for lookup.
          try {
            decodedStart = URLDecoder.decode(start, "utf-8");
          } catch (UnsupportedEncodingException e) {
            throw new WSDLQueryException(
                new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e);
          }

          if (!doneSchemas.containsKey(decodedStart)) {
            String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
            if (resolvedSchemaLocation == null) {
              try {
                checkSchemaUrl(doneSchemas, start, decodedStart, imp);
              } catch (MalformedURLException e) {
                if (doneSchemas.put(decodedStart, imp) == null) {
                  updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
                }
              }
            } else {
              if (doneSchemas.put(decodedStart, imp) == null) {
                doneSchemas.put(resolvedSchemaLocation, imp);
                updateSchemaImports(imp.getReferencedSchema(), doneSchemas, base);
              }
            }
          }
        }
      }
    }

    List<SchemaReference> includes = CastUtils.cast(schema.getIncludes());
    for (SchemaReference included : includes) {
      String start = included.getSchemaLocationURI();

      if (start != null) {
        String decodedStart = null;
        // Always use the URL decoded version to ensure that we have a
        // canonical representation of the import URL for lookup.
        try {
          decodedStart = URLDecoder.decode(start, "utf-8");
        } catch (UnsupportedEncodingException e) {
          /*throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL",
          LOG,
          start), e); */
        }

        String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
        if (resolvedSchemaLocation == null) {
          if (!doneSchemas.containsKey(decodedStart)) {
            try {
              checkSchemaUrl(doneSchemas, start, decodedStart, included);
            } catch (MalformedURLException e) {
              if (doneSchemas.put(decodedStart, included) == null) {
                updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
              }
            }
          }
        } else if (!doneSchemas.containsKey(decodedStart)
            || !doneSchemas.containsKey(resolvedSchemaLocation)) {
          doneSchemas.put(decodedStart, included);
          doneSchemas.put(resolvedSchemaLocation, included);
          updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
        }
      }
    }
    List<SchemaReference> redefines = CastUtils.cast(schema.getRedefines());
    for (SchemaReference included : redefines) {
      String start = included.getSchemaLocationURI();

      if (start != null) {
        String decodedStart = null;
        // Always use the URL decoded version to ensure that we have a
        // canonical representation of the import URL for lookup.
        try {
          decodedStart = URLDecoder.decode(start, "utf-8");
        } catch (UnsupportedEncodingException e) {
          throw new WSDLQueryException(
              new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e);
        }

        String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
        if (resolvedSchemaLocation == null) {
          if (!doneSchemas.containsKey(decodedStart)) {
            try {
              checkSchemaUrl(doneSchemas, start, decodedStart, included);
            } catch (MalformedURLException e) {
              if (doneSchemas.put(decodedStart, included) == null) {
                updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
              }
            }
          }
        } else if (!doneSchemas.containsKey(decodedStart)
            || !doneSchemas.containsKey(resolvedSchemaLocation)) {
          doneSchemas.put(decodedStart, included);
          doneSchemas.put(resolvedSchemaLocation, included);
          updateSchemaImports(included.getReferencedSchema(), doneSchemas, base);
        }
      }
    }
  }