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

The following examples show how to use org.apache.cxf.frontend.ClientProxyFactoryBean#setServiceClass() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: JAXWSExporterWithoutHttpServiceTest.java    From fuchsia with Apache License 2.0 2 votes vote down vote up
@Test
public void remoteWSInvokationShouldSucceed() throws BinderException {

    Map<String, Object> metadata = new HashMap<String, Object>();
    metadata.put(ID, "TestJAXWSDeclaration");
    metadata.put("fuchsia.export.cxf.class.name", ServiceForExportation.class.getName());
    metadata.put("fuchsia.export.cxf.url.context", "/" + ServiceForExportation.class.getSimpleName());

    ExportDeclaration declaration = spy(ExportDeclarationBuilder.fromMetadata(metadata).build());
    declaration.bind(serviceReferenceFromExporter);

    exporter.registration(serviceReferenceFromExporter);

    exporter.addDeclaration(declaration);

    /**
     * Configure CXF Client to connect to the endpoint.
     */

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();

    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());

    factory.setServiceClass(ServiceForExportation.class);

    String endPointURL = "http://localhost:" + HTTP_PORT + "/cxf/" + ServiceForExportation.class.getSimpleName();
    factory.setAddress(endPointURL);

    ServiceForExportation objectProxy = (ServiceForExportation) factory.create();

    final String stringValue = "coucou";
    final Integer intValue = 1789;

    objectProxy.ping();
    verify(id, times(1)).ping();

    objectProxy.ping(intValue);
    verify(id, times(1)).ping(intValue);

    objectProxy.ping(stringValue);
    verify(id, times(1)).ping(stringValue);

    String returnPongString = objectProxy.pongString(stringValue);
    verify(id, times(1)).pongString(stringValue);
    Assert.assertEquals(returnPongString, stringValue);

    Integer returnPongInteger = objectProxy.pongInteger(intValue);
    verify(id, times(1)).pongInteger(intValue);
    Assert.assertEquals(returnPongInteger, intValue);


}