Search in sources :

Example 1 with AbstractSEIModelImpl

use of com.sun.xml.ws.model.AbstractSEIModelImpl in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method createSEIModel.

private static AbstractSEIModelImpl createSEIModel(WSDLPort wsdlPort, Class<?> implType, @NotNull QName serviceName, @NotNull QName portName, WSBinding binding, SDDocumentSource primaryWsdl) {
    DatabindingFactory fac = DatabindingFactory.newInstance();
    DatabindingConfig config = new DatabindingConfig();
    config.setEndpointClass(implType);
    config.getMappingInfo().setServiceName(serviceName);
    config.setWsdlPort(wsdlPort);
    config.setWSBinding(binding);
    config.setClassLoader(implType.getClassLoader());
    config.getMappingInfo().setPortName(portName);
    if (primaryWsdl != null)
        config.setWsdlURL(primaryWsdl.getSystemId());
    config.setMetadataReader(getExternalMetadatReader(implType, binding));
    com.sun.xml.ws.db.DatabindingImpl rt = (com.sun.xml.ws.db.DatabindingImpl) fac.createRuntime(config);
    return (AbstractSEIModelImpl) rt.getModel();
}
Also used : DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) DatabindingFactory(com.sun.xml.ws.api.databinding.DatabindingFactory) AbstractSEIModelImpl(com.sun.xml.ws.model.AbstractSEIModelImpl)

Example 2 with AbstractSEIModelImpl

use of com.sun.xml.ws.model.AbstractSEIModelImpl in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method create.

public <T> WSEndpoint<T> create(Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker, @Nullable QName serviceName, @Nullable QName portName, @Nullable Container container, @Nullable WSBinding binding, @Nullable SDDocumentSource primaryWsdl, @Nullable Collection<? extends SDDocumentSource> metadata, EntityResolver resolver, boolean isTransportSynchronous, boolean isStandard) {
    if (implType == null)
        throw new IllegalArgumentException();
    MetadataReader metadataReader = getExternalMetadatReader(implType, binding);
    if (isStandard) {
        verifyImplementorClass(implType, metadataReader);
    }
    if (invoker == null) {
        invoker = InstanceResolver.createDefault(implType).createInvoker();
    }
    // Performance analysis indicates that reading and parsing imported schemas is
    // a major component of Endpoint creation time.  Therefore, modify SDDocumentSource
    // handling to delay iterating collection as long as possible.
    Collection<SDDocumentSource> md = new CollectionCollection<>();
    if (primaryWsdl != null) {
        if (metadata != null) {
            Iterator<? extends SDDocumentSource> it = metadata.iterator();
            if (it.hasNext() && primaryWsdl.equals(it.next()))
                md.addAll(metadata);
            else {
                md.add(primaryWsdl);
                md.addAll(metadata);
            }
        } else
            md.add(primaryWsdl);
    } else if (metadata != null)
        md.addAll(metadata);
    if (container == null)
        container = ContainerResolver.getInstance().getContainer();
    if (serviceName == null)
        serviceName = getDefaultServiceName(implType, metadataReader);
    if (portName == null)
        portName = getDefaultPortName(serviceName, implType, metadataReader);
    {
        // error check
        String serviceNS = serviceName.getNamespaceURI();
        String portNS = portName.getNamespaceURI();
        if (!serviceNS.equals(portNS)) {
            throw new ServerRtException("wrong.tns.for.port", portNS, serviceNS);
        }
    }
    // setting a default binding
    if (binding == null)
        binding = BindingImpl.create(BindingID.parse(implType));
    if (isStandard && primaryWsdl != null) {
        verifyPrimaryWSDL(primaryWsdl, serviceName);
    }
    QName portTypeName = null;
    if (isStandard && implType.getAnnotation(WebServiceProvider.class) == null) {
        portTypeName = RuntimeModeler.getPortTypeName(implType, metadataReader);
    }
    // Categorises the documents as WSDL, Schema etc
    Collection<SDDocumentImpl> docList = categoriseMetadata(md.iterator(), serviceName, portTypeName);
    // Finds the primary WSDL and makes sure that metadata doesn't have
    // two concrete or abstract WSDLs
    SDDocumentImpl primaryDoc = primaryWsdl != null ? SDDocumentImpl.create(primaryWsdl, serviceName, portTypeName) : findPrimary(docList);
    EndpointAwareTube terminal;
    WSDLPort wsdlPort = null;
    AbstractSEIModelImpl seiModel = null;
    // create WSDL model
    if (primaryDoc != null) {
        wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
    }
    WebServiceFeatureList features = ((BindingImpl) binding).getFeatures();
    if (isStandard) {
        features.parseAnnotations(implType);
    }
    PolicyMap policyMap = null;
    // create terminal pipe that invokes the application
    if (isUseProviderTube(implType, isStandard)) {
        // TODO incase of Provider, provide a way to User for complete control of the message processing by giving
        // ability to turn off the WSDL/Policy based features and its associated tubes.
        // Even in case of Provider, merge all features configured via WSDL/Policy or deployment configuration
        Iterable<WebServiceFeature> configFtrs;
        if (wsdlPort != null) {
            policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
            // Merge features from WSDL and other policy configuration
            configFtrs = wsdlPort.getFeatures();
        } else {
            // No WSDL, so try to merge features from Policy configuration
            policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(null, container, implType, false));
            configFtrs = PolicyUtil.getPortScopedFeatures(policyMap, serviceName, portName);
        }
        features.mergeFeatures(configFtrs, true);
        terminal = createProviderInvokerTube(implType, binding, invoker, container);
    } else {
        // Create runtime model for non Provider endpoints
        seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding, primaryDoc);
        if (binding instanceof SOAPBindingImpl) {
            // set portKnownHeaders on Binding, so that they can be used for MU processing
            ((SOAPBindingImpl) binding).setPortKnownHeaders(((SOAPSEIModel) seiModel).getKnownHeaders());
        }
        // Generate WSDL for SEI endpoints(not for Provider endpoints)
        if (primaryDoc == null) {
            primaryDoc = generateWSDL(binding, seiModel, docList, container, implType);
            // create WSDL model
            wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
            seiModel.freeze(wsdlPort);
        }
        policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
        // New Features might have been added in WSDL through Policy.
        // Merge features from WSDL and other policy configuration
        // This sets only the wsdl features that are not already set(enabled/disabled)
        features.mergeFeatures(wsdlPort.getFeatures(), true);
        terminal = createSEIInvokerTube(seiModel, invoker, binding);
    }
    // Process @HandlerChain, if handler-chain is not set via Deployment Descriptor
    if (processHandlerAnnotation) {
        processHandlerAnnotation(binding, implType, serviceName, portName);
    }
    // Selects only required metadata for this endpoint from the passed-in metadata
    if (primaryDoc != null) {
        docList = findMetadataClosure(primaryDoc, docList, resolver);
    }
    ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null;
    return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton, terminal, isTransportSynchronous, policyMap);
}
Also used : BindingImpl(com.sun.xml.ws.binding.BindingImpl) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl) AbstractSEIModelImpl(com.sun.xml.ws.model.AbstractSEIModelImpl) QName(javax.xml.namespace.QName) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) WebServiceFeatureList(com.sun.xml.ws.binding.WebServiceFeatureList) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) PolicyMap(com.sun.xml.ws.policy.PolicyMap) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl)

Example 3 with AbstractSEIModelImpl

use of com.sun.xml.ws.model.AbstractSEIModelImpl in project metro-jax-ws by eclipse-ee4j.

the class WsgenTool method buildModel.

/**
 */
public boolean buildModel(String endpoint, Listener listener) throws BadCommandLineException {
    final ErrorReceiverFilter errReceiver = new ErrorReceiverFilter(listener);
    if (!options.nosource) {
        List<String> args = new ArrayList<>(6 + (options.nocompile ? 1 : 0) + (options.encoding != null ? 2 : 0));
        args.add("-d");
        args.add(options.destDir.getAbsolutePath());
        args.add("-classpath");
        args.add(options.classpath);
        args.add("-s");
        args.add(options.sourceDir.getAbsolutePath());
        if (options.nocompile) {
            args.add("-proc:only");
        }
        if (options.encoding != null) {
            args.add("-encoding");
            args.add(options.encoding);
        }
        if (options.javacOptions != null) {
            args.addAll(options.getJavacOptions(args, listener));
        }
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null) {
            out.println(WscompileMessages.WSCOMPILE_CANT_GET_COMPILER(property("java.home"), property("java.version"), property("java.vendor")));
            return false;
        }
        DiagnosticListener<JavaFileObject> diagnostics = new DiagnosticListener<>() {

            @Override
            public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
                boolean fromFile = diagnostic.getSource() != null;
                StringBuilder message = new StringBuilder();
                if (fromFile) {
                    message.append(diagnostic.getSource().getName());
                }
                message.append(diagnostic.getMessage(Locale.getDefault()));
                if (fromFile) {
                    message.append("");
                }
                switch(diagnostic.getKind()) {
                    case ERROR:
                        Locator2Impl l = new Locator2Impl();
                        if (fromFile) {
                            l.setSystemId(diagnostic.getSource().getName());
                        } else {
                            l.setSystemId(null);
                        }
                        l.setLineNumber((int) diagnostic.getLineNumber());
                        l.setColumnNumber((int) diagnostic.getColumnNumber());
                        SAXParseException ex = new SAXParseException(message.toString(), l);
                        listener.error(ex);
                        break;
                    case MANDATORY_WARNING:
                    case WARNING:
                        listener.message(message.toString());
                        break;
                    default:
                        if (options.verbose) {
                            listener.message(message.toString());
                        }
                }
            }
        };
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, args, Collections.singleton(endpoint.replaceAll("\\$", ".")), null);
        task.setProcessors(Collections.singleton(new WebServiceAp(options, out)));
        boolean result = task.call();
        if (!result) {
            out.println(WscompileMessages.WSCOMPILE_ERROR(WscompileMessages.WSCOMPILE_COMPILATION_FAILED()));
            return false;
        }
    }
    if (options.genWsdl) {
        DatabindingConfig config = new DatabindingConfig();
        List<String> externalMetadataFileNames = options.externalMetadataFiles;
        boolean disableXmlSecurity = options.disableXmlSecurity;
        if (externalMetadataFileNames != null && externalMetadataFileNames.size() > 0) {
            config.setMetadataReader(new ExternalMetadataReader(getExternalFiles(externalMetadataFileNames), null, null, true, disableXmlSecurity));
        }
        String tmpPath = options.destDir.getAbsolutePath() + File.pathSeparator + options.classpath;
        ClassLoader classLoader = new URLClassLoader(Options.pathToURLs(tmpPath), this.getClass().getClassLoader());
        Class<?> endpointClass;
        try {
            endpointClass = classLoader.loadClass(endpoint);
        } catch (ClassNotFoundException e) {
            throw new BadCommandLineException(WscompileMessages.WSGEN_CLASS_NOT_FOUND(endpoint));
        }
        BindingID bindingID = options.getBindingID(options.protocol);
        if (!options.protocolSet) {
            bindingID = BindingID.parse(endpointClass);
        }
        WebServiceFeatureList wsfeatures = new WebServiceFeatureList(endpointClass);
        // rtModeler.setClassLoader(classLoader);
        if (options.portName != null)
            // rtModeler.setPortName(options.portName);
            config.getMappingInfo().setPortName(options.portName);
        // AbstractSEIModelImpl rtModel = rtModeler.buildRuntimeModel();
        DatabindingFactory fac = DatabindingFactory.newInstance();
        config.setEndpointClass(endpointClass);
        config.getMappingInfo().setServiceName(options.serviceName);
        config.setFeatures(wsfeatures.toArray());
        config.setClassLoader(classLoader);
        config.getMappingInfo().setBindingID(bindingID);
        com.sun.xml.ws.db.DatabindingImpl rt = (com.sun.xml.ws.db.DatabindingImpl) fac.createRuntime(config);
        // used to capture the generated WSDL file.
        final File[] wsdlFileName = new File[1];
        final Map<String, File> schemaFiles = new HashMap<>();
        WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
        wsdlGenInfo.setSecureXmlProcessingDisabled(disableXmlSecurity);
        wsdlGenInfo.setWsdlResolver(new WSDLResolver() {

            private File toFile(String suggestedFilename) {
                return new File(options.nonclassDestDir, suggestedFilename);
            }

            private Result toResult(File file) {
                Result result;
                try {
                    result = new StreamResult(new FileOutputStream(file));
                    result.setSystemId(file.getPath().replace('\\', '/'));
                } catch (FileNotFoundException e) {
                    errReceiver.error(e);
                    return null;
                }
                return result;
            }

            @Override
            public Result getWSDL(String suggestedFilename) {
                File f = toFile(suggestedFilename);
                wsdlFileName[0] = f;
                return toResult(f);
            }

            public Result getSchemaOutput(String namespace, String suggestedFilename) {
                if (namespace == null)
                    return null;
                File f = toFile(suggestedFilename);
                schemaFiles.put(namespace, f);
                return toResult(f);
            }

            @Override
            public Result getAbstractWSDL(Holder<String> filename) {
                return toResult(toFile(filename.value));
            }

            @Override
            public Result getSchemaOutput(String namespace, Holder<String> filename) {
                return getSchemaOutput(namespace, filename.value);
            }
        });
        wsdlGenInfo.setContainer(container);
        wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class, ServiceLoader.load(WSDLGeneratorExtension.class)).toArray());
        wsdlGenInfo.setInlineSchemas(options.inlineSchemas);
        rt.generateWSDL(wsdlGenInfo);
        if (options.wsgenReport != null)
            generateWsgenReport(endpointClass, (AbstractSEIModelImpl) rt.getModel(), wsdlFileName[0], schemaFiles);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Diagnostic(javax.tools.Diagnostic) BindingID(com.sun.xml.ws.api.BindingID) WebServiceFeatureList(com.sun.xml.ws.binding.WebServiceFeatureList) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) WSDLResolver(com.oracle.webservices.api.databinding.WSDLResolver) JavaFileObject(javax.tools.JavaFileObject) SAXParseException(org.xml.sax.SAXParseException) StandardJavaFileManager(javax.tools.StandardJavaFileManager) URLClassLoader(java.net.URLClassLoader) DatabindingFactory(com.sun.xml.ws.api.databinding.DatabindingFactory) StreamResult(javax.xml.transform.stream.StreamResult) AbstractSEIModelImpl(com.sun.xml.ws.model.AbstractSEIModelImpl) WebServiceAp(com.sun.tools.ws.processor.modeler.annotation.WebServiceAp) JavaCompiler(javax.tools.JavaCompiler) DiagnosticListener(javax.tools.DiagnosticListener) ExternalMetadataReader(com.sun.xml.ws.model.ExternalMetadataReader) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) URLClassLoader(java.net.URLClassLoader) FileOutputStream(java.io.FileOutputStream) WSDLGeneratorExtension(com.sun.xml.ws.api.wsdl.writer.WSDLGeneratorExtension) File(java.io.File) Locator2Impl(org.xml.sax.ext.Locator2Impl)

Aggregations

AbstractSEIModelImpl (com.sun.xml.ws.model.AbstractSEIModelImpl)3 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)2 DatabindingFactory (com.sun.xml.ws.api.databinding.DatabindingFactory)2 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)2 WSDLResolver (com.oracle.webservices.api.databinding.WSDLResolver)1 WebServiceAp (com.sun.tools.ws.processor.modeler.annotation.WebServiceAp)1 BindingID (com.sun.xml.ws.api.BindingID)1 MetadataReader (com.sun.xml.ws.api.databinding.MetadataReader)1 WSDLGenInfo (com.sun.xml.ws.api.databinding.WSDLGenInfo)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)1 WSDLGeneratorExtension (com.sun.xml.ws.api.wsdl.writer.WSDLGeneratorExtension)1 BindingImpl (com.sun.xml.ws.binding.BindingImpl)1 SOAPBindingImpl (com.sun.xml.ws.binding.SOAPBindingImpl)1 ExternalMetadataReader (com.sun.xml.ws.model.ExternalMetadataReader)1 PolicyMap (com.sun.xml.ws.policy.PolicyMap)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1