use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class ServerFactoryTest method testJaxbExtraClass.
@Test
public void testJaxbExtraClass() throws Exception {
ServerFactoryBean svrBean = new ServerFactoryBean();
svrBean.setAddress("http://localhost/Hello");
svrBean.setServiceClass(HelloServiceImpl.class);
svrBean.setBus(getBus());
Map<String, Object> props = svrBean.getProperties();
if (props == null) {
props = new HashMap<>();
}
props.put("jaxb.additionalContextClasses", new Class[] { GreetMe.class, GreetMeOneWay.class });
svrBean.setProperties(props);
Server serv = svrBean.create();
Class<?>[] extraClass = ((JAXBDataBinding) serv.getEndpoint().getService().getDataBinding()).getExtraClass();
assertEquals(extraClass.length, 2);
assertEquals(extraClass[0], GreetMe.class);
assertEquals(extraClass[1], GreetMeOneWay.class);
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class NotificationTest method basicReceptionOfWrappedEvents.
@Test
public void basicReceptionOfWrappedEvents() throws IOException {
NotificatorService service = createNotificatorService();
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
EndpointReferenceType eventSinkERT = new EndpointReferenceType();
AttributedURIType eventSinkAddr = new AttributedURIType();
String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
eventSinkAddr.setValue(url);
eventSinkERT.setAddress(eventSinkAddr);
subscribe.setDelivery(new DeliveryType());
subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
FormatType formatType = new FormatType();
formatType.setName(EventingConstants.DELIVERY_FORMAT_WRAPPED);
subscribe.setFormat(formatType);
eventSourceClient.subscribeOp(subscribe);
eventSourceClient.subscribeOp(subscribe);
eventSourceClient.subscribeOp(subscribe);
Server eventSinkServer = createWrappedEventSink(url);
TestingWrappedEventSinkImpl.RECEIVED_FIRES.set(0);
service.start();
Emitter emitter = new EmitterImpl(service);
emitter.dispatch(new FireEvent("Canada", 8));
for (int i = 0; i < 10; i++) {
if (TestingWrappedEventSinkImpl.RECEIVED_FIRES.get() == 3) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
eventSinkServer.stop();
if (TestingWrappedEventSinkImpl.RECEIVED_FIRES.get() != 3) {
Assert.fail("TestingWrappedEventSinkImpl should have received 3 events but received " + TestingWrappedEventSinkImpl.RECEIVED_FIRES.get());
}
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class NotificationTest method withFilterNegative.
/**
* We request only to receive notifications about fires in Russia
* and there will be only a fire in Canada. We should not receive
* this notification.
*/
@Test
public void withFilterNegative() throws IOException {
NotificatorService service = createNotificatorService();
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
EndpointReferenceType eventSinkERT = new EndpointReferenceType();
AttributedURIType eventSinkAddr = new AttributedURIType();
String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
eventSinkAddr.setValue(url);
eventSinkERT.setAddress(eventSinkAddr);
subscribe.setDelivery(new DeliveryType());
subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
subscribe.setFilter(new FilterType());
subscribe.getFilter().getContent().add("/*[local-name()='fire']/location[text()='Russia']");
eventSourceClient.subscribeOp(subscribe);
Server eventSinkServer = createEventSink(url);
TestingEventSinkImpl.RECEIVED_FIRES.set(0);
service.start();
Emitter emitter = new EmitterImpl(service);
emitter.dispatch(new FireEvent("Canada", 8));
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
eventSinkServer.stop();
if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
Assert.fail("TestingEventSinkImpl should have received 0 events but received " + TestingEventSinkImpl.RECEIVED_FIRES.get());
}
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class NotificationTest method withWSAAction.
@Test
public void withWSAAction() throws Exception {
NotificatorService service = createNotificatorService();
Subscribe subscribe = new Subscribe();
ExpirationType exp = new ExpirationType();
exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
subscribe.setExpires(exp);
EndpointReferenceType eventSinkERT = new EndpointReferenceType();
AttributedURIType eventSinkAddr = new AttributedURIType();
String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
eventSinkAddr.setValue(url);
eventSinkERT.setAddress(eventSinkAddr);
subscribe.setDelivery(new DeliveryType());
subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
eventSourceClient.subscribeOp(subscribe);
Server eventSinkServer = createEventSinkWithWSAActionAssertion(url, "http://www.fire.com");
TestingEventSinkImpl.RECEIVED_FIRES.set(0);
service.start();
Emitter emitter = new EmitterImpl(service);
emitter.dispatch(new FireEvent("Canada", 8));
for (int i = 0; i < 10; i++) {
if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 1) {
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
eventSinkServer.stop();
if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 1) {
Assert.fail("TestingEventSinkImpl should have received 1 events but received " + TestingEventSinkImpl.RECEIVED_FIRES.get());
}
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class LifeCycleTest method testRecursive.
@Test
public void testRecursive() {
assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
manager.registerListener(new ServerLifeCycleListener() {
public void startServer(Server server) {
String address = server.getEndpoint().getEndpointInfo().getAddress();
verifyNotification(startNotificationMap, address, 0);
updateMap(startNotificationMap, address);
if (recursiveCount < RECURSIVE_LIMIT) {
recursiveEndpoints[recursiveCount++] = Endpoint.publish(ADDRESSES[recursiveCount], new GreeterImpl());
}
}
public void stopServer(Server server) {
String address = server.getEndpoint().getEndpointInfo().getAddress();
verifyNotification(stopNotificationMap, address, 0);
updateMap(stopNotificationMap, address);
if (recursiveCount > 0) {
recursiveEndpoints[--recursiveCount].stop();
}
}
});
Endpoint.publish(ADDRESSES[0], new GreeterImpl()).stop();
for (int i = 0; i < ADDRESSES.length; i++) {
verifyNotification(startNotificationMap, ADDRESSES[i], 1);
verifyNotification(stopNotificationMap, ADDRESSES[i], 1);
}
}
Aggregations