Java Code Examples for org.apache.cxf.frontend.ServerFactoryBean#setBus()

The following examples show how to use org.apache.cxf.frontend.ServerFactoryBean#setBus() . 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: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 2
Source File: RountripTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneWay() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello2");
    svrBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    svrBean.setServiceBean(new GreeterImplDoc());
    svrBean.setServiceClass(Greeter.class);
    svrBean.setEndpointName(new QName("http://apache.org/hello_world_doc_lit",
                                    "SoapPort"));
    svrBean.setServiceName(new QName("http://apache.org/hello_world_doc_lit",
                                     "SOAPService"));
    svrBean.setWsdlLocation("testutils/hello_world_doc_lit.wsdl");
    svrBean.setBus(getBus());

    svrBean.create();
}
 
Example 3
Source File: RountripTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerFactoryBean() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setServiceClass(HelloService.class);
    svrBean.setBus(getBus());

    svrBean.create();

    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress("http://localhost/Hello");
    clientBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(getBus());

    HelloService client = (HelloService) proxyFactory.create();

    assertEquals("hello", client.sayHello());
    assertEquals("hello", client.echo("hello"));
}
 
Example 4
Source File: StaxDatabindingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCallback() throws Exception {
    String address = "local://foo";

    ServerFactoryBean sf = new ServerFactoryBean();
    sf.setServiceBean(new CallbackService());
    sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    sf.setAddress(address);
    sf.setDataBinding(new StaxDataBinding());
    sf.getFeatures().add(new StaxDataBindingFeature());
    sf.setBus(getBus());
    sf.create();

    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "req.xml");

    assertValid("//bleh", res);
}
 
Example 5
Source File: CodeFirstTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Definition createService(boolean wrapped) throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();

    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(Hello.class);
    bean.setWrapped(wrapped);

    Service service = bean.create();

    InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
    assertEquals(5, i.getOperations().size());

    ServerFactoryBean svrFactory = new ServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);
    svrFactory.setAddress(address);
    svrFactory.create();

    Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
    assertEquals(1, bindings.size());

    ServiceWSDLBuilder wsdlBuilder =
        new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
    return wsdlBuilder.build();
}
 
Example 6
Source File: SoapFaultTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUpBus();

    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(bus);
    bean.setServiceClass(GreeterImpl.class);

    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);
    bean.setInvoker(invoker);

    service = bean.create();

    ServerFactoryBean svrFactory = new ServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);

    svrFactory.create();
}
 
Example 7
Source File: ClientServiceConfigTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
    super.setUp();

    ReflectionServiceFactoryBean factory = new ReflectionServiceFactoryBean();
    factory.setInvoker(new BeanInvoker(new EchoImpl()));
    factory.setDataBinding(new AegisDatabinding());

    ServerFactoryBean svrFac = new ServerFactoryBean();
    svrFac.setAddress("local://Echo");
    svrFac.setServiceFactory(factory);
    svrFac.setServiceClass(Echo.class);
    svrFac.setBus(getBus());
    svrFac.create();

    Endpoint endpoint = Endpoint.create(new EchoImpl());
    impl = (EndpointImpl) endpoint;
    impl.setDataBinding(new AegisDatabinding());
    endpoint.publish("local://JaxWsEcho");
}
 
Example 8
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 9
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
            //serverFactoryBean.destroy(); //升级到cxf 3后编译失败,暂时注掉 - 杨俊明
            if (serverFactoryBean.getServer() != null) {
                serverFactoryBean.getServer().destroy();
            }
        }
    };
}
 
Example 10
Source File: WebServiceProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
	String addr = url.getIp() + ":" + url.getPort();
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
	serverFactoryBean.setServiceClass(type);
	serverFactoryBean.setServiceBean(impl);
	serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
	serverFactoryBean.create();
    return new Runnable() {
        public void run() {
        	serverFactoryBean.destroy();
        }
    };
}
 
Example 11
Source File: CodeFirstWSDLTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Definition createService(Class<?> clazz) throws Exception {

        JaxWsImplementorInfo info = new JaxWsImplementorInfo(clazz);
        ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(info);

        Bus bus = getBus();
        bean.setBus(bus);

        Service service = bean.create();

        InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
        assertEquals(5, i.getOperations().size());

        ServerFactoryBean svrFactory = new ServerFactoryBean();
        svrFactory.setBus(bus);
        svrFactory.setServiceFactory(bean);
        svrFactory.setServiceBean(clazz.newInstance());
        svrFactory.setAddress(address);
        svrFactory.create();

        Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
        assertEquals(1, bindings.size());

        ServiceWSDLBuilder wsdlBuilder =
            new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
        return wsdlBuilder.build();
    }
 
Example 12
Source File: AnnotationInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    fb = new ServerFactoryBean();
    fb.setAddress("local://localhost");
    fb.setBus(getBus());

    jfb = new JaxWsServerFactoryBean();
    jfb.setAddress("local://localhost");
    jfb.setBus(getBus());
}
 
Example 13
Source File: SimpleFrontendTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void createServers() throws Exception {
    bus = BusFactory.getDefaultBus();
    ServerFactoryBean sf = new ServerFactoryBean();
    sf.setServiceBean(new WSSimpleImpl());
    sf.setAddress(add11);
    sf.setBus(bus);
    sf.create();


}
 
Example 14
Source File: GreeterTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(bus);
    bean.setServiceClass(GreeterImpl.class);
    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);


    Service service = bean.create();

    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals("http://apache.org/hello_world_soap_http", service.getName().getNamespaceURI());

    ServerFactoryBean svr = new ServerFactoryBean();
    svr.setBus(bus);
    svr.setServiceFactory(bean);
    svr.setInvoker(invoker);

    svr.create();

    Node response = invoke("http://localhost:9000/SoapContext/SoapPort",
                       LocalTransportFactory.TRANSPORT_ID,
                       "GreeterMessage.xml");

    assertEquals(1, greeter.getInvocationCount());

    assertNotNull(response);

    addNamespace("h", "http://apache.org/hello_world_soap_http/types");

    assertValid("/s:Envelope/s:Body", response);
    assertValid("//h:sayHiResponse", response);
}
 
Example 15
Source File: WebServiceProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = getAddr(url);
    HttpServer httpServer = serverMap.get(addr);
    if (httpServer == null) {
        httpServer = httpBinder.bind(url, new WebServiceHandler());
        serverMap.put(addr, httpServer);
    }
    final ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
    serverFactoryBean.setAddress(url.getAbsolutePath());
    serverFactoryBean.setServiceClass(type);
    serverFactoryBean.setServiceBean(impl);
    serverFactoryBean.setBus(bus);
    serverFactoryBean.setDestinationFactory(transportFactory);
    serverFactoryBean.create();
    return new Runnable() {
        @Override
        public void run() {
            if(serverFactoryBean.getServer()!= null) {
                serverFactoryBean.getServer().destroy();
            }
            if(serverFactoryBean.getBus()!=null) {
                serverFactoryBean.getBus().shutdown(true);
            }
        }
    };
}
 
Example 16
Source File: ServerFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetDF() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceClass(HelloService.class);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());
    svrBean.setDestinationFactory(new CustomDestinationFactory());

    ServerImpl server = (ServerImpl)svrBean.create();
    assertTrue(server.getDestination() instanceof CustomDestination);
}
 
Example 17
Source File: ServerFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXF1758() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Generics");
    svrBean.setServiceBean(new TestServiceImpl<String>() { });
    svrBean.setBus(getBus());
    ServerImpl server = (ServerImpl)svrBean.create();
    //XMLUtils.printDOM(getWSDLDocument(server));
    assertValid("//xsd:schema/xsd:complexType[@name='open']/xsd:sequence/"
                + "xsd:element[@type='xsd:string']",
                getWSDLDocument(server));
}
 
Example 18
Source File: HeaderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
    public void testInvocation() throws Exception {
        JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();

        Bus bus = getBus();
        bean.setBus(bus);
        bean.setServiceClass(TestHeaderImpl.class);

        Service service = bean.create();

        OperationInfo op = service.getServiceInfos().get(0).getInterface().getOperation(
            new QName(service.getName().getNamespaceURI(), "testHeader5"));
        assertNotNull(op);
        List<MessagePartInfo> parts = op.getInput().getMessageParts();
        assertEquals(1, parts.size());

        MessagePartInfo part = parts.get(0);
        assertNotNull(part.getTypeClass());
        assertEquals(TestHeader5.class, part.getTypeClass());

        parts = op.getOutput().getMessageParts();
        assertEquals(2, parts.size());

        part = parts.get(1);
        assertNotNull(part.getTypeClass());
        assertEquals(TestHeader5ResponseBody.class, part.getTypeClass());

        part = parts.get(0);
        assertNotNull(part.getTypeClass());
        assertEquals(TestHeader5.class, part.getTypeClass());

//        part = parts.get(1);
//        assertNotNull(part.getTypeClass());

        ServerFactoryBean svr = new ServerFactoryBean();
        svr.setBus(bus);
        svr.setServiceFactory(bean);
        svr.setServiceBean(new TestHeaderImpl());
        svr.setAddress("http://localhost:9104/SoapHeaderContext/SoapHeaderPort");
        svr.setBindingConfig(new JaxWsSoapBindingConfiguration(bean));


        svr.create();

        Node response = invoke("http://localhost:9104/SoapHeaderContext/SoapHeaderPort",
                               LocalTransportFactory.TRANSPORT_ID,
                               "testHeader5.xml");

        assertNotNull(response);
        assertNoFault(response);

        addNamespace("t", "http://apache.org/header_test/types");
        assertValid("//s:Header/t:testHeader5", response);
    }
 
Example 19
Source File: ReflectionServiceFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testServerFactoryBean() throws Exception {
    Service service = createService(true);
    assertEquals("test", service.get("test"));

    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceFactory(serviceFactory);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());

    Map<String, Object> props = new HashMap<>();
    props.put("test", "test");
    serviceFactory.setProperties(props);
    svrBean.setProperties(props);

    Server server = svrBean.create();
    assertNotNull(server);
    Map<QName, Endpoint> eps = service.getEndpoints();
    assertEquals(1, eps.size());

    Endpoint ep = eps.values().iterator().next();
    EndpointInfo endpointInfo = ep.getEndpointInfo();

    assertEquals("test", ep.get("test"));

    BindingInfo b = endpointInfo.getService().getBindings().iterator().next();

    assertTrue(b instanceof SoapBindingInfo);

    SoapBindingInfo sb = (SoapBindingInfo) b;
    assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
    assertEquals("document", sb.getStyle());

    assertEquals(4, b.getOperations().size());

    BindingOperationInfo bop = b.getOperations().iterator().next();
    SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);
    assertNotNull(sop);
    assertEquals("", sop.getAction());
    assertEquals("document", sop.getStyle());
}
 
Example 20
Source File: JAXWSExporter.java    From fuchsia with Apache License 2.0 2 votes vote down vote up
@Override
public void useExportDeclaration(ExportDeclaration exportDeclaration) throws BinderException {

    LOG.info("exporting {}", exportDeclaration.getMetadata());

    JAXWSExportDeclarationWrapper pojo = JAXWSExportDeclarationWrapper.create(exportDeclaration);

    try {

        ServerFactoryBean srvFactory = new ServerFactoryBean();

        Class ref = FuchsiaUtils.loadClass(this.context, pojo.getClazz());

        srvFactory.setServiceClass(ref);

        srvFactory.setBus(cxfbus);

        ServiceReference[] jaxWsReferences = context.getAllServiceReferences(pojo.getClazz(), pojo.getFilter());

        if (jaxWsReferences == null) {
            LOG.warn("instance not found to be exported, ignoring exportation request, filter:" + pojo.getFilter());
            return;
        }

        Object object = context.getService(jaxWsReferences[0]);

        srvFactory.setServiceBean(object);

        srvFactory.setAddress(pojo.getWebcontext());

        org.apache.cxf.endpoint.Server endpoint = srvFactory.create();

        exportDeclaration.handle(serviceReference);

        exportedDeclaration.put(pojo.getWebcontext(), endpoint);

        srvFactory.getServer().start();

        LOG.info("Pushing CXF endpoint: {}", endpoint.getEndpoint().getEndpointInfo().getAddress());

    } catch (Exception e) {
        LOG.error("Failed exporting in CXF", e);
        throw new BinderException(e);
    }
}