use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class HttpUserService method profile.
/**
* 查看用户的个人profile
*
* @param command
* @return
*/
public CommandResponse profile(Command command) {
CommandResponse commandResponse = new CommandResponse();
ErrorCode2 errorCode = ErrorCode2.ERROR;
try {
HaiUserProfileProto.HaiUserProfileRequest request = HaiUserProfileProto.HaiUserProfileRequest.parseFrom(command.getParams());
String siteUserId = request.getSiteUserId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNotBlank(siteUserId)) {
UserProfileBean bean = UserProfileDao.getInstance().getUserProfileById(siteUserId);
if (bean != null && StringUtils.isNotBlank(bean.getSiteUserId())) {
UserProto.UserProfile profile = UserProto.UserProfile.newBuilder().setSiteUserId(bean.getSiteUserId()).setUserName(String.valueOf(bean.getUserName())).setUserPhoto(String.valueOf(bean.getUserPhoto())).setUserStatusValue(bean.getUserStatus()).build();
HaiUserProfileProto.HaiUserProfileResponse response = HaiUserProfileProto.HaiUserProfileResponse.newBuilder().setUserProfile(profile).build();
commandResponse.setParams(response.toByteArray());
errorCode = ErrorCode2.SUCCESS;
}
} else {
errorCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errorCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errorCode);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class HttpRequestService method process.
public CommandResponse process(Command command) {
HttpUriAction huaEnum = HttpUriAction.getUriActionEnum(command.getUri());
command.setMethod(huaEnum.getMethod());
CommandResponse response = null;
try {
switch(huaEnum) {
case HAI_USER_UPDATE:
case HAI_USER_SEALUP:
if (!checkPermissions(command.getSiteUserId())) {
break;
}
case HAI_USER_LIST:
case HAI_USER_SEARCH:
case HAI_USER_PROFILE:
case HAI_USER_RELATIONLIST:
return new HttpUserService().execute(command);
case HAI_GROUP_LIST:
case HAI_GROUP_PROFILE:
case HAI_GROUP_MEMBERS:
case HAI_GROUP_ADDMEMBER:
case HAI_GROUP_DELETE:
case HAI_GROUP_REMOVEMEMBER:
case HAI_GROUP_SETADMIN:
case HAI_GROUP_UPDATEPROFILE:
case HAI_GROUP_NONMEMBERS:
if (checkPermissions(command.getSiteUserId())) {
response = new HttpGroupService().execute(command);
}
break;
case HAI_FRIEND_APPLY:
response = new HttpFriendService().execute(command);
break;
case HAI_SITE_GETCONFIG:
case HAI_SITE_UPDATECONFIG:
if (checkPermissions(command.getSiteUserId())) {
response = new HttpSiteConfigService().execute(command);
}
break;
case HAI_PLUGIN_ADD:
case HAI_PLUGIN_DELETE:
case HAI_PLUGIN_DISABLE:
case HAI_PLUGIN_LIST:
case HAI_PLUGIN_PROFILE:
case HAI_PLUGIN_UPDATE:
case HAI_PLUGIN_UPDATESTATUS:
if (checkPermissions(command.getSiteUserId())) {
response = new HttpPluginService().execute(command);
}
break;
case HAI_UIC_CREATE:
case HAI_UIC_INFO:
case HAI_UIC_LIST:
if (checkPermissions(command.getSiteUserId())) {
response = new HttpUICService().execute(command);
}
break;
default:
logger.error("error http request command={}", command.toString());
break;
}
} catch (Exception e) {
logger.error("http request service error.", e);
}
if (response == null) {
response = new CommandResponse();
}
return response.setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class Bootstrap method startHttpServer.
/**
* 启动Http服务,提供与扩展服务之间的hai(http application interface)接口功能
*
* @throws Exception
*/
private static void startHttpServer(String address, int port) throws Exception {
new HttpServer() {
@Override
public void loadExecutor(AbstracteExecutor<Command, CommandResponse> executor) {
executor.addChain(HttpUriAction.HTTP_ACTION.getUri(), new HttpRequestHandler());
}
}.start(address, port);
logger.info("{} start http server {}:{} ok.", AkxProject.PLN, address, port);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class HttpRequestHandler method handle.
@Override
public CommandResponse handle(Command command) {
try {
ChannelHandlerContext context = command.getChannelContext();
if (context == null) {
logger.error("{} client={} http request error context={}", AkxProject.PLN, command.getClientIp(), context);
return null;
}
CommandResponse comamndResponse = new HttpRequestService().process(command);
comamndResponse.setVersion(CommandConst.PROTOCOL_VERSION);
comamndResponse.setAction(CommandConst.ACTION_RES);
String authKey = command.getField(PluginConst.PLUGIN_AUTH_KEY, String.class);
fullHttpResponse(context, comamndResponse, authKey);
return comamndResponse;
} catch (Exception e) {
logger.error("api request error.", e);
}
return null;
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ImSiteAuthHandler method defaultErrorResponse.
private CommandResponse defaultErrorResponse() {
CommandResponse commandResponse = new CommandResponse().setVersion(CommandConst.PROTOCOL_VERSION).setAction(CommandConst.ACTION_RES);
commandResponse.setErrCode2(ErrorCode2.ERROR);
return commandResponse;
}
Aggregations