public void parseChunkHint( String chunkHint, MutableInt chunkPartition, MutableLong chunkSeekChar) { List<String> strings = new ArrayList<String>(); StringSet.split(strings, chunkHint, "_"); if (StringUtils.isEmptyOrNull(chunkHint)) { chunkPartition.setValue(-1); chunkSeekChar.setValue(0); } else { chunkPartition.setValue(Integer.parseInt(strings.get(0))); chunkSeekChar.setValue(Integer.parseInt(strings.get(1))); } }
/** * Used to convert the mstart and mstop time fields of the string representation of this class * instance, see toString(), into a Timestamp object. * * @return Timestamp representation of mstart and mstop from toString() method. */ private Timestamp toTimestamp(String milliseconds) { Timestamp timestamp = null; if (!StringUtils.isEmptyOrNull(milliseconds)) { try { timestamp = new Timestamp(Long.parseLong(milliseconds)); } catch (NumberFormatException nfe) { s_log.error("Exception caught", nfe); } } return timestamp; }
protected void executeAction(ClientService svc, CreateTicketForm form) throws Exception { String purpose = form.getPurpose(); if (StringUtils.isEmptyOrNull(purpose)) { svc.getResponse() .sendError(HttpServletResponse.SC_FORBIDDEN, "You must supply a ticket purpose"); return; } String email = svc.getClientInfo().getPrimaryEmail(); String ticket = createTicket(purpose, email); svc.sendHeader(TICKET_HEADER, ticket); }
public ClientSession getClientSession(String activationToken) { if (!StringUtils.hasValue(activationToken)) { m_logCategory.warn("activationToken is required"); return null; } File file = getSessionFile(activationToken); if (!file.exists()) { // Can't assume it's an authentication problem -- session file is removed // during active->recovery transition. // If this occurs, the client gets a 401 and will call into 'transition' or 'checkin'. LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Session file not found"); lmg.param(LoggingConsts.FILENAME, file.getAbsolutePath()); m_logCategory.info(lmg.toString()); return null; } try { ClientSession clientSession = null; clientSession = new ClientSession(); clientSession.read(file); clientSession.setActivationToken(activationToken); return clientSession; } catch (IOException ioe) { // Possible if the state file was removed after the file.exists() above, // or some other problem. // info, not warning because a client could ask for this file right when // the session is being removed. The client will then do a 'checkin', // same as described above. LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Unable to read session file"); lmg.param(LoggingConsts.FILENAME, file.getAbsolutePath()); m_logCategory.info(lmg.toString(), ioe); } return null; }
// Override the execute function because there will not be an ACTIVATION ID public ActionForward execute( ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws IOException { // If the userName parameter is not present don't bother validating the backend. This is to // support older clients that do not pass the userName parameter. String userName = request.getParameter(EMS_RIM_PARAM_USER_NAME); String userPin = request.getParameter(EMS_RIM_PARAM_USER_PIN); if (!StringUtils.isNullOrEmptyIgnoreWS(userName)) { IDomainXrefManager dxm = ManagementContainer.getInstance().getDomainXrefManager(); String backend = request.getParameter(EMS_RIM_PARAM_BACKEND_LOCATION); if (StringUtils.isNullOrEmptyIgnoreWS(backend)) { backend = IDomainXrefManager.Location.NONE.toString(); } dxm.getUserBackend(userName, DomainXrefManager.getLocationFromString(backend)); if (StringUtils.isNullOrEmptyIgnoreWS(backend)) { LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Cannot determine backend for user"); lmg.param(LoggingConsts.USERNAME, userName); lmg.param(LoggingConsts.PIN, userPin); m_logCategory.warn(lmg.toString()); return null; } if (!isLocalBackend(backend)) { // We are on the wrong backend. Redirect. // Note that Global URL isn't supported for old agents. // Pre-pancit agents don't have requisite logic for handling the // redirects. So, this code is somewhat moot. response.setHeader(EMS_RIM_BACKEND_HEADER, backend); response.setHeader(EMS_RIM_ERROR_CODE_HEADER, HTTP_STATUS_REDIRECT); response.sendError(HttpServletResponse.SC_MOVED_TEMPORARILY, "Redirect to backend"); return null; } } // has username IDeviceManager deviceManager = ManagementContainer.getInstance().getDeviceManager(); if (!validatePin(userPin, null)) { return null; } // Preload the user and device to prevent multiple loads later. Device device = getDevice(userPin, null); if (device == null) { return null; } if (!assertLegacyApiUseAllowed(device)) { return null; } UserAccount user = getUser(null, device); if (user == null) { return null; } String currVersion = device.getAgentVersion(); currVersion = currVersion == null ? "" : currVersion; String agentVersion = request.getParameter(EMS_RIM_PARAM_AGENT_VERSIN); // If currVersion is empty it means an agent was never installed. // EMSDEV-4679 if (!"".equals(currVersion) && (!Device.usesOldRimBackendApi(agentVersion) || !Device.usesOldRimBackendApi(currVersion))) { // This helps close a security hole. // The 'outlook' BB API has stronger authentication. // The old service would allow clients to get in w/o a valid // auth-token. // This service returns the 'activation-id' with no other authentication // than a valid pin. That activation-id may then be used to access // GetRimMailAction. // We need to prevent this. This is the only service that sends // activation-id's. The other way id-s are delivered to old agents is via // push messages. We don't send old-style push messages to new agents. LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Mixing legacy/current agent APIs not permitted"); lmg.param(LoggingConsts.PIN, userPin); lmg.param(LoggingConsts.USER_ID, device.getUserId()); lmg.param("attemptedVersion", agentVersion); lmg.param("currVersion", currVersion); m_logCategory.warn(lmg.toString()); return null; } // 'phone' isn't known by agents 6.1 and earlier so just send a blank. deviceManager.setAgentVersionForInit(device.getPin(), agentVersion, ""); // The executeAction method must set any header to be returned in the response return executeAction(mapping, actionForm, request, response, user, device); }
// Use this to set headers that are required on all responses. protected void setResponseHeaders( ActionForm actionForm, HttpServletResponse response, UserAccount user, Device device) throws IOException { // The url is static across all devices in a customer. ICustomerManager customerManager = ManagementContainer.getInstance().getCustomerManager(); Customer cust = customerManager.getCustomer(user.getCustomerID()); IRimManager rimManager = ManagementContainer.getInstance().getRimManager(); String cappUrl = cust.getCappUrl(); if (m_devDebug) { // Our dev boxes use http and specifcy a port, this conflicts with the https // assumption of getCappUrl() cappUrl = "http://turbodog.austin.messageone.com:8080/"; } URL url = null; try { url = new URL(cappUrl); } catch (MalformedURLException e) { LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Bad URL"); lmg.param(LoggingConsts.URL, cappUrl); lmg.param(LoggingConsts.USER_ID, device.getUserId()); lmg.param(LoggingConsts.CUSTOMER_ID, device.getCustomerId()); lmg.param(LoggingConsts.PIN, device.getPin()); // This would come from the customer config, so it's bad. m_logCategory.error(lmg.toString(), e); response.setHeader(SUCCESS, "false"); return; } int deviceCheckin = cust.getCapabilities().getIntCapability(Capabilities.CAP_RIM_DEVICE_PERIODIC_CHECKIN, 30); response.setHeader("rim-access-url-protocol", url.getProtocol()); response.setHeader("rim-access-url-hostname", url.getHost()); if (url.getPort() > 0) { response.setHeader("rim-access-url-port", Integer.toString(url.getPort())); } response.setHeader(EMS_RIM_DISPLAY_NAME, device.getDisplayName()); response.setHeader("get-mail-path", "wfe/getRimMail.do"); response.setHeader("send-mail-path", "wfe/sendRimMail.do"); response.setHeader("get-display-name-path", "wfe/rimGetDisplayName.do"); response.setHeader("checkin-path", "wfe/rimCheckin.do"); response.setHeader("periodic-checkin", Integer.toString(deviceCheckin)); CustomerState state = user.getUserState(); String stateString = "ready"; if (CustomerState.ACTIVE.equals(state) || CustomerState.TEST.equals(state)) { stateString = "active"; String activationId = rimManager.getActivationId(device.getPin()); if (StringUtils.isEmptyOrNull(activationId)) { // EMSDEV-4722 // If an old agent is installed during activation, the dat_rim_user_connection_status // won't exist and thus no activation ID. If needed, create one on the fly. // Incidently, this will fix most of the problems we've had with activationId's // disappearing for various reasons. LogMessageGen.log( "Old agent activationId not found; will create one on the fly", m_logCategory) .param(LoggingConsts.PIN, device.getPin()) .param(LoggingConsts.USER_ID, device.getUserId()) .info(); activationId = rimManager.activateOldAgent(device.getPin(), device.getCustomerId()); // Try again. if (StringUtils.isEmptyOrNull(activationId)) { LogMessageGen.log("Unable to create activationId for old agent", m_logCategory) .param(LoggingConsts.PIN, device.getPin()) .param(LoggingConsts.USER_ID, device.getUserId()) .error(); } } // no activationId response.setHeader("activation-id", activationId); } // active. response.setHeader("application-state", stateString); response.setHeader(SUCCESS, "true"); }