Java Code Examples for org.apache.cxf.jaxws.JaxWsProxyFactoryBean

The following examples show how to use org.apache.cxf.jaxws.JaxWsProxyFactoryBean. These examples are extracted from open source projects. 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 Project: java-specialagent   Source File: CxfTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWs(final MockTracer tracer) {
  final String msg = "hello";

  // prepare server
  final JaxWsServerFactoryBean serverFactory = new JaxWsServerFactoryBean();
  serverFactory.setServiceClass(Echo.class);
  serverFactory.setAddress(BASE_URI);
  serverFactory.setServiceBean(new EchoImpl());
  final Server server = serverFactory.create();

  // prepare client
  final JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
  clientFactory.setServiceClass(Echo.class);
  clientFactory.setAddress(BASE_URI);
  final Echo echo = (Echo)clientFactory.create();

  final String response = echo.echo(msg);

  assertEquals(msg, response);
  assertEquals(2, tracer.finishedSpans().size());

  server.destroy();
  serverFactory.getBus().shutdown(true);
}
 
Example 2
Source Project: java-specialagent   Source File: CXFITest.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
  final String msg = "hello";

  final JaxWsServerFactoryBean serverFactory = new JaxWsServerFactoryBean();
  serverFactory.setAddress(BASE_URI);
  serverFactory.setServiceBean(new EchoImpl());
  final Server server = serverFactory.create();

  final JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
  clientFactory.setServiceClass(Echo.class);
  clientFactory.setAddress(BASE_URI);
  final Echo echo = (Echo)clientFactory.create();

  echo.echo(msg);

  // CXF Tracing span has no "component" tag, cannot use TestUtil.checkSpan()
  checkSpans(2);

  server.destroy();
  serverFactory.getBus().shutdown(true);
}
 
Example 3
/**
 * Standard service initialization. Concrete implementations can change the
 * client initialization logic
 */
@SuppressWarnings("unchecked")
protected void initClient(Class<T> serviceClass, int gzipThreshold, boolean log) {
	// Needed to get rig of CXF exception
	// "Cannot create a secure XMLInputFactory"
	System.setProperty("org.apache.cxf.stax.allowInsecureParser", "true");

	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
	if (log) {
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
	}

	if (gzipThreshold >= 0) {
		factory.getInInterceptors().add(new GZIPInInterceptor());
		factory.getOutInterceptors().add(new GZIPOutInterceptor(gzipThreshold));
	}

	factory.setServiceClass(serviceClass);
	factory.setAddress(endpoint);
	client = (T) factory.create();
}
 
Example 4
Source Project: cxf   Source File: StudentTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnMap() throws Exception {

    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(StudentService.class);
    sf.setServiceBean(new StudentServiceImpl());
    sf.setAddress("local://StudentService");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

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

    StudentService clientInterface = proxyFac.create(StudentService.class);
    Map<Long, Student> fullMap = clientInterface.getStudentsMap();
    assertNotNull(fullMap);
    Student one = fullMap.get(Long.valueOf(1));
    assertNotNull(one);
    assertEquals("Student1", one.getName());

    Map<String, ?> wildMap = clientInterface.getWildcardMap();
    assertEquals("valuestring", wildMap.get("keystring"));
}
 
Example 5
Source Project: cxf   Source File: OpenTracingTracingTest.java    License: Apache License 2.0 6 votes vote down vote up
private static BookStoreService createJaxWsService(final Map<String, List<String>> headers,
        final Feature feature) {

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.setServiceClass(BookStoreService.class);
    factory.setAddress("http://localhost:" + PORT + "/BookStore");

    if (feature != null) {
        factory.getFeatures().add(feature);
    }

    final BookStoreService service = (BookStoreService) factory.create();
    final Client proxy = ClientProxy.getClient(service);
    proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);

    return service;
}
 
Example 6
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 6 votes vote down vote up
@Bean(name = "ticketAgentProxyBean")
public TicketAgent ticketAgent() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();
  jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class);
  jaxWsProxyFactoryBean.setAddress(address);

  // add the WSS4J OUT interceptor to sign the request message
  jaxWsProxyFactoryBean.getOutInterceptors().add(clientWssOut());
  // add the WSS4J IN interceptor to verify the signature on the response message
  jaxWsProxyFactoryBean.getInInterceptors().add(clientWssIn());

  // log the request and response messages
  jaxWsProxyFactoryBean.getInInterceptors()
      .add(loggingInInterceptor());
  jaxWsProxyFactoryBean.getOutInterceptors()
      .add(loggingOutInterceptor());

  return (TicketAgent) jaxWsProxyFactoryBean.create();
}
 
Example 7
Source Project: cxf   Source File: ExceptionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = HelloException.class)
public void testJaxws() throws Exception {
    JaxWsServerFactoryBean sfbean = new JaxWsServerFactoryBean();
    sfbean.setServiceClass(ExceptionService.class);
    setupAegis(sfbean);
    sfbean.setAddress("local://ExceptionService4");
    Server server = sfbean.create();
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new ExceptionServiceImpl()));

    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionService4");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());
    ExceptionService clientInterface = proxyFac.create(ExceptionService.class);

    clientInterface.sayHiWithException();
}
 
Example 8
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 6 votes vote down vote up
@Bean(name = "ticketAgentProxy")
public TicketAgent ticketAgentProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();
  jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class);
  jaxWsProxyFactoryBean.setAddress(address);

  // add an interceptor to log the outgoing request messages
  jaxWsProxyFactoryBean.getOutInterceptors()
      .add(loggingOutInterceptor());
  // add an interceptor to log the incoming response messages
  jaxWsProxyFactoryBean.getInInterceptors()
      .add(loggingInInterceptor());
  // add an interceptor to log the incoming fault messages
  jaxWsProxyFactoryBean.getInFaultInterceptors()
      .add(loggingInInterceptor());

  return (TicketAgent) jaxWsProxyFactoryBean.create();
}
 
Example 9
Source Project: BIMserver   Source File: SoapChannel.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public void connect(TokenHolder tokenHolder) {
	for (Class<? extends PublicInterface> interface1 : interfaces) {
		JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
		cpfb.setServiceClass(interface1);
		cpfb.setAddress(address + "/" + interface1.getSimpleName());
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put("mtom-enabled", Boolean.TRUE);
		cpfb.setProperties(properties);
		
		PublicInterface serviceInterface = (PublicInterface) cpfb.create();
		
		client = ClientProxy.getClient(serviceInterface);
		HTTPConduit http = (HTTPConduit) client.getConduit();
		http.getClient().setConnectionTimeout(360000);
		http.getClient().setAllowChunking(false);
		http.getClient().setReceiveTimeout(320000);
		
		if (!useSoapHeaderSessions) {
			((BindingProvider) serviceInterface).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
		}
		add(interface1.getName(), serviceInterface);
	}
	tokenHolder.registerTokenChangeListener(this);
	notifyOfConnect();
}
 
Example 10
Source Project: cxf   Source File: SpringBeansTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClientFromFactory() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/clients.xml"});


    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    Greeter g = factory.create(Greeter.class);
    ClientImpl c = (ClientImpl)ClientProxy.getClient(g);
    for (Interceptor<? extends Message> i : c.getInInterceptors()) {
        if (i instanceof LoggingInInterceptor) {
            ctx.close();
            return;
        }
    }
    ctx.close();
    fail("Did not configure the client");
}
 
Example 11
Source Project: yes-cart   Source File: PerUserPerServiceClientFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected PerUserPerServiceClientFactory(final NodeService nodeService,
                                         final Class<T> serviceInterface,
                                         final String userName,
                                         final String password,
                                         final String url,
                                         final long timeout) {
    this.userName = userName;
    this.password = password;
    this.url = url;
    this.timeout = timeout;
    this.factory = new JaxWsProxyFactoryBean();
    this.factory.setServiceClass(serviceInterface);
    this.factory.setAddress(this.url);

    final Slf4JLoggingInInterceptor loggingInInterceptor = new Slf4JLoggingInInterceptor(nodeService);
    loggingInInterceptor.setPrettyLogging(false);
    final Slf4JLoggingOutInterceptor loggingOutInterceptor = new Slf4JLoggingOutInterceptor(nodeService);
    loggingOutInterceptor.setPrettyLogging(false);

    this.factory.getInInterceptors().add(loggingInInterceptor);
    this.factory.getInFaultInterceptors().add(loggingInInterceptor);
    this.factory.getOutInterceptors().add(loggingOutInterceptor);
    this.factory.getOutFaultInterceptors().add(loggingOutInterceptor);
}
 
Example 12
Source Project: camelinaction2   Source File: WssAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
protected static OrderEndpoint createCXFClient(String url, String user, String passwordCallbackClass) {
    List<Interceptor<? extends Message>> outInterceptors = new ArrayList();

    // Define WSS4j properties for flow outgoing
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "UsernameToken Timestamp");
    outProps.put("user", user);
    outProps.put("passwordCallbackClass", passwordCallbackClass);

    WSS4JOutInterceptor wss4j = new WSS4JOutInterceptor(outProps);
    // Add LoggingOutInterceptor
    LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();

    outInterceptors.add(wss4j);
    outInterceptors.add(loggingOutInterceptor);

    // we use CXF to create a client for us as its easier than JAXWS and works
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setOutInterceptors(outInterceptors);
    factory.setServiceClass(OrderEndpoint.class);
    factory.setAddress(url);
    return (OrderEndpoint) factory.create();
}
 
Example 13
Source Project: cxf   Source File: EventSinkInterfaceNotificationTask.java    License: Apache License 2.0 6 votes vote down vote up
protected Object getProxy(Class<?> sinkInterface, Class<?>... extraClasses) {
    //needed SOAP handlers
    ReferenceParametersAddingHandler handler = new
            ReferenceParametersAddingHandler(
            target.getNotificationReferenceParams());

    JaxWsProxyFactoryBean service = new JaxWsProxyFactoryBean();
    service.getOutInterceptors().add(new LoggingOutInterceptor());
    service.setServiceClass(sinkInterface);
    service.setAddress(target.getTargetURL());
    service.getHandlers().add(handler);

    // do we need to apply a filter?
    if (target.getFilter() != null && target.getFilter().getContent().size() > 0) {
        service.getOutInterceptors().add(new FilteringInterceptor(target.getFilter()));
    }

    if (extraClasses != null && extraClasses.length > 0) {
        Map<String, Object> props = new HashMap<>();
        props.put("jaxb.additionalContextClasses", extraClasses);
        service.getClientFactoryBean().getServiceFactory().setProperties(props);
    }

    return service.create();
}
 
Example 14
Source Project: servicemix   Source File: Client.java    License: Apache License 2.0 6 votes vote down vote up
public void sendRequest() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:8181/cxf/HelloWorldSecurity");
    HelloWorld client = (HelloWorld) factory.create();
    
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "UsernameToken");

    //add a CustomerSecurityInterceptor for client side to init wss4j staff
    //retrieve and set user/password,  users can easily add this interceptor
    //through spring configuration also
    ClientProxy.getClient(client).getOutInterceptors().add(new CustomerSecurityInterceptor());
    ClientProxy.getClient(client).getOutInterceptors().add(new WSS4JOutInterceptor());
    String ret = client.sayHi("ffang");
    System.out.println(ret);
}
 
Example 15
Source Project: servicemix   Source File: Client.java    License: Apache License 2.0 6 votes vote down vote up
public void sendRequest() throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("http://localhost:8181/cxf/HelloWorldSecurity");
    HelloWorld client = (HelloWorld) factory.create();
    
    Map<String, Object> outProps = new HashMap<String, Object>();
    outProps.put("action", "UsernameToken");

    //add a CustomerSecurityInterceptor for client side to init wss4j staff
    //retrieve and set user/password,  users can easily add this interceptor
    //through spring configuration also
    ClientProxy.getClient(client).getOutInterceptors().add(new CustomerSecurityInterceptor());
    ClientProxy.getClient(client).getOutInterceptors().add(new WSS4JOutInterceptor());
    String ret = client.sayHi("ffang");
    System.out.println(ret);
}
 
Example 16
Source Project: cxf   Source File: AttributeTest.java    License: Apache License 2.0 6 votes vote down vote up
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
    testUtilities.setBus(getBean(Bus.class, "cxf"));

    testUtilities.initializeRhino();
    testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");

    clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
    client = clientProxyFactory.getClientFactoryBean().create();
    serviceInfos = client.getEndpoint().getService().getServiceInfos();
    // there can only be one.
    assertEquals(1, serviceInfos.size());
    ServiceInfo serviceInfo = serviceInfos.get(0);
    schemata = serviceInfo.getSchemas();
    nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixAccumulator =
        new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixAccumulator, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
        testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
    }
}
 
Example 17
Source Project: cxf   Source File: ClientMtomXopWithJMSTest.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface,
                                boolean enableMTOM) throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceName(serviceName);
    factory.setServiceClass(serviceEndpointInterface);
    factory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl").toExternalForm());
    factory.setFeatures(Collections.singletonList(cff));
    factory.getInInterceptors().add(new TestMultipartMessageInterceptor());
    factory.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    @SuppressWarnings("unchecked")
    T proxy = (T)factory.create();
    BindingProvider bp = (BindingProvider)proxy;
    SOAPBinding binding = (SOAPBinding)bp.getBinding();
    binding.setMTOMEnabled(true);
    return proxy;
}
 
Example 18
Source Project: cxf   Source File: SerializationTest.java    License: Apache License 2.0 6 votes vote down vote up
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
    testUtilities.setBus(getBean(Bus.class, "cxf"));

    testUtilities.initializeRhino();
    testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");

    clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
    client = clientProxyFactory.getClientFactoryBean().create();
    serviceInfos = client.getEndpoint().getService().getServiceInfos();
    // there can only be one.
    assertEquals(1, serviceInfos.size());
    ServiceInfo serviceInfo = serviceInfos.get(0);
    schemata = serviceInfo.getSchemas();
    nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixAccumulator =
        new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixAccumulator, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
        testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
    }
}
 
Example 19
Source Project: cxf   Source File: AegisClientServerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCollection() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setWsdlLocation("http://localhost:" + PORT + "/jaxwsAndAegisSports?wsdl");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();

    Collection<Team> teams = service.getTeams();
    assertEquals(1, teams.size());
    assertEquals("Patriots", teams.iterator().next().getName());

    //CXF-1251
    String s = service.testForMinOccurs0("A", null, "b");
    assertEquals("Anullb", s);
}
 
Example 20
Source Project: cxf   Source File: AegisClientServerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexMapResult() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Map<String, Map<Integer, Integer>> result = service.testComplexMapResult();
    assertEquals(result.size(), 1);
    assertTrue(result.containsKey("key1"));
    assertNotNull(result.get("key1"));
    assertEquals(result.toString(), "{key1={1=3}}");
}
 
Example 21
Source Project: cxf   Source File: IntegrationBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
protected Resource createClient(ReferenceParametersType refParams) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    Map<String, Object> props = factory.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
            ExpressionType.class);
    factory.setProperties(props);

    factory.setBus(bus);
    factory.setServiceClass(Resource.class);
    factory.setAddress(RESOURCE_ADDRESS);
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    EndpointReferenceType endpoint = new EndpointReferenceType();
    endpoint.setReferenceParameters(refParams);
    endpoint.setAddress(ContextUtils.getAttributedURI(RESOURCE_ADDRESS));
    addrProps.setTo(endpoint);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 22
Source Project: cxf   Source File: JavaFirstNoWsdlTest.java    License: Apache License 2.0 5 votes vote down vote up
private void specNoWsdlService(String messageType) throws Exception {
    String address = SERVICE_ADDRESS + ((messageType != null) ? "&messageType=" + messageType : "");
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.getFeatures().add(cff);
    factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
    factory.setServiceClass(Hello.class);
    factory.setAddress(address);
    Hello client = (Hello)markForClose(factory.create());
    String reply = client.sayHi(" HI");
    Assert.assertEquals("get HI", reply);
}
 
Example 23
Source Project: cxf   Source File: ResourceFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
private ResourceFactory createClient() {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(ResourceFactory.class);
    factory.setAddress(RESOURCE_FACTORY_ADDRESS);
    return (ResourceFactory) factory.create();
}
 
Example 24
Source Project: cxf   Source File: UDPTransportTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBroadcastUDP() throws Exception {
    // Disable the test on Redhat Enterprise Linux which doesn't enable the UDP broadcast by default
    if ("Linux".equals(System.getProperties().getProperty("os.name"))
        && System.getProperties().getProperty("os.version").indexOf("el") > 0) {
        System.out.println("Skipping broadcast test for REL");
        return;
    }

    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    int count = 0;
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (!networkInterface.isUp() || networkInterface.isLoopback()) {
            continue;
        }
        count++;
    }
    if (count == 0) {
        //no non-loopbacks, cannot do broadcasts
        System.out.println("Skipping broadcast test");
        return;
    }

    JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
    fact.setAddress("udp://:" + PORT + "/foo");
    Greeter g = fact.create(Greeter.class);
    assertEquals("Hello World", g.greetMe("World"));

    ((java.io.Closeable)g).close();
}
 
Example 25
Source Project: cxf   Source File: StaxToDOMEncryptionIdentifierTest.java    License: Apache License 2.0 5 votes vote down vote up
private Echo createClientProxy() {
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setServiceClass(Echo.class);
    proxyFac.setAddress("local://Echo");
    proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);

    return (Echo)proxyFac.create();
}
 
Example 26
Source Project: cxf   Source File: NoSpringServletClientTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHelloService() throws Exception {
    JaxWsProxyFactoryBean cpfb = new JaxWsProxyFactoryBean();
    String address = serviceURL + "Hello";
    cpfb.setServiceClass(Hello.class);
    cpfb.setAddress(address);
    Hello hello = (Hello) cpfb.create();
    String reply = hello.sayHi(" Willem");
    assertEquals("Get the wrongreply ", reply, "get Willem");
}
 
Example 27
Source Project: cxf-jaxws   Source File: HelloWorldImplTest.java    License: MIT License 5 votes vote down vote up
private static HelloWorldPortType createClientProxy() {
  // create a CXF JaxWsProxyFactoryBean for creating JAX-WS proxies
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();

  // // set the HelloWorld portType class
  jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class);
  // set the address at which the HelloWorld endpoint will be called
  jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS);

  // create a JAX-WS proxy for the HelloWorld portType
  return (HelloWorldPortType) jaxWsProxyFactoryBean.create();
}
 
Example 28
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 5 votes vote down vote up
@Bean(name = "helloWorldProxy")
public HelloWorldPortType helloWorldProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();
  jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class);
  jaxWsProxyFactoryBean.setAddress(address);

  return (HelloWorldPortType) jaxWsProxyFactoryBean.create();
}
 
Example 29
Source Project: cxf-jaxws   Source File: HelloWorldImplTest.java    License: MIT License 5 votes vote down vote up
private static HelloWorldPortType createClientProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();

  // create the loggingInInterceptor and loggingOutInterceptor
  LoggingInInterceptor loggingInInterceptor =
      new LoggingInInterceptor();
  loggingInInterceptor.setPrettyLogging(true);
  LoggingOutInterceptor loggingOutInterceptor =
      new LoggingOutInterceptor();
  loggingOutInterceptor.setPrettyLogging(true);

  // add loggingInterceptor to print the received/sent messages
  jaxWsProxyFactoryBean.getInInterceptors()
      .add(loggingInInterceptor);
  jaxWsProxyFactoryBean.getInFaultInterceptors()
      .add(loggingInInterceptor);
  jaxWsProxyFactoryBean.getOutInterceptors()
      .add(loggingOutInterceptor);
  jaxWsProxyFactoryBean.getOutFaultInterceptors()
      .add(loggingOutInterceptor);

  jaxWsProxyFactoryBean.setServiceClass(HelloWorldPortType.class);
  jaxWsProxyFactoryBean.setAddress(ENDPOINT_ADDRESS);

  return (HelloWorldPortType) jaxWsProxyFactoryBean.create();
}
 
Example 30
Source Project: cxf-jaxws   Source File: ClientConfig.java    License: MIT License 5 votes vote down vote up
@Bean(name = "ticketAgentProxy")
public TicketAgent ticketAgentProxy() {
  JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
      new JaxWsProxyFactoryBean();
  jaxWsProxyFactoryBean.setServiceClass(TicketAgent.class);
  jaxWsProxyFactoryBean.setAddress(address);

  return (TicketAgent) jaxWsProxyFactoryBean.create();
}