Java Code Examples for org.apache.cxf.frontend.ClientProxyFactoryBean#create()

The following examples show how to use org.apache.cxf.frontend.ClientProxyFactoryBean#create() . 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: ExceptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = HelloException.class)
public void testJaxwsServerSimpleClient() throws Exception {
    JaxWsServerFactoryBean sfbean = new JaxWsServerFactoryBean();
    sfbean.setServiceClass(ExceptionService.class);
    sfbean.setDataBinding(new AegisDatabinding());
    sfbean.setAddress("local://ExceptionServiceJaxWs1");
    Server server = sfbean.create();
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new ExceptionServiceImpl()));

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionServiceJaxWs1");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    ExceptionService clientInterface = proxyFac.create(ExceptionService.class);

    clientInterface.sayHiWithException();
}
 
Example 2
Source File: ExceptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHeaders() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionService");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    ExceptionService client = proxyFac.create(ExceptionService.class);

    try {
        client.sayHiWithException();
        fail("Must throw exception!");
    } catch (HelloException e) {
        // nothing
    }

    //check to make sure the fault is an element
    Document wsdl = getWSDLDocument("ExceptionService");
    addNamespace("tns", "http://exception.aegis.cxf.apache.org");
    assertValid("//wsdl:message[@name='HelloException']/wsdl:part[@name='HelloException']"
                + "[@element='tns:String']",
                 wsdl);
}
 
Example 3
Source File: ProxyTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testProxy() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://HelloProxyService");
    proxyFac.setBus(getBus());
    AegisContext aegisContext = new AegisContext();
    aegisContext.getBeanImplementationMap().put(Hello.class, MyHello.class.getName());
    AegisDatabinding binding = new AegisDatabinding();
    binding.setAegisContext(aegisContext);

    setupAegis(proxyFac.getClientFactoryBean(), binding);
    HelloProxyService client = proxyFac.create(HelloProxyService.class);

    Hello h = client.sayHiWithProxy();
    assertTrue(h instanceof MyHello);
}
 
Example 4
Source File: LazyRemoteServiceRegistryConnector.java    From rice with Educational Community License v2.0 6 votes vote down vote up
protected ServiceRegistry initializeRemoteServiceRegistry() {
	String registryBootstrapUrl = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.REGISTRY_SERVICE_URL);
	if (StringUtils.isBlank(registryBootstrapUrl)) {
		throw new RiceRuntimeException("Failed to load registry bootstrap service from url: " + registryBootstrapUrl);
	}
	ClientProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
	clientFactory.setServiceClass(ServiceRegistry.class);
	clientFactory.setBus(cxfBus);
	clientFactory.setAddress(registryBootstrapUrl);

       boolean registrySecurity = ConfigContext.getCurrentContextConfig().getBooleanProperty(SERVICE_REGISTRY_SECURITY_CONFIG, true);

	// Set security interceptors
	clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(registrySecurity));
	clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(registrySecurity));

       //Set transformation interceptors
       clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
	
	Object service = clientFactory.create();
	if (!(service instanceof ServiceRegistry)) {
		throw new RiceRuntimeException("Endpoint to service registry at URL '" + registryBootstrapUrl + "' was not an instance of ServiceRegistry, instead was: " + service);
	}
	return (ServiceRegistry)service;
}
 
Example 5
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 6
Source File: Client.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    String serviceURL;
    if (args != null && args.length > 0 && !"".equals(args[0])) {
        serviceURL = args[0];
    } else {
        serviceURL = "http://localhost:9000/Hello";
    }
    factory.setServiceName(new QName("http://server.hw.demo/", "HelloWorldService"));
    factory.setAddress(serviceURL);
    factory.setWsdlURL(serviceURL + "?wsdl");
    factory.getServiceFactory().setDataBinding(new AegisDatabinding());
    HelloWorld client = factory.create(HelloWorld.class);
    System.out.println("Invoke sayHi()....");
    System.out.println(client.sayHi(System.getProperty("user.name")));
    System.exit(0);
}
 
Example 7
Source File: ExceptionInheritanceTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();

    AegisContext globalContext = new AegisContext();
    globalContext.setWriteXsiTypes(true);

    Set<String> l = new HashSet<>();
    l.add(SimpleBean.class.getName());
    l.add(WS1ExtendedException.class.getName());
    globalContext.setRootClassNames(l);
    AegisDatabinding binding = new AegisDatabinding();
    binding.setAegisContext(globalContext);

    ClientProxyFactoryBean pf = new ClientProxyFactoryBean();
    setupAegis(pf.getClientFactoryBean(), binding);
    pf.getServiceFactory().setProperties(props);
    pf.setAddress("local://WS1");
    pf.setProperties(props);

    client = pf.create(WS1.class);

    Server server = createService(WS1.class, new WS1Impl(), "WS1", binding);
    server.getEndpoint().getService().setInvoker(new BeanInvoker(new WS1Impl()));
}
 
Example 8
Source File: MtomTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setupForTest(boolean enableClientMTOM) throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    aegisBinding.setMtomEnabled(enableClientMTOM);
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setDataBinding(aegisBinding);
    proxyFac.setAddress("http://localhost:" + PORT + "/mtom");

    JaxWsProxyFactoryBean jaxwsFac = new JaxWsProxyFactoryBean();
    jaxwsFac.setDataBinding(new AegisDatabinding());
    jaxwsFac.setAddress("http://localhost:" + PORT + "/jaxWsMtom");

    Map<String, Object> props = new HashMap<>();
    if (enableClientMTOM) {
        props.put("mtom-enabled", Boolean.TRUE);
    }
    proxyFac.setProperties(props);

    client = proxyFac.create(MtomTestService.class);
    jaxwsClient = jaxwsFac.create(MtomTestService.class);
    impl = (MtomTestImpl)applicationContext.getBean("mtomImpl");
}
 
Example 9
Source File: FlatArrayTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlatCollection() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setDataBinding(new AegisDatabinding());
    proxyFac.setAddress("local://FlatArray");
    proxyFac.setBus(getBus());

    FlatArrayServiceInterface client = proxyFac.create(FlatArrayServiceInterface.class);
    BeanWithFlatCollection bwfc = new BeanWithFlatCollection();
    bwfc.getValues().add(1);
    bwfc.getValues().add(2);
    bwfc.getValues().add(3);
    bwfc = client.echoBeanWithFlatCollection(bwfc);
    assertEquals(3, bwfc.getValues().size());
    assertEquals(Integer.valueOf(1), bwfc.getValues().get(0));
    assertEquals(Integer.valueOf(2), bwfc.getValues().get(1));
    assertEquals(Integer.valueOf(3), bwfc.getValues().get(2));
}
 
Example 10
Source File: ClientServerMiscTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleClientWithWsdlAndBindingId() throws Exception {
    QName portName = new QName("http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
        "DocLitWrappedCodeFirstServicePort");
    QName servName = new QName("http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService",
        "DocLitWrappedCodeFirstService");

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    factory.setBindingId("http://cxf.apache.org/bindings/xformat");
    factory.setWsdlURL(ServerMisc.DOCLIT_CODEFIRST_URL_XMLBINDING + "?wsdl");
    factory.setServiceName(servName);
    factory.setServiceClass(DocLitWrappedCodeFirstService.class);
    factory.setEndpointName(portName);
    factory.setAddress(ServerMisc.DOCLIT_CODEFIRST_URL_XMLBINDING);
    DocLitWrappedCodeFirstService port = (DocLitWrappedCodeFirstService) factory.create();
    assertNotNull(port);
    assertEquals(factory.getBindingId(), "http://cxf.apache.org/bindings/xformat");
    assertTrue(ClientProxy.getClient(port).getEndpoint().getBinding() instanceof XMLBinding);

    String echoMsg = port.echo("Hello");
    assertEquals("Hello", echoMsg);
}
 
Example 11
Source File: DOMMappingTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    createService(DocumentService.class, "DocService");
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    ReflectionServiceFactoryBean factory = new ReflectionServiceFactoryBean();
    factory.getServiceConfigurations()
        .add(0, new org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration());
    proxyFac.setServiceFactory(factory);
    proxyFac.setDataBinding(new AegisDatabinding());

    proxyFac.setAddress("local://DocService");
    proxyFac.setBus(getBus());

    Object proxyObj = proxyFac.create(IDocumentService.class);
    docClient = (IDocumentService)proxyObj;
    Client client = ClientProxy.getClient(proxyObj);
    ClientImpl clientImpl = (ClientImpl)client;
    clientImpl.setSynchronousTimeout(1000000000);
}
 
Example 12
Source File: ClientServiceConfigTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void ordinaryParamNameTest() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    ReflectionServiceFactoryBean factory = new ReflectionServiceFactoryBean();
    proxyFac.setServiceFactory(factory);
    proxyFac.setDataBinding(new AegisDatabinding());

    proxyFac.setAddress("local://Echo");
    proxyFac.setBus(getBus());

    Echo echo = proxyFac.create(Echo.class);
    String boing = echo.simpleEcho("reflection");
    assertEquals("reflection", boing);
}
 
Example 13
Source File: CxfClientToCxfServerIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
	JaxWsServerFactoryBean jaxWsServer = createJaxWsServer();
	jaxWsServer.getFeatures().add(new LoggingFeature());
	jaxWsServer.getFeatures().add(new TraceeCxfFeature(serverBackend, Profile.DEFAULT));
	server = jaxWsServer.create();

	final ClientProxyFactoryBean factoryBean = new ClientProxyFactoryBean();
	factoryBean.getFeatures().add(new LoggingFeature());
	factoryBean.getFeatures().add(new TraceeCxfFeature(clientBackend, Profile.DEFAULT));
	factoryBean.setServiceClass(HelloWorldTestService.class);
	factoryBean.setBus(CXFBusFactory.getDefaultBus());
	factoryBean.setAddress(endpointAddress);
	helloWorldPort = (HelloWorldTestService) factoryBean.create();
}
 
Example 14
Source File: InterfaceInheritanceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClient() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://IInterfaceService");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    IInterfaceService client = proxyFac.create(IInterfaceService.class);

    IChild child = client.getChild();
    assertNotNull(child);
    assertEquals("child", child.getChildName());
    assertEquals("parent", child.getParentName());

    IParent parent = client.getChildViaParent();
    assertEquals("parent", parent.getParentName());
    assertFalse(parent instanceof IChild);

    IGrandChild grandChild = client.getGrandChild();
    assertEquals("parent", grandChild.getParentName());

    Document wsdl = getWSDLDocument("IInterfaceService");
    assertValid("//xsd:complexType[@name='IGrandChild']", wsdl);
    assertValid("//xsd:complexType[@name='IGrandChild']//xsd:element[@name='grandChildName']", wsdl);
    assertValid("//xsd:complexType[@name='IGrandChild']//xsd:element[@name='childName'][1]", wsdl);
    assertInvalid("//xsd:complexType[@name='IGrandChild']//xsd:element[@name='childName'][2]", wsdl);
    assertValid("//xsd:complexType[@name='IChild']", wsdl);
    assertValid("//xsd:complexType[@name='IParent']", wsdl);
    assertInvalid("//xsd:complexType[@name='IChild'][@abstract='true']", wsdl);
}
 
Example 15
Source File: AegisClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testAegisClient() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(AuthService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/service");
    AuthService service = (AuthService) proxyFactory.create();
    assertTrue(service.authenticate("Joe", "Joe", "123"));
    assertFalse(service.authenticate("Joe1", "Joe", "fang"));
    assertTrue(service.authenticate("Joe", null, "123"));
    List<String> list = service.getRoles("Joe");
    assertEquals(3, list.size());
    assertEquals("Joe", list.get(0));
    assertEquals("Joe-1", list.get(1));
    assertEquals("Joe-2", list.get(2));
    String[] roles = service.getRolesAsArray("Joe");
    assertEquals(2, roles.length);
    assertEquals("Joe", roles[0]);
    assertEquals("Joe-1", roles[1]);

    assertEquals("get Joe", service.getAuthentication("Joe"));
    Authenticate au = new Authenticate();
    au.setSid("ffang");
    au.setUid("ffang");
    assertTrue(service.authenticate(au));
    au.setUid("ffang1");
    assertFalse(service.authenticate(au));
}
 
Example 16
Source File: Client.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    if (args != null && args.length > 0 && !"".equals(args[0])) {
        factory.setAddress(args[0]);
    } else {
        factory.setAddress("http://localhost:9000/Hello");
    }
    HelloWorld client = factory.create(HelloWorld.class);
    System.out.println("Invoke sayHi()....");
    System.out.println(client.sayHi(System.getProperty("user.name")));
    System.exit(0);
}
 
Example 17
Source File: FlatArrayTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDataMovementBean() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setDataBinding(new AegisDatabinding());
    proxyFac.setAddress("local://FlatArray");
    proxyFac.setBus(getBus());

    FlatArrayServiceInterface client = proxyFac.create(FlatArrayServiceInterface.class);
    BeanWithFlatArray bwfa = new BeanWithFlatArray();
    bwfa.setValues(INT_ARRAY);
    client.takeBeanWithFlatArray(bwfa);
    assertArrayEquals(INT_ARRAY, service.beanWithFlatArrayValue.getValues());
}
 
Example 18
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
  	ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
  	proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
  	proxyFactoryBean.setServiceClass(serviceType);
  	proxyFactoryBean.setBus(bus);
  	T ref = (T) proxyFactoryBean.create();
  	Client proxy = ClientProxy.getClient(ref);  
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
conduit.setClient(policy);
      return ref;
  }
 
Example 19
Source File: WebServiceProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
  	ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
  	proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
  	proxyFactoryBean.setServiceClass(serviceType);
  	proxyFactoryBean.setBus(bus);
  	T ref = (T) proxyFactoryBean.create();
  	Client proxy = ClientProxy.getClient(ref);  
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
conduit.setClient(policy);
      return ref;
  }
 
Example 20
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
  	ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean();
  	proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString());
  	proxyFactoryBean.setServiceClass(serviceType);
  	proxyFactoryBean.setBus(bus);
  	T ref = (T) proxyFactoryBean.create();
  	Client proxy = ClientProxy.getClient(ref);  
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
conduit.setClient(policy);
      return ref;
  }