org.apache.cxf.service.factory.ServiceConstructionException Java Examples

The following examples show how to use org.apache.cxf.service.factory.ServiceConstructionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectionServiceFactorBeanTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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
    }
}
 
Example #2
Source File: JaxRsProxyClientConfiguration.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setJaxrsResources(JAXRSClientFactoryBean factory) {
    Class<?> serviceClass = getServiceClass();
    if (serviceClass != null) {
        factory.setServiceClass(serviceClass);
    } else if (!StringUtils.isEmpty(scanPackages)) {
        try {
            final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
                ClasspathScanner.findClasses(scanPackages, Path.class, Provider.class);
            factory.setServiceClass(
                JAXRSClientFactoryBeanDefinitionParser.getServiceClass(classes.get(Path.class)));
            factory.setProviders(
                JAXRSClientFactoryBeanDefinitionParser.getProviders(context, classes.get(Provider.class)));
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
}
 
Example #3
Source File: JaxRsWebClientConfiguration.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
protected void setJaxrsResources(JAXRSClientFactoryBean factory) {
    factory.setServiceClass(WebClient.class);

    if (!StringUtils.isEmpty(scanPackages)) {
        try {
            final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
                ClasspathScanner.findClasses(scanPackages, Provider.class);

            factory.setProviders(
                JAXRSClientFactoryBeanDefinitionParser.getProviders(context, classes.get(Provider.class)));
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
}
 
Example #4
Source File: AbstractJaxrsClassesScanServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
    try {
        final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
            ClasspathScanner.findClasses(basePackages, Provider.class, Path.class);

        List<Object> jaxrsServices = JAXRSServerFactoryBeanDefinitionParser
            .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Path.class), null);
        List<Object> jaxrsProviders = JAXRSServerFactoryBeanDefinitionParser
            .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Provider.class), null);

        factory.setServiceBeans(jaxrsServices);
        factory.setProviders(jaxrsProviders);
    } catch (Exception ex) {
        throw new ServiceConstructionException(ex);
    }

}
 
Example #5
Source File: AbstractJAXRSFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #6
Source File: SingletonResourceProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void init(Endpoint ep) {
    if (resourceInstance instanceof Constructor) {
        Constructor<?> c = (Constructor<?>)resourceInstance;
        Message m = new MessageImpl();
        ExchangeImpl exchange = new ExchangeImpl();
        exchange.put(Endpoint.class, ep);
        m.setExchange(exchange);
        Object[] values = 
            ResourceUtils.createConstructorArguments(c, m, false, Collections.emptyMap());
        try {
            resourceInstance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{});
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
    if (callPostConstruct) {
        InjectionUtils.invokeLifeCycleMethod(resourceInstance,
            ResourceUtils.findPostConstructMethod(ClassHelper.getRealClass(resourceInstance)));
    }    
}
 
Example #7
Source File: ClientFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
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 | BusException e) {
        throw new ServiceConstructionException(e);
    }
    applyFeatures(client);
    this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED, client, ep);
    return client;
}
 
Example #8
Source File: JAXWSMethodDispatcher.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void bind(OperationInfo o, Method... methods) {
    Method [] newMethods = new Method[methods.length];
    int i = 0;
    for (Method m : methods) {
        try {
            newMethods[i] = getImplementationMethod(m);
            i++;
        } catch (NoSuchMethodException e) {
            if (m.getName().endsWith("Async")
                && (Future.class.equals(m.getReturnType())
                    || Response.class.equals(m.getReturnType()))) {
                newMethods[i] = m;
                i++;
                continue;
            }
            Class<?> endpointClass = implInfo.getImplementorClass();
            Message msg = new Message("SEI_METHOD_NOT_FOUND", LOG,
                                      m.getName(), endpointClass.getName());
            throw new ServiceConstructionException(msg, e);
        }
    }
    super.bind(o, newMethods);
}
 
Example #9
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) {
    SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(),
                                      getQualifyWrapperSchema());
    XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart());
    if (e != null) {
        mpi.setXmlSchema(e);
        return;
    }
    XmlSchema schema = si.getSchema();
    si.setElement(null); //cached element is now invalid

    XmlSchemaElement el = new XmlSchemaElement(schema, true);
    el.setName(mpi.getElementQName().getLocalPart());
    el.setNillable(true);

    XmlSchemaType tp = (XmlSchemaType)mpi.getXmlSchema();
    if (tp == null) {
        throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG,
                                                           mpi.getName(),
                                                           mpi.getMessageInfo().getName()));
    }
    el.setSchemaTypeName(tp.getQName());
    mpi.setXmlSchema(el);
}
 
Example #10
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Class<?> getBeanClass(Class<?> exClass) {
    if (java.rmi.RemoteException.class.isAssignableFrom(exClass)) {
        return null;
    }

    if (FaultOutInterceptor.FaultInfoException.class.isAssignableFrom(exClass)) {
        try {
            Method m = exClass.getMethod("getFaultInfo");
            return m.getReturnType();
        } catch (SecurityException | NoSuchMethodException e) {
            throw new ServiceConstructionException(e);
        }
    }

    return exClass;
}
 
Example #11
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Method getProviderServiceObjectMethod(Method m, Class<?> serviceObjectClass) {
    if (!Provider.class.isAssignableFrom(serviceObjectClass)) {
        return m;
    }
    Class<?> currentSvcClass = serviceObjectClass;
    Class<?> genericType = null;

    while (currentSvcClass != null) {
        genericType = getProviderGenericType(currentSvcClass);
        if (genericType != null) {
            break;
        }
        // Check superclass until top
        currentSvcClass = currentSvcClass.getSuperclass();
    }
    // Should never happens
    if (genericType == null) {
        return m;
    }
    try {
        return serviceObjectClass.getMethod("invoke", genericType);
    } catch (Exception e) {
        throw new ServiceConstructionException(e);
    }
}
 
Example #12
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void validateSchemas(SchemaCollection xmlSchemaCollection) {
    final StringBuilder errorBuilder = new StringBuilder();
    XercesXsdValidationImpl v = new XercesXsdValidationImpl();
    v.validateSchemas(xmlSchemaCollection.getXmlSchemaCollection(), new DOMErrorHandler() {
        public boolean handleError(DOMError error) {
            errorBuilder.append(error.getMessage());
            LOG.warning(error.getMessage());
            return true;
        }
    });
    if (errorBuilder.length() > 0) {
        throw new ServiceConstructionException(new Message("XSD_VALIDATION_ERROR", LOG,
                                                           errorBuilder.toString()));
    }
}
 
Example #13
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected InterfaceInfo getInterfaceInfo() {
    if (getEndpointInfo() != null) {
        return getEndpointInfo().getInterface();
    }
    QName qn = this.getInterfaceName();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (qn.equals(si.getInterface().getName())) {
            return si.getInterface();
        }
    }
    throw new ServiceConstructionException(new Message("COULD_NOT_FIND_PORTTYPE", LOG, qn));
}
 
Example #14
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void initializeServiceModel() {
    if (isFromWsdl()) {
        buildServiceFromWSDL(getWsdlURL());
    } else if (getServiceClass() != null) {
        buildServiceFromClass();
    } else {
        throw new ServiceConstructionException(new Message("NO_WSDL_NO_SERVICE_CLASS_PROVIDED", LOG, getWsdlURL()));
    }

    if (isValidate()) {
        validateServiceModel();
    }
}
 
Example #15
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example #16
Source File: DefaultServiceConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getDefaultLocalName(OperationInfo op, Method method, int paramNumber, String prefix) {
    Class<?> impl = getServiceFactory().getServiceClass();
    // try to grab the implementation class so we can read the debug symbols from it
    if (impl != null) {
        try {
            method = impl.getMethod(method.getName(), method.getParameterTypes());
        } catch (Exception e) {
            throw new ServiceConstructionException(e);
        }
    }

    return DefaultServiceConfiguration.createName(method, paramNumber, op.getInput()
        .getMessagePartsNumber(), false, prefix);
}
 
Example #17
Source File: WSDLServiceFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public WSDLServiceFactory(Bus b, String url, QName sn) {
    setBus(b);
    wsdlUrl = url;
    try {
        // use wsdl manager to parse wsdl or get cached definition
        definition = getBus().getExtension(WSDLManager.class).getDefinition(url);
    } catch (WSDLException ex) {
        throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
    }

    serviceName = sn;
}
 
Example #18
Source File: WSDLServiceFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public WSDLServiceFactory(Bus b, String url) {
    setBus(b);
    wsdlUrl = url;
    try {
        // use wsdl manager to parse wsdl or get cached definition
        definition = getBus().getExtension(WSDLManager.class).getDefinition(url);
    } catch (WSDLException ex) {
        throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
    }
}
 
Example #19
Source File: JAXRSBindingFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void addListener(Destination d, Endpoint e) {
    synchronized (d) {
        if (d.getMessageObserver() != null) {
            throw new ServiceConstructionException(new Message("ALREADY_RUNNING", LOG,
                                                               e.getEndpointInfo().getAddress()));
        }
        super.addListener(d, e);
    }
}
 
Example #20
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #21
Source File: AbstractSpringComponentScanServer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
    Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
    Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
        
    for (String beanName : applicationContext.getBeanDefinitionNames()) {
        if (isValidComponent(beanName, Path.class, componentScanPackagesSet, componentScanBeansSet)) {
            SpringResourceFactory resourceFactory = new SpringResourceFactory(beanName);
            resourceFactory.setApplicationContext(applicationContext);
            resourceProviders.add(resourceFactory);
        } else if (isValidComponent(beanName, Provider.class, componentScanPackagesSet, componentScanBeansSet)) {
            jaxrsProviders.add(getProviderBean(beanName));
        } else if (isValidComponent(beanName, org.apache.cxf.annotations.Provider.class, 
                                componentScanPackagesSet, componentScanBeansSet)) {
            addCxfProvider(getProviderBean(beanName));
        }
    }

    if (!StringUtils.isEmpty(classesScanPackages)) {
        try {
            final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
                ClasspathScanner.findClasses(classesScanPackages, Provider.class,
                                             org.apache.cxf.annotations.Provider.class);

            jaxrsProviders.addAll(JAXRSServerFactoryBeanDefinitionParser
                .createBeansFromDiscoveredClasses(applicationContext, classes.get(Provider.class), null));
            warnIfDuplicatesAvailable(jaxrsProviders);
            addCxfProvidersFromClasses(classes.get(org.apache.cxf.annotations.Provider.class));
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }

    factory.setResourceProviders(getResourceProviders());
    factory.setProviders(getJaxrsProviders());
    setFactoryCxfProviders(factory);

}
 
Example #22
Source File: DynamicClientFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private URL composeUrl(String s) {
    try {
        URIResolver resolver = new URIResolver(null, s, getClass());

        if (resolver.isResolved()) {
            return resolver.getURI().toURL();
        }
        throw new ServiceConstructionException(new Message("COULD_NOT_RESOLVE_URL", LOG, s));
    } catch (IOException e) {
        throw new ServiceConstructionException(new Message("COULD_NOT_RESOLVE_URL", LOG, s), e);
    }
}
 
Example #23
Source File: ServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public <T> T getPort(QName portName, Class<T> serviceEndpointInterface, WebServiceFeature... features) {
    if (portName == null) {
        throw new WebServiceException(BUNDLE.getString("PORT_NAME_NULL_EXC"));
    }

    try {
        return createPort(portName, null, serviceEndpointInterface, features);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
}
 
Example #24
Source File: ServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public <T> T getPort(Class<T> serviceEndpointInterface, WebServiceFeature... features) {
    try {
        return createPort(null, null, serviceEndpointInterface, features);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
}
 
Example #25
Source File: JAXWSProviderMethodDispatcher.java    From cxf with Apache License 2.0 5 votes vote down vote up
public JAXWSProviderMethodDispatcher(JaxWsImplementorInfo implInfo) {
    try {
        invoke = ReflectionUtil.getMethod(implInfo.getImplementorClass(), "invoke", 
                                          new Class[] {implInfo.getProviderParameterType()});
        ReflectionUtil.setAccessible(invoke);
    } catch (Exception e1) {
        //fall back to the raw Provider provided invoke method
        try {
            invoke = Provider.class.getMethod("invoke", new Class[] {Object.class});
        } catch (Exception e) {
            throw new ServiceConstructionException(e);
        }
    }
}
 
Example #26
Source File: JAXRSServerFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the JAX-RS Server instance
 * @return the server
 */
public Server create() {
    ClassLoaderHolder origLoader = null;
    try {
        Bus bus = getBus();
        ClassLoader loader = bus.getExtension(ClassLoader.class);
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        serviceFactory.setBus(bus);
        checkResources(true);
        if (serviceFactory.getService() == null) {
            serviceFactory.create();
        }

        Endpoint ep = createEndpoint();

        getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE,
                                      server);

        server = new ServerImpl(getBus(),
                                ep,
                                getDestinationFactory(),
                                getBindingFactory());

        Invoker invoker = serviceFactory.getInvoker();
        if (invoker == null) {
            ep.getService().setInvoker(createInvoker());
        } else {
            ep.getService().setInvoker(invoker);
        }

        ServerProviderFactory factory = setupFactory(ep);
        
        ep.put(Application.class.getName(), appProvider);
        factory.setRequestPreprocessor(
            new RequestPreprocessor(languageMappings, extensionMappings));
        ep.put(Bus.class.getName(), getBus());
        if (documentLocation != null) {
            ep.put(JAXRSUtils.DOC_LOCATION, documentLocation);
        }
        if (rc != null) {
            ep.put("org.apache.cxf.jaxrs.comparator", rc);
        }
        checkPrivateEndpoint(ep);

        applyBusFeatures(getBus());
        applyFeatures();

        updateClassResourceProviders(ep);
        injectContexts(factory, (ApplicationInfo)ep.get(Application.class.getName()));
        factory.applyDynamicFeatures(getServiceFactory().getClassResourceInfo());
        
        
        getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED,
                                      server,
                                      null,
                                      null);


        if (start) {
            try {
                server.start();
            } catch (RuntimeException re) {
                server.destroy(); // prevent resource leak
                throw re;
            }
        }
    } catch (Exception e) {
        throw new ServiceConstructionException(e);
    } finally {
        if (origLoader != null) {
            origLoader.reset();
        }
    }

    return server;
}
 
Example #27
Source File: AbstractSpringComponentScanServer.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #28
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null
        && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG,
                                                           getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;

    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }

    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());

    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());

    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();

    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());

    sendEvent(Event.SERVICE_SET, getService());

    createInterface(serviceInfo);


    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();

    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }

    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method)opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }

        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }

        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName)fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
 
Example #29
Source File: AbstractWSDLBasedEndpointFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example #30
Source File: ServerFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
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) {
                server.destroy(); // prevent resource leak
                throw re;
            }
        }
        getServiceFactory().reset();

        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}