org.apache.cxf.frontend.ClientProxyFactoryBean Java Examples

The following examples show how to use org.apache.cxf.frontend.ClientProxyFactoryBean. 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: ClientServerMiscTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleClientWithWsdl() 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.setWsdlURL(ServerMisc.DOCLIT_CODEFIRST_URL + "?wsdl");
    factory.setServiceName(servName);
    factory.setServiceClass(DocLitWrappedCodeFirstService.class);
    factory.setEndpointName(portName);

    DocLitWrappedCodeFirstService port = (DocLitWrappedCodeFirstService) factory.create();
    assertNotNull(port);

    String echoMsg = port.echo("Hello");
    assertEquals("Hello", echoMsg);
}
 
Example #2
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 #3
Source File: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapMap() throws Exception {

    ServerFactoryBean sf = new ServerFactoryBean();
    sf.setServiceClass(StudentServiceDocLiteral.class);
    sf.setServiceBean(new StudentServiceDocLiteralImpl());
    sf.setAddress("local://StudentServiceDocLiteral");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://StudentServiceDocLiteral");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());
    //CHECKSTYLE:OFF
    HashMap<String, Student> mss = new HashMap<>();
    mss.put("Alice", new Student());
    HashMap<String, HashMap<String, Student>> mmss = new HashMap<>();
    mmss.put("Bob", mss);

    StudentServiceDocLiteral clientInterface = proxyFac.create(StudentServiceDocLiteral.class);
    clientInterface.takeMapMap(mmss);
    //CHECKSTYLE:ON
}
 
Example #4
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 #5
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 #6
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 #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: 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 #9
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 #10
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 #11
Source File: DocLitBareTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testNamespaceCrash() {
    ServerFactoryBean svrFactory = new ServerFactoryBean();
    svrFactory.setServiceClass(University.class);
    svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    svrFactory.setAddress("local://dlbTest");
    svrFactory.setServiceBean(new UniversityImpl());
    svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
    svrFactory.create();

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    factory.getServiceFactory().setDataBinding(new AegisDatabinding());

    factory.setServiceClass(University.class);
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    factory.setAddress("local://dlbTest");
    University client = (University) factory.create();

    Teacher tr = client.getTeacher(new Course(40, "Intro to CS", "Introductory Comp Sci"));
    assertNotNull(tr);
    assertEquals(52, tr.getAge());
    assertEquals("Mr. Tom", tr.getName());
}
 
Example #12
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 #13
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();
    if (args != null && args.length > 0 && !"".equals(args[0])) {
        factory.setAddress(args[0]);
    } else {
        factory.setAddress("http://localhost:9000/Hello");
    }
    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")));
    Document doc = client.getADocument();
    Element e = (Element) doc.getFirstChild();
    System.out.println(e.getTagName());
    Text t = (Text) e.getFirstChild();
    System.out.println(t);
}
 
Example #14
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 #15
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 #16
Source File: WebServiceProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
@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 #17
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 #18
Source File: ServiceImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void configureBean(String bn, Object beanInstance, boolean checkWildcards) {
    if (beanInstance instanceof JaxWsClientFactoryBean) {
        isJAXWSClientFactoryConfigured = true;
    }
    if (beanInstance instanceof ClientProxyFactoryBean) {
        isClientProxyFactoryBeanConfigured = true;
    }
}
 
Example #19
Source File: MissingTypeWSDLTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMissingTransliteration() throws Exception {
    Server server = createService(MissingType.class, new MissingTypeImpl(), null);
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new MissingTypeImpl()));
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://MissingType");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    Document wsdl = getWSDLDocument("MissingType");
    assertValid("/wsdl:definitions/wsdl:types"
                + "/xsd:schema[@targetNamespace='urn:org:apache:cxf:aegis:type:missing']"
                + "/xsd:complexType[@name=\"Inner\"]", wsdl);
}
 
Example #20
Source File: CxfClientToJaxwsServerIT.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.getHandlers().add(new TraceeClientHandler(serverBackend));
	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.setAddress(endpointAddress);
	helloWorldPort = (HelloWorldTestService) factoryBean.create();
}
 
Example #21
Source File: CollectionTestsWithService.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    impl = new CollectionService();
    createService(CollectionServiceInterface.class, impl, null);

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.getServiceFactory().getServiceConfigurations().add(0,
                                                          new XFireCompatibilityServiceConfiguration());
    proxyFac.setDataBinding(new AegisDatabinding());
    proxyFac.setAddress("local://CollectionServiceInterface");
    proxyFac.setBus(getBus());

    csi = proxyFac.create(CollectionServiceInterface.class);
}
 
Example #22
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 #23
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 #24
Source File: FlatArrayTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDataMovementPart() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setDataBinding(new AegisDatabinding());
    proxyFac.setAddress("local://FlatArray");
    proxyFac.setBus(getBus());

    FlatArrayServiceInterface client = proxyFac.create(FlatArrayServiceInterface.class);
    client.submitStringArray(STRING_ARRAY);
    assertArrayEquals(STRING_ARRAY, service.stringArrayValue);
}
 
Example #25
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 #26
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 #27
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 #28
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 #29
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 #30
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;
  }