PushContext pushContext = pushContextFactory.getPushContext();
String forgetPushSessionId = externalContext.getRequestParameterMap().get(FORGET_PUSH_SESSION_ID_PARAM);
if (forgetPushSessionId != null) {
Session oldSession = pushContext.getSessionManager().getPushSession(forgetPushSessionId);
if (oldSession != null) {
oldSession.invalidate();
}
}
Session session = pushContext.getSessionFactory().createSession(UUID.randomUUID().toString());
String[] topicNames = externalContext.getRequestParameterValuesMap().get(PUSH_TOPIC_PARAM);
if (topicNames == null) {
throw new IllegalArgumentException(PUSH_TOPIC_PARAM + " request parameter must be present");
}
session.subscribe(topicNames);
Map<String, Object> subscriptionData = new HashMap<String, Object>(4);
subscriptionData.put("sessionId", session.getId());
Map<TopicKey, String> failedSubscriptions = session.getFailedSubscriptions();
subscriptionData.put("failures", getFailuresMap(failedSubscriptions));
Writer outWriter = facesContext.getExternalContext().getResponseOutputWriter();
ScriptUtils.appendScript(outWriter, subscriptionData);
}