Java Code Examples for org.apache.commons.lang3.StringUtils#isNoneEmpty()

The following examples show how to use org.apache.commons.lang3.StringUtils#isNoneEmpty() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ourea   File: ConfigUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static ZkConfig buildConfig(Properties properties){

        assertEmpty("zkAddress", properties.getProperty("zkAddress"));
        ZkConfig zkConfig = new ZkConfig(properties.getProperty("zkAddress"));

        if (StringUtils.isNoneEmpty(properties.getProperty("baseSleepTimeMs"))){
            zkConfig.setBaseSleepTimeMs(Integer.parseInt(properties.getProperty("baseSleepTimeMs")));
        }

        if (StringUtils.isNoneEmpty(properties.getProperty("maxRetries"))){
            zkConfig.setMaxRetries(Integer.parseInt(properties.getProperty("maxRetries")));
        }

        if (StringUtils.isNoneEmpty(properties.getProperty("maxSleepTimeMs"))){
            zkConfig.setMaxSleepTimeMs(Integer.parseInt(properties.getProperty("maxSleepTimeMs")));
        }

        if (StringUtils.isNoneEmpty(properties.getProperty("zkTimeout"))){
            zkConfig.setZkTimeout(Integer.parseInt(properties.getProperty("zkTimeout")));
        }

        return zkConfig;
    }
 
Example 2
Source Project: syncope   File: LabelInfo.java    License: Apache License 2.0 6 votes vote down vote up
public LabelInfo(final String id, final Collection<String> title) {
    super(id, StringUtils.EMPTY);
    if (CollectionUtils.isEmpty(title)) {
        this.title = StringUtils.EMPTY;
    } else {
        StringBuilder titleBuilder = new StringBuilder();
        for (String el : title) {
            if (titleBuilder.length() > 0) {
                titleBuilder.append("; ");
            }
            if (StringUtils.isNoneEmpty(el)) {
                titleBuilder.append(el);
            }
        }
        this.title = StringUtils.abbreviate(titleBuilder.toString(), 50);
    }
}
 
Example 3
Source Project: joyqueue   File: IgniteTopic.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readBinary(BinaryReader reader) throws BinaryObjectException {
    //this.id = reader.readString(COLUMN_ID);
    String namespace = reader.readString(COLUMN_NAMESPACE);
    String topicCode = reader.readString(COLUMN_CODE);
    this.name = new TopicName(topicCode, namespace);

    this.partitions = reader.readShort(COLUMN_PARTITIONS);
    this.type = Type.valueOf(reader.readByte(COLUMN_TYPE));

    String priorityPartitionsStr = reader.readString(COLUMN_PRIORITY_PARTITIONS);
    this.priorityPartitions = new TreeSet<>();
    if (StringUtils.isNoneEmpty(priorityPartitionsStr) && priorityPartitionsStr.length() > 2) {
        this.priorityPartitions.addAll(
                (Arrays.stream(priorityPartitionsStr.substring(1, priorityPartitionsStr.length() - 1).split(",")).
                        map(s -> Short.parseShort(s.trim())).collect(Collectors.toSet()))
        );
    }
}
 
Example 4
private AdlsGen2BackupConfig generateBackupConfig(String location) {
    if (StringUtils.isNotEmpty(location)) {
        String locationWithoutScheme = getLocationWithoutSchemePrefixes(location, ADLS_GEN2_SCHEME_PREFIXES);
        String[] locationSplit = locationWithoutScheme.split("@");
        String[] storageWithSuffix = locationSplit[0].split("/", 2);
        String folderPrefix = storageWithSuffix.length < 2 ? "" :  "/" + storageWithSuffix[1];
        if (locationSplit.length < 2) {
            return new AdlsGen2BackupConfig(folderPrefix, storageWithSuffix[0], null);
        } else {
            String[] splitByDomain = locationSplit[1].split("." + AZURE_DFS_DOMAIN_SUFFIX);
            String account = splitByDomain[0];
            if (splitByDomain.length > 1) {
                String folderPrefixAfterDomain = splitByDomain[1];
                if (StringUtils.isNoneEmpty(folderPrefix, folderPrefixAfterDomain)) {
                    throw new CloudbreakServiceException(String.format("Invalid ADLS Gen2 path: %s", location));
                }
                folderPrefix = StringUtils.isNotEmpty(folderPrefixAfterDomain) ? folderPrefixAfterDomain : folderPrefix;
            }
            return new AdlsGen2BackupConfig(folderPrefix, storageWithSuffix[0], account);
        }
    }
    throw new CloudbreakServiceException("Storage location parameter is missing for ADLS Gen2");
}
 
Example 5
@Override
public ResponseMsg shareBlog(BlogDetail blogDetail) {

    if (StringUtils.isNoneEmpty(blogDetail.getUsername())){
        String id = MD5Util.getMD5(blogDetail.getUsername() + new Date().toString());
        blogDetail.setId(id);
    }else {
        return ResponseMsgUtil.returnCodeMessage(ResponseCode.REQUEST_FAIL);
    }

    //  default value
    blogDetail.setTime(new Date());
    blogDetail.setComment_times(0);
    blogDetail.setVisit_times(0);
    blogDetail.setState(1);

    ArticleInfo articleInfo = new ArticleInfo();
    articleInfo.setTitle(blogDetail.getTitle());
    articleInfo.setPost_time(blogDetail.getTime());
    articleInfo.setPrivilege(1);
    articleInfo.setState(1);
    articleInfo.setVisit_id(blogDetail.getId());
    articleInfo.setVisit_times(0);
    articleInfo.setUser_name(blogDetail.getUsername());
    articleInfo.setModification_time(blogDetail.getTime());
    articleInfo.setType(1);
    articleInfo.setComment_times(0);
    articleInfo.setUp_vote(0);
    articleInfo.setDown_vote(0);
    articleInfo.setUser_id(userService.selectUserByloginName(blogDetail.getUsername()).getId());
    articleService.insrt(articleInfo);

    blogRepository.save(blogDetail);
    return ResponseMsgUtil.returnCodeMessage(ResponseCode.REQUEST_SUCCESS, blogDetail.getId());
}
 
Example 6
Source Project: wind-im   File: ApiFriendService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取好友的设置信息
 * 
 * @param command
 * @return
 */
public CommandResponse setting(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		ApiFriendSettingProto.ApiFriendSettingRequest request = ApiFriendSettingProto.ApiFriendSettingRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteFriendId = request.getSiteFriendId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNoneEmpty(siteUserId, siteFriendId)) {
			UserFriendBean bean = UserFriendDao.getInstance().getFriendSetting(siteUserId, siteFriendId);
			if (bean != null) {
				ApiFriendSettingProto.ApiFriendSettingResponse response = ApiFriendSettingProto.ApiFriendSettingResponse
						.newBuilder().setMessageMute(bean.isMute()).build();
				commandResponse.setParams(response.toByteArray());
				errCode = ErrorCode2.SUCCESS;
			} else {
				errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;// 数据库执行错误
			}

		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 7
/**
 * Validate request Object of get the pattern and translation when combine field value have
 * region parameter
 *
 * 
 */
public boolean isPatternTransaltionWithRegion(TranslationWithPatternDTO data) {
   return StringUtils.isNoneEmpty(data.getLanguage()) && StringUtils.isNoneEmpty(data.getScope())
         && StringUtils.isNoneEmpty(data.getProductName())
         && StringUtils.isNoneEmpty(data.getVersion())
         && StringUtils.isNoneEmpty(data.getRegion()) && (data.getComponents().size() > 0);
}
 
Example 8
Source Project: openzaly   File: ApiGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 个人更新群设置信息
 *
 * @param command
 * @return
 */
@Deprecated
public CommandResponse updateSetting(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest request = ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		boolean isMute = request.getMessageMute();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNoneEmpty(siteUserId, groupId)) {
			UserGroupBean bean = new UserGroupBean();
			bean.setSiteGroupId(groupId);
			bean.setMute(isMute);
			if (UserGroupDao.getInstance().updateUserGroupSetting(siteUserId, bean)) {
				errCode = ErrorCode2.SUCCESS;
			} else {
				errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
			}
		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example 9
Source Project: neodymium-library   File: BrowserRunnerHelper.java    License: MIT License 5 votes vote down vote up
public static Proxy createProxyCapabilities()
{
    final String proxyHost = Neodymium.configuration().getProxyHost() + ":" + Neodymium.configuration().getProxyPort();

    final Proxy webdriverProxy = new Proxy();
    webdriverProxy.setHttpProxy(proxyHost);
    webdriverProxy.setSslProxy(proxyHost);
    webdriverProxy.setFtpProxy(proxyHost);
    if (!StringUtils.isAllEmpty(Neodymium.configuration().getProxySocketUsername(), Neodymium.configuration().getProxySocketPassword())
        || Neodymium.configuration().getProxySocketVersion() != null)
    {
        webdriverProxy.setSocksProxy(proxyHost);
        if (StringUtils.isNoneEmpty(Neodymium.configuration().getProxySocketUsername(),
                                    Neodymium.configuration().getProxySocketPassword()))
        {
            webdriverProxy.setSocksUsername(Neodymium.configuration().getProxySocketUsername());
            webdriverProxy.setSocksPassword(Neodymium.configuration().getProxySocketPassword());
        }
        if (Neodymium.configuration().getProxySocketVersion() != null)
        {
            webdriverProxy.setSocksVersion(4);
        }
    }

    webdriverProxy.setNoProxy(Neodymium.configuration().getProxyBypass());
    return webdriverProxy;
}
 
Example 10
Source Project: WePush   File: WxCpMsgSender.java    License: MIT License 5 votes vote down vote up
@Override
public SendResult send(String[] msgData) {
    SendResult sendResult = new SendResult();

    try {
        String openId = msgData[0];
        WxCpMessage wxCpMessage = wxCpMsgMaker.makeMsg(msgData);
        wxCpMessage.setToUser(openId);
        if (PushControl.dryRun) {
            sendResult.setSuccess(true);
            return sendResult;
        } else {
            WxCpMessageSendResult wxCpMessageSendResult = wxCpService.messageSend(wxCpMessage);
            if (wxCpMessageSendResult.getErrCode() != 0 || StringUtils.isNoneEmpty(wxCpMessageSendResult.getInvalidUser())) {
                sendResult.setSuccess(false);
                sendResult.setInfo(wxCpMessageSendResult.toString());
                log.error(wxCpMessageSendResult.toString());
                return sendResult;
            }
        }
    } catch (Exception e) {
        sendResult.setSuccess(false);
        sendResult.setInfo(e.getMessage());
        log.error(ExceptionUtils.getStackTrace(e));
        return sendResult;
    }

    sendResult.setSuccess(true);
    return sendResult;
}
 
Example 11
Source Project: incubator-atlas   File: Servlets.java    License: Apache License 2.0 5 votes vote down vote up
public static String getDoAsUser(HttpServletRequest request) {
    if (StringUtils.isNoneEmpty(request.getQueryString())) {
        List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
        if (list != null) {
            for (NameValuePair nv : list) {
                if (DO_AS.equals(nv.getName())) {
                    return nv.getValue();
                }
            }
        }
    }
    return null;
}
 
Example 12
Source Project: openzaly   File: ApiFriendService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取好友的设置信息
 * 
 * @param command
 * @return
 */
public CommandResponse setting(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	ErrorCode2 errCode = ErrorCode2.ERROR;
	try {
		ApiFriendSettingProto.ApiFriendSettingRequest request = ApiFriendSettingProto.ApiFriendSettingRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String siteFriendId = request.getSiteFriendId();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNoneEmpty(siteUserId, siteFriendId)) {
			UserFriendBean bean = UserFriendDao.getInstance().getFriendSetting(siteUserId, siteFriendId);
			if (bean != null) {
				ApiFriendSettingProto.ApiFriendSettingResponse response = ApiFriendSettingProto.ApiFriendSettingResponse
						.newBuilder().setMessageMute(bean.isMute()).build();
				commandResponse.setParams(response.toByteArray());
				errCode = ErrorCode2.SUCCESS;
			} else {
				errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;// 数据库执行错误
			}

		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode2(errCode);
}
 
Example 13
Source Project: openzaly   File: ApiGroupService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 个人更新群设置信息
 *
 * @param command
 * @return
 */
@Deprecated
public CommandResponse updateSetting(Command command) {
	CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
	IErrorCode errCode = ErrorCode2.ERROR;
	try {
		ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest request = ApiGroupUpdateSettingProto.ApiGroupUpdateSettingRequest
				.parseFrom(command.getParams());
		String siteUserId = command.getSiteUserId();
		String groupId = request.getGroupId();
		boolean isMute = request.getMessageMute();
		LogUtils.requestDebugLog(logger, command, request.toString());

		if (StringUtils.isNoneEmpty(siteUserId, groupId)) {
			UserGroupBean bean = new UserGroupBean();
			bean.setSiteGroupId(groupId);
			bean.setMute(isMute);
			if (UserGroupDao.getInstance().updateUserGroupSetting(siteUserId, bean)) {
				errCode = ErrorCode2.SUCCESS;
			} else {
				errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
			}
		} else {
			errCode = ErrorCode2.ERROR_PARAMETER;
		}

	} catch (Exception e) {
		errCode = ErrorCode2.ERROR_SYSTEMERROR;
		LogUtils.requestErrorLog(logger, command, e);
	}
	return commandResponse.setErrCode(errCode);
}
 
Example 14
@RequestMapping(value = "/tx", method = RequestMethod.GET)
public ListTransactionByPageVo transactions(@RequestParam(value = "block", required = false) Long block,
    @RequestParam(value = "a", required = false) String address,
    @RequestParam(value = "p", required = false, defaultValue = "1") int page,
    @RequestParam(value = "isPending", required = false, defaultValue = "false") Boolean isPending)
    throws IOException {

    String type;
    if (null != block) {
        type = "block";
    } else if (StringUtils.isNoneEmpty(address)) {
        type = "address";
    } else {
        type = "total";
    }

    long count = 0;
    List<Transaction> txs;
    if (isPending) {
        PageIterator<Transaction> pageIterator = ethService.pendingTransactions(page, PAGE_SIZE, address);
        count = pageIterator.getTotalCount();
        txs = pageIterator.getData();
    } else {
        count = ethService.countTransaction(address, block);
        txs = ethService.transactions(page, PAGE_SIZE, address, block);
    }

    ListTransactionByPageVo vo = new ListTransactionByPageVo();
    vo.setData(new ListTransactionByPageVo.TransactionByPage.Builder()
        .txnList(ConverterFunctionUtil.toVoTransactions.apply(txs))
        .txnCnt(count)
        .currentPage(page)
        .totalPage((int) (count / PAGE_SIZE + 1))
        .maxDisplayCnt(count)
        .type(type)
        .build());
    return vo;
}
 
Example 15
Source Project: cs-actions   File: SQLCommandService.java    License: Apache License 2.0 4 votes vote down vote up
public static String executeSqlCommand(final SQLInputs sqlInputs) throws Exception {
    final ConnectionService connectionService = new ConnectionService();
    try (final Connection connection = connectionService.setUpConnection(sqlInputs)){

        connection.setReadOnly(false);

        final String dbType = sqlInputs.getDbType();
        if (ORACLE_DB_TYPE.equalsIgnoreCase(dbType) && sqlInputs.getSqlCommand().toLowerCase().contains(DBMS_OUTPUT)) {

            final PreparedStatement preparedStatement = connection.prepareStatement(sqlInputs.getSqlCommand());
            preparedStatement.setQueryTimeout(sqlInputs.getTimeout());
            OracleDbmsOutput oracleDbmsOutput = new OracleDbmsOutput(connection);
            preparedStatement.executeQuery();
            sqlInputs.setIUpdateCount(preparedStatement.getUpdateCount());
            preparedStatement.close();
            final String output = oracleDbmsOutput.getOutput();
            oracleDbmsOutput.close();
            return output;
        } else {
            final Statement statement = connection.createStatement(sqlInputs.getResultSetType(), sqlInputs.getResultSetConcurrency());
            statement.setQueryTimeout(sqlInputs.getTimeout());
            try {
                statement.execute(sqlInputs.getSqlCommand());
            } catch (SQLException e) {
                if (SYBASE_DB_TYPE.equalsIgnoreCase(dbType)) {
                    //during a dump sybase sends back status as exceptions.
                    if (sqlInputs.getSqlCommand().trim().toLowerCase().startsWith("dump")) {
                        return SQLUtils.processDumpException(e);
                    } else if (sqlInputs.getSqlCommand().trim().toLowerCase().startsWith("load")) {
                        return SQLUtils.processLoadException(e);
                    }
                } else {
                    throw e;
                }
            }

            ResultSet rs = statement.getResultSet();
            if (rs != null) {
                ResultSetMetaData rsMtd = rs.getMetaData();
                if (rsMtd != null) {
                    sqlInputs.getLRows().clear();
                    int colCount = rsMtd.getColumnCount();

                    if (sqlInputs.getSqlCommand().trim().toLowerCase().startsWith("dbcc")) {
                        while (rs.next()) {
                            if (colCount >= 4) {
                                sqlInputs.getLRows().add(rs.getString(4));
                            }
                        }
                    } else {
                        String delimiter = (StringUtils.isNoneEmpty(sqlInputs.getStrDelim())) ? sqlInputs.getStrDelim() : ",";
                        String strRowHolder;
                        while (rs.next()) {
                            strRowHolder = "";
                            for (int i = 1; i <= colCount; i++) {
                                if (i > 1) {
                                    strRowHolder += delimiter;
                                }
                                strRowHolder += rs.getString(i);
                            }
                            sqlInputs.getLRows().add(strRowHolder);
                        }
                    }
                    rs.close();
                }

            }
            //For sybase, when dbcc command is executed, the result is shown in warning message
            else if (dbType.equalsIgnoreCase(SYBASE_DB_TYPE) && sqlInputs.getSqlCommand().trim().toLowerCase().startsWith("dbcc")) {
                SQLWarning warning = statement.getWarnings();
                while (warning != null) {
                    sqlInputs.getLRows().add(warning.getMessage());
                    warning = warning.getNextWarning();
                }
            }

            sqlInputs.setIUpdateCount(statement.getUpdateCount());
        }
    }
    return "Command completed successfully";
}
 
Example 16
Source Project: wind-im   File: ApiPluginService.java    License: 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 17
Source Project: Lottor   File: TransactionMsgAdapter.java    License: MIT License 4 votes vote down vote up
public Builder setSubTaskId(String subTaskId) {
    if (StringUtils.isNoneEmpty(subTaskId)) {
        transactionMsg.setSubTaskId(subTaskId);
    }
    return this;
}
 
Example 18
Source Project: Lottor   File: TransactionMsg.java    License: MIT License 4 votes vote down vote up
public Builder setMethod(String method) {
    if (StringUtils.isNoneEmpty(method)) {
        transactionMsg.setMethod(method);
    }
    return this;
}
 
Example 19
Source Project: openzaly   File: ApiPluginService.java    License: 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 20
/**
 * Validate get the pattern request Object when request data has region parameter
 *
 * 
 */
public boolean isPatternWithRegion(TranslationWithPatternDTO data) {
   return StringUtils.isNoneEmpty(data.getLanguage()) && StringUtils.isNoneEmpty(data.getScope())
         && StringUtils.isNoneEmpty(data.getRegion());
}