* @return The identified Device.
* @throws RepositoryException If there is a problem retrieving the Device.
*/
public Device getDevice(HttpServletRequest request)
throws RepositoryException {
Volantis volantisBean = ApplicationInternals.getVolantisBean(this);
if (volantisBean == null) {
throw new IllegalStateException("MCS Application not initialised");
}
// Get the session
HttpSession session = request.getSession(true);
if (logger.isDebugEnabled()) {
logger.debug("Session information: " + session.toString());
logger.debug("Session max interval time: " +
session.getMaxInactiveInterval());
}
// See if the device has previously been stored in the session and
// use it if it has.
DefaultDevice device = (DefaultDevice)
session.getAttribute(SESSION_DEVICE_NAME);
// Throw away devices which were constructed via serialisation
// from persisted sessions, since we do not properly support
// serialisation for now.
if (device != null && !device.isValid()) {
device = null;
}
// No device in the session, so we need to ID it.
if(device == null) {
// Use the device repository to retrieve the device.
DeviceRepository deviceRepository;
try {
deviceRepository = getRuntimeDeviceRepository();
HttpHeaders headers = servletFactory.getHTTPHeaders(request);
String defaultDeviceName = volantisBean.getDevicesConfiguration().getDefaultDeviceName();
// null value of defaultDeviceName is OK, it means that
// we let DeviceRepository subsystem use its own default
device = (DefaultDevice) deviceRepository
.getDevice(headers, defaultDeviceName);