Search in sources :

Example 1 with WSDLGenInfo

use of com.sun.xml.ws.api.databinding.WSDLGenInfo in project metro-jax-ws by eclipse-ee4j.

the class WsDatabindingTestBase method createProxy.

public static <T> T createProxy(Class<T> proxySEI, DatabindingConfig srvConfig, DatabindingConfig cliConfig, boolean debug) throws Exception {
    Class<?> endpointClass = srvConfig.getEndpointClass();
    // TODO default BindingID
    if (srvConfig.getMappingInfo().getBindingID() == null)
        srvConfig.getMappingInfo().setBindingID(BindingID.parse(endpointClass));
    Databinding srvDb = (Databinding) factory.createRuntime(srvConfig);
    InVmWSDLResolver result = new InVmWSDLResolver();
    WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
    wsdlGenInfo.setWsdlResolver(result);
    // wsdlGenInfo.setContainer(container);
    wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
    wsdlGenInfo.setInlineSchemas(true);
    srvDb.generateWSDL(wsdlGenInfo);
    if (debug)
        result.print();
    WSDLModel wsdl = RuntimeWSDLParser.parse(result.getWsdlSource(), result.getEntityResolver(), false, null, new WSDLParserExtension[0]);
    QName serviceName = wsdl.getFirstServiceName();
    WSDLPort wsdlPort = wsdl.getService(serviceName).getFirstPort();
    if (cliConfig.getWsdlPort() == null)
        cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(serviceName);
    Databinding cliDb = (Databinding) factory.createRuntime(cliConfig);
    Class<?>[] intf = { proxySEI };
    WsDatabindingTestFacade h = new WsDatabindingTestFacade(cliDb, srvDb, endpointClass);
    h.wireLog = debug;
    Object proxy = Proxy.newProxyInstance(proxySEI.getClassLoader(), intf, h);
    return proxySEI.cast(proxy);
}
Also used : QName(javax.xml.namespace.QName) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo) Databinding(com.sun.xml.ws.api.databinding.Databinding) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 2 with WSDLGenInfo

use of com.sun.xml.ws.api.databinding.WSDLGenInfo in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method generateWSDL.

/**
 * Generates the WSDL and XML Schema for the endpoint if necessary
 * It generates WSDL only for SOAP1.1, and for XSOAP1.2 bindings
 */
private static SDDocumentImpl generateWSDL(WSBinding binding, AbstractSEIModelImpl seiModel, Collection<SDDocumentImpl> docs, Container container, Class implType) {
    BindingID bindingId = binding.getBindingId();
    if (!bindingId.canGenerateWSDL()) {
        throw new ServerRtException("can.not.generate.wsdl", bindingId);
    }
    if (bindingId.toString().equals(SOAPBindingImpl.X_SOAP12HTTP_BINDING)) {
        String msg = ServerMessages.GENERATE_NON_STANDARD_WSDL();
        logger.warning(msg);
    }
    // Generate WSDL and schema documents using runtime model
    WSDLGenResolver wsdlResolver = new WSDLGenResolver(docs, seiModel.getServiceQName(), seiModel.getPortTypeName());
    WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
    wsdlGenInfo.setWsdlResolver(wsdlResolver);
    wsdlGenInfo.setContainer(container);
    wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
    wsdlGenInfo.setInlineSchemas(false);
    wsdlGenInfo.setSecureXmlProcessingDisabled(isSecureXmlProcessingDisabled(binding.getFeatures()));
    seiModel.getDatabinding().generateWSDL(wsdlGenInfo);
    // wsdlGen.doGeneration();
    return wsdlResolver.updateDocs();
}
Also used : BindingID(com.sun.xml.ws.api.BindingID) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo)

Example 3 with WSDLGenInfo

use of com.sun.xml.ws.api.databinding.WSDLGenInfo in project metro-jax-ws by eclipse-ee4j.

the class SDODatabindingTestBase method createProxy.

public static <T> T createProxy(Class<T> proxySEI, DatabindingConfig srvConfig, DatabindingConfig cliConfig, boolean debug) throws Exception {
    Class<?> endpointClass = srvConfig.getEndpointClass();
    // TODO default BindingID
    if (srvConfig.getMappingInfo().getBindingID() == null)
        srvConfig.getMappingInfo().setBindingID(BindingID.parse(endpointClass));
    Databinding srvDb = (Databinding) factory.createRuntime(srvConfig);
    InVmWSDLResolver result = new InVmWSDLResolver();
    WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
    wsdlGenInfo.setWsdlResolver(result);
    // wsdlGenInfo.setContainer(container);
    wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
    wsdlGenInfo.setInlineSchemas(true);
    srvDb.generateWSDL(wsdlGenInfo);
    if (debug)
        result.print();
    WSDLModel wsdl = RuntimeWSDLParser.parse(result.getWsdlSource(), result.getEntityResolver(), false, null, new WSDLParserExtension[0]);
    QName serviceName = wsdl.getFirstServiceName();
    WSDLPort wsdlPort = wsdl.getService(serviceName).getFirstPort();
    // ((AbstractSEIModelImpl)((DatabindingImpl)srvDb).getModel()).freeze((WSDLPortImpl)wsdlPort);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(serviceName);
    Databinding cliDb = (Databinding) factory.createRuntime(cliConfig);
    Class<?>[] intf = { proxySEI };
    WsDatabindingTestFacade h = new WsDatabindingTestFacade(cliDb, srvDb, endpointClass);
    h.wireLog = debug;
    Object proxy = Proxy.newProxyInstance(proxySEI.getClassLoader(), intf, h);
    return proxySEI.cast(proxy);
}
Also used : QName(javax.xml.namespace.QName) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo) Databinding(com.sun.xml.ws.api.databinding.Databinding) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 4 with WSDLGenInfo

use of com.sun.xml.ws.api.databinding.WSDLGenInfo 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

WSDLGenInfo (com.sun.xml.ws.api.databinding.WSDLGenInfo)4 BindingID (com.sun.xml.ws.api.BindingID)2 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)2 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)2 QName (javax.xml.namespace.QName)2 WSDLResolver (com.oracle.webservices.api.databinding.WSDLResolver)1 WebServiceAp (com.sun.tools.ws.processor.modeler.annotation.WebServiceAp)1 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)1 DatabindingFactory (com.sun.xml.ws.api.databinding.DatabindingFactory)1 WSDLGeneratorExtension (com.sun.xml.ws.api.wsdl.writer.WSDLGeneratorExtension)1 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)1 AbstractSEIModelImpl (com.sun.xml.ws.model.AbstractSEIModelImpl)1 ExternalMetadataReader (com.sun.xml.ws.model.ExternalMetadataReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1