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());
}
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);
}
}
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
}
}
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();
}
}
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);
}
Aggregations