Search in sources :

Example 31 with ServerFactoryBean

use of org.apache.cxf.frontend.ServerFactoryBean in project camel by apache.

the class CxfProducerTest method startService.

@Before
public void startService() throws Exception {
    // start a simple front service
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress(getSimpleServerAddress());
    svrBean.setServiceClass(HelloService.class);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(BusFactory.getDefaultBus());
    server = svrBean.create();
    GreeterImpl greeterImpl = new GreeterImpl();
    endpoint = Endpoint.publish(getJaxWsServerAddress(), greeterImpl);
}
Also used : GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) Before(org.junit.Before)

Example 32 with ServerFactoryBean

use of org.apache.cxf.frontend.ServerFactoryBean in project camel by apache.

the class CxfEndpoint method createServerFactoryBean.

/**
     * Create a CXF server factory bean
     */
ServerFactoryBean createServerFactoryBean() throws Exception {
    Class<?> cls = null;
    if (getDataFormat() == DataFormat.POJO) {
        ObjectHelper.notNull(getServiceClass(), CxfConstants.SERVICE_CLASS);
    }
    if (getWsdlURL() == null && getServiceClass() == null) {
        // no WSDL and serviceClass specified, set our default serviceClass
        if (getDataFormat().equals(DataFormat.PAYLOAD)) {
            setServiceClass(org.apache.camel.component.cxf.DefaultPayloadProviderSEI.class.getName());
        }
    }
    if (getServiceClass() != null) {
        cls = getServiceClass();
    }
    // create server factory bean
    // Shouldn't use CxfEndpointUtils.getServerFactoryBean(cls) as it is for
    // CxfSoapComponent
    ServerFactoryBean answer = null;
    if (cls == null) {
        checkName(portName, " endpoint/port name");
        checkName(serviceName, " service name");
        answer = new JaxWsServerFactoryBean(new WSDLServiceFactoryBean()) {

            {
                doInit = false;
            }
        };
        cls = Provider.class;
    } else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
        answer = new JaxWsServerFactoryBean();
    } else {
        answer = new ServerFactoryBean();
    }
    // setup server factory bean
    setupServerFactoryBean(answer, cls);
    return answer;
}
Also used : ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 33 with ServerFactoryBean

use of org.apache.cxf.frontend.ServerFactoryBean in project cxf by apache.

the class EJBEndpoint method publish.

public Server publish() throws Exception {
    jndiContext = new InitialContext();
    Object obj = jndiContext.lookup(config.getJNDIName());
    ejbHome = (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class);
    Class<?> interfaceClass = Class.forName(getServiceClassName());
    boolean isJaxws = isJaxWsServiceInterface(interfaceClass);
    ServerFactoryBean factory = isJaxws ? new JaxWsServerFactoryBean() : new ServerFactoryBean();
    factory.setServiceClass(interfaceClass);
    if (config.getWsdlURL() != null) {
        factory.getServiceFactory().setWsdlURL(config.getWsdlURL());
    }
    factory.setInvoker(new EJBInvoker(ejbHome));
    String baseAddress = isNotNull(getEjbServantBaseURL()) ? getEjbServantBaseURL() : getDefaultEJBServantBaseURL();
    String address = baseAddress + "/" + config.getJNDIName();
    factory.setAddress(address);
    if (address.length() >= 5 && HTTPS_PREFIX.equalsIgnoreCase(address.substring(0, 5))) {
        throw new UnsupportedOperationException("EJBEndpoint creation by https protocol is unsupported");
    }
    if (getWorkManager() != null) {
        setWorkManagerThreadPoolToJetty(factory.getBus(), baseAddress);
    }
    Server server = factory.create();
    LOG.info("Published EJB Endpoint of [" + config.getJNDIName() + "] at [" + address + "]");
    return server;
}
Also used : Server(org.apache.cxf.endpoint.Server) PortableRemoteObject(javax.rmi.PortableRemoteObject) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) InitialContext(javax.naming.InitialContext)

Example 34 with ServerFactoryBean

use of org.apache.cxf.frontend.ServerFactoryBean in project cxf by apache.

the class SoapBindingSelectionTest method testMultipleSoapBindings.

@Test
public void testMultipleSoapBindings() throws Exception {
    ServerFactoryBean svrBean1 = new ServerFactoryBean();
    svrBean1.setAddress("http://localhost/Hello");
    svrBean1.setServiceClass(HelloService.class);
    svrBean1.setServiceBean(new HelloServiceImpl());
    svrBean1.setBus(getBus());
    svrBean1.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {

        public void handleMessage(Message message) throws Fault {
            service1Invoked = true;
        }
    });
    svrBean1.create();
    ServerFactoryBean svrBean2 = new ServerFactoryBean();
    svrBean2.setAddress("http://localhost/Hello");
    svrBean2.setServiceClass(HelloService.class);
    svrBean2.setServiceBean(new HelloServiceImpl());
    svrBean2.setBus(getBus());
    svrBean2.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {

        public void handleMessage(Message message) throws Fault {
            service2Invoked = true;
        }
    });
    SoapBindingConfiguration config = new SoapBindingConfiguration();
    config.setVersion(Soap12.getInstance());
    svrBean2.setBindingConfig(config);
    ServerImpl server2 = (ServerImpl) svrBean2.create();
    Destination d = server2.getDestination();
    MessageObserver mo = d.getMessageObserver();
    assertTrue(mo instanceof MultipleEndpointObserver);
    MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
    assertEquals(2, meo.getEndpoints().size());
    Node nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap11.xml");
    assertEquals("http://schemas.xmlsoap.org/soap/envelope/", getNs(nd));
    assertTrue(service1Invoked);
    assertFalse(service2Invoked);
    service1Invoked = false;
    nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
    assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
    assertFalse(service1Invoked);
    assertTrue(service2Invoked);
    server2.stop();
    server2.start();
    nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
    assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
    assertFalse(service1Invoked);
    assertTrue(service2Invoked);
}
Also used : Destination(org.apache.cxf.transport.Destination) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ServerImpl(org.apache.cxf.endpoint.ServerImpl) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) Node(org.w3c.dom.Node) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) HelloServiceImpl(org.apache.cxf.service.factory.HelloServiceImpl) Fault(org.apache.cxf.interceptor.Fault) Test(org.junit.Test) AbstractSimpleFrontendTest(org.apache.cxf.service.factory.AbstractSimpleFrontendTest)

Example 35 with ServerFactoryBean

use of org.apache.cxf.frontend.ServerFactoryBean in project cxf by apache.

the class SpringBeansTest method testServers.

@Test
public void testServers() throws Exception {
    ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/servers.xml" });
    ServerFactoryBean bean = (ServerFactoryBean) ctx.getBean("simple");
    assertNotNull(bean);
    if (!(bean.getServiceBean() instanceof HelloServiceImpl)) {
        fail("can't get the right serviceBean");
    }
    bean = (ServerFactoryBean) ctx.getBean("inlineImplementor");
    if (!(bean.getServiceBean() instanceof HelloServiceImpl)) {
        fail("can't get the right serviceBean");
    }
    bean = (ServerFactoryBean) ctx.getBean("inlineSoapBinding");
    assertNotNull(bean);
    BindingConfiguration bc = bean.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    bean = (ServerFactoryBean) ctx.getBean("simpleWithBindingId");
    assertEquals("get the wrong BindingId", bean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
    bean = (ServerFactoryBean) ctx.getBean("simpleWithWSDL");
    assertNotNull(bean);
    assertEquals(bean.getWsdlLocation(), "org/apache/cxf/frontend/spring/simple.wsdl");
    bean = (ServerFactoryBean) ctx.getBean("proxyBean");
    assertNotNull(bean);
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) HelloServiceImpl(org.apache.cxf.service.factory.HelloServiceImpl) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Aggregations

ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)48 Test (org.junit.Test)16 Server (org.apache.cxf.endpoint.Server)9 Before (org.junit.Before)9 BeforeClass (org.junit.BeforeClass)9 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)8 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)6 QName (javax.xml.namespace.QName)5 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)5 Service (org.apache.cxf.service.Service)5 Node (org.w3c.dom.Node)5 Bus (org.apache.cxf.Bus)4 ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)4 HashMap (java.util.HashMap)3 ServerImpl (org.apache.cxf.endpoint.ServerImpl)3 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)3 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)3 AbstractCXFTest (org.apache.cxf.test.AbstractCXFTest)3 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)3 URL (java.net.URL)2