Search in sources :

Example 31 with ServiceInfo

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

the class RPCInInterceptor method setMessage.

private void setMessage(Message message, BindingOperationInfo operation) {
    Exchange ex = message.getExchange();
    ex.put(BindingOperationInfo.class, operation);
    ex.setOneWay(operation.getOperationInfo().isOneWay());
    // Set standard MessageContext properties required by JAX_WS, but not specific to JAX_WS.
    message.put(Message.WSDL_OPERATION, operation.getName());
    ServiceInfo si = operation.getBinding().getService();
    QName serviceQName = si.getName();
    message.put(Message.WSDL_SERVICE, serviceQName);
    QName interfaceQName = si.getInterface().getName();
    message.put(Message.WSDL_INTERFACE, interfaceQName);
    EndpointInfo endpointInfo = ex.getEndpoint().getEndpointInfo();
    QName portQName = endpointInfo.getName();
    message.put(Message.WSDL_PORT, portQName);
    URI wsdlDescription = endpointInfo.getProperty("URI", URI.class);
    if (wsdlDescription == null) {
        String address = endpointInfo.getAddress();
        try {
            wsdlDescription = new URI(address + "?wsdl");
        } catch (URISyntaxException e) {
        // do nothing
        }
        endpointInfo.setProperty("URI", wsdlDescription);
    }
    message.put(Message.WSDL_DESCRIPTION, wsdlDescription);
    // configure endpoint and operation level schema validation
    setOperationSchemaValidation(message);
}
Also used : Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) QName(javax.xml.namespace.QName) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 32 with ServiceInfo

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

the class DispatchImpl method addInvokeOperation.

private void addInvokeOperation(QName operationName, boolean oneWay) {
    ServiceInfo info = client.getEndpoint().getEndpointInfo().getService();
    OperationInfo invokeOpInfo = info.getInterface().getOperation(oneWay ? INVOKE_ONEWAY_QNAME : INVOKE_QNAME);
    OperationInfo opInfo = info.getInterface().addOperation(operationName);
    opInfo.setInput(invokeOpInfo.getInputName(), invokeOpInfo.getInput());
    if (!oneWay) {
        opInfo.setOutput(invokeOpInfo.getOutputName(), invokeOpInfo.getOutput());
    }
    for (BindingInfo bind : client.getEndpoint().getEndpointInfo().getService().getBindings()) {
        BindingOperationInfo bo = new BindingOperationInfo(bind, opInfo);
        bind.addOperation(bo);
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo)

Example 33 with ServiceInfo

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

the class ServiceImpl method initializePorts.

private void initializePorts() {
    try {
        Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL);
        javax.wsdl.Service serv = def.getService(serviceName);
        if (serv == null) {
            throw new WebServiceException("Could not find service named " + serviceName + " in wsdl " + wsdlURL);
        }
        Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts());
        for (Port port : wsdlports.values()) {
            QName name = new QName(serviceName.getNamespaceURI(), port.getName());
            String address = null;
            String bindingID = null;
            List<? extends ExtensibilityElement> extensions = CastUtils.cast(port.getBinding().getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                } else if (e instanceof SOAP12Binding) {
                    bindingID = SOAPBinding.SOAP12HTTP_BINDING;
                } else if (e instanceof javax.wsdl.extensions.soap.SOAPBinding) {
                    bindingID = SOAPBinding.SOAP11HTTP_BINDING;
                }
            }
            extensions = CastUtils.cast(port.getExtensibilityElements());
            if (!extensions.isEmpty()) {
                ExtensibilityElement e = extensions.get(0);
                if (e instanceof SoapAddress) {
                    address = ((SoapAddress) e).getLocationURI();
                } else if (e instanceof AddressType) {
                    address = ((AddressType) e).getLocation();
                } else if (e instanceof SOAP12Address) {
                    address = ((SOAP12Address) e).getLocationURI();
                } else if (e instanceof SOAPAddress) {
                    address = ((SOAPAddress) e).getLocationURI();
                } else if (e instanceof HTTPAddress) {
                    address = ((HTTPAddress) e).getLocationURI();
                }
            }
            addPort(name, bindingID, address);
        }
    } catch (WebServiceException e) {
        throw e;
    } catch (Throwable e) {
        if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, e.getLocalizedMessage(), e);
        }
        WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
        Service service = sf.create();
        for (ServiceInfo si : service.getServiceInfos()) {
            for (EndpointInfo ei : si.getEndpoints()) {
                String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId());
                addPort(ei.getName(), bindingID, ei.getAddress());
            }
        }
    }
}
Also used : HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) Port(javax.wsdl.Port) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) SoapAddress(org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLManager(org.apache.cxf.wsdl.WSDLManager) AddressType(org.apache.cxf.wsdl.http.AddressType)

Example 34 with ServiceInfo

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

the class ServiceImpl method createDispatchService.

private AbstractServiceFactoryBean createDispatchService(DataBinding db) {
    AbstractServiceFactoryBean serviceFactory;
    final Service dispatchService;
    if (null != wsdlURL) {
        WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
        dispatchService = sf.create();
        dispatchService.setDataBinding(db);
        serviceFactory = sf;
    } else {
        ReflectionServiceFactoryBean sf = new JaxWsServiceFactoryBean();
        sf.setBus(bus);
        sf.setServiceName(serviceName);
        // maybe we can find another way to create service which have no SEI
        sf.setServiceClass(DummyImpl.class);
        sf.setDataBinding(db);
        dispatchService = sf.create();
        serviceFactory = sf;
    }
    configureObject(dispatchService);
    for (ServiceInfo si : dispatchService.getServiceInfos()) {
        si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
        if (null == wsdlURL) {
            for (EndpointInfo ei : si.getEndpoints()) {
                ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
            }
        }
        for (BindingInfo bind : si.getBindings()) {
            for (BindingOperationInfo bop : bind.getOperations()) {
                // force to bare, no unwrapping
                if (bop.isUnwrappedCapable()) {
                    bop.getOperationInfo().setUnwrappedOperation(null);
                    bop.setUnwrappedOperation(null);
                }
            }
        }
    }
    return serviceFactory;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)

Example 35 with ServiceInfo

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

the class JAXBDataBinding method initialize.

@SuppressWarnings("unchecked")
public synchronized void initialize(Service service) {
    inInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
    inFaultInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
    // context is already set, don't redo it
    if (context != null) {
        return;
    }
    contextClasses = new LinkedHashSet<>();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        JAXBContextInitializer initializer = new JAXBContextInitializer(getBus(), serviceInfo, contextClasses, typeRefs, this.getUnmarshallerProperties());
        initializer.walk();
        if (serviceInfo.getProperty("extra.class") != null) {
            Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class", Set.class);
            contextClasses.addAll(exClasses);
        }
    }
    String tns = getNamespaceToUse(service);
    final CachedContextAndSchemas cachedContextAndSchemas;
    try {
        cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
    } catch (JAXBException e1) {
        throw new ServiceConstructionException(e1);
    }
    final JAXBContext ctx = cachedContextAndSchemas.getContext();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "CREATED_JAXB_CONTEXT", new Object[] { ctx, contextClasses });
    }
    setContext(ctx);
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection col = serviceInfo.getXmlSchemaCollection();
        if (col.getXmlSchemas().length > 1) {
            // someone has already filled in the types
            justCheckForJAXBAnnotations(serviceInfo);
            continue;
        }
        boolean schemasFromCache = false;
        Collection<DOMSource> schemas = getSchemas();
        if (schemas == null || schemas.isEmpty()) {
            schemas = cachedContextAndSchemas.getSchemas();
            if (schemas != null) {
                schemasFromCache = true;
            }
        } else {
            schemasFromCache = true;
        }
        Set<DOMSource> bi = new LinkedHashSet<>();
        if (schemas == null) {
            schemas = new LinkedHashSet<>();
            try {
                for (DOMResult r : generateJaxbSchemas()) {
                    DOMSource src = new DOMSource(r.getNode(), r.getSystemId());
                    if (isInBuiltInSchemas(r)) {
                        bi.add(src);
                    } else {
                        schemas.add(src);
                    }
                }
                // put any builtins at the end.   Anything that DOES import them
                // will cause it to load automatically and we'll skip them later
                schemas.addAll(bi);
            } catch (IOException e) {
                throw new ServiceConstructionException("SCHEMA_GEN_EXC", LOG, e);
            }
        }
        for (DOMSource r : schemas) {
            if (bi.contains(r)) {
                String ns = ((Document) r.getNode()).getDocumentElement().getAttribute("targetNamespace");
                if (serviceInfo.getSchema(ns) != null) {
                    continue;
                }
            }
            // StaxUtils.print(r.getNode());
            // System.out.println();
            addSchemaDocument(serviceInfo, col, (Document) r.getNode(), r.getSystemId());
        }
        JAXBSchemaInitializer schemaInit = new JAXBSchemaInitializer(serviceInfo, col, context, this.qualifiedSchemas, tns);
        schemaInit.walk();
        if (cachedContextAndSchemas != null && !schemasFromCache) {
            cachedContextAndSchemas.setSchemas(schemas);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) IOException(java.io.IOException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas)

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