Search in sources :

Example 6 with ExpirationType

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

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

the class SubscriptionGrantingTest method testExpirationGrantingWithBestEffort.

/**
 * When BestEffort=true, the server doesn't have to grant exactly the date as we requested
 * @throws IOException
 */
@Test
public void testExpirationGrantingWithBestEffort() throws IOException {
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    DeliveryType delivery = new DeliveryType();
    XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
    exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
    exp.setBestEffort(true);
    subscribe.setExpires(exp);
    subscribe.setDelivery(delivery);
    subscribe.getDelivery().getContent().add(createDummyNotifyTo());
    SubscribeResponse 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()));
}
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)

Example 8 with ExpirationType

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

the class SubscriptionGrantingTest method noDeliveryMechanismSpecified.

@Test
public void noDeliveryMechanismSpecified() 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);
    try {
        eventSourceClient.subscribeOp(subscribe);
    } catch (SOAPFaultException ex) {
        Assert.assertTrue(ex.getFault().getFaultCode().contains(NoDeliveryMechanismEstablished.LOCAL_PART));
        Assert.assertTrue(ex.getFault().getTextContent().contains(NoDeliveryMechanismEstablished.REASON));
        return;
    }
    Assert.fail("Event source should have sent a NoDeliveryMechanismEstablished fault");
}
Also used : ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Subscribe(org.apache.cxf.ws.eventing.Subscribe) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Example 9 with ExpirationType

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

the class SubscriptionManagementTest method getStatus.

/**
 * Creates a subscription and then retrieves its status from the Subscription Manager.
 */
@Test
public void getStatus() throws Exception {
    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);
    SubscriptionManagerEndpoint client = createSubscriptionManagerClient(resp.getSubscriptionManager().getReferenceParameters());
    GetStatusResponse response = client.getStatusOp(new GetStatus());
    System.out.println("EXPIRES: " + response.getGrantedExpires().getValue());
    Assert.assertTrue("GetStatus operation should return a XMLGregorianCalendar", DurationAndDateUtil.isXMLGregorianCalendar(response.getGrantedExpires().getValue()));
}
Also used : GetStatusResponse(org.apache.cxf.ws.eventing.GetStatusResponse) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) SubscriptionManagerEndpoint(org.apache.cxf.ws.eventing.manager.SubscriptionManagerEndpoint) Subscribe(org.apache.cxf.ws.eventing.Subscribe) SubscribeResponse(org.apache.cxf.ws.eventing.SubscribeResponse) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) GetStatus(org.apache.cxf.ws.eventing.GetStatus) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Example 10 with ExpirationType

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

Aggregations

ExpirationType (org.apache.cxf.ws.eventing.ExpirationType)21 Subscribe (org.apache.cxf.ws.eventing.Subscribe)17 DeliveryType (org.apache.cxf.ws.eventing.DeliveryType)16 SimpleEventingIntegrationTest (org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)16 Test (org.junit.Test)16 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)9 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)9 ObjectFactory (org.apache.cxf.ws.eventing.ObjectFactory)9 Server (org.apache.cxf.endpoint.Server)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 FireEvent (org.apache.cxf.ws.eventing.integration.notificationapi.FireEvent)8 SubscribeResponse (org.apache.cxf.ws.eventing.SubscribeResponse)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 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 GetStatusResponse (org.apache.cxf.ws.eventing.GetStatusResponse)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2