@Override public void format(Object arg0, ExecutorResponse[] responses) throws ExecutorException { CliTransaction cli = new CliTransaction(CliTransaction.TYPE_MODULE); cli.setFunctionName("FormatResponse"); try { formatter.format(arg0, responses); for (int i = 0; i < responses.length; i++) { ExecutorResponse executorResponse = responses[i]; cli.addData("ResponseName", executorResponse.getExecutorType()); cli.addData("ResponseDetail", executorResponse.toString()); } } catch (Exception e) { cli.setStatus(e); throw new ExecutorException(e); } finally { cli.complete(); } }
/* * (non-Javadoc) * * @see * com.telenav.cserver.framework.executor.protocol.ProtocolRequestParser * #parse(java.lang.Object) */ public ExecutorRequest[] parse(Object arg0) throws ExecutorException { CliTransaction cli = new CliTransaction(CliTransaction.TYPE_MODULE); cli.setFunctionName("ParseRequest"); try { ExecutorRequest[] requests = parser.parse(arg0); for (int i = 0; i < requests.length; i++) { ExecutorRequest executorRequest = requests[i]; cli.addData("RequestName", executorRequest.getExecutorType()); cli.addData("RequestDetail", executorRequest.toString()); } return requests; } catch (Exception e) { cli.setStatus(e); throw new ExecutorException(e); } finally { cli.complete(); } }
/** * @TODO query nickname * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse queryNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("queryNickName"); long userId = nickNameRequest.getUserId(); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); nickNameResponse.setUserId(userId); nickNameResponse.setNickName(""); UserManagementServiceStub stub = null; try { // set query conditions GetUserRequestDTO getUserRequest = new GetUserRequestDTO(); getUserRequest.setParam(Long.toString(userId)); getUserRequest.setParamType(UserQueryBy.USER_ID); getUserRequest.setClientName(HtmlConstants.clientName); getUserRequest.setClientVersion(HtmlConstants.clientVersion); getUserRequest.setContextString(tnContext.toContextString()); getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // get userInfo stub = getServer(); GetUserResponseDTO responseDto = stub.getUser(getUserRequest); if (responseDto != null) { User user = responseDto.getUser(); if (user != null) // set response param { logger.debug("queryNickName userId:" + userId + ",user name:" + user.getUserName()); // set query result nickNameResponse.setNickName(user.getUserName()); } cli.addData("Response", "Status Code:" + responseDto.getResponseStatus()); } // nickNameResponse.setMessage("Status Code =" + statusCode + " Message=" + statusMsg); } catch (Exception e) { // TODO Auto-generated catch block logger.error(e); e.printStackTrace(); cli.setStatus(e); cli.setState(CliConstants.STATUS_FAIL); } finally { cli.complete(); WebServiceUtils.cleanupStub(stub); } return nickNameResponse; }
/** * @TODO check nickname if exist * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse checkNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("checkNickName"); String nickNameStr = nickNameRequest.getNickName(); nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); UserManagementServiceStub stub = null; try { // set conditions IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO(); isUniqueRequest.setUserName(nickNameStr); isUniqueRequest.setClientName(HtmlConstants.clientName); isUniqueRequest.setClientVersion(HtmlConstants.clientVersion); isUniqueRequest.setContextString(tnContext.toContextString()); isUniqueRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // check NickName stub = getServer(); IsUniqueUsernameResponseDTO isUniqueResponse = stub.isUniqueUsername(isUniqueRequest); nickNameResponse.setNickName(nickNameStr); if (isUniqueResponse != null) { boolean isUnique = isUniqueResponse.getUnique(); logger.debug("checkNickName userName:"******",isUnique" + isUnique); cli.addData("data", "checkNickName userName:"******",isUnique" + isUnique); if (isUnique) { // the nick name is unique nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); } else { // the nick name has exist nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME); } } } catch (Exception e) { // TODO Auto-generated catch block logger.error(e); e.printStackTrace(); cli.setStatus(e); cli.setState(CliConstants.STATUS_FAIL); } finally { cli.complete(); WebServiceUtils.cleanupStub(stub); } return nickNameResponse; }
/** override from Action */ public final ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { CliTransaction cli = new CliTransaction(CliTransaction.TYPE_URL); cli.setApplicationId(getCliApplicationID()); cli.setFunctionName(request.getServletPath()); try { String requestURL = request.getRequestURL().toString(); String servletPath = request.getServletPath(); request.setAttribute("Host_url", HtmlClientHelper.getHostURL(requestURL, servletPath)); HtmlClientInfo clientInfo = getClientInfo(request); // Put clientInfo to request request.setAttribute(HtmlFrameworkConstants.HTML_CLIENT_INFO, clientInfo); // prepare the resource needed in screen initializeScreen(request, clientInfo); // Do action. ActionForward forward = doAction(mapping, request, response); // add cli object cli.addData(CliTransaction.LABEL_CLIENT_INTO, getClientInfoFromRequest(request)); return forward; } catch (Exception e) { e.printStackTrace(); logger.error("Browser Application Server Exception.", e); cli.setStatus(e); cli.setState(CliTransaction.STATUS_FAIL); return mapping.findForward("Globe_Exception"); } finally { cli.complete(); } }
/** * TODO add a new record about nickname * * @param nickNameRequest * @param nickNameResponse * @param tnContext * @return */ public HtmlNickNameResponse checkAndaddNickName( HtmlNickNameRequest nickNameRequest, HtmlNickNameResponse nickNameResponse, TnContext tnContext) { CliTransaction cli = new CliTransaction(CliConstants.TYPE_MODULE); cli.setFunctionName("checkAndaddNickName"); nickNameResponse.setStatus(ExecutorResponse.STATUS_OK); UserManagementServiceStub stub = null; try { String userName = nickNameRequest.getNickName(); // set conditions IsUniqueUsernameRequestDTO isUniqueRequest = new IsUniqueUsernameRequestDTO(); isUniqueRequest.setUserName(userName); isUniqueRequest.setClientName(HtmlConstants.clientName); isUniqueRequest.setClientVersion(HtmlConstants.clientVersion); isUniqueRequest.setContextString(tnContext.toContextString()); isUniqueRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // check NickName stub = getServer(); IsUniqueUsernameResponseDTO isUniqueResponse = stub.isUniqueUsername(isUniqueRequest); nickNameResponse.setNickName(userName); if (isUniqueResponse != null) { boolean isUnique = isUniqueResponse.getUnique(); logger.debug("checkNickName userName:"******",isUnique" + isUnique); cli.addData("data", "checkNickName userName:"******",isUnique" + isUnique); if (isUnique) { // the nick name is unique nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); long userId = nickNameRequest.getUserId(); logger.debug("addNickName userId:" + userId + ",userName" + userName); // set conditions GetUserRequestDTO getUserRequest = new GetUserRequestDTO(); getUserRequest.setParam(Long.toString(userId)); getUserRequest.setParamType(UserQueryBy.USER_ID); getUserRequest.setClientName(HtmlConstants.clientName); getUserRequest.setClientVersion(HtmlConstants.clientVersion); getUserRequest.setContextString(tnContext.toContextString()); getUserRequest.setTransactionId(HtmlPoiUtil.getTrxId()); // get user GetUserResponseDTO responseDto = stub.getUser(getUserRequest); User user = responseDto.getUser(); if (user != null) { user.setUserName(userName); // update user UpdateUserRequestDTO updateRequest = new UpdateUserRequestDTO(); updateRequest.setUser(user); updateRequest.setClientName(HtmlConstants.clientName); updateRequest.setClientVersion(HtmlConstants.clientVersion); updateRequest.setContextString(tnContext.toContextString()); updateRequest.setTransactionId(HtmlPoiUtil.getTrxId()); UserManagementResponseDTO updateResponse = stub.updateUser(updateRequest); } } else { // the nick name has exist nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_NOT_UNIQUE_NICKNAME); } } else { nickNameResponse.setIsUniqueNickName(HtmlConstants.OPERATE_UNIQUE_NICKNAME); } } catch (Exception e) { logger.error(e); e.printStackTrace(); cli.setStatus(e); cli.setState(CliConstants.STATUS_FAIL); } finally { cli.complete(); WebServiceUtils.cleanupStub(stub); } return nickNameResponse; }
public TnContext getTnContext(UserProfile userProfile, ExecutorContext context) { String userID = userProfile.getUserId(); long lUserID = -1; if (userID != null && userID.length() > 0) { lUserID = Long.parseLong(userID); } ContextMgrService cms = new ContextMgrService(); ContextMgrStatus myStatus = null; if (logger.isDebugEnabled()) { logger.debug("needRegister:" + needRegister); } TnContext tc = new TnContext(); try { if (needRegister) { // get the tncontext from DSM db // tc = getTnContextFromDsmDB(userProfile.getMin()); // set user profile into tncontext setUserProfileToTnContext(tc, userProfile, context); // set the need register dsm rule into tncontext setNeedRegisterDsmRuleToTnContext(userProfile, tc); if (logger.isDebugEnabled()) { logger.debug("tc -->" + tc); logger.debug("tc.length = " + tc.toContextString().length()); } myStatus = cms.registerContext(lUserID, Constants.CALLER_CSERVER, tc); } else { // set user profile into tncontext setUserProfileToTnContext(tc, userProfile, context); myStatus = cms.updateContext(tc); } } catch (Exception e) { logger.fatal(e, e); } // set all the dsm rules in to tncontext setAllDsmRuleToTnContext(userProfile, tc); DevicePropertiesHolder deviceHolder = (DevicePropertiesHolder) ResourceHolderManager.getResourceHolder(HolderType.DEVICE_TYPE); if (deviceHolder != null) { DeviceProperties deviceProperties = deviceHolder.getDeviceProperties(userProfile, tc); if (deviceProperties != null) { tc.addProperty( GENERATE_LANE_INFO, String.valueOf(deviceProperties.getBooleanDefFalse(NAV_ENABLE_LANE_ASSIST))); } } if (myStatus == null || myStatus.getStatusCode() != Error.NO_ERROR) { CliTransaction cli = com.telenav.cserver.framework.cli.CliTransactionFactory.getInstance( CliConstants.TYPE_MODULE); cli.setFunctionName("getTnContext"); cli.addData( "cms_status(has issue)", myStatus != null ? myStatus.getStatusCode() + "" : "null"); tc = getDefaultTnContext(tc); if (logger.isDebugEnabled()) { logger.debug("tnContext has issue."); } cli.complete(); } logger.debug("final tc:>>" + tc); return tc; }