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;
}
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()));
}
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()));
}
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);
}
}
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());
}
}
Aggregations