Search in sources :

Example 11 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class ServiceImpl method createEndpointInfo.

private EndpointInfo createEndpointInfo(AbstractServiceFactoryBean serviceFactory, QName portName, PortInfoImpl portInfo) throws BusException {
    EndpointInfo ei = null;
    String address = portInfo.getAddress();
    String bindingID = BindingID.getBindingID(portInfo.getBindingID());
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        // the bindingId might be the transportId, just attempt to
        // load it to force the factory to load
        dfm.getDestinationFactory(bindingID);
    } catch (BusException ex) {
    // ignore
    }
    DestinationFactory df = dfm.getDestinationFactoryForUri(address);
    String transportId = null;
    if (df != null && df.getTransportIds() != null && !df.getTransportIds().isEmpty()) {
        transportId = df.getTransportIds().get(0);
    } else {
        transportId = bindingID;
    }
    Object config = null;
    if (serviceFactory instanceof JaxWsServiceFactoryBean) {
        config = new JaxWsSoapBindingConfiguration((JaxWsServiceFactoryBean) serviceFactory);
    }
    BindingInfo bindingInfo = bus.getExtension(BindingFactoryManager.class).getBindingFactory(bindingID).createBindingInfo(serviceFactory.getService(), bindingID, config);
    Service service = serviceFactory.getService();
    service.getServiceInfos().get(0).addBinding(bindingInfo);
    ei = new EndpointInfo(service.getServiceInfos().get(0), transportId);
    ei.setName(portName);
    ei.setAddress(address);
    ei.setBinding(bindingInfo);
    service.getServiceInfos().get(0).addEndpoint(ei);
    return ei;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) DestinationFactory(org.apache.cxf.transport.DestinationFactory) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) JaxWsSoapBindingConfiguration(org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingConfiguration) BusException(org.apache.cxf.BusException)

Example 12 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class AbstractWSDLBasedEndpointFactory method createBindingInfo.

protected BindingInfo createBindingInfo() {
    BindingFactoryManager mgr = bus.getExtension(BindingFactoryManager.class);
    String binding = bindingId;
    if (binding == null && bindingConfig != null) {
        binding = bindingConfig.getBindingId();
    }
    if (binding == null) {
        // default to soap binding
        binding = "http://schemas.xmlsoap.org/soap/";
    }
    try {
        if (binding.contains("/soap")) {
            if (bindingConfig == null) {
                bindingConfig = createSoapBindingConfig();
            }
            if (bindingConfig instanceof SoapBindingConfiguration && !((SoapBindingConfiguration) bindingConfig).isSetStyle()) {
                ((SoapBindingConfiguration) bindingConfig).setStyle(serviceFactory.getStyle());
            }
        }
        bindingFactory = mgr.getBindingFactory(binding);
        BindingInfo inf = bindingFactory.createBindingInfo(serviceFactory.getService(), binding, bindingConfig);
        for (BindingOperationInfo boi : inf.getOperations()) {
            serviceFactory.updateBindingOperation(boi);
            Method m = serviceFactory.getMethodDispatcher().getMethod(boi);
            serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_OPERATION_CREATED, inf, boi, m);
        }
        serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_CREATED, inf);
        return inf;
    } catch (BusException ex) {
        throw new ServiceConstructionException(new Message("COULD.NOT.RESOLVE.BINDING", LOG, bindingId), ex);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 13 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class ClientFactoryBean method create.

public Client create() {
    getServiceFactory().reset();
    if (getServiceFactory().getProperties() == null) {
        getServiceFactory().setProperties(properties);
    } else if (properties != null) {
        getServiceFactory().getProperties().putAll(properties);
    }
    Client client = null;
    Endpoint ep = null;
    try {
        ep = createEndpoint();
        this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_CLIENT_CREATE, ep);
        applyProperties(ep);
        client = createClient(ep);
        initializeAnnotationInterceptors(ep, getServiceClass());
    } catch (EndpointException e) {
        throw new ServiceConstructionException(e);
    } catch (BusException e) {
        throw new ServiceConstructionException(e);
    }
    applyFeatures(client);
    this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED, client, ep);
    return client;
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointException(org.apache.cxf.endpoint.EndpointException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Client(org.apache.cxf.endpoint.Client) BusException(org.apache.cxf.BusException)

Example 14 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class ServerFactoryBean method create.

public Server create() {
    ClassLoaderHolder orig = null;
    try {
        Server server = null;
        try {
            if (bus != null) {
                ClassLoader loader = bus.getExtension(ClassLoader.class);
                if (loader != null) {
                    orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                }
            }
            if (getServiceFactory().getProperties() == null) {
                getServiceFactory().setProperties(getProperties());
            } else if (getProperties() != null) {
                getServiceFactory().getProperties().putAll(getProperties());
            }
            if (serviceBean != null && getServiceClass() == null) {
                setServiceClass(ClassHelper.getRealClass(bus, serviceBean));
            }
            if (invoker != null) {
                getServiceFactory().setInvoker(invoker);
            } else if (serviceBean != null) {
                invoker = createInvoker();
                getServiceFactory().setInvoker(invoker);
            }
            Endpoint ep = createEndpoint();
            getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getBus(), getServiceBean()) : getServiceClass());
            server = new ServerImpl(getBus(), ep, getDestinationFactory(), getBindingFactory());
            if (ep.getService().getInvoker() == null) {
                if (invoker == null) {
                    ep.getService().setInvoker(createInvoker());
                } else {
                    ep.getService().setInvoker(invoker);
                }
            }
        } catch (EndpointException e) {
            throw new ServiceConstructionException(e);
        } catch (BusException e) {
            throw new ServiceConstructionException(e);
        } catch (IOException e) {
            throw new ServiceConstructionException(e);
        }
        if (serviceBean != null) {
            Class<?> cls = ClassHelper.getRealClass(getServiceBean());
            if (getServiceClass() == null || cls.equals(getServiceClass())) {
                initializeAnnotationInterceptors(server.getEndpoint(), cls);
            } else {
                initializeAnnotationInterceptors(server.getEndpoint(), cls, getServiceClass());
            }
        } else if (getServiceClass() != null) {
            initializeAnnotationInterceptors(server.getEndpoint(), getServiceClass());
        }
        applyFeatures(server);
        getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getServiceBean()) : getServiceClass());
        if (start) {
            try {
                server.start();
            } catch (RuntimeException re) {
                // prevent resource leak
                server.destroy();
                throw re;
            }
        }
        getServiceFactory().reset();
        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}
Also used : Server(org.apache.cxf.endpoint.Server) Endpoint(org.apache.cxf.endpoint.Endpoint) ServerImpl(org.apache.cxf.endpoint.ServerImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) IOException(java.io.IOException) BusException(org.apache.cxf.BusException)

Example 15 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class WSDLServiceBuilder method buildEndpoint.

public EndpointInfo buildEndpoint(ServiceInfo service, BindingInfo bi, Port port) {
    List<?> elements = port.getExtensibilityElements();
    String ns = null;
    DestinationFactory factory = null;
    EndpointInfo ei = null;
    if (null != elements && !elements.isEmpty()) {
        for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
            ns = el.getElementType().getNamespaceURI();
            try {
                factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
            } catch (BusException e) {
            // do nothing
            }
            if (factory != null) {
                break;
            }
        }
        if (factory == null) {
            ns = ((ExtensibilityElement) elements.get(0)).getElementType().getNamespaceURI();
        }
    }
    if (factory == null) {
        // get the transport id from bindingInfo
        elements = port.getBinding().getExtensibilityElements();
        if (null != elements && !elements.isEmpty()) {
            for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
                if (el instanceof SOAPBinding) {
                    ns = ((SOAPBinding) el).getTransportURI();
                    break;
                } else if (el instanceof SOAP12Binding) {
                    ns = ((SOAP12Binding) el).getTransportURI();
                    break;
                // TODO: this is really ugly, but how to link between
                // this binding and this transport ?
                }
            }
        }
        if (ns == null) {
            if (ignoreUnknownBindings) {
                return null;
            }
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("MISSING_DESTINATION_FACTORY", LOG, port.getName());
            throw new WSDLRuntimeException(msg);
        }
        try {
            factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
        } catch (BusException e) {
        // do nothing
        }
    }
    if (factory instanceof WSDLEndpointFactory) {
        WSDLEndpointFactory wFactory = (WSDLEndpointFactory) factory;
        ei = wFactory.createEndpointInfo(bus, service, bi, port.getExtensibilityElements());
    }
    if (ei == null) {
        ei = new EndpointInfo(service, ns);
    }
    copyDocumentation(ei, port);
    ei.setName(new QName(service.getName().getNamespaceURI(), port.getName()));
    ei.setBinding(bi);
    copyExtensors(ei, port.getExtensibilityElements());
    copyExtensionAttributes(ei, port);
    service.addEndpoint(ei);
    DescriptionInfo d = service.getDescription();
    if (null != d) {
        d.getDescribed().add(ei);
    }
    return ei;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) BusException(org.apache.cxf.BusException)

Aggregations

BusException (org.apache.cxf.BusException)28 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)6 EndpointException (org.apache.cxf.endpoint.EndpointException)6 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)6 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)5 BindingInfo (org.apache.cxf.service.model.BindingInfo)5 Bus (org.apache.cxf.Bus)4 Message (org.apache.cxf.common.i18n.Message)4 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)4 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)4 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)4 DestinationFactory (org.apache.cxf.transport.DestinationFactory)4 WebServiceContext (javax.xml.ws.WebServiceContext)3 BindingFactory (org.apache.cxf.binding.BindingFactory)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)3 Endpoint (org.apache.cxf.endpoint.Endpoint)3 GreeterImpl (org.apache.hello_world_soap_http.GreeterImpl)3