Search in sources :

Example 11 with Subscribe

use of org.apache.cxf.ws.eventing.Subscribe 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 12 with Subscribe

use of org.apache.cxf.ws.eventing.Subscribe 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 13 with Subscribe

use of org.apache.cxf.ws.eventing.Subscribe 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)

Example 14 with Subscribe

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

the class SubscriptionEndTest method doTest.

@Test
public void doTest() throws IOException {
    NotificatorService service = createNotificatorService();
    service.start();
    Subscribe subscribe = new Subscribe();
    EndpointReferenceType eventSinkERT = new EndpointReferenceType();
    AttributedURIType eventSinkAddr = new AttributedURIType();
    String eventSinkURL = TestUtil.generateRandomURLWithLocalTransport();
    eventSinkAddr.setValue(eventSinkURL);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));
    JAXBElement<String> idqn = new JAXBElement<String>(new QName("http://www.example.org", "MyReferenceParameter"), String.class, "380");
    ReferenceParametersType myParams = new ReferenceParametersType();
    myParams.getAny().add(idqn);
    eventSinkERT.setReferenceParameters(myParams);
    EndpointReferenceType endToERT = new EndpointReferenceType();
    AttributedURIType endToAddr = new AttributedURIType();
    String endToURL = TestUtil.generateRandomURLWithLocalTransport();
    endToAddr.setValue(endToURL);
    endToERT.setAddress(endToAddr);
    subscribe.setEndTo(endToERT);
    SubscribeResponse response = eventSourceClient.subscribeOp(subscribe);
    Element referenceParams = (Element) response.getSubscriptionManager().getReferenceParameters().getAny().get(0);
    Server endToEndpoint = createEndToEndpointWithReferenceParametersAssertion(endToURL, myParams);
    TestingEndToEndpointImpl.RECEIVED_ENDS.set(0);
    SingletonSubscriptionManagerContainer.getInstance().subscriptionEnd(UUID.fromString(referenceParams.getTextContent()), "Sorry, " + "but we don't like you anymore", SubscriptionEndStatus.SOURCE_CANCELLING);
    for (int i = 0; i < 10; i++) {
        if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    endToEndpoint.stop();
    if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() != 1) {
        Assert.fail("TestingEndToEndpointImpl should have received 1 subscription end notification but received " + TestingEndToEndpointImpl.RECEIVED_ENDS.get());
    }
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) 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) SubscribeResponse(org.apache.cxf.ws.eventing.SubscribeResponse) ObjectFactory(org.apache.cxf.ws.eventing.ObjectFactory) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Example 15 with Subscribe

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

the class SubscriptionGrantingTest method testExpirationGrantingWithoutBestEffort.

/*    */
/**
 * specification:
 * The expiration time MAY be either a specific time or a duration but MUST
 * be of the same type as the wse:Expires element of the corresponding request.
 * If the corresponding request did not contain a wse:Expires element, this
 * element MUST be a duration (xs:duration).
 *
 * @throws IOException
 */
@Test
public void testExpirationGrantingWithoutBestEffort() throws IOException {
    // we specify a xs:duration
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);
    DeliveryType delivery = new DeliveryType();
    subscribe.setDelivery(delivery);
    subscribe.getDelivery().getContent().add(createDummyNotifyTo());
    SubscribeResponse resp = eventSourceClient.subscribeOp(subscribe);
    Assert.assertTrue("Specification requires that EventSource return a xs:duration " + "expirationType if a xs:duration was requested by client", DurationAndDateUtil.isDuration(resp.getGrantedExpires().getValue()));
    // we specify a xs:dateTime
    subscribe = new Subscribe();
    exp = new ExpirationType();
    XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
    exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
    subscribe.setExpires(exp);
    delivery = new DeliveryType();
    subscribe.setDelivery(delivery);
    subscribe.getDelivery().getContent().add(createDummyNotifyTo());
    resp = eventSourceClient.subscribeOp(subscribe);
    Assert.assertTrue("Specification requires that EventSource return a " + "xs:dateTime expirationType if a xs:dateTime was requested by client", DurationAndDateUtil.isXMLGregorianCalendar(resp.getGrantedExpires().getValue()));
    XMLGregorianCalendar returned = DurationAndDateUtil.parseXMLGregorianCalendar(resp.getGrantedExpires().getValue());
    System.out.println("granted expiration: " + returned.normalize().toXMLFormat());
    System.out.println("requested expiration: " + dateRequest.normalize().toXMLFormat());
    Assert.assertTrue("Server should have returned exactly the same date as we requested", returned.equals(dateRequest));
    // we don't specify anything
    subscribe = new Subscribe();
    delivery = new DeliveryType();
    subscribe.setDelivery(delivery);
    subscribe.getDelivery().getContent().add(createDummyNotifyTo());
    resp = eventSourceClient.subscribeOp(subscribe);
    Assert.assertTrue("Specification requires that EventSource return a xs:duration " + "expirationType if no specific expirationType was requested by client", DurationAndDateUtil.isDuration(resp.getGrantedExpires().getValue()));
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) Subscribe(org.apache.cxf.ws.eventing.Subscribe) SubscribeResponse(org.apache.cxf.ws.eventing.SubscribeResponse) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Aggregations

Subscribe (org.apache.cxf.ws.eventing.Subscribe)19 DeliveryType (org.apache.cxf.ws.eventing.DeliveryType)17 ExpirationType (org.apache.cxf.ws.eventing.ExpirationType)17 SimpleEventingIntegrationTest (org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)17 Test (org.junit.Test)17 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)10 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)10 ObjectFactory (org.apache.cxf.ws.eventing.ObjectFactory)10 Server (org.apache.cxf.endpoint.Server)9 NotificatorService (org.apache.cxf.ws.eventing.backend.notification.NotificatorService)9 SubscribeResponse (org.apache.cxf.ws.eventing.SubscribeResponse)8 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)5 GetStatus (org.apache.cxf.ws.eventing.GetStatus)4 SubscriptionManagerEndpoint (org.apache.cxf.ws.eventing.manager.SubscriptionManagerEndpoint)4 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 GetStatusResponse (org.apache.cxf.ws.eventing.GetStatusResponse)3 JAXBElement (javax.xml.bind.JAXBElement)2