com.akaxin.proto.site.ApiPluginProxyProto Java Examples
The following examples show how to use
com.akaxin.proto.site.ApiPluginProxyProto.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiPluginService.java From wind-im with Apache License 2.0 | 4 votes |
/** * <pre> * 获取插件扩展的展示页面,支持两种方式 * 1.非加密方式,此时扩展authkey不存在 * 2.加密方式,此时扩展authkey存在 * </pre> * * @param command * @return */ public CommandResponse page(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginPageProto.ApiPluginPageRequest request = ApiPluginPageProto.ApiPluginPageRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestPage = request.getPage();// /index || index.php || index.html String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (StringUtils.isNoneEmpty(siteUserId, pluginId)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pageUrl = buildUrl(bean.getApiUrl(), requestPage, bean.getUrlPage()); logger.debug("http request uri={}", pageUrl); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pageUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { logger.error("http request uri={} response={}", pageUrl, httpResponse); } } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #2
Source File: ApiPluginService.java From wind-im with Apache License 2.0 | 4 votes |
/** * <pre> * 代理前台客户端中扩展的请求 * 1.界面请求后台一般使用http请求 * 2.使用tcp代理,代替http请求 * </pre> * * @param command * @return */ public CommandResponse proxy(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginProxyProto.ApiPluginProxyRequest request = ApiPluginProxyProto.ApiPluginProxyRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestApi = request.getApi(); String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (!StringUtils.isAnyBlank(siteUserId, pluginId, requestApi)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pluginUrl = this.buildUrl(bean.getApiUrl(), requestApi, null); logger.debug("action={} pluginId={} api={} url={} params={}", command.getAction(), pluginId, requestApi, pluginUrl, requestParams); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin // byte[] tsk = AESCrypto.generateTSKey(bean.getAuthKey()); byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pluginUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray());// httpResposne,callback方法的回调方法参数 } errCode = ErrorCode2.SUCCESS; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #3
Source File: ApiPluginService.java From openzaly with Apache License 2.0 | 4 votes |
/** * <pre> * 获取插件扩展的展示页面,支持两种方式 * 1.非加密方式,此时扩展authkey不存在 * 2.加密方式,此时扩展authkey存在 * </pre> * * @param command * @return */ public CommandResponse page(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginPageProto.ApiPluginPageRequest request = ApiPluginPageProto.ApiPluginPageRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestPage = request.getPage();// /index || index.php || index.html String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (StringUtils.isNoneEmpty(siteUserId, pluginId)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pageUrl = buildUrl(bean.getApiUrl(), requestPage, bean.getUrlPage()); logger.debug("http request uri={}", pageUrl); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pageUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { logger.error("http request uri={} response={}", pageUrl, httpResponse); } } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #4
Source File: ApiPluginService.java From openzaly with Apache License 2.0 | 4 votes |
/** * <pre> * 代理前台客户端中扩展的请求 * 1.界面请求后台一般使用http请求 * 2.使用tcp代理,代替http请求 * </pre> * * @param command * @return */ public CommandResponse proxy(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginProxyProto.ApiPluginProxyRequest request = ApiPluginProxyProto.ApiPluginProxyRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestApi = request.getApi(); String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (!StringUtils.isAnyBlank(siteUserId, pluginId, requestApi)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pluginUrl = this.buildUrl(bean.getApiUrl(), requestApi, null); logger.debug("action={} pluginId={} api={} url={} params={}", command.getAction(), pluginId, requestApi, pluginUrl, requestParams); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin // byte[] tsk = AESCrypto.generateTSKey(bean.getAuthKey()); byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pluginUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray());// httpResposne,callback方法的回调方法参数 } errCode = ErrorCode2.SUCCESS; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #5
Source File: ApiPluginService.java From openzaly with Apache License 2.0 | 4 votes |
/** * <pre> * 获取插件扩展的展示页面,支持两种方式 * 1.非加密方式,此时扩展authkey不存在 * 2.加密方式,此时扩展authkey存在 * </pre> * * @param command * @return */ public CommandResponse page(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginPageProto.ApiPluginPageRequest request = ApiPluginPageProto.ApiPluginPageRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestPage = request.getPage();// /index || index.php || index.html String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (StringUtils.isNoneEmpty(siteUserId, pluginId)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pageUrl = buildUrl(bean.getApiUrl(), requestPage, bean.getUrlPage()); logger.debug("http request uri={}", pageUrl); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pageUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { logger.error("http request uri={} response={}", pageUrl, httpResponse); } } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #6
Source File: ApiPluginService.java From openzaly with Apache License 2.0 | 4 votes |
/** * <pre> * 代理前台客户端中扩展的请求 * 1.界面请求后台一般使用http请求 * 2.使用tcp代理,代替http请求 * </pre> * * @param command * @return */ public CommandResponse proxy(Command command) { CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiPluginProxyProto.ApiPluginProxyRequest request = ApiPluginProxyProto.ApiPluginProxyRequest .parseFrom(command.getParams()); String siteUserId = command.getSiteUserId(); String pluginId = request.getPluginId(); String requestApi = request.getApi(); String requestParams = request.getParams(); LogUtils.requestDebugLog(logger, command, request.toString()); Map<Integer, String> header = command.getHeader(); String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE); String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE); if (!StringUtils.isAnyBlank(siteUserId, pluginId, requestApi)) { PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId)); if (bean != null && bean.getApiUrl() != null) { String pluginUrl = this.buildUrl(bean.getApiUrl(), requestApi, null); logger.debug("action={} pluginId={} api={} url={} params={}", command.getAction(), pluginId, requestApi, pluginUrl, requestParams); PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder(); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId); packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis())); if (StringUtils.isNotEmpty(pluginRefere)) { packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere); } if (StringUtils.isNotEmpty(requestParams)) { packageBuilder.setData(requestParams); } byte[] httpContent = packageBuilder.build().toByteArray(); String authKey = bean.getAuthKey(); if (StringUtils.isNotEmpty(authKey)) { // AES 加密整个proto,通过http传输给plugin // byte[] tsk = AESCrypto.generateTSKey(bean.getAuthKey()); byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1); byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent); httpContent = enPostContent; } byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pluginUrl, httpContent); if (httpResponse != null) { ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse .newBuilder().setData(ByteString.copyFrom(httpResponse)).build(); commandResponse.setParams(response.toByteArray());// httpResposne,callback方法的回调方法参数 } errCode = ErrorCode2.SUCCESS; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }