Search in sources :

Example 16 with Subscribe

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

the class SubscriptionGrantingTest method cannotProcessFilter.

@Test
public void cannotProcessFilter() 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());
    subscribe.setFilter(new FilterType());
    subscribe.getFilter().getContent().add("@^5this-is-not-a-valid-xpath-expression!!!*-/");
    try {
        eventSourceClient.subscribeOp(subscribe);
    } catch (SOAPFaultException ex) {
        Assert.assertTrue(ex.getFault().getFaultCode().contains(CannotProcessFilter.LOCAL_PART));
        Assert.assertTrue(ex.getFault().getTextContent().contains(CannotProcessFilter.REASON));
        return;
    }
    Assert.fail("Event source should have sent a CannotProcessFilter fault");
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) FilterType(org.apache.cxf.ws.eventing.FilterType) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Subscribe(org.apache.cxf.ws.eventing.Subscribe) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Example 17 with Subscribe

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

the class SubscriptionManagementTest method renewWithDateTime.

/**
 * Tests the Renew operation, while specifying an xs:dateTime in the renew request,
 * eg. the subscriber requests to set the subscription expiration to a specific date/time.
 */
@Test
public void renewWithDateTime() throws IOException {
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp(// 5 minutes
    "2018-10-21T14:52:46.826+02:00")));
    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());
    String expirationBefore = response.getGrantedExpires().getValue();
    System.out.println("EXPIRES before renew: " + expirationBefore);
    Assert.assertTrue(expirationBefore.length() > 0);
    Renew renewRequest = new Renew();
    ExpirationType renewExp = new ExpirationType();
    renewExp.setValue(DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp(// 10 minutes
    "2056-10-21T14:54:46.826+02:00")));
    renewRequest.setExpires(renewExp);
    client.renewOp(renewRequest);
    response = client.getStatusOp(new GetStatus());
    String expirationAfter = response.getGrantedExpires().getValue();
    System.out.println("EXPIRES after renew: " + expirationAfter);
    Assert.assertFalse("Renew request should change the expiration time at least a bit", expirationAfter.equals(expirationBefore));
}
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) Renew(org.apache.cxf.ws.eventing.Renew) 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 18 with Subscribe

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

the class SubscriptionManagementTest method renewWithDuration.

/**
 * Tests the Renew operation, while specifying an xs:duration in the renew request,
 * eg. the subscriber requests to prolong the subscription by a specific amount of time.
 */
@Test
public void renewWithDuration() throws IOException {
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(DurationAndDateUtil.convertToXMLString(// 5 minutes
    DurationAndDateUtil.parseDurationOrTimestamp("PT5M0S")));
    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());
    String expirationBefore = response.getGrantedExpires().getValue();
    System.out.println("EXPIRES before renew: " + expirationBefore);
    Assert.assertTrue(expirationBefore.length() > 0);
    Renew renewRequest = new Renew();
    ExpirationType renewExp = new ExpirationType();
    renewExp.setValue(DurationAndDateUtil.convertToXMLString(// 10 minutes
    DurationAndDateUtil.parseDurationOrTimestamp("PT10M0S")));
    renewRequest.setExpires(renewExp);
    client.renewOp(renewRequest);
    response = client.getStatusOp(new GetStatus());
    String expirationAfter = response.getGrantedExpires().getValue();
    System.out.println("EXPIRES after renew: " + expirationAfter);
    Assert.assertFalse("Renew request should change the expiration time at least a bit", expirationAfter.equals(expirationBefore));
}
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) Renew(org.apache.cxf.ws.eventing.Renew) 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 19 with Subscribe

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

the class SubscriptionManagementTest method unsubscribeAndThenGetStatus.

/**
 * Tries to create a subscription, then cancel it, then obtain its status.
 * The last mentioned operation should fail.
 */
@Test
public void unsubscribeAndThenGetStatus() 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 subscribeResponse = eventSourceClient.subscribeOp(subscribe);
    SubscriptionManagerEndpoint client = createSubscriptionManagerClient(subscribeResponse.getSubscriptionManager().getReferenceParameters());
    UnsubscribeResponse unsubscribeResponse = client.unsubscribeOp(new Unsubscribe());
    Assert.assertNotNull(unsubscribeResponse);
    try {
        client.getStatusOp(new GetStatus());
    } catch (javax.xml.ws.soap.SOAPFaultException ex) {
        Assert.assertTrue(ex.getFault().getFaultCode().contains(UnknownSubscription.LOCAL_PART));
        Assert.assertTrue(ex.getFault().getTextContent().contains(UnknownSubscription.REASON));
        return;
    }
    Assert.fail("The subscription manager should have refused to send status of a cancelled subscription");
}
Also used : 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) UnsubscribeResponse(org.apache.cxf.ws.eventing.UnsubscribeResponse) Unsubscribe(org.apache.cxf.ws.eventing.Unsubscribe) 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)

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