Search in sources :

Example 1 with Factory

use of org.apache.cxf.service.invoker.Factory in project cxf by apache.

the class AnnotationsFactoryBeanListener method setScope.

private void setScope(Server server, Class<?> cls) {
    FactoryType scope = cls.getAnnotation(FactoryType.class);
    if (scope != null) {
        Invoker i = server.getEndpoint().getService().getInvoker();
        if (i instanceof FactoryInvoker) {
            Factory f;
            if (scope.factoryClass() == FactoryType.DEFAULT.class) {
                switch(scope.value()) {
                    case Session:
                        if (scope.args().length > 0) {
                            f = new SessionFactory(cls, Boolean.parseBoolean(scope.args()[0]));
                        } else {
                            f = new SessionFactory(cls);
                        }
                        break;
                    case PerRequest:
                        f = new PerRequestFactory(cls);
                        break;
                    case Pooled:
                        f = new PooledFactory(cls, Integer.parseInt(scope.args()[0]));
                        break;
                    default:
                        f = new SingletonFactory(cls);
                        break;
                }
            } else {
                try {
                    f = scope.factoryClass().getConstructor(Class.class, String[].class).newInstance(cls, scope.args());
                } catch (Throwable t) {
                    throw new ServiceConstructionException(t);
                }
            }
            ((FactoryInvoker) i).setFactory(f);
        }
    }
}
Also used : SessionFactory(org.apache.cxf.service.invoker.SessionFactory) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker) Invoker(org.apache.cxf.service.invoker.Invoker) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) Factory(org.apache.cxf.service.invoker.Factory) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory) SessionFactory(org.apache.cxf.service.invoker.SessionFactory) SingletonFactory(org.apache.cxf.service.invoker.SingletonFactory) FactoryType(org.apache.cxf.annotations.FactoryType) FactoryInvoker(org.apache.cxf.service.invoker.FactoryInvoker) SingletonFactory(org.apache.cxf.service.invoker.SingletonFactory) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory)

Example 2 with Factory

use of org.apache.cxf.service.invoker.Factory in project cxf by apache.

the class ServerMisc method run.

protected void run() {
    Factory factory = new PerRequestFactory(DocLitWrappedCodeFirstServiceImpl.class);
    factory = new PooledFactory(factory, 4);
    JAXWSMethodInvoker invoker = new JAXWSMethodInvoker(factory);
    JaxWsServerFactoryBean factoryBean;
    Map<String, Object> properties = new HashMap<>();
    properties.put("bus.jmx.usePlatformMBeanServer", Boolean.TRUE);
    properties.put("bus.jmx.enabled", Boolean.TRUE);
    Bus b = new CXFBusFactory().createBus(null, properties);
    setBus(b);
    MetricRegistry registry = new MetricRegistry();
    CodahaleMetricsProvider.setupJMXReporter(b, registry);
    b.setExtension(registry, MetricRegistry.class);
    factoryBean = new JaxWsServerFactoryBean();
    factoryBean.setBus(b);
    factoryBean.setAddress(DOCLIT_CODEFIRST_URL);
    factoryBean.setServiceClass(DocLitWrappedCodeFirstServiceImpl.class);
    factoryBean.setFeatures(Arrays.asList(new MetricsFeature()));
    factoryBean.setInvoker(invoker);
    servers.add(factoryBean.create());
    factoryBean = new JaxWsServerFactoryBean();
    factoryBean.setBus(b);
    factoryBean.setAddress(DOCLIT_CODEFIRST_URL_XMLBINDING);
    factoryBean.setServiceClass(DocLitWrappedCodeFirstServiceImpl.class);
    factoryBean.setFeatures(Arrays.asList(new MetricsFeature()));
    factoryBean.setInvoker(invoker);
    factoryBean.setBindingId("http://cxf.apache.org/bindings/xformat");
    factoryBean.setWsdlURL("cxf6866.wsdl");
    servers.add(factoryBean.create());
    factoryBean = new JaxWsServerFactoryBean();
    factoryBean.setAddress(DOCLIT_CODEFIRST_SETTINGS_URL);
    factoryBean.setServiceClass(DocLitWrappedCodeFirstServiceImpl.class);
    factoryBean.setInvoker(invoker);
    factoryBean.getServiceFactory().setAnonymousWrapperTypes(true);
    factoryBean.getServiceFactory().getServiceConfigurations().add(0, new AbstractServiceConfiguration() {

        public Boolean isWrapperPartNillable(MessagePartInfo mpi) {
            return Boolean.TRUE;
        }

        public Long getWrapperPartMinOccurs(MessagePartInfo mpi) {
            return Long.valueOf(1L);
        }
    });
    servers.add(factoryBean.create());
    // Object implementor4 = new DocLitWrappedCodeFirstServiceImpl();
    // endpoints.add(Endpoint.publish(DOCLIT_CODEFIRST_URL, implementor4));
    Object implementor7 = new DocLitBareCodeFirstServiceImpl();
    EndpointImpl ep = (EndpointImpl) Endpoint.publish(DOCLITBARE_CODEFIRST_URL, implementor7);
    ep.getServer().getEndpoint().getInInterceptors().add(new SAAJInInterceptor());
    endpoints.add(ep);
    Object implementor6 = new InterfaceInheritTestImpl();
    endpoints.add(Endpoint.publish(DOCLIT_CODEFIRST_BASE_URL, implementor6));
    Object implementor1 = new AnonymousComplexTypeImpl();
    String address = "http://localhost:" + PORT + "/anonymous_complex_typeSOAP";
    endpoints.add(Endpoint.publish(address, implementor1));
    Object implementor2 = new JaxbElementTestImpl();
    address = "http://localhost:" + PORT + "/jaxb_element_test";
    endpoints.add(Endpoint.publish(address, implementor2));
    Object implementor3 = new OrderedParamHolderImpl();
    address = "http://localhost:" + PORT + "/ordered_param_holder/";
    endpoints.add(Endpoint.publish(address, implementor3));
    // Object implementor4 = new DocLitWrappedCodeFirstServiceImpl();
    // endpoints.add(Endpoint.publish(DOCLIT_CODEFIRST_URL, implementor4));
    Object implementor5 = new RpcLitCodeFirstServiceImpl();
    endpoints.add(Endpoint.publish(RPCLIT_CODEFIRST_URL, implementor5));
    endpoints.add(Endpoint.publish("http://localhost:" + PORT + "/InheritContext/InheritPort", new InheritImpl()));
    endpoints.add(Endpoint.publish(CXF_5064_URL, new SOAPHeaderServiceImpl()));
}
Also used : HashMap(java.util.HashMap) MetricsFeature(org.apache.cxf.metrics.MetricsFeature) Factory(org.apache.cxf.service.invoker.Factory) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory) CXFBusFactory(org.apache.cxf.bus.CXFBusFactory) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) PooledFactory(org.apache.cxf.service.invoker.PooledFactory) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) CXFBusFactory(org.apache.cxf.bus.CXFBusFactory) JaxbElementTestImpl(org.apache.cxf.jaxb_element_test.JaxbElementTestImpl) Bus(org.apache.cxf.Bus) SOAPHeaderServiceImpl(org.apache.cxf.systest.jaxws.cxf5064.SOAPHeaderServiceImpl) MetricRegistry(com.codahale.metrics.MetricRegistry) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) JAXWSMethodInvoker(org.apache.cxf.jaxws.JAXWSMethodInvoker) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) AbstractServiceConfiguration(org.apache.cxf.wsdl.service.factory.AbstractServiceConfiguration) AnonymousComplexTypeImpl(org.apache.cxf.anonymous_complex_type.AnonymousComplexTypeImpl) OrderedParamHolderImpl(org.apache.cxf.ordered_param_holder.OrderedParamHolderImpl) PerRequestFactory(org.apache.cxf.service.invoker.PerRequestFactory)

Aggregations

Factory (org.apache.cxf.service.invoker.Factory)2 PerRequestFactory (org.apache.cxf.service.invoker.PerRequestFactory)2 PooledFactory (org.apache.cxf.service.invoker.PooledFactory)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 HashMap (java.util.HashMap)1 Bus (org.apache.cxf.Bus)1 FactoryType (org.apache.cxf.annotations.FactoryType)1 AnonymousComplexTypeImpl (org.apache.cxf.anonymous_complex_type.AnonymousComplexTypeImpl)1 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)1 CXFBusFactory (org.apache.cxf.bus.CXFBusFactory)1 JaxbElementTestImpl (org.apache.cxf.jaxb_element_test.JaxbElementTestImpl)1 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)1 JAXWSMethodInvoker (org.apache.cxf.jaxws.JAXWSMethodInvoker)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 MetricsFeature (org.apache.cxf.metrics.MetricsFeature)1 OrderedParamHolderImpl (org.apache.cxf.ordered_param_holder.OrderedParamHolderImpl)1 FactoryInvoker (org.apache.cxf.service.invoker.FactoryInvoker)1 Invoker (org.apache.cxf.service.invoker.Invoker)1 SessionFactory (org.apache.cxf.service.invoker.SessionFactory)1 SingletonFactory (org.apache.cxf.service.invoker.SingletonFactory)1