/* ---------------------------------------------------------------------------- * (c) Copyright European Space Agency, 2017 * European Space Operations Centre * Darmstadt Germany * The copyright of this document is vested in the European Space Agency. This * document may only be reproduced in whole or in part, stored in a retrieval * system, transmitted in any form, or by any means e.g. electronically, * mechanically or by photocopying, or otherwise, with the prior permission of * the Agency. * ---------------------------------------------------------------------------- * System : EDDS * Component : edds-stream-client * Classname : esa.egos.edds.streamclient.PacketTmStore.java * ---------------------------------------------------------------------------- */ package esa.egos.edds.streamclient; import java.io.IOException; import javax.annotation.PostConstruct; import javax.xml.bind.JAXBException; import javax.xml.ws.WebServiceException; import org.apache.log4j.Logger; import org.springframework.beans.factory.InitializingBean; import esa.egos.edds.model.JobIdPart; import esa.egos.edds.model.PacketTMProto.PacketTMBinary; import esa.egos.edds.notifications.NotificationChannel; import esa.egos.edds.service.AuthenticationFault; import esa.egos.edds.service.AuthorizationFault; import esa.egos.edds.service.PasswordExpiredFault; import esa.egos.edds.service.RequestFault; import esa.egos.edds.service.SessionFault; import esa.egos.edds.streamclient.store.StoreTmToFile; import esa.egos.edds.streamclient.store.tm.TmToFileFactory; import esa.egos.edds.ws.client.EddsService; import esa.egos.edds.ws.client.notifications.NotificationListener; import esa.egos.edds.ws.client.notifications.NotificationManager; /** * Main class to manage and start the saving process of stream data. */ public class PacketTmStore implements NotificationListener , InitializingBean { /** The logger interface. */ private static final Logger logger = Logger.getLogger(PacketTmStore.class); /** The EDDS Web Server interface. */ private EddsService eddsService; /** The username to log in with. */ private String username; /** The password to log in with. */ private String password; /** The request id. */ private static String requestId; /** The outbox. */ private String outbox; /** The service address. */ private String serviceAddress; /** The file store maganer. */ private StoreTmToFile fileStoreManager; /** The save time interval in sec. */ private long saveTimeIntervalInSec = 30; /** The output format. */ private String outputFormat; /** The event type */ private static int spacecrafteventType; /** * Inits the configuration and start stream listening. * * @throws WebServiceException the web service exception * @throws AuthenticationFault the authentication fault * @throws PasswordExpiredFault the password expired fault * @throws AuthorizationFault the authorization fault * @throws SessionFault the session fault * @throws RequestFault the request fault * @throws JAXBException the JAXB exception * @throws IOException Signals that an I/O exception has occurred. */ @PostConstruct public void init() throws WebServiceException, AuthenticationFault, PasswordExpiredFault, AuthorizationFault, SessionFault, RequestFault, JAXBException, IOException { logger.info("Logging in..."); String sessionId = null; logger.info("Asking for request ID: " + requestId); JobIdPart jobPart = new JobIdPart(); jobPart.setJob(requestId); NotificationManager nm = null; try { nm = new NotificationManager(eddsService, serviceAddress); eddsService.setNotificationManager(nm); eddsService.connectToServer(); sessionId = eddsService.logIn(username, password); this.fileStoreManager = TmToFileFactory.getFileStorerByType(outputFormat, saveTimeIntervalInSec, outbox); nm.registerListener(NotificationChannel.PKT_TM_STREAM, this); eddsService.startStreamData(jobPart); } catch (Exception e) { logger.error("ERROR:" + e.getMessage()); } logger.debug("Expired: " + eddsService.hasSessionExpired()); logger.debug("Is connected: " + nm.isConnected()); logger.info("Session id: " + sessionId); logger.info("Init complete"); } /** * On notification. * * @param notification the notification * @param requestId the request id * @see esa.egos.edds.ws.client.notifications.NotificationListener#onNotification(java.lang.Object, java.lang.String) */ @Override public void onNotification(PacketTMBinary notification, String requestId) { if (PacketTmStore.requestId.equals(requestId)) { logger.debug("PACKET: " + requestId + "\n" + notification); try { fileStoreManager.save(notification); } catch (IOException e) { logger.error(e.getMessage()); } } } /** * Gets the edds service. * * @return the edds service */ public EddsService getEddsService() { return eddsService; } /** * Sets the edds service. * * @param eddsService the new edds service */ public void setEddsService(EddsService eddsService) { this.eddsService = eddsService; } /** * Gets the username. * * @return the username */ public String getUsername() { return username; } /** * Sets the username. * * @param username the new username */ public void setUsername(String username) { this.username = username; } /** * Gets the password. * * @return the password */ public String getPassword() { return password; } /** * Sets the password. * * @param password the new password */ public void setPassword(String password) { this.password = password; } /** * Gets the request id. * * @return the request id */ public static String getRequestId() { return requestId; } /** * Sets the request id. * * @param requestId the new request id */ public static void setRequestId(String requestId) { PacketTmStore.requestId = requestId; } /** * Gets the outbox. * * @return the outbox */ public String getOutbox() { return outbox; } /** * Sets the outbox. * * @param outbox the new outbox */ public void setOutbox(String outbox) { this.outbox = outbox; } /** * Gets the service address. * * @return the service address */ public String getServiceAddress() { return serviceAddress; } /** * Sets the service address. * * @param serviceAddress the new service address */ public void setServiceAddress(String serviceAddress) { this.serviceAddress = serviceAddress; } /** * Gets the save time interval in sec. * * @return the save time interval in sec */ public long getSaveTimeIntervalInSec() { return saveTimeIntervalInSec; } /** * Gets the output format. * * @return the output format */ public String getOutputFormat() { return outputFormat; } /** * Sets the output format. * * @param outputFormat the new output format */ public void setOutputFormat(String outputFormat) { this.outputFormat = outputFormat; } /** * Sets the save time interval in sec. * * @param saveTimeIntervalInSec the new save time interval in sec */ public void setSaveTimeIntervalInSec(long saveTimeIntervalInSec) { this.saveTimeIntervalInSec = saveTimeIntervalInSec; } /** * @return the spacecrafteventType */ public static int getSpacecrafteventType() { return spacecrafteventType; } /** * @param spacecrafteventType the spacecrafteventType to set */ public static void setSpacecrafteventType(int spacecrafteventType) { PacketTmStore.spacecrafteventType = spacecrafteventType; } /** * After properties set. * * @throws Exception the exception * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { init(); } }