Search in sources :

Example 6 with Emitter

use of org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter in project cxf by apache.

the class NotificationTest method expiration.

/**
 * request a subscription that expires soon
 * an event will be emitted after the expiration
 * we should not receive notification about the event
 * @throws IOException
 */
@Test
public void expiration() throws IOException {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT1S")));
    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 = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    service.start();
    Emitter emitter = new EmitterImpl(service);
    try {
        Thread.sleep(3000);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    emitter.dispatch(new FireEvent("Canada", 8));
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
        Assert.fail("TestingEventSinkImpl should not have received any events but received " + TestingEventSinkImpl.RECEIVED_FIRES.get());
    }
}
Also used : Emitter(org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Server(org.apache.cxf.endpoint.Server) NotificatorService(org.apache.cxf.ws.eventing.backend.notification.NotificatorService) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Subscribe(org.apache.cxf.ws.eventing.Subscribe) FireEvent(org.apache.cxf.ws.eventing.integration.notificationapi.FireEvent) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) EmitterImpl(org.apache.cxf.ws.eventing.backend.notification.emitters.EmitterImpl) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest) Test(org.junit.Test)

Example 7 with Emitter

use of org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter in project cxf by apache.

the class NotificationTest method withReferenceParameters.

@Test
public void withReferenceParameters() 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();
    JAXBElement<String> idqn = new JAXBElement<String>(new QName("http://www.example.org", "MyReferenceParameter"), String.class, "380");
    JAXBElement<String> idqn2 = new JAXBElement<String>(new QName("http://www.example.org", "MyReferenceParameter2"), String.class, "381");
    eventSinkERT.setReferenceParameters(new ReferenceParametersType());
    eventSinkERT.getReferenceParameters().getAny().add(idqn);
    eventSinkERT.getReferenceParameters().getAny().add(idqn2);
    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 = createEventSinkWithReferenceParametersAssertion(url, eventSinkERT.getReferenceParameters());
    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();
    int received = TestingEventSinkImpl.RECEIVED_FIRES.get();
    if (received != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 events but received " + received);
    }
}
Also used : Emitter(org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) NotificatorService(org.apache.cxf.ws.eventing.backend.notification.NotificatorService) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Subscribe(org.apache.cxf.ws.eventing.Subscribe) JAXBElement(javax.xml.bind.JAXBElement) FireEvent(org.apache.cxf.ws.eventing.integration.notificationapi.FireEvent) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) EmitterImpl(org.apache.cxf.ws.eventing.backend.notification.emitters.EmitterImpl) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest) Test(org.junit.Test)

Example 8 with Emitter

use of org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter in project cxf by apache.

the class NotificationTest method withFilter.

/**
 * We request only to receive notifications about fires in Canada
 * and there will be a fire in Canada. We should receive
 * this notification.
 */
@Test
public void withFilter() 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' and " + "namespace-uri()='http://www.events.com']/location[text()='Canada']");
    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));
    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());
    }
}
Also used : Emitter(org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Server(org.apache.cxf.endpoint.Server) NotificatorService(org.apache.cxf.ws.eventing.backend.notification.NotificatorService) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Subscribe(org.apache.cxf.ws.eventing.Subscribe) FireEvent(org.apache.cxf.ws.eventing.integration.notificationapi.FireEvent) FilterType(org.apache.cxf.ws.eventing.FilterType) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) EmitterImpl(org.apache.cxf.ws.eventing.backend.notification.emitters.EmitterImpl) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest) Test(org.junit.Test)

Aggregations

Server (org.apache.cxf.endpoint.Server)8 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)8 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)8 DeliveryType (org.apache.cxf.ws.eventing.DeliveryType)8 ExpirationType (org.apache.cxf.ws.eventing.ExpirationType)8 ObjectFactory (org.apache.cxf.ws.eventing.ObjectFactory)8 Subscribe (org.apache.cxf.ws.eventing.Subscribe)8 NotificatorService (org.apache.cxf.ws.eventing.backend.notification.NotificatorService)8 Emitter (org.apache.cxf.ws.eventing.backend.notification.emitters.Emitter)8 EmitterImpl (org.apache.cxf.ws.eventing.backend.notification.emitters.EmitterImpl)8 SimpleEventingIntegrationTest (org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)8 FireEvent (org.apache.cxf.ws.eventing.integration.notificationapi.FireEvent)8 Test (org.junit.Test)8 FilterType (org.apache.cxf.ws.eventing.FilterType)3 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)1 FormatType (org.apache.cxf.ws.eventing.FormatType)1 EarthquakeEvent (org.apache.cxf.ws.eventing.integration.notificationapi.EarthquakeEvent)1