List of usage examples for javax.management AttributeList AttributeList
public AttributeList()
AttributeList
. From source file:org.rifidi.edge.rest.SensorManagerServiceRestletImpl.java
public Router initRestlet() { final SensorManagerServiceRestletImpl self = this; Restlet readers = new Restlet() { @Override//from w ww . j ava 2 s . c o m public void handle(Request request, Response response) { logger.info("readers requested"); setResponseHeaders(request, response); Set<ReaderDTO> dtos = sensorManagerService.getReaders(); List<ReaderNameDTO> rnd = new LinkedList<ReaderNameDTO>(); for (ReaderDTO dto : dtos) { ReaderNameDTO r = new ReaderNameDTO(); r.setReaderID(dto.getReaderID()); r.setReaderType(dto.getReaderFactoryID()); rnd.add(r); } ReaderResponseMessageDTO rrmd = new ReaderResponseMessageDTO(); rrmd.setReaders(rnd); response.setEntity(self.generateReturnString(rrmd), MediaType.TEXT_XML); } }; Restlet commands = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("commands requested"); setResponseHeaders(request, response); Set<CommandConfigurationDTO> dtos = commandManagerService.getCommands(); List<CommandNameDTO> cnd = new LinkedList<CommandNameDTO>(); for (CommandConfigurationDTO dto : dtos) { CommandNameDTO c = new CommandNameDTO(); c.setCommandID(dto.getCommandConfigID()); c.setCommandType(dto.getCommandConfigFactoryID()); cnd.add(c); } CommandResponseMessageDTO crmd = new CommandResponseMessageDTO(); crmd.setCommands(cnd); response.setEntity(self.generateReturnString(crmd), MediaType.TEXT_XML); } }; Restlet readerStatus = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("readerStatus requested"); setResponseHeaders(request, response); Set<ReaderDTO> dtos = sensorManagerService.getReaders(); ReaderStatusResponseMessageDTO rsrmd = new ReaderStatusResponseMessageDTO(); boolean readerFound = false; try { for (ReaderDTO dto : dtos) { if (dto.getReaderID().equals(request.getAttributes().get("readerID"))) { readerFound = true; ReaderNameDTO r = new ReaderNameDTO(); r.setReaderID(dto.getReaderID()); r.setReaderType(dto.getReaderFactoryID()); rsrmd.setReader(r); List<SessionNameDTO> slist = new LinkedList<SessionNameDTO>(); for (SessionDTO sdto : dto.getSessions()) { SessionNameDTO snd = new SessionNameDTO(); snd.setSessionId(sdto.getID()); snd.setSessionStatus(sdto.getStatus().toString()); List<ExecutingCommandDTO> exec = new ArrayList<ExecutingCommandDTO>(); for (CommandDTO command : sdto.getCommands()) { ExecutingCommandDTO ecdto = new ExecutingCommandDTO(); ecdto.setCommandID(command.getCommandID()); Set<CommandConfigurationDTO> configdtos = commandManagerService.getCommands(); for (CommandConfigurationDTO configdto : configdtos) { if (configdto.getCommandConfigID().equals(command.getCommandID())) { ecdto.setFactoryID(configdto.getCommandConfigFactoryID()); } } ecdto.setInterval(command.getInterval()); exec.add(ecdto); } snd.setExecutingCommands(exec); slist.add(snd); } rsrmd.setSessions(slist); response.setEntity(self.generateReturnString(rsrmd), MediaType.TEXT_XML); break; } } if (!readerFound) { throw new Exception( "No reader with ID " + request.getAttributes().get("readerID") + " found."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet startSession = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("startSession requested"); setResponseHeaders(request, response); String strReaderId = (String) request.getAttributes().get("readerID"); String strSessionID = (String) request.getAttributes().get("sessionID"); SessionStatus checkSessionState = sensorManagerService.getSession(strReaderId, strSessionID) .getStatus(); if (!checkSessionState.equals(SessionStatus.PROCESSING) && !checkSessionState.equals(SessionStatus.CONNECTING)) { sensorManagerService.startSession(strReaderId, strSessionID); SessionStatus currentSessionState = checkSessionState(strReaderId, strSessionID, SessionStatus.PROCESSING); if (currentSessionState.equals(SessionStatus.PROCESSING)) { // Generate a success message response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { // Generate a failure message with // currentSessionStatus response.setEntity(self.generateReturnString(self.generateErrorMessage( "Session already started, current state is " + currentSessionState + " - See Rifidi Edge Sever Log for details", currentSessionState.toString())), MediaType.TEXT_XML); } } else { response.setEntity(self.generateReturnString(self.generateErrorMessage( "Unable to start session, current state is " + checkSessionState, checkSessionState.toString())), MediaType.TEXT_XML); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet stopSession = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("stopSession requested"); setResponseHeaders(request, response); String strReaderId = (String) request.getAttributes().get("readerID"); String strSessionID = (String) request.getAttributes().get("sessionID"); sensorManagerService.stopSession(strReaderId, strSessionID); SessionStatus currentSessionState = checkSessionState(strReaderId, strSessionID, SessionStatus.CLOSED); if (currentSessionState.equals(SessionStatus.CLOSED)) { // Generate a success message response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { // Generate a failure message with currentSessionStatus response.setEntity(self.generateReturnString(self.generateErrorMessage( "Unable to stop session, current state is " + currentSessionState + " - See Rifidi Edge Sever Log for details", currentSessionState.toString())), MediaType.TEXT_XML); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet createSession = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("createSession requested"); String readerID = (String) request.getAttributes().get("readerID"); List<SessionDTO> sessions = sensorManagerService.getReader(readerID).getSessions(); // only one session allowed. if (!sessions.isEmpty()) { throw new Exception("Reader " + readerID + " already has a session."); } setResponseHeaders(request, response); sensorManagerService.createSession(readerID); CreateSessionResponseMessageDTO sr = new CreateSessionResponseMessageDTO(); sr.setSessionID(1); // The sessionID for any reader should // be 1. response.setEntity(self.generateReturnString(sr), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet deleteSession = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("deleteSession requested"); setResponseHeaders(request, response); sensorManagerService.deleteSession((String) request.getAttributes().get("readerID"), (String) request.getAttributes().get("sessionID")); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet resetSession = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("resetSession requested"); String readerID = (String) request.getAttributes().get("readerID"); String sessionID = (String) request.getAttributes().get("sessionID"); setResponseHeaders(request, response); //Get the current commands List<CommandDTO> commands = sensorManagerService.getSession(readerID, sessionID).getCommands(); //Delete the session sensorManagerService.deleteSession(readerID, sessionID); //Recreate the session sensorManagerService.createSession(readerID); //Re-execute commands for (CommandDTO command : commands) { sensorManagerService.submitCommand(readerID, sessionID, command.getCommandID(), command.getInterval(), command.getTimeUnit()); } //Start the session sensorManagerService.startSession(readerID, sessionID); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet deleteReader = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("deleteReader requested"); setResponseHeaders(request, response); sensorManagerService.deleteReader((String) request.getAttributes().get("readerID")); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet deleteCommand = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("deleteCommand requested"); setResponseHeaders(request, response); commandManagerService.deleteCommand((String) request.getAttributes().get("commandID")); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet executeCommand = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("executeCommand requested"); setResponseHeaders(request, response); sensorManagerService.submitCommand((String) request.getAttributes().get("readerID"), (String) request.getAttributes().get("sessionID"), (String) request.getAttributes().get("commandID"), Long.parseLong((String) request.getAttributes().get("repeatInterval")), TimeUnit.MILLISECONDS); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (NumberFormatException nEx) { response.setEntity(self.generateReturnString(self.generateErrorMessage(nEx.getMessage(), null)), MediaType.TEXT_XML); } catch (CommandSubmissionException cEx) { response.setEntity(self.generateReturnString(self.generateErrorMessage(cEx.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet setProperties = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("setProperties requested"); try { setResponseHeaders(request, response); String strObjectId = (String) request.getAttributes().get("readerID"); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); boolean readerExists = readerExists(strObjectId); boolean commandExists = commandExists(strObjectId); // Check if command or reader exists before submit // getproperties if (!commandExists && !readerExists) { throw new Exception("Neither reader nor command with id " + strObjectId + " exist"); } AttributeList attributes = getProcessedAttributes(strPropAttr); // Check if reader id exists if (readerExists) { // Set properties for reader, if parameter is a reader // id sensorManagerService.setReaderProperties(strObjectId, attributes); } else if (commandExists) { // Check if command exists // Set properties for command, if parameter is a command // id commandManagerService.setCommandProperties(strObjectId, attributes); } // Validate properties for this reader or command validateAttributesForReaderOrCommand(strObjectId, attributes); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (NotValidPropertyForObjectException nEx) { response.setEntity(self.generateReturnString(self.generateWarningMessage(nEx.getMessage())), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet getProperties = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("getProperties requested"); try { setResponseHeaders(request, response); String strObjectId = (String) request.getAttributes().get("readerID"); // Check if reader or command exists before submit // getproperties if (!commandExists(strObjectId) && !readerExists(strObjectId)) { throw new Exception("Neither reader nor command with id " + strObjectId + " exist"); } Configuration configuration = configService.getConfiguration(strObjectId); PropertyResponseMessageDTO prmd = new PropertyResponseMessageDTO(); List<PropertyNameDTO> pndList = new LinkedList<PropertyNameDTO>(); for (String key : configuration.getAttributes().keySet()) { PropertyNameDTO pnd = new PropertyNameDTO(); pnd.setPropertyName(key); if (configuration.getAttributes().get(key) != null) { pnd.setPropertyValue(configuration.getAttributes().get(key).toString()); } else { pnd.setPropertyValue("null"); } pndList.add(pnd); } prmd.setProperties(pndList); // System.out.println(self.generateReturnString(prmd) // .toString()); response.setEntity(self.generateReturnString(prmd).toString(), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet createReader = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("createReader requested"); String readerId = null; try { setResponseHeaders(request, response); String strReaderType = (String) request.getAttributes().get("readerType"); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes AttributeList attributes = new AttributeList(); if (strPropAttr != null) { strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); attributes = getProcessedAttributes(strPropAttr); // From attributes, extract the readerID property if is // there Attribute attributeToDelete = null; for (Attribute attribute : attributes.asList()) { if (attribute.getName().equals(ReaderIDPropertyName)) { readerId = (String) attribute.getValue(); // remove readerID from attributes, so when the // time // to validate the properties for reader comes, // it does // not throw error because of this readerID // property name // Hold a reference of attribute to be deleted, // to delete // outside this loop, because if try to delete // inside, // we get an ConcurrentModificationException attributeToDelete = attribute; } } if (attributeToDelete != null) { attributes.remove(attributeToDelete); } } // Create reader if (readerId == null) { // no reader id is provided, so call the default create // method readerId = sensorManagerService.createReader(strReaderType, attributes); } else { // reader id is provided readerId = sensorManagerService.createReader(strReaderType, attributes, readerId); } // Validate what properties are wrong for this created // reader validateAttributesForReaderOrCommand(readerId, attributes); CreateReaderResponseMessageDTO crmd = new CreateReaderResponseMessageDTO(); crmd.setReaderID(readerId); response.setEntity(self.generateReturnString(crmd), MediaType.TEXT_XML); } catch (NotValidPropertyForObjectException nE) { // If there was an invalid property creating the reader, // and the reader was created, the reader must be deleted if (readerId != null) { sensorManagerService.deleteReader(readerId); } response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet createCommand = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("createCommand requested"); String strCommandId = null; try { setResponseHeaders(request, response); String strPropAttr = (String) request.getAttributes().get("properties"); AttributeList attributes = new AttributeList(); if (strPropAttr != null) { // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); attributes = getProcessedAttributes(strPropAttr); } // Create the command strCommandId = self.commandManagerService .createCommand((String) request.getAttributes().get("commandType"), attributes); // Validate properties for this command validateAttributesForReaderOrCommand(strCommandId, attributes); CreateCommandResponseMessageDTO ccrmd = new CreateCommandResponseMessageDTO(); ccrmd.setCommandID(strCommandId); response.setEntity(self.generateReturnString(ccrmd), MediaType.TEXT_XML); } catch (NotValidPropertyForObjectException nE) { // If there was an invalid property creating the command, // and the command was created, the command must be deleted if (strCommandId != null) { commandManagerService.deleteCommand(strCommandId); } response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet startApp = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("startApp requested"); try { setResponseHeaders(request, response); appManager.startApp((Integer.parseInt((String) request.getAttributes().get("appID")))); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet stopApp = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("stopApp requested"); try { setResponseHeaders(request, response); appManager.stopApp((Integer.parseInt((String) request.getAttributes().get("appID")))); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet readerTypes = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("readerTypes requested"); try { setResponseHeaders(request, response); ReaderTypesReponseMessageDTO rtr = new ReaderTypesReponseMessageDTO(); Set<ReaderFactoryDTO> grf = self.sensorManagerService.getReaderFactories(); List<ReaderTypeDTO> ret = new LinkedList<ReaderTypeDTO>(); for (ReaderFactoryDTO rfd : grf) { ReaderTypeDTO rtd = new ReaderTypeDTO(); rtd.setReaderDesc(rfd.getReaderFactoryDescription()); rtd.setReaderType(rfd.getReaderFactoryID()); ret.add(rtd); } rtr.setSensors(ret); response.setEntity(self.generateReturnString(rtr).toString(), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet readerMetadata = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("readerMetadata requested"); try { setResponseHeaders(request, response); ReaderMetadataResponseMessageDTO rmrmd = new ReaderMetadataResponseMessageDTO(); String cat_str = "org.rifidi.edge.category"; String order_value = "org.rifidi.edge.ordervalue"; String display_name = "displayName"; List<ReaderFactoryMetadataDTO> readerFactoryMetadataList = new ArrayList<ReaderFactoryMetadataDTO>(); Set<AbstractSensorFactory<?>> readerfactories = self.readerDAO.getReaderFactories(); for (AbstractSensorFactory<?> factory : readerfactories) { List<ReaderMetadataDTO> readerMetadataList = new ArrayList<ReaderMetadataDTO>(); MBeanAttributeInfo[] attArray = factory.getServiceDescription(factory.getFactoryID()) .getAttributes(); for (MBeanAttributeInfo att : attArray) { ReaderMetadataDTO readerMetadata = new ReaderMetadataDTO(); OpenMBeanAttributeInfoSupport supp = (OpenMBeanAttributeInfoSupport) att; if (supp.getDefaultValue() != null) { readerMetadata.setDefaultValue(supp.getDefaultValue().toString()); } if (supp.getDescription() != null) { readerMetadata.setDescription(supp.getDescription()); } if (supp.getMaxValue() != null) { readerMetadata.setMaxValue(supp.getMaxValue().toString()); } if (supp.getMinValue() != null) { readerMetadata.setMinValue(supp.getMinValue().toString()); } if (supp.getType() != null) { readerMetadata.setType(supp.getType()); } if (supp.getName() != null) { readerMetadata.setName(supp.getName()); } if (supp.getDescriptor().getFieldValue(cat_str) != null) { readerMetadata.setCategory((String) supp.getDescriptor().getFieldValue(cat_str)); } if (supp.getDescriptor().getFieldValue(order_value) != null) { readerMetadata .setOrderValue((Float) supp.getDescriptor().getFieldValue(order_value)); } if (supp.getDescriptor().getFieldValue(display_name) != null) { readerMetadata .setDisplayName((String) supp.getDescriptor().getFieldValue(display_name)); } readerMetadata.setWritable(supp.isWritable()); readerMetadataList.add(readerMetadata); } ReaderFactoryMetadataDTO readerMetaFactory = new ReaderFactoryMetadataDTO(); readerMetaFactory.setReadermetadata(readerMetadataList); readerMetaFactory.setId(factory.getFactoryID()); readerFactoryMetadataList.add(readerMetaFactory); } List<CommandFactoryMetadataDTO> commandFactoryMetadataList = new ArrayList<CommandFactoryMetadataDTO>(); Set<AbstractCommandConfigurationFactory<?>> commandfactories = self.commandDAO .getCommandFactories(); for (AbstractCommandConfigurationFactory<?> factory : commandfactories) { List<CommandMetadataDTO> commandMetadataList = new ArrayList<CommandMetadataDTO>(); MBeanAttributeInfo[] attArray = factory.getServiceDescription(factory.getFactoryID()) .getAttributes(); for (MBeanAttributeInfo att : attArray) { CommandMetadataDTO commandMetadata = new CommandMetadataDTO(); OpenMBeanAttributeInfoSupport supp = (OpenMBeanAttributeInfoSupport) att; if (supp.getDefaultValue() != null) { commandMetadata.setDefaultValue(supp.getDefaultValue().toString()); } if (supp.getDescription() != null) { commandMetadata.setDescription(supp.getDescription()); } if (supp.getMaxValue() != null) { commandMetadata.setMaxValue(supp.getMaxValue().toString()); } if (supp.getMinValue() != null) { commandMetadata.setMinValue(supp.getMinValue().toString()); } if (supp.getType() != null) { commandMetadata.setType(supp.getType()); } if (supp.getName() != null) { commandMetadata.setName(supp.getName()); } if (supp.getDescriptor().getFieldValue(cat_str) != null) { commandMetadata.setCategory((String) supp.getDescriptor().getFieldValue(cat_str)); } if (supp.getDescriptor().getFieldValue(order_value) != null) { commandMetadata .setOrderValue((Float) supp.getDescriptor().getFieldValue(order_value)); } if (supp.getDescriptor().getFieldValue(display_name) != null) { commandMetadata .setDisplayName((String) supp.getDescriptor().getFieldValue(display_name)); } commandMetadata.setWritable(supp.isWritable()); commandMetadataList.add(commandMetadata); } CommandFactoryMetadataDTO commandMetaFactory = new CommandFactoryMetadataDTO(); commandMetaFactory.setCommandmetadata(commandMetadataList); commandMetaFactory.setId(factory.getFactoryID()); commandMetaFactory.setReaderID(factory.getReaderFactoryID()); commandFactoryMetadataList.add(commandMetaFactory); } rmrmd.setCommandMetaList(commandFactoryMetadataList); rmrmd.setReaderMetaList(readerFactoryMetadataList); response.setEntity(self.generateReturnString(rmrmd).toString(), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet commandTypes = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("commandTypes requested"); try { setResponseHeaders(request, response); CommandTypesResponseMessageDTO rtr = new CommandTypesResponseMessageDTO(); Set<CommandConfigFactoryDTO> grf = self.commandManagerService.getCommandConfigFactories(); List<CommandTypeDTO> ret = new LinkedList<CommandTypeDTO>(); for (CommandConfigFactoryDTO rfd : grf) { CommandTypeDTO rtd = new CommandTypeDTO(); rtd.setCommandDesc(rfd.getDescription()); rtd.setCommandType(rfd.getCommandFactoryID()); rtd.setReaderFactory(rfd.getReaderFactoryID()); ret.add(rtd); } rtr.setCommands(ret); response.setEntity(self.generateReturnString(rtr).toString(), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet apps = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("apps requested"); try { setResponseHeaders(request, response); Map<Integer, RifidiApp> apps = appManager.getApps(); List<AppNameDTO> appNames = new LinkedList<AppNameDTO>(); for (Integer i : apps.keySet()) { AppNameDTO and = new AppNameDTO(); and.setAppName(apps.get(i).getGroup() + ":" + apps.get(i).getName()); and.setAppNumber(Integer.toString(i)); and.setAppStatus(apps.get(i).getState().toString()); appNames.add(and); } AppResponseMessageDTO armd = new AppResponseMessageDTO(); armd.setApps(appNames); response.setEntity(self.generateReturnString(armd), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet loadApp = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("loadApp requested"); try { provisioningService.provision((String) request.getAttributes().get("path")); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet save = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("save requested"); try { setResponseHeaders(request, response); configService.storeConfiguration(); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet currenttags = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("currenttags requested"); try { setResponseHeaders(request, response); Map<String, CurrentTagDTO> currenttags = new HashMap<String, CurrentTagDTO>(); CurrentTagsSubscriber sub = new CurrentTagsSubscriber(currenttags); ReadZone zone = new ReadZone((String) request.getAttributes().get("readerID")); CurrentTagsAggregator agg = new CurrentTagsAggregator(sub, zone, rawTagMonitoringService); agg.initstart(); CurrentTagsReponseMessageDTO tagresponse = new CurrentTagsReponseMessageDTO(); List<CurrentTagDTO> tempList = new ArrayList<CurrentTagDTO>(); tempList.addAll(currenttags.values()); tagresponse.setTags(tempList); response.setEntity(self.generateReturnString(tagresponse), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet llrpGetReaderConfig = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpGetReaderConfig requested"); setResponseHeaders(request, response); llrpGetOperation(request, response, LLRPGetOperations.GET_READER_CONFIG); } }; Restlet llrpGetRospecs = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpGetRospecs requested"); setResponseHeaders(request, response); llrpGetOperation(request, response, LLRPGetOperations.GET_ROSPECS); } }; Restlet llrpGetReaderCapabilities = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpGetReaderCapabilities requested"); setResponseHeaders(request, response); llrpGetOperation(request, response, LLRPGetOperations.GET_READER_CAPABILITIES); } }; Restlet llrpEncode = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpEncode requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, null); } }; Restlet llrpEpcWrite = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpEpcWrite requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPEPCWrite); } }; Restlet llrpAccessPasswordWrite = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpAccessPasswordWrite requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPAccessPasswordWrite); } }; Restlet llrpKillPasswordWrite = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpKillPasswordWrite requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPKillPasswordWrite); } }; Restlet llrpEPCLock = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpEPCLock requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPEPCLock); } }; Restlet llrpAccessPasswordLock = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpAccessPasswordLock requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPAccessPasswordLock); } }; Restlet llrpKillPasswordLock = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpKillPasswordLock requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPKillPasswordLock); } }; Restlet llrpUserMemoryLock = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpUserMemoryLock requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPUserMemoryLock); } }; Restlet llrpEpcRead = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpEpcRead requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPEPCRead); } }; Restlet llrpAccessPwdValidate = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpAccessPwdValidate requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPAccessPasswordValidate); } }; Restlet llrpKillPwdRead = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpKillPwdRead requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPKillPasswordRead); } }; Restlet llrpUserMemoryRead = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpUserMemoryRead requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPUserMemoryRead); } }; Restlet llrpUserMemoryWrite = new Restlet() { @Override public void handle(Request request, Response response) { logger.info("llrpUserMemoryWrite requested"); setResponseHeaders(request, response); executeLlrpOperation(request, response, LLRPReaderSession.LLRP_OPERATION_CODE.LLRPUserMemoryWrite); } }; Restlet llrpMessage = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("llrpMessage requested"); setResponseHeaders(request, response); AbstractSensor<?> sensor = readerDAO .getReaderByID((String) request.getAttributes().get("readerID")); if (sensor == null) { throw new Exception("ReaderID is missing or invalid"); } Map<String, SensorSession> sessionMap = sensor.getSensorSessions(); String llrpResponse = ""; if (sessionMap != null && sessionMap.containsKey(request.getAttributes().get("sessionID"))) { LLRPReaderSession session = (LLRPReaderSession) sessionMap .get(request.getAttributes().get("sessionID")); Boolean sendonly = false; try { sendonly = Boolean.parseBoolean((String) request.getAttributes().get("sendonly")); } catch (Exception e) { // Do nothing } SAXBuilder sb = new SAXBuilder(); String strEntityAsText = request.getEntityAsText(); Document doc = sb.build(new StringReader(strEntityAsText)); llrpResponse = session.sendLLRPMessage(doc, sendonly); if (llrpResponse == null) { llrpResponse = self.generateReturnString(self.generateSuccessMessage()); } response.setEntity(llrpResponse, MediaType.TEXT_XML); } else { throw new Exception("SessionID is missing or invalid"); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet ping = new Restlet() { @Override public void handle(Request request, Response response) { setResponseHeaders(request, response); PingDTO ping = new PingDTO(); ping.setTimestamp(Long.toString(System.currentTimeMillis())); response.setEntity(self.generateReturnString(ping), MediaType.TEXT_XML); } }; Restlet getAppProperties = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("getAppProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); Properties appProperties = RifidiEdgeHelper.getApplicationProperties(app.getGroup(), app.getName()); PropertyResponseMessageDTO responseMessageDTO = new PropertyResponseMessageDTO(); List<PropertyNameDTO> propertyNameList = new LinkedList<PropertyNameDTO>(); for (Map.Entry<Object, Object> mapEntry : appProperties.entrySet()) { PropertyNameDTO pnd = new PropertyNameDTO(); pnd.setPropertyName((String) mapEntry.getKey()); pnd.setPropertyValue((String) mapEntry.getValue()); propertyNameList.add(pnd); } responseMessageDTO.setProperties(propertyNameList); response.setEntity(self.generateReturnString(responseMessageDTO).toString(), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet getGroupProperties = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("getGroupProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); Properties groupProperties = RifidiEdgeHelper.getGroupProperties(app.getGroup()); PropertyResponseMessageDTO responseMessageDTO = new PropertyResponseMessageDTO(); List<PropertyNameDTO> propertyNameList = new LinkedList<PropertyNameDTO>(); for (Map.Entry<Object, Object> mapEntry : groupProperties.entrySet()) { PropertyNameDTO pnd = new PropertyNameDTO(); pnd.setPropertyName((String) mapEntry.getKey()); pnd.setPropertyValue((String) mapEntry.getValue()); propertyNameList.add(pnd); } responseMessageDTO.setProperties(propertyNameList); response.setEntity(self.generateReturnString(responseMessageDTO).toString(), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet getReadZones = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("getReadZones requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); HashMap<String, ReadZone> readZones = RifidiEdgeHelper.getReadZones(app.getGroup()); PropertyResponseMessageDTO responseMessageDTO = new PropertyResponseMessageDTO(); List<PropertyNameDTO> propertyNameList = new LinkedList<PropertyNameDTO>(); for (String strReadZone : readZones.keySet()) { PropertyNameDTO pnd = new PropertyNameDTO(); pnd.setPropertyName(null); pnd.setPropertyValue(strReadZone); propertyNameList.add(pnd); } responseMessageDTO.setProperties(propertyNameList); response.setEntity(self.generateReturnString(responseMessageDTO).toString(), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet deleteReadZone = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("deleteReadZone requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String readZone = (String) request.getAttributes().get("readZone"); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); RifidiEdgeHelper.deleteReadZone(app.getGroup(), readZone); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet getReadZoneProperties = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("getReadZoneProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String readZoneName = (String) request.getAttributes().get("readZoneName"); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); Properties readZoneProperties = RifidiEdgeHelper.getReadZoneProperties(app.getGroup(), app.getName(), readZoneName); PropertyResponseMessageDTO responseMessageDTO = new PropertyResponseMessageDTO(); List<PropertyNameDTO> propertyNameList = new LinkedList<PropertyNameDTO>(); for (Map.Entry<Object, Object> mapEntry : readZoneProperties.entrySet()) { PropertyNameDTO pnd = new PropertyNameDTO(); pnd.setPropertyName((String) mapEntry.getKey()); pnd.setPropertyValue((String) mapEntry.getValue()); propertyNameList.add(pnd); } responseMessageDTO.setProperties(propertyNameList); response.setEntity(self.generateReturnString(responseMessageDTO).toString(), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet setAppProperties = new Restlet() { @Override public void handle(Request request, Response response) { // String strCommandId = null; try { logger.info("setAppProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); AttributeList attributes = getProcessedAttributes(strPropAttr); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); RifidiEdgeHelper.setApplicationProperties(app.getGroup(), app.getName(), attributes); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (NotValidPropertyForObjectException nE) { response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { // e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet setGroupProperties = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("setGroupProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); AttributeList attributes = getProcessedAttributes(strPropAttr); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); RifidiEdgeHelper.setGroupProperties(app.getGroup(), attributes); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (NotValidPropertyForObjectException nE) { response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { // e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet addReadZone = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("addReadZone requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String readZone = (String) request.getAttributes().get("readZone"); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); AttributeList attributes = getProcessedAttributes(strPropAttr); // Validate that properties are valid for readzone validateReadzoneProperties(attributes); // Validate that properties contain the minimum required // ones validateMinumimRequiredReadzoneProperties(attributes); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); RifidiEdgeHelper.addReadZone(app.getGroup(), readZone, attributes); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (NotValidPropertyForObjectException nE) { response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { // e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet setReadZoneProperties = new Restlet() { @Override public void handle(Request request, Response response) { try { logger.info("setReadZoneProperties requested"); setResponseHeaders(request, response); Integer intAppId = Integer.parseInt((String) request.getAttributes().get("appID")); String readZone = (String) request.getAttributes().get("readZoneName"); String strPropAttr = (String) request.getAttributes().get("properties"); // Decode url attributes strPropAttr = URLDecoder.decode(strPropAttr, "UTF-8"); AttributeList attributes = getProcessedAttributes(strPropAttr); // Validate that properties are valid for readzone validateReadzoneProperties(attributes); Map<Integer, RifidiApp> appMap = appManager.getApps(); if (appMap != null && appMap.get(intAppId) != null) { RifidiApp app = appMap.get(intAppId); RifidiEdgeHelper.setReadZoneProperties(app.getGroup(), readZone, attributes); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } else { throw new Exception("Application with id " + intAppId + " does not exist."); } } catch (NotValidPropertyForObjectException nE) { response.setEntity(self.generateReturnString(self.generateErrorMessage(nE.getMessage(), null)), MediaType.TEXT_XML); } catch (Exception e) { // e.printStackTrace(); response.setEntity(self.generateReturnString(self.generateErrorMessage(e.getMessage(), null)), MediaType.TEXT_XML); } } }; Restlet updateServersFile = new Restlet() { @Override public void handle(Request request, Response response) { try { setResponseHeaders(request, response); String data = (String) request.getAttributes().get("data"); String decodedData = URLDecoder.decode(data, "UTF-8"); RifidiEdgeHelper.updateServersFile(decodedData); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet getServersFile = new Restlet() { @Override public void handle(Request request, Response response) { try { setResponseHeaders(request, response); byte[] data = RifidiEdgeHelper.getServersFile(); String str = new String(data, "UTF-8"); response.setEntity(str, MediaType.APPLICATION_JSON); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet updateUIPropertiesFile = new Restlet() { @Override public void handle(Request request, Response response) { try { setResponseHeaders(request, response); String data = (String) request.getAttributes().get("data"); String decodedData = URLDecoder.decode(data, "UTF-8"); RifidiEdgeHelper.updateUIPropertiesFile(decodedData); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet getUIPropertiesFile = new Restlet() { @Override public void handle(Request request, Response response) { try { setResponseHeaders(request, response); byte[] data = RifidiEdgeHelper.getUIPropertiesFile(); String str = new String(data, "UTF-8"); response.setEntity(str, MediaType.APPLICATION_JSON); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet addDefaultApplication = new Restlet() { @Override public void handle(Request request, Response response) { try { setResponseHeaders(request, response); String group = (String) request.getAttributes().get("group"); RifidiEdgeHelper.addDefaultApp(group); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet shutdown = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); Thread thread = new Thread(new RestletShutdown()); thread.start(); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet restart = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); if (SystemUtils.IS_OS_LINUX) { Thread thread = new Thread(new RestletRestart()); thread.start(); } else { throw new Exception("Restart will only work on Linux"); } } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet bundles = new Restlet() { @Override @Post @Get public void handle(Request request, Response response) { try { Map<Integer, String> states = new HashMap<Integer, String>(); states.put(1, "UNINSTALLED"); states.put(2, "INSTALLED"); states.put(4, "RESOLVED"); states.put(8, "STARTING"); states.put(16, "STOPPING"); states.put(32, "ACTIVE"); final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); BundleResponseMessageDTO bundleResponse = new BundleResponseMessageDTO(); List<BundleDTO> bundleDTOs = new LinkedList<BundleDTO>(); for (Bundle bundle : bundleContext.getBundles()) { BundleDTO bundleDTO = new BundleDTO(); bundleDTO.setName(bundle.getSymbolicName()); bundleDTO.setId(bundle.getBundleId()); bundleDTO.setState(states.get(bundle.getState())); bundleDTOs.add(bundleDTO); } bundleResponse.setBundles(bundleDTOs); setResponseHeaders(request, response); response.setEntity(self.generateReturnString(bundleResponse), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet startBundle = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { String bundleID = (String) request.getAttributes().get("bundleID"); final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); logger.info("Starting a bundle: " + bundleContext.getBundle(Long.parseLong(bundleID)).getSymbolicName()); bundleContext.getBundle(Long.parseLong(bundleID)).start(); ; setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet stopBundle = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { String bundleID = (String) request.getAttributes().get("bundleID"); final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); logger.info("Stopping a bundle: " + bundleContext.getBundle(Long.parseLong(bundleID)).getSymbolicName()); bundleContext.getBundle(Long.parseLong(bundleID)).stop(); setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet installBundle = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { String bundlePath = (String) request.getEntityAsText(); logger.info("Installing a bundle: " + bundlePath); final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); bundleContext.installBundle(bundlePath); setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Restlet uninstallBundle = new Restlet() { @Override @Post public void handle(Request request, Response response) { try { String bundleID = (String) request.getAttributes().get("bundleID"); final BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); logger.info("Uninstalling a bundle: " + bundleContext.getBundle(Long.parseLong(bundleID)).getSymbolicName()); bundleContext.getBundle(Long.parseLong(bundleID)).uninstall(); setResponseHeaders(request, response); response.setEntity(self.generateReturnString(self.generateSuccessMessage()), MediaType.TEXT_XML); } catch (Exception e) { response.setEntity(self.generateReturnString(self.generateErrorMessage(e.toString(), null)), MediaType.TEXT_XML); } } }; Router router = new Router(getContext().createChildContext()); router.attach("/shutdown", shutdown); router.attach("/restart", restart); router.attach("/ss", bundles); router.attach("/startbundle/{bundleID}", startBundle); router.attach("/stopbundle/{bundleID}", stopBundle); router.attach("/installbundle", installBundle); router.attach("/uninstallbundle/{bundleID}", uninstallBundle); router.attach("/readers", readers); router.attach("/commands", commands); router.attach("/readerstatus/{readerID}", readerStatus); router.attach("/startsession/{readerID}/{sessionID}", startSession); router.attach("/stopsession/{readerID}/{sessionID}", stopSession); router.attach("/createsession/{readerID}", createSession); router.attach("/deletesession/{readerID}/{sessionID}", deleteSession); router.attach("/resetsession/{readerID}/{sessionID}", resetSession); router.attach("/deletereader/{readerID}", deleteReader); router.attach("/deletecommand/{commandID}", deleteCommand); router.attach("/executecommand/{readerID}/{sessionID}/{commandID}/{repeatInterval}", executeCommand); // get and set properties for a reader router.attach("/getproperties/{readerID}", getProperties); router.attach("/setproperties/{readerID}/{properties}", setProperties); // get properties for an application router.attach("/getAppProperties/{appID}", getAppProperties); // set properties for an application router.attach("/setAppProperties/{appID}/{properties}", setAppProperties); // get properties for a group router.attach("/getGroupProperties/{appID}", getGroupProperties); // set properties for a group router.attach("/setGroupProperties/{appID}/{properties}", setGroupProperties); // get readzones router.attach("/getReadZones/{appID}", getReadZones); // delete readzone router.attach("/deleteReadZone/{appID}/{readZone}", deleteReadZone); // add readzone router.attach("/addReadZone/{appID}/{readZone}/{properties}", addReadZone); // get readzone properties router.attach("/getReadZoneProperties/{appID}/{readZoneName}", getReadZoneProperties); // set readzone properties router.attach("/setReadZoneProperties/{appID}/{readZoneName}/{properties}", setReadZoneProperties); // createreader with properties router.attach("/createreader/{readerType}/{properties}", createReader); // createreader with no properties router.attach("/createreader/{readerType}", createReader); // createcommand with properties router.attach("/createcommand/{commandType}/{properties}", createCommand); // createcommand with no properties router.attach("/createcommand/{commandType}", createCommand); router.attach("/startapp/{appID}", startApp); router.attach("/stopapp/{appID}", stopApp); router.attach("/loadapp/{path}", loadApp); router.attach("/adddefaultapp/{group}", addDefaultApplication); router.attach("/commandtypes", commandTypes); router.attach("/readertypes", readerTypes); router.attach("/readermetadata", readerMetadata); router.attach("/apps", apps); router.attach("/save", save); router.attach("/currenttags/{readerID}", currenttags); // thinkify commands // router.attach("/rcs/{readerID}/{sessionID}", rcs); // single shot commands router.attach("/llrpgetrospecs/{readerID}/{sessionID}", llrpGetRospecs); router.attach("/llrpgetreaderconfig/{readerID}/{sessionID}", llrpGetReaderConfig); router.attach("/llrpgetreadercapabilities/{readerID}/{sessionID}", llrpGetReaderCapabilities); // LLRPEPCWrite single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCWrite", llrpEpcWrite); // LLRPEPCWrite single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCWrite/{properties}", llrpEpcWrite); // llrpAccessPasswordWrite single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordWrite", llrpAccessPasswordWrite); // llrpAccessPasswordWrite single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordWrite/{properties}", llrpAccessPasswordWrite); // llrpKillPasswordWrite single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordWrite", llrpKillPasswordWrite); // llrpKillPasswordWrite single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordWrite/{properties}", llrpKillPasswordWrite); // llrpEPCLock single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCLock", llrpEPCLock); // llrpEPCLock single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCLock/{properties}", llrpEPCLock); // llrpAccessPasswordLock single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordLock", llrpAccessPasswordLock); // llrpAccessPasswordLock single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordLock/{properties}", llrpAccessPasswordLock); // llrpKillPasswordLock single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordLock", llrpKillPasswordLock); // llrpKillPasswordLock single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordLock/{properties}", llrpKillPasswordLock); // llrpUserMemoryLock single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryLock", llrpUserMemoryLock); // llrpUserMemoryLock single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryLock/{properties}", llrpUserMemoryLock); // LLRPEPCRead single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCRead", llrpEpcRead); // LLRPEPCRead single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPEPCRead/{properties}", llrpEpcRead); // LLRPAccessPasswordValidate single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordValidate", llrpAccessPwdValidate); // LLRPAccessPasswordValidate single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPAccessPasswordValidate/{properties}", llrpAccessPwdValidate); // LLRPKillPasswordRead single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordRead", llrpKillPwdRead); // LLRPKillPasswordRead single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPKillPasswordRead/{properties}", llrpKillPwdRead); // LLRPUserMemoryRead single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryRead", llrpUserMemoryRead); // LLRPUserMemoryRead single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryRead/{properties}", llrpUserMemoryRead); // LLRPUserMemoryWrite single shot command with no properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryWrite", llrpUserMemoryWrite); // LLRPUserMemoryWrite single shot command with properties router.attach("/llrpencode/{readerID}/{sessionID}/LLRPUserMemoryWrite/{properties}", llrpUserMemoryWrite); // llrp encode router.attach("/llrpencode/{readerID}/{sessionID}/{tag}", llrpEncode); router.attach("/llrpmessage/{readerID}/{sessionID}", llrpMessage); router.attach("/llrpmessage/{readerID}/{sessionID}/{sendonly}", llrpMessage); router.attach("/ping", ping); // router to update servers file router.attach("/updateServersFile/{data}", updateServersFile); // router to get servers file router.attach("/getServersFile", getServersFile); // router to update ui properties file router.attach("/updateUIPropertiesFile/{data}", updateUIPropertiesFile); // router to get properties file router.attach("/getUIPropertiesFile", getUIPropertiesFile); // Attach web administration dashboard app String appPath = "file:///" + System.getProperty("org.rifidi.home") + File.separator + "admin" + File.separator + "app" + File.separator; Directory directory = new Directory(getContext(), appPath); router.attach("/dashboard", directory); return router; }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public AttributeList getAttributes(String[] attributeNames) { if (attributeNames == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }/*from w w w . ja v a2 s.com*/ // If no controller, we can't do any work in here. if (this.controller == null) { throw new RuntimeOperationsException(new NullPointerException("Controller is null"), "Controller is null"); } AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (int i = 0; i < attributeNames.length; i++) { try { Object value = getAttribute(attributeNames[i]); resultList.add(new Attribute(attributeNames[i], value)); } catch (Exception e) { e.printStackTrace(); } } return (resultList); }
From source file:org.archive.crawler.admin.CrawlJob.java
public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }//w w w . j a va 2 s .c o m AttributeList resultList = new AttributeList(); if (attributes.size() == 0) { return resultList; } for (int i = 0; i < attributes.size(); i++) { try { Attribute attr = (Attribute) attributes.get(i); setAttributeInternal(attr); String an = attr.getName(); Object newValue = getAttribute(an); resultList.add(new Attribute(an, newValue)); } catch (Exception e) { e.printStackTrace(); } } // prompt updating of settings-sensitive components kickUpdate(); return resultList; }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }// www. j a va 2 s .c om AttributeList resultList = new AttributeList(); if (attributes.size() == 0) { return resultList; } for (int i = 0; i < attributes.size(); i++) { try { Attribute attr = (Attribute) attributes.get(i); setAttribute(attr); String an = attr.getName(); Object newValue = getAttribute(an); resultList.add(new Attribute(an, newValue)); } catch (Exception e) { e.printStackTrace(); } } return resultList; }
From source file:com.cyberway.issue.crawler.Heritrix.java
public AttributeList getAttributes(String[] attributeNames) { if (attributeNames == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }/* w ww . j a v a 2 s .co m*/ AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (int i = 0; i < attributeNames.length; i++) { try { Object value = getAttribute(attributeNames[i]); resultList.add(new Attribute(attributeNames[i], value)); } catch (Exception e) { e.printStackTrace(); } } return (resultList); }
From source file:com.cyberway.issue.crawler.Heritrix.java
public AttributeList setAttributes(AttributeList attributes) { return new AttributeList(); // always empty }
From source file:org.rifidi.edge.rest.SensorManagerServiceRestletImpl.java
/** * Processes a chain of semicolon separated properties and checks whether it * is a well formed pair/*from w ww .j a v a2 s . c om*/ * * @param propertiesChain * separated values of properties, for example: * (prop1=val2;prop2=val2;prop3=val3) * @return AttributeList containing the attributes * @throws Exception * if any property has no recognizable value */ private AttributeList getProcessedAttributes(String propertiesChain) throws Exception { AttributeList attributes = new AttributeList(); // Check if propertiesChain has properties to process... if (propertiesChain != null && !propertiesChain.isEmpty()) { String[] splitProp = propertiesChain.split(";"); for (String pair : splitProp) { String[] prop = pair.split("="); // check if property has a property and a value if (prop.length == 2) { // It has property and value attributes.add(new Attribute(prop[0], prop[1])); } else { // Property with no recognizable value, for example // Port=123=456, or Port, throw new Exception("Property with no recognizable value: " + prop[0]); } } } return attributes; }