Search in sources :

Example 6 with Subscribe

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

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

the class CreateSubscriptionServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        resp.getWriter().append("<html><body>");
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(EventSourceEndpoint.class);
        factory.setAddress("http://localhost:8080/ws_eventing/services/EventSource");
        EventSourceEndpoint requestorClient = (EventSourceEndpoint) factory.create();
        String expires = null;
        if (req.getParameter("expires-set") == null) {
            expires = req.getParameter("expires");
        } else {
            if (!req.getParameter("expires-set").equals("false")) {
                expires = req.getParameter("expires");
            }
        }
        Subscribe sub = createSubscribeMessage(req.getParameter("targeturl"), req.getParameter("filter-set") == null ? req.getParameter("filter") : null, expires);
        resp.getWriter().append("<h3>Subscription request</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(sub));
        SubscribeResponse subscribeResponse = requestorClient.subscribeOp(sub);
        resp.getWriter().append("<h3>Response from Event Source</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(subscribeResponse));
        resp.getWriter().append("<br/><a href=\"index.jsp\">Back to main page</a>");
        resp.getWriter().append("</body></html>");
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) EventSourceEndpoint(org.apache.cxf.ws.eventing.eventsource.EventSourceEndpoint) Subscribe(org.apache.cxf.ws.eventing.Subscribe) SubscribeResponse(org.apache.cxf.ws.eventing.SubscribeResponse) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 8 with Subscribe

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

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

the class NotificationTest method basicReceptionOfEvents.

@Test
public void basicReceptionOfEvents() 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));
    eventSourceClient.subscribeOp(subscribe);
    eventSourceClient.subscribeOp(subscribe);
    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() == 3) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 3) {
        Assert.fail("TestingEventSinkImpl should have received 3 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 10 with Subscribe

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

the class NotificationTest method withFilter2.

/**
 * We request only to receive notifications about earthquakes in Russia with Richter scale equal to 3.5
 * and there will be one fire in Canada and one earthquake in Russia. We should
 * receive only one notification.
 */
@Test
public void withFilter2() 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()='earthquake']/location[text()='Russia']/" + "../richterScale[contains(text(),'3.5')]");
    eventSourceClient.subscribeOp(subscribe);
    Server eventSinkServer = createEventSink(url);
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    TestingEventSinkImpl.RECEIVED_EARTHQUAKES.set(0);
    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    emitter.dispatch(new EarthquakeEvent(3.5f, "Russia"));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    if (TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get() != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 earthquake event but received " + TestingEventSinkImpl.RECEIVED_EARTHQUAKES.get());
    }
    if (TestingEventSinkImpl.RECEIVED_FIRES.get() != 0) {
        Assert.fail("TestingEventSinkImpl should have not received a fire event" + 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) EarthquakeEvent(org.apache.cxf.ws.eventing.integration.notificationapi.EarthquakeEvent) 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

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