com.akaxin.proto.site.ApiPluginPageProto Java Examples

The following examples show how to use com.akaxin.proto.site.ApiPluginPageProto. 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 vote down vote up
/**
 * <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 openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * <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 #3
Source File: ApiPluginService.java    From openzaly with Apache License 2.0 4 votes vote down vote up
/**
 * <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);
}