Search in sources :

Example 11 with ServiceConstructionException

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

the class ReflectionServiceFactoryBean method createEndpoints.

protected void createEndpoints() {
    Service service = getService();
    BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
    for (ServiceInfo inf : service.getServiceInfos()) {
        for (EndpointInfo ei : inf.getEndpoints()) {
            for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
                updateBindingOperation(boi);
            }
            try {
                bfm.getBindingFactory(ei.getBinding().getBindingId());
            } catch (BusException e1) {
                continue;
            }
            try {
                Endpoint ep = createEndpoint(ei);
                service.getEndpoints().put(ei.getName(), ep);
            } catch (EndpointException e) {
                throw new ServiceConstructionException(e);
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 12 with ServiceConstructionException

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

the class ReflectionServiceFactorBeanTest method testEmptyWsdlAndNoServiceClass.

@Test
public void testEmptyWsdlAndNoServiceClass() throws Exception {
    final String dummyWsdl = "target/dummy.wsdl";
    ReflectionServiceFactoryBean bean = new ReflectionServiceFactoryBean();
    Bus bus = control.createMock(Bus.class);
    WSDLManager wsdlmanager = control.createMock(WSDLManager.class);
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(wsdlmanager);
    EasyMock.expect(wsdlmanager.getDefinition(dummyWsdl)).andThrow(new WSDLException("PARSER_ERROR", "Problem parsing '" + dummyWsdl + "'."));
    EasyMock.expect(bus.getExtension(FactoryBeanListenerManager.class)).andReturn(null);
    control.replay();
    bean.setWsdlURL(dummyWsdl);
    bean.setServiceName(new QName("http://cxf.apache.org/hello_world_soap_http", "GreeterService"));
    bean.setBus(bus);
    try {
        bean.create();
        fail("no valid wsdl nor service class specified");
    } catch (ServiceConstructionException e) {
    // ignore
    }
}
Also used : Bus(org.apache.cxf.Bus) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Test(org.junit.Test)

Example 13 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException 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 | BusException | 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) IOException(java.io.IOException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 14 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException 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);
    }
    final Client client;
    final Endpoint ep;
    try {
        ep = createEndpoint();
        this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_CLIENT_CREATE, ep);
        applyProperties(ep);
        client = createClient(ep);
        initializeAnnotationInterceptors(ep, getServiceClass());
    } catch (EndpointException | 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 15 with ServiceConstructionException

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

the class SecureProxyServiceFactoryImpl method createSecureClientFactory.

private <ProxyServiceType> ProxyServiceType createSecureClientFactory(WebServiceProperties<ProxyServiceType> wsp, SecurityToken token) throws UnsupportedOperationException {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    boolean populateFromClass = unavailableWsdls.contains(wsp.endpointWsdlURL);
    if (populateFromClass) {
        LOGGER.debug("Using service class to create client rather than WSDL.");
    }
    clientFactory.getClientFactoryBean().getServiceFactory().setPopulateFromClass(populateFromClass);
    LOGGER.debug("Configuring client proxy properties");
    configureProxyFactoryProperties(clientFactory, token, wsp);
    clientFactory.getOutInterceptors().add(new TokenPassThroughInterceptor());
    ProxyServiceType proxyServiceType;
    try {
        proxyServiceType = clientFactory.create(wsp.serviceClass);
    } catch (ServiceConstructionException e) {
        LOGGER.debug("Unable to use WSDL to build client. Attempting to use service class.", e);
        unavailableWsdls.add(wsp.endpointWsdlURL);
        clientFactory.getClientFactoryBean().getServiceFactory().setPopulateFromClass(true);
        proxyServiceType = clientFactory.create(wsp.serviceClass);
    }
    return proxyServiceType;
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) 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