Search in sources :

Example 41 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JMSEndpointWSDLUtil method getWSDLExtensor.

public static <T> T getWSDLExtensor(EndpointInfo ei, Class<T> cls) {
    ServiceInfo si = ei.getService();
    BindingInfo bi = ei.getBinding();
    Object o = ei.getExtensor(cls);
    if (o == null && si != null) {
        o = si.getExtensor(cls);
    }
    if (o == null && bi != null) {
        o = bi.getExtensor(cls);
    }
    if (o == null) {
        return null;
    }
    if (cls.isInstance(o)) {
        return cls.cast(o);
    }
    return null;
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo)

Example 42 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class RMEndpoint method createEndpoint.

void createEndpoint(org.apache.cxf.transport.Destination d, ProtocolVariation protocol) {
    final QName bindingQName = new QName(protocol.getWSRMNamespace(), BINDING_NAME);
    WrappedService service = services.get(protocol);
    ServiceInfo si = service.getServiceInfo();
    buildBindingInfo(si, protocol);
    EndpointInfo aei = applicationEndpoint.getEndpointInfo();
    String transportId = aei.getTransportId();
    EndpointInfo ei = new EndpointInfo(si, transportId);
    if (d != null) {
        ei.setProperty(MAPAggregator.DECOUPLED_DESTINATION, d);
    }
    ei.setAddress(aei.getAddress());
    ei.setName(RMUtils.getConstants(protocol.getWSRMNamespace()).getPortName());
    ei.setBinding(si.getBinding(bindingQName));
    // if addressing was enabled on the application endpoint by means
    // of the UsingAddressing element extensor, use this for the
    // RM endpoint also
    Object ua = getUsingAddressing(aei);
    if (null != ua) {
        ei.addExtensor(ua);
    }
    si.addEndpoint(ei);
    ei.setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
    Endpoint endpoint = new WrappedEndpoint(applicationEndpoint, ei, service);
    if (applicationEndpoint.getEndpointInfo() != null && applicationEndpoint.getEndpointInfo().getProperties() != null) {
        for (String key : applicationEndpoint.getEndpointInfo().getProperties().keySet()) {
            endpoint.getEndpointInfo().setProperty(key, applicationEndpoint.getEndpointInfo().getProperty(key));
        }
    }
    service.setEndpoint(endpoint);
    endpoints.put(protocol, endpoint);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) QName(javax.xml.namespace.QName)

Example 43 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JAXBDataBinding method addSchemas.

private void addSchemas(Options opts, SchemaCompiler schemaCompiler, SchemaCollection schemaCollection) {
    Set<String> ids = new HashSet<>();
    @SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    for (ServiceInfo si : serviceList) {
        for (SchemaInfo sci : si.getSchemas()) {
            String key = sci.getSystemId();
            if (ids.contains(key)) {
                continue;
            }
            ids.add(key);
        }
    }
    Bus bus = context.get(Bus.class);
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        if (ids.contains(key)) {
            continue;
        }
        if (!key.startsWith("file:") && !key.startsWith("jar:")) {
            XmlSchemaSerializer xser = new XmlSchemaSerializer();
            xser.setExtReg(schemaCollection.getExtReg());
            Document[] docs;
            try {
                docs = xser.serializeSchema(schema, false);
            } catch (XmlSchemaSerializerException e) {
                throw new RuntimeException(e);
            }
            Element ele = docs[0].getDocumentElement();
            if (context.fullValidateWSDL()) {
                String uri = null;
                try {
                    uri = docs[0].getDocumentURI();
                } catch (Throwable ex) {
                // ignore - DOM level 3
                }
                validateSchema(ele, uri, catalog, schemaCollection);
            }
            ele = removeImportElement(ele, key, catalog);
            try {
                docs[0].setDocumentURI(key);
            } catch (Throwable t) {
            // ignore - DOM level 3
            }
            InputSource is = new InputSource((InputStream) null);
            // key = key.replaceFirst("#types[0-9]+$", "");
            is.setSystemId(key);
            is.setPublicId(key);
            opts.addGrammar(is);
            try {
                schemaCompiler.parseSchema(key, createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)));
            } catch (XMLStreamException e) {
                throw new ToolException(e);
            }
        }
    }
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        String tns = schema.getTargetNamespace();
        String ltns = schema.getLogicalTargetNamespace();
        // accepting also a null tns (e.g., reported by apache.ws.xmlschema for no-namespace)
        if (ids.contains(key) || (tns == null && !StringUtils.isEmpty(ltns))) {
            continue;
        }
        if (key.startsWith("file:") || key.startsWith("jar:")) {
            InputStream in = null;
            try {
                // NOPMD
                if (key.startsWith("file:")) {
                    in = Files.newInputStream(new File(new URI(key)).toPath());
                } else {
                    in = new URL(key).openStream();
                }
                XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
                reader = createNoCDATAReader(new LocationFilterReader(reader, catalog));
                InputSource is = new InputSource(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, reader);
                reader.close();
            } catch (RuntimeException ex) {
                throw ex;
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    }
    addSchemasForServiceInfos(catalog, serviceList, opts, schemaCompiler, schemaCollection);
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URI(java.net.URI) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ToolException(org.apache.cxf.tools.common.ToolException) HashSet(java.util.HashSet) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) Bus(org.apache.cxf.Bus) InputStream(java.io.InputStream) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) SAXException(org.xml.sax.SAXException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) BadCommandLineException(com.sun.tools.xjc.BadCommandLineException) SAXParseException(org.xml.sax.SAXParseException) XMLStreamException(javax.xml.stream.XMLStreamException) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) File(java.io.File)

Example 44 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JAXBDataBinding method addSchemasForServiceInfos.

private void addSchemasForServiceInfos(OASISCatalogManager catalog, List<ServiceInfo> serviceList, Options opts, SchemaCompiler schemaCompiler, SchemaCollection schemaCollection) {
    Set<String> ids = new HashSet<>();
    for (ServiceInfo si : serviceList) {
        for (SchemaInfo sci : si.getSchemas()) {
            String key = sci.getSystemId();
            if (ids.contains(key)) {
                continue;
            }
            ids.add(key);
            Element ele = sci.getElement();
            if (context.fullValidateWSDL()) {
                validateSchema(ele, sci.getSystemId(), catalog, schemaCollection);
            }
            ele = removeImportElement(ele, key, catalog);
            InputSource is = new InputSource((InputStream) null);
            // key = key.replaceFirst("#types[0-9]+$", "");
            is.setSystemId(key);
            is.setPublicId(key);
            opts.addGrammar(is);
            try {
                XMLStreamReader reader = createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key));
                schemaCompiler.parseSchema(key, reader);
            } catch (XMLStreamException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) Element(org.w3c.dom.Element) HashSet(java.util.HashSet) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 45 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JavaScriptContainer method execute.

@SuppressWarnings("unchecked")
public void execute() throws ToolException {
    if (hasInfoOption()) {
        return;
    }
    buildToolContext();
    validate(context);
    WSDLConstants.WSDLVersion version = getWSDLVersion();
    String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
    List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
    if (serviceList == null) {
        serviceList = new ArrayList<>();
        PluginLoader pluginLoader = PluginLoader.newInstance();
        // for JavaScript generation, we always use JAX-WS.
        FrontEndProfile frontend = pluginLoader.getFrontEndProfile("jaxws");
        // Build the ServiceModel from the WSDLModel
        if (version == WSDLConstants.WSDLVersion.WSDL11) {
            AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
            builder.setContext(context);
            builder.setBus(getBus());
            context.put(Bus.class, getBus());
            builder.build(URIParserUtil.getAbsoluteURI(wsdlURL));
            builder.customize();
            Definition definition = builder.getWSDLModel();
            context.put(Definition.class, definition);
            builder.validate(definition);
            WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
            String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
            if (serviceName != null) {
                List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
                serviceList.addAll(services);
            } else if (definition.getServices().size() > 0) {
                serviceList = serviceBuilder.buildServices(definition);
            } else {
                serviceList = serviceBuilder.buildMockServices(definition);
            }
        } else {
            // TODO: wsdl2.0 support
            throw new ToolException("Only WSDL 1.1 supported");
        }
    }
    if (serviceList.isEmpty()) {
        throw new ToolException("Did not find any services in WSDL");
    }
    Map<String, InterfaceInfo> interfaces = new LinkedHashMap<>();
    ServiceInfo service0 = serviceList.get(0);
    SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
    context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
    context.put(ToolConstants.PORTTYPE_MAP, interfaces);
    context.put(ClassCollector.class, new ClassCollector());
    WSDLToJavaScriptProcessor processor = new WSDLToJavaScriptProcessor();
    for (ServiceInfo service : serviceList) {
        context.put(ServiceInfo.class, service);
        validate(service);
        processor.setEnvironment(context);
        processor.process();
    }
}
Also used : AbstractWSDLBuilder(org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder) ClassCollector(org.apache.cxf.tools.util.ClassCollector) Definition(javax.wsdl.Definition) FrontEndProfile(org.apache.cxf.tools.wsdlto.core.FrontEndProfile) LinkedHashMap(java.util.LinkedHashMap) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLConstants(org.apache.cxf.wsdl.WSDLConstants) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ToolException(org.apache.cxf.tools.common.ToolException) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) PluginLoader(org.apache.cxf.tools.wsdlto.core.PluginLoader)

Aggregations

ServiceInfo (org.apache.cxf.service.model.ServiceInfo)195 QName (javax.xml.namespace.QName)89 Test (org.junit.Test)76 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)47 BindingInfo (org.apache.cxf.service.model.BindingInfo)43 OperationInfo (org.apache.cxf.service.model.OperationInfo)37 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)36 Service (org.apache.cxf.service.Service)33 Endpoint (org.apache.cxf.endpoint.Endpoint)31 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)29 File (java.io.File)28 ArrayList (java.util.ArrayList)27 Bus (org.apache.cxf.Bus)26 InputStream (java.io.InputStream)23 Definition (javax.wsdl.Definition)20 Method (java.lang.reflect.Method)16 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)15 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)15 IOException (java.io.IOException)12