Search in sources :

Example 21 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class JAXWSMethodDispatcher method getImplementationMethod.

public Method getImplementationMethod(Method method) throws NoSuchMethodException {
    Class<?> endpointClass = implInfo.getImplementorClass();
    if (!endpointClass.isAssignableFrom(method.getDeclaringClass())) {
        try {
            Method m2 = endpointClass.getMethod(method.getName(), method.getParameterTypes());
            if (Modifier.isVolatile(m2.getModifiers())) {
                // bridge method, need to map the generics
                Class<?>[] params = method.getParameterTypes();
                for (Type t : method.getGenericParameterTypes()) {
                    if (t instanceof TypeVariable) {
                        TypeVariable<?> tv = (TypeVariable<?>) t;
                        for (int x = 0; x < implInfo.getSEIClass().getTypeParameters().length; x++) {
                            TypeVariable<?> t2 = implInfo.getSEIClass().getTypeParameters()[x];
                            if (t2.getName().equals(tv.getName())) {
                                params[x] = (Class<?>) implInfo.getSEIType().getActualTypeArguments()[x];
                            }
                        }
                    }
                }
                method = endpointClass.getMethod(method.getName(), params);
            } else {
                method = m2;
            }
            try {
                ReflectionUtil.setAccessible(method);
            } catch (Throwable t) {
            // ignore
            }
        } catch (SecurityException e) {
            throw new ServiceConstructionException(e);
        }
    }
    return method;
}
Also used : Type(java.lang.reflect.Type) TypeVariable(java.lang.reflect.TypeVariable) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 22 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class ServiceImpl method createDispatch.

public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
    // using this instead of JaxWsClientFactoryBean so that handlers are configured
    JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
    // Initialize Features.
    configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
    final AbstractServiceFactoryBean sf;
    try {
        DataBinding db;
        if (context != null) {
            db = new JAXBDataBinding(context);
        } else {
            db = new SourceDataBinding(type);
        }
        sf = createDispatchService(db);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
    JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
    // if the client factory has properties specified, then set those into the endpoint
    if (clientFac.getProperties() != null) {
        endpoint.putAll(clientFac.getProperties());
    }
    // add all the client factory features onto the endpoint feature list
    endpoint.getFeatures().addAll(clientFac.getFeatures());
    // if the client factory has a bus specified (other than the thread default),
    // then use that for the client.  Otherwise use the bus from this service.
    Bus clientBus = getBus();
    if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
        clientBus = clientFac.getBus();
    }
    @SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
    // CXF-3956
    hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
    endpoint.getJaxwsBinding().setHandlerChain(hc);
    // create the client object, then initialize the endpoint features against it
    Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
    for (Feature af : endpoint.getFeatures()) {
        af.initialize(client, clientBus);
    }
    // CXF-2822
    initIntercepors(client, clientFac);
    if (executor != null) {
        client.getEndpoint().setExecutor(executor);
    }
    // then try to get it from the wsdl
    if (!StringUtils.isEmpty(clientFac.getAddress())) {
        client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
    } else {
        // Set the the EPR's address in EndpointInfo
        PortInfoImpl portInfo = portInfos.get(portName);
        if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
            client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
        }
    }
    Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
    configureObject(disp);
    return disp;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 23 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class AbstractJAXRSFactoryBean method checkResources.

protected void checkResources(boolean server) {
    List<ClassResourceInfo> list = serviceFactory.getRealClassResourceInfo();
    if (server) {
        for (Iterator<ClassResourceInfo> it = list.iterator(); it.hasNext(); ) {
            ClassResourceInfo cri = it.next();
            if (!isValidClassResourceInfo(cri)) {
                it.remove();
            }
        }
    }
    if (list.isEmpty()) {
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("NO_RESOURCES_AVAILABLE", BUNDLE);
        LOG.severe(msg.toString());
        throw new ServiceConstructionException(msg);
    }
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

Example 24 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class AbstractSpringComponentScanServer method createJaxRsServer.

@Override
protected Server createJaxRsServer() {
    JAXRSServerFactoryBean factoryBean = null;
    String[] beanNames = applicationContext.getBeanNamesForAnnotation(ApplicationPath.class);
    if (beanNames.length > 0) {
        Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
        Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
        for (String beanName : beanNames) {
            if (isComponentMatched(beanName, componentScanPackagesSet, componentScanBeansSet)) {
                Application app = applicationContext.getBean(beanName, Application.class);
                factoryBean = createFactoryBeanFromApplication(app);
                for (String cxfBeanName : applicationContext.getBeanNamesForAnnotation(org.apache.cxf.annotations.Provider.class)) {
                    if (isComponentMatched(cxfBeanName, componentScanPackagesSet, componentScanBeansSet)) {
                        addCxfProvider(getProviderBean(cxfBeanName));
                    }
                }
                break;
            }
        }
    }
    if (!StringUtils.isEmpty(classesScanPackages)) {
        try {
            final Map<Class<? extends Annotation>, Collection<Class<?>>> appClasses = ClasspathScanner.findClasses(classesScanPackages, ApplicationPath.class);
            List<Application> apps = CastUtils.cast(JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, appClasses.get(ApplicationPath.class), null));
            if (!apps.isEmpty()) {
                factoryBean = createFactoryBeanFromApplication(apps.get(0));
                final Map<Class<? extends Annotation>, Collection<Class<?>>> cxfClasses = ClasspathScanner.findClasses(classesScanPackages, org.apache.cxf.annotations.Provider.class);
                addCxfProvidersFromClasses(cxfClasses.get(org.apache.cxf.annotations.Provider.class));
            }
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
    if (factoryBean != null) {
        setFactoryCxfProviders(factoryBean);
        return factoryBean.create();
    }
    return super.createJaxRsServer();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Annotation(java.lang.annotation.Annotation) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) Provider(javax.ws.rs.ext.Provider) Collection(java.util.Collection) Application(javax.ws.rs.core.Application)

Example 25 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class JaxWsServiceFactoryBean method setServiceClass.

@Override
public void setServiceClass(Class<?> serviceClass) {
    if (serviceClass == null) {
        Message message = new Message("SERVICECLASS_MUST_BE_SET", LOG);
        throw new ServiceConstructionException(message);
    }
    setJaxWsImplementorInfo(new JaxWsImplementorInfo(serviceClass));
    super.setServiceClass(getJaxWsImplementorInfo().getEndpointClass());
    super.setServiceType(getJaxWsImplementorInfo().getSEIType());
}
Also used : Message(org.apache.cxf.common.i18n.Message) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

Aggregations

ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)32 Message (org.apache.cxf.common.i18n.Message)10 Endpoint (org.apache.cxf.endpoint.Endpoint)8 Method (java.lang.reflect.Method)7 QName (javax.xml.namespace.QName)7 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 BusException (org.apache.cxf.BusException)5 Annotation (java.lang.annotation.Annotation)4 Collection (java.util.Collection)4 Bus (org.apache.cxf.Bus)4 EndpointException (org.apache.cxf.endpoint.EndpointException)4 IOException (java.io.IOException)3 Application (javax.ws.rs.core.Application)3 Provider (javax.ws.rs.ext.Provider)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 MalformedURLException (java.net.MalformedURLException)2