Search in sources :

Example 1 with ObjectFactory

use of org.apache.cxf.ws.eventing.ObjectFactory 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());
    }
}
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 2 with ObjectFactory

use of org.apache.cxf.ws.eventing.ObjectFactory 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());
    }
}
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)

Example 3 with ObjectFactory

use of org.apache.cxf.ws.eventing.ObjectFactory 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());
    }
}
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) FormatType(org.apache.cxf.ws.eventing.FormatType) 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 4 with ObjectFactory

use of org.apache.cxf.ws.eventing.ObjectFactory in project cxf by apache.

the class CreateSubscriptionServlet method createSubscribeMessage.

public Subscribe createSubscribeMessage(String targetURL, String filter, String expires) throws DatatypeConfigurationException {
    Subscribe sub = new Subscribe();
    // expires
    if (expires != null) {
        sub.setExpires(new ExpirationType());
        sub.getExpires().setValue(expires);
    }
    // delivery
    EndpointReferenceType eventSink = new EndpointReferenceType();
    AttributedURIType eventSinkAddr = new AttributedURIType();
    eventSinkAddr.setValue(targetURL);
    eventSink.setAddress(eventSinkAddr);
    sub.setDelivery(new DeliveryType());
    sub.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSink));
    // filter
    if (filter != null && filter.length() > 0) {
        sub.setFilter(new FilterType());
        sub.getFilter().getContent().add(filter);
    }
    return sub;
}
Also used : FilterType(org.apache.cxf.ws.eventing.FilterType) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Subscribe(org.apache.cxf.ws.eventing.Subscribe) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType)

Example 5 with ObjectFactory

use of org.apache.cxf.ws.eventing.ObjectFactory in project cxf by apache.

the class SimpleEventingIntegrationTest method createDummyNotifyTo.

protected JAXBElement<EndpointReferenceType> createDummyNotifyTo() {
    EndpointReferenceType eventSinkERT = new EndpointReferenceType();
    AttributedURIType eventSinkAddr = new AttributedURIType();
    eventSinkAddr.setValue("local://dummy-sink");
    eventSinkERT.setAddress(eventSinkAddr);
    return new ObjectFactory().createNotifyTo(eventSinkERT);
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType)

Aggregations

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