Search in sources :

Example 86 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class LifeCycleTest method testClientLifecycle.

@Test
public void testClientLifecycle() throws Exception {
    final AtomicBoolean created = new AtomicBoolean();
    final AtomicBoolean destroyed = new AtomicBoolean();
    bus.getExtension(ClientLifeCycleManager.class).registerListener(new ClientLifeCycleListener() {

        public void clientCreated(Client client) {
            created.set(true);
        }

        public void clientDestroyed(Client client) {
            destroyed.set(true);
        }
    });
    org.apache.hello_world_soap_http.SOAPService service = new org.apache.hello_world_soap_http.SOAPService();
    Greeter client = service.getSoapPort();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESSES[0]);
    assertTrue("clientCreated not called", created.get());
    client = null;
    int count = 0;
    while (count < 10 && !destroyed.get()) {
        System.gc();
        System.runFinalization();
        count++;
        if (count > 5) {
            Thread.sleep(100);
        }
    }
    assertTrue("clientDestroyed not called", destroyed.get());
    created.set(false);
    destroyed.set(false);
    client = service.getSoapPort();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESSES[0]);
    assertTrue("clientCreated not called", created.get());
    ((java.io.Closeable) client).close();
    assertTrue("clientDestroyed not called", destroyed.get());
}
Also used : Endpoint(javax.xml.ws.Endpoint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) Greeter(org.apache.hello_world_soap_http.Greeter) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 87 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class CountersClientServerTest method testCountersWithInstrumentationManager.

@Test
public void testCountersWithInstrumentationManager() throws Exception {
    // create Client with other bus
    Bus bus = getStaticBus();
    BusFactory.setDefaultBus(bus);
    bus.getExtension(WorkQueueManager.class);
    CounterRepository cr = bus.getExtension(CounterRepository.class);
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl impl = (InstrumentationManagerImpl) im;
    assertTrue(impl.isEnabled());
    assertNotNull(impl.getMBeanServer());
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":" + ManagementConstants.BUS_ID_PROP + "=cxf" + bus.hashCode() + ",*");
    SOAPService service = new SOAPService();
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    String response = new String("Bonjour");
    String reply = greeter.sayHi();
    // assertNotNull("no response received from service", reply);
    // assertEquals(response, reply);
    assertEquals("The Counters are not create yet", 4, cr.getCounters().size());
    Set<?> counterNames = mbs.queryNames(name, null);
    assertEquals("The Counters are not export to JMX: " + counterNames, 4 + 3, counterNames.size());
    ObjectName sayHiCounter = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":operation=\"sayHi\",*");
    Set<?> s = mbs.queryNames(sayHiCounter, null);
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 1);
    }
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    s = mbs.queryNames(sayHiCounter, null);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 2);
    }
    greeter.greetMeOneWay("hello");
    for (int count = 0; count < 10; count++) {
        if (6 != cr.getCounters().size()) {
            Thread.sleep(100);
        } else {
            break;
        }
    }
    assertEquals("The Counters are not create yet", 6, cr.getCounters().size());
    for (int count = 0; count < 10; count++) {
        if (10 > mbs.queryNames(name, null).size()) {
            Thread.sleep(100);
        } else {
            break;
        }
    }
    counterNames = mbs.queryNames(name, null);
    assertEquals("The Counters are not export to JMX " + counterNames, 6 + 4, counterNames.size());
    ObjectName greetMeOneWayCounter = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":operation=\"greetMeOneWay\",*");
    s = mbs.queryNames(greetMeOneWayCounter, null);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName counterName = (ObjectName) it.next();
        Object val = mbs.getAttribute(counterName, "NumInvocations");
        assertEquals("Wrong Counters Number of Invocations", val, 1);
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) CounterRepository(org.apache.cxf.management.counters.CounterRepository) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) Endpoint(javax.xml.ws.Endpoint) ObjectName(javax.management.ObjectName) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Greeter(org.apache.hello_world_soap_http.Greeter) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 88 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ManagedClientServerTest method testManagedEndpoint.

@Test
public void testManagedEndpoint() throws Exception {
    Bus bus = getStaticBus();
    BusFactory.setDefaultBus(bus);
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl impl = (InstrumentationManagerImpl) im;
    assertTrue(impl.isEnabled());
    assertNotNull(impl.getMBeanServer());
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus.Service.Endpoint,*");
    Set<?> s = mbs.queryNames(name, null);
    assertEquals(1, s.size());
    name = (ObjectName) s.iterator().next();
    Object val = mbs.invoke(name, "getState", new Object[0], new String[0]);
    assertEquals("Service should have been started.", "STARTED", val);
    SOAPService service = new SOAPService();
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    String response = new String("Bonjour");
    String reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    mbs.invoke(name, "stop", new Object[0], new String[0]);
    val = mbs.getAttribute(name, "State");
    assertEquals("Service should have been stopped.", "STOPPED", val);
    try {
        reply = greeter.sayHi();
        fail("Endpoint should not be active at this point.");
    } catch (Exception ex) {
    // Expected
    }
    mbs.invoke(name, "start", new Object[0], new String[0]);
    val = mbs.invoke(name, "getState", new Object[0], new String[0]);
    assertEquals("Service should have been started.", "STARTED", val);
    reply = greeter.sayHi();
    assertNotNull("no response received from service", reply);
    assertEquals(response, reply);
    mbs.invoke(name, "destroy", new Object[0], new String[0]);
    try {
        mbs.getMBeanInfo(name);
        fail("destroy failed to unregister MBean.");
    } catch (InstanceNotFoundException e) {
    // Expected
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Greeter(org.apache.hello_world_soap_http.Greeter) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 89 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class ClientServerWebSocketTest method testBasicAuth.

@Test
public void testBasicAuth() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    try {
        // try the jaxws way
        BindingProvider bp = (BindingProvider) greeter;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        String s = greeter.greetMe("secure");
        assertEquals("Hello BJ", s);
        bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
        bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);
        ((Closeable) greeter).close();
        greeter = service.getPort(portName, Greeter.class);
        updateGreeterAddress(greeter, PORT);
        // try setting on the conduit directly
        Client client = ClientProxy.getClient(greeter);
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        AuthorizationPolicy policy = new AuthorizationPolicy();
        policy.setUserName("BJ2");
        policy.setPassword("pswd");
        httpConduit.setAuthorization(policy);
        s = greeter.greetMe("secure");
        ((Closeable) greeter).close();
        assertEquals("Hello BJ2", s);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world_soap_http.Greeter) Closeable(java.io.Closeable) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 90 with Greeter

use of org.apache.hello_world_soap_http.Greeter in project cxf by apache.

the class PublishedEndpointUrlTest method testPublishedEndpointUrl.

@Test
public void testPublishedEndpointUrl() throws Exception {
    Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceClass(Greeter.class);
    svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
    svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
    svrFactory.setServiceBean(implementor);
    Server server = svrFactory.create();
    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
    HttpURLConnection connect = (HttpURLConnection) url.openConnection();
    assertEquals(500, connect.getResponseCode());
    Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
    assertNotNull(wsdl);
    Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
    final String failMesg = "WSDL provided incorrect soap:address location";
    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        for (Port port : ports) {
            List<?> extensions = port.getExtensibilityElements();
            for (Object extension : extensions) {
                String actualUrl = null;
                if (extension instanceof SOAP12Address) {
                    actualUrl = ((SOAP12Address) extension).getLocationURI();
                } else if (extension instanceof SOAPAddress) {
                    actualUrl = ((SOAPAddress) extension).getLocationURI();
                }
                // System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
                assertEquals(failMesg, publishedEndpointUrl, actualUrl);
            }
        }
    }
    server.stop();
    server.destroy();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) WSDLReader(javax.wsdl.xml.WSDLReader) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

Aggregations

Greeter (org.apache.hello_world_soap_http.Greeter)104 Test (org.junit.Test)78 SOAPService (org.apache.hello_world_soap_http.SOAPService)55 URL (java.net.URL)47 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)24 BindingProvider (javax.xml.ws.BindingProvider)23 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)21 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)21 Service (javax.xml.ws.Service)19 Client (org.apache.cxf.endpoint.Client)17 Endpoint (javax.xml.ws.Endpoint)13 QName (javax.xml.namespace.QName)10 Bus (org.apache.cxf.Bus)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)10 ExecutorService (java.util.concurrent.ExecutorService)9 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 File (java.io.File)6 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)6 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)6 InvocationHandler (java.lang.reflect.InvocationHandler)5