Search in sources :

Example 1 with SubscribeResponse

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

the class AbstractEventSource method generateResponseMessageFor.

protected SubscribeResponse generateResponseMessageFor(SubscriptionTicketGrantingResponse dbResponse, boolean shouldConvertToDuration) {
    SubscribeResponse ret = new SubscribeResponse();
    // SubscriptionManager part
    ret.setSubscriptionManager(dbResponse.getSubscriptionManagerReference());
    // Expires part
    if (shouldConvertToDuration) {
        ret.setGrantedExpires(DurationAndDateUtil.toExpirationTypeContainingDuration(dbResponse.getExpires()));
    } else {
        ret.setGrantedExpires(DurationAndDateUtil.toExpirationTypeContainingGregorianCalendar(dbResponse.getExpires()));
    }
    return ret;
}
Also used : SubscribeResponse(org.apache.cxf.ws.eventing.SubscribeResponse)

Example 2 with SubscribeResponse

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

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

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

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

Aggregations

SubscribeResponse (org.apache.cxf.ws.eventing.SubscribeResponse)9 Subscribe (org.apache.cxf.ws.eventing.Subscribe)8 DeliveryType (org.apache.cxf.ws.eventing.DeliveryType)7 SimpleEventingIntegrationTest (org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)7 Test (org.junit.Test)7 ExpirationType (org.apache.cxf.ws.eventing.ExpirationType)6 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 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 Renew (org.apache.cxf.ws.eventing.Renew)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 QName (javax.xml.namespace.QName)1 Server (org.apache.cxf.endpoint.Server)1 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)1 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)1