コード例 #1
0
  /*
   * If source and target namespace are also passed in,
   * then if the mex resolver is found and it cannot get
   * the data, wsimport attempts to add ?wsdl to the
   * address and retrieve the data with a normal http get.
   * This behavior should only happen when trying a
   * mex request first.
   */
  private @Nullable Element getFromMetadataResolver(String systemId, Exception ex) {
    // try MEX
    MetaDataResolver resolver;
    ServiceDescriptor serviceDescriptor = null;
    for (MetadataResolverFactory resolverFactory :
        ServiceFinder.find(MetadataResolverFactory.class)) {
      resolver = resolverFactory.metadataResolver(options.entityResolver);
      try {
        serviceDescriptor = resolver.resolve(new URI(systemId));
        // we got the ServiceDescriptor, now break
        if (serviceDescriptor != null) break;
      } catch (URISyntaxException e) {
        throw new ParseException(e);
      }
    }

    if (serviceDescriptor != null) {
      errorReceiver.warning(
          new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
      return parseMetadata(systemId, serviceDescriptor);
    } else {
      errorReceiver.error(
          null,
          WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(
              ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)),
          ex);
    }
    return null;
  }
コード例 #2
0
  /**
   * Locates {@link TransportTubeFactory}s and create a suitable transport {@link Tube}.
   *
   * @param classLoader used to locate {@code META-INF/servces} files.
   * @return Always non-null, since we fall back to our default {@link Tube}.
   */
  public static Tube create(
      @Nullable ClassLoader classLoader, @NotNull ClientTubeAssemblerContext context) {
    for (TransportTubeFactory factory :
        ServiceFinder.find(TransportTubeFactory.class, classLoader)) {
      Tube tube = factory.doCreate(context);
      if (tube != null) {
        TransportTubeFactory.logger.fine(factory.getClass() + " successfully created " + tube);
        return tube;
      }
    }

    // See if there is a {@link TransportPipeFactory} out there and use it for compatibility.
    ClientPipeAssemblerContext ctxt =
        new ClientPipeAssemblerContext(
            context.getAddress(),
            context.getWsdlModel(),
            context.getService(),
            context.getBinding(),
            context.getContainer());
    for (TransportPipeFactory factory :
        ServiceFinder.find(TransportPipeFactory.class, classLoader)) {
      Pipe pipe = factory.doCreate(ctxt);
      if (pipe != null) {
        logger.fine(factory.getClass() + " successfully created " + pipe);
        return PipeAdapter.adapt(pipe);
      }
    }

    // default built-in transports
    String scheme = context.getAddress().getURI().getScheme();
    if (scheme != null) {
      if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))
        return new HttpTransportPipe(context.getCodec(), context.getBinding());
    }

    throw new WebServiceException(
        "Unsupported endpoint address: " + context.getAddress()); // TODO: i18n
  }
コード例 #3
0
  public W3CEndpointReference createW3CEndpointReference(
      String address,
      QName serviceName,
      QName portName,
      List<Element> metadata,
      String wsdlDocumentLocation,
      List<Element> referenceParameters) {
    Container container = ContainerResolver.getInstance().getContainer();
    if (address == null) {
      if (serviceName == null || portName == null) {
        throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS_SERVICE_ENDPOINT());
      } else {
        // check if it is run in a Java EE Container and if so, get address using serviceName and
        // portName
        Module module = container.getSPI(Module.class);
        if (module != null) {
          List<BoundEndpoint> beList = module.getBoundEndpoints();
          for (BoundEndpoint be : beList) {
            WSEndpoint wse = be.getEndpoint();
            if (wse.getServiceName().equals(serviceName) && wse.getPortName().equals(portName)) {
              try {
                address = be.getAddress().toString();
              } catch (WebServiceException e) {
                // May be the container does n't support this
                // just ignore the exception
              }
              break;
            }
          }
        }
        // address is still null? may be its not run in a JavaEE Container
        if (address == null) throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS());
      }
    }
    if ((serviceName == null) && (portName != null)) {
      throw new IllegalStateException(ProviderApiMessages.NULL_SERVICE());
    }
    // Validate Service and Port in WSDL
    if (wsdlDocumentLocation != null) {
      try {
        EntityResolver er = XmlUtil.createDefaultCatalogResolver();

        URL wsdlLoc = new URL(wsdlDocumentLocation);
        WSDLModelImpl wsdlDoc =
            RuntimeWSDLParser.parse(
                wsdlLoc,
                new StreamSource(wsdlLoc.toExternalForm()),
                er,
                false,
                container,
                ServiceFinder.find(WSDLParserExtension.class).toArray());
        if (serviceName != null) {
          WSDLService wsdlService = wsdlDoc.getService(serviceName);
          if (wsdlService == null)
            throw new IllegalStateException(
                ProviderApiMessages.NOTFOUND_SERVICE_IN_WSDL(serviceName, wsdlDocumentLocation));
          if (portName != null) {
            WSDLPort wsdlPort = wsdlService.get(portName);
            if (wsdlPort == null)
              throw new IllegalStateException(
                  ProviderApiMessages.NOTFOUND_PORT_IN_WSDL(
                      portName, serviceName, wsdlDocumentLocation));
          }
        }
      } catch (Exception e) {
        throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e);
      }
    }
    // Supress writing ServiceName and EndpointName in W3C EPR,
    // Until the ns for those metadata elements is resolved.
    return new WSEndpointReference(
            AddressingVersion.fromSpecClass(W3CEndpointReference.class),
            address,
            null /*serviceName*/,
            null /*portName*/,
            null,
            metadata,
            null /*wsdlDocumentLocation*/,
            referenceParameters)
        .toSpec(W3CEndpointReference.class);
  }