/** * Instantiates a new trigger specification. * * @param ldapOperation the LDAP operation * @param actionTime the action time * @param spSpecs the stored procedure specs */ public TriggerSpecification( LdapOperation ldapOperation, ActionTime actionTime, List<SPSpec> spSpecs ) { super(); if ( ( ldapOperation == null ) || ( actionTime == null ) || ( spSpecs == null ) ) { throw new NullArgumentException( I18n.err( I18n.ERR_04331 ) ); } if ( spSpecs.isEmpty() ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_04332 ) ); } this.ldapOperation = ldapOperation; this.actionTime = actionTime; this.spSpecs = spSpecs; }
/** * 寻找目录下面的jar * @param dir * @return */ public static final File[] findJarFileByDir(File dir) { if(dir==null) { throw new NullArgumentException("dir ==null"); } if(dir.isFile()) { throw new IllegalArgumentException("dir "+dir+" is not a dir"); } if(!dir.exists()) { throw new IllegalArgumentException("dir "+dir+" not found"); } File[] jarFiles = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".jar"); } }); return jarFiles; }
@Override public void execute(String queueName, Task task) { if(shutdown) { rejectTask(task); } if(queueName==null || task ==null) { throw new NullArgumentException("queueName is null"); } TaskQueueImpl tasksQueue = getTaskQueue(queueName); if(tasksQueue!=null) { tasksQueue.offer(task); } }
@Override public void execute(String queueName,List<Task> tasks) { if(shutdown) { for(Task t:tasks) { rejectTask(t); } } if(queueName==null || tasks ==null) { throw new NullArgumentException("queueName is null"); } TaskQueueImpl tasksQueue = getTaskQueue(queueName); if(tasksQueue!=null) { tasksQueue.addAll(tasks); } }
@Override public void execute(String queueName, Task task) { if(queueName==null || task ==null) { throw new NullArgumentException("queueName is null"); } if(shutdown) { rejectTask(task); } TaskQueueImpl tasksQueue = getTaskQueue(queueName); if(tasksQueue!=null) { tasksQueue.offer(task); } }
@Override public void execute(String queueName,List<Task> tasks) { if(queueName==null || tasks ==null) { throw new NullArgumentException("queueName is null"); } if(shutdown) { for(Task t:tasks) { rejectTask(t); } } TaskQueueImpl tasksQueue = getTaskQueue(queueName); if(tasksQueue!=null) { tasksQueue.addAll(tasks); } }
@Override public Map<String, Object> buildSignatureParams() { if (StringUtils.isBlank(this.appId)) { throw new NullArgumentException(IWxPay.Const.APP_ID); } if (StringUtils.isBlank(this.transactionId) && StringUtils.isBlank(this.outTradeNo) && StringUtils.isBlank(this.outRefundNo) && StringUtils.isBlank(this.refundId)) { throw new NullArgumentException(""); } // Map<String, Object> _params = super.buildSignatureParams(); _params.put(IWxPay.Const.APP_ID, appId); _params.put(IWxPay.Const.DEVICE_INFO, deviceInfo); _params.put("transaction_id", transactionId); _params.put(IWxPay.Const.OUT_TRADE_NO, outTradeNo); _params.put("out_refund_no", outRefundNo); _params.put("refund_id", refundId); return _params; }
@Override public Map<String, Object> buildSignatureParams() { if (StringUtils.isBlank(this.appId)) { throw new NullArgumentException(IWxPay.Const.APP_ID); } if (StringUtils.isBlank(this.billData)) { throw new NullArgumentException("bill_date"); } if (this.billType == null) { throw new NullArgumentException("bill_type"); } Map<String, Object> _params = super.buildSignatureParams(); _params.put(IWxPay.Const.APP_ID, appId); _params.put(IWxPay.Const.DEVICE_INFO, deviceInfo); _params.put("bill_date", billData); _params.put("bill_type", billType.name()); if (this.tarType) { _params.put("tar_type", "GZIP"); } return _params; }
@Override public Map<String, Object> buildSignatureParams() { if (StringUtils.isBlank(this.appId)) { throw new NullArgumentException(IWxPay.Const.APP_ID); } if (StringUtils.isBlank(this.mchBillNo)) { throw new NullArgumentException("mch_billno"); } if (StringUtils.isBlank(this.billType)) { this.billType = "MCHT"; } Map<String, Object> _params = super.buildSignatureParams(); _params.put(IWxPay.Const.APP_ID, appId); _params.put("mch_billno", mchBillNo); _params.put("bill_type", billType); return _params; }
public AliPayBaseRequest(AliPayAccountMeta accountMeta, String method, String version, DATA bizContent, boolean needNotify, boolean needReturn, IAliPayResponseParser<RESPONSE> responseParser) { if (accountMeta == null) { throw new NullArgumentException("accountMeta"); } if (StringUtils.isBlank(method)) { throw new NullArgumentException("method"); } if (bizContent == null) { throw new NullArgumentException("bizContent"); } if (responseParser == null) { throw new NullArgumentException("responseParser"); } // this.accountMeta = accountMeta; this.method = method; this.version = StringUtils.defaultIfBlank(version, "1.0"); this.bizContent = bizContent; // this.needNotify = needNotify; this.needReturn = needReturn; // this.responseParser = responseParser; }
public AliPayAccountMeta(String appId, String signType, String privateKey, String publicKey) { if (StringUtils.isBlank(appId)) { throw new NullArgumentException("app_id"); } if (StringUtils.isBlank(signType) || !StringUtils.equalsIgnoreCase(signType, IAliPay.Const.SIGN_TYPE_RSA2) && !StringUtils.equalsIgnoreCase(signType, IAliPay.Const.SIGN_TYPE_RSA)) { throw new IllegalArgumentException("sign_type"); } if (StringUtils.isBlank(privateKey)) { throw new NullArgumentException("private_key"); } if (StringUtils.isBlank(publicKey)) { throw new NullArgumentException("public_key"); } this.appId = appId; this.signType = IAliPay.SignType.valueOf(signType.toUpperCase()); this.privateKey = privateKey; this.publicKey = publicKey; }
@Test public void testItemStack() { when(loreGenerator.generateLore(pearl)).thenReturn(new LinkedList<String>()); ItemStack is = pearl.createItemStack(); // Positive test when(loreGenerator.getPearlIdFromItemStack(is)).thenReturn(pearl.getPearlId()); assertTrue(pearl.validateItemStack(is)); // Negative test when(loreGenerator.getPearlIdFromItemStack(is)).thenReturn(0); assertFalse(pearl.validateItemStack(is)); // Null arg throws exception Throwable e = null; try { pearl.validateItemStack(null); } catch (Throwable ex) { e = ex; } assertTrue(e instanceof NullArgumentException); }
/** * @param filePath 目标文件路径 * @return 将文件路径转换成URL对象, 返回值可能为NULL, 若想将jar包中文件,必须使用URL.toString()方法生成filePath参数—即以"jar:"开头 */ public static URL toURL(String filePath) { if (StringUtils.isBlank(filePath)) { throw new NullArgumentException("filePath"); } try { if (!filePath.startsWith("jar:") && !filePath.startsWith("file:") && !filePath.startsWith("zip:") && !filePath.startsWith("http:") && !filePath.startsWith("ftp:")) { return new File(filePath).toURI().toURL(); } return new URL(filePath); } catch (MalformedURLException e) { // DO NOTHING... } return null; }
/** * Joins the array of values with a given separator and returns the . */ public static String join(String[] arrayOfStrings, String separator) { boolean appendSeparator = false; if(arrayOfStrings!=null) { StringBuilder stringBuilder = new StringBuilder(); for(String string : arrayOfStrings) { if(appendSeparator) { stringBuilder.append(separator); } else { appendSeparator=true; } stringBuilder.append(string); } return stringBuilder.toString(); } else { throw new NullArgumentException("arrayOfStrings"); } }
/** * * @param player * @return */ public Event playerJoin(final Player player) { if ((player == null) || !player.isOnline()) throw new NullArgumentException("Player is null"); if (!this.hasPlayerJoined(player)) { this.joineds.add(player); this.updateSigns(); if (safeInventory()) { this.playerBackup(player); player.getInventory().clear(); player.getInventory().setArmorContents(new ItemStack[4]); } final Location teleportTo = getRandomTeleport("lobby"); if (teleportTo != null) player.teleport(teleportTo); else EventoZero.consoleMessage("O teleporte (lobby) do evento (" + getName() + ") esta nulo."); } return this; }
/** * Helper method to handle any media management change. If the channel is the INFO text channel, we delegate to * {@link #handleMMInfoText(String)} instead. This helper method will simply get the next MM identifier and send the * json representation out for the channel change (this ensures unique messages for each MM notification) * * @param channelId a non-null, non-empty channelId * @param value the value for the channel * @throws IllegalArgumentException if channelID is null or empty */ private void handleMMChange(String channelId, String value) { if (StringUtils.isEmpty(channelId)) { throw new NullArgumentException("channelId cannot be null or empty"); } final AtomicInteger ai = mmSeqNbrs.get(channelId); if (ai == null) { logger.error("Channel {} does not have an ID configuration - programmer error!", channelId); } else { if (channelId.equals(RioConstants.CHANNEL_SOURCEMMINFOTEXT)) { value = handleMMInfoText(value); if (value == null) { return; } } final int id = ai.getAndIncrement(); final String json = gson.toJson(new IdValue(id, value)); stateChanged(channelId, new StringType(json)); } }
@Override public UpdateMovieResponseType updateMovie(UpdateMovieRequestType request) { if (request.movie == null) { throw new NullArgumentException("movie"); } Long movieId = request.movie.id; int targetIndex = -1; for (int i = 0; i < movies.size(); ++i) { if (movieId.equals(movies.get(i).id)) { targetIndex = i; break; } } if (targetIndex == -1) { throw new RuntimeException("The specified movie not found."); } synchronized (syncRoot) { if (movies.get(targetIndex).id != movieId) { throw new RuntimeException("The specified movie not found."); } movies.set(targetIndex, request.movie); } return new UpdateMovieResponseType(null); }
@Override public FindMoviesByGenreResponseType findMoviesByGenre( FindMoviesByGenreRequestType request) { if (request.genre == null) { throw new NullArgumentException("genre"); } String loweredGenre = request.genre.toLowerCase(); List<MovieDto> retMovies = new ArrayList<MovieDto>(); for (int i = 0; i < movies.size(); ++i) { MovieDto movie = movies.get(i); if (request.genre.toLowerCase().contains(loweredGenre)) { retMovies.add(movie); break; } } return new FindMoviesByGenreResponseType(null, retMovies); }
@SuppressWarnings("unused") public void changeFileId(String oldFileId, String newFileId) { if (null == oldFileId) { throw new NullArgumentException("oldFileId"); } if (null == newFileId) { throw new NullArgumentException("newFileId"); } if (!files.containsKey(oldFileId)) { throw new IllegalStateException("There is no file with the id " + oldFileId); } if (oldFileId.equals(newFileId)) { return; } if (files.containsKey(newFileId)) { throw new IllegalStateException("There already is a file with the id " + newFileId); } addFile(newFileId, files.remove(oldFileId)); if (defaultFileId.equals(oldFileId)) { defaultFileId = newFileId; } }
public TreeSortKeyDomainObject(String treeSortKey) { if (null == treeSortKey) { throw new NullArgumentException("treeSortKey"); } String[] keyStrings = treeSortKey.trim().split("\\D+", 0); List<Integer> keyList = new ArrayList<Integer>(); for (String keyString : keyStrings) { try { Integer key = Integer.valueOf(keyString); keyList.add(key); } catch (NumberFormatException ignored) { } } keys = ArrayUtils.toPrimitive(keyList.toArray(new Integer[keyList.size()])); this.treeSortKey = treeSortKey; }
private boolean raterValidation() { final boolean nullPointerException = super.uri == null || super.url == null || super.file == null; if (nullPointerException) throw new NullArgumentException("uri and url, file"); boolean illegalArgumentException = false; try { illegalArgumentException = !super.uri.toURL().equals(url) || StringUtils.isBlank(super.url.getFile()) || !file.exists() || !file.isFile(); } catch (MalformedURLException e) { System.out.println(e.getMessage()); } finally { if (illegalArgumentException) throw new IllegalArgumentException(); } return true; }
/** * Default constructor for this class * * @param context the context where the Resource will live. * @throws NullArgumentException if any of the passed parameters is null */ public ProxymaResource (ProxymaRequest request, ProxymaResponse response, ProxymaContext context) throws NullArgumentException { //initialize the logger for this class. log = context.getLogger(); if (context == null) { log.severe("Null context passed to the constructor."); throw new NullArgumentException("Unable to create a resource from a null context"); } if (request == null) { log.severe("Null request passed to the constructor."); throw new NullArgumentException("Unable to create a resource from a null request"); } if (response == null) { log.severe("Null response passed to the constructor."); throw new NullArgumentException("Unable to create a response from a null response"); } this.context = context; this.request = request; this.response = response; log.finer("Created new eesource for context " + context.getName()); }
/** * Add a new Attribute to the resource. * Note: any duplicated entry will be overwritten. Use the containsAttribute() method to check if you care about to not overwrite anything. * * @param attributeName the name of the attribute to add. * @param attributeValue the value of the attribute, it can be any kind of object so it's a responsability of the reader to do the upper-cast to the proper class. * @throws NullArgumentException if the attribute name is null */ public void addAttibute(String attributeName, Object attributeValue) throws NullArgumentException { if (attributeName == null || attributeValue == null) { log.warning("Null attribute name or value parameter.. Ignoring operation"); throw new NullArgumentException("Null attribute name parameter.. Ignoring operation"); } else { boolean exists = attributes.containsKey(attributeName); if (exists) { log.finer("The attribute \"" + attributeName + "\" already exists.. overwriting it."); attributes.remove(attributeName); } else { log.finer("Adding new attribute " + attributeName); } attributes.put(attributeName, attributeValue); } }
/** * Adds an header to the response headers using the given name and value to create it.<br/> * This method allows to set multiple values for the same headerName.<br/> * You can use the containsHeader method if you want to test for the presence * of a an existing header before setting its value. * @throws NullArgumentException is raised if the header name is null * @see ProxymaHttpHeader */ public void addHeader(String headerName, String headerValue) throws NullArgumentException { if (headerName == null) throw new NullArgumentException("You can't set a null-named header"); //Evaulate if the Map already countains the header. String lowercaseHeaderName = headerName.toLowerCase().trim(); if (this.headers.containsKey(lowercaseHeaderName)) { Object existingValue = this.headers.get(lowercaseHeaderName); if (existingValue instanceof ProxymaHttpHeader) { //A single value already exists LinkedList<ProxymaHttpHeader> newValue = new LinkedList<ProxymaHttpHeader>(); newValue.add((ProxymaHttpHeader)existingValue); newValue.add(new ProxymaHttpHeader(headerName, headerValue)); this.headers.put(lowercaseHeaderName, newValue); } else if (existingValue instanceof LinkedList) { //Multiple values already exists ((LinkedList<ProxymaHttpHeader>)existingValue).add(new ProxymaHttpHeader(headerName, headerValue)); } } else { //The header doesn't exists this.headers.put(lowercaseHeaderName, new ProxymaHttpHeader(headerName, headerValue)); } }
/** * Standard setter method for folderName.<br/> * Setting the folder name will set also the URLEncoded version of it.<br/> * Note: The foldername can't contain "/" characters. * * @param folderName the folder name to set * @throws NullArgumentException if some parameter is null * @throws IllegalArgumentException if the folder name is not valid * @throws UnsupportedEncodingException if the default encoding charset specified on the configuration is not supported. */ public synchronized void setFolderName(String newFolderName) throws NullArgumentException, IllegalArgumentException, UnsupportedEncodingException { if (newFolderName == null) { log.warning("Null folderName passed."); throw new NullArgumentException("Null folderName passed."); } else { this.folderName = newFolderName.trim(); if (this.folderName.length() == 0) { log.warning("The passed folderName is an empty (or blank)"); throw new IllegalArgumentException("The passed folderName is an empty (or blank)"); } else { //encoding-decoding the folder name if (this.folderName.indexOf("/") != -1) { log.warning("The foldername can't contain a \"/\" character"); throw new IllegalArgumentException("The foldername can't contain a \"/\" character"); } else { //register the new urlEncoded name for the context (if the folder has a context) String oldURLEncodedName = this.URLEncodedName; this.URLEncodedName = URLEncoder.encode(this.folderName, defaultEncoding); if (context != null) context.updateFolderURLEncodedIndex(oldURLEncodedName, this); } } } }
/** * Builds a new ProxyFolder to the specified destination setting it up * and ready to be attached to a context. * * @param FolderName the path (and name) of the proxy folder. * @param destination the destination URI to masquerade * @param context the proxyma context where to take default settings. * @throws NullArgumentException if some parameter is null * @throws IllegalArgumentException if the folder name or the destination parameter are invalid or malformed * @throws UnsupportedEncodingException if the default encoding charset specified on the configuration is not supported. */ public ProxyFolderBean createNewProxyFolder (String FolderName, String destination, ProxymaContext context) throws NullArgumentException, IllegalArgumentException, UnsupportedEncodingException { ProxyFolderBean theFolder = new ProxyFolderBean(FolderName, destination, context); //Set single value parameters theFolder.setMaxPostSize(Integer.parseInt(context.getSingleValueParameter(ProxymaTags.FOLDER_MAX_POST_SIZE))); theFolder.setCacheProvider(context.getSingleValueParameter(ProxymaTags.FOLDER_CACHEPROVIDER)); theFolder.setRetriver(context.getSingleValueParameter(ProxymaTags.FOLDER_RETRIVER)); theFolder.setSerializer(context.getSingleValueParameter(ProxymaTags.FOLDER_SERIALIZER)); //Set multi value parameters Collection<String> preprocessors = context.getMultiValueParameter(ProxymaTags.FOLDER_PREPROCESSORS); Iterator<String> iter = preprocessors.iterator(); while (iter.hasNext()) theFolder.registerPreprocessor(iter.next()); Collection<String> transformers = context.getMultiValueParameter(ProxymaTags.FOLDER_TRANSFORMERS); iter = transformers.iterator(); while (iter.hasNext()) theFolder.registerTransformer(iter.next()); return theFolder; }
/** * Unregister an existing and empty context from the pool * NOTE: This method requires that the context is empty. * In other words, it will remove the context only if it doesn't contain * any ProxyFolderBean. * * @param the context to unregister * @throws IllegalArgumentException if the doesn't exists * @throws NullArgumentException if a null argument is passed to this method * @throws IllegalStateException if the context is not empty */ public void unregisterContext(ProxymaContext context) throws NullArgumentException, IllegalArgumentException, IllegalStateException { if (context == null) { log.warning("Null context argument received.. operation aborted"); throw new NullArgumentException("Null context argument received.. operation aborted"); } else if (context.getProxyFoldersCount() > 0) { log.warning("Context \"" + context.getName() + "\" is not empty.. operation aborted"); throw new IllegalStateException("Context \"" + context.getName() + "\" is not empty.. operation aborted"); } else if (!proxymaContexts.containsKey(context.getName())) { log.warning("Context \"" + context.getName() + "\" doesn't exists.. operation aborted."); throw new IllegalArgumentException("Context \"" + context.getName() + "\" doesn't exists.. operation aborted."); } else { log.finer("Removing context \"" + context.getName() + "\" from the pool."); proxymaContexts.remove(context.getName()); } }
/** * Test of deleteCookie method, of class ProxymaResponseDataBean. */ public void testDeleteCookie() { System.out.println("deleteCookie"); ProxymaResponseDataBean instance = new ProxymaResponseDataBean(); instance.addCookie(new Cookie("name1", "value1")); instance.addCookie(new Cookie("name2", "value2")); instance.addCookie(new Cookie("name1", "value3")); Collection<Cookie> result = instance.getCookies(); assertEquals(2, result.size()); try { instance.deleteCookie(null); fail("exception not thrown"); } catch (NullArgumentException x) { assertTrue(true); } instance.deleteCookie("unexistent"); result = instance.getCookies(); assertEquals(2, result.size()); instance.deleteCookie("name1"); result = instance.getCookies(); assertEquals(1, result.size()); }
/** * 构造器 * * @param accountId 微信公众帐号原始ID * @param appId 第三方应用唯一凭证 * @param appSecret 第三方应用唯一凭证密钥 * @param appAesKey 消息加密密钥由43位字符组成,可随机修改,字符范围为A-Z,a-z,0-9 * @param redirectUri OAuth授权后重定向的URL地址 * @param type 公众号类型 * @param isVerfied 是否已认证 */ public AccountDataMeta(String accountId, String appId, String appSecret, String appAesKey, String redirectUri, int type, int isVerfied) { if (StringUtils.isBlank(accountId)) { throw new NullArgumentException("accountId"); } if (StringUtils.isBlank(appId)) { throw new NullArgumentException("appId"); } if (StringUtils.isBlank(appSecret)) { throw new NullArgumentException("appSecret"); } // this.accountId = accountId; this.appId = appId; this.appSecret = appSecret; this.appAesKey = appAesKey; this.redirectUri = redirectUri; this.type = type; this.isVerified = isVerfied; }
/** * 初始化微信公众平台服务接入框架管理器 * * @param config * @throws Exception */ public static void initialize(IWeChatConfig config) throws Exception { if (!__IS_INITED) { if (config == null) { throw new NullArgumentException("config"); } if ((__dataProvider = config.getAccountDataProviderImpl()) == null) { throw new NullArgumentException("AccountDataProviderImpl"); } __dataProvider.initialize(); // if ((__messageProcessor = config.getMessageProcessorImpl()) == null) { // _LOG.debug("Default Message Processor Used"); if (config.getMessageHandlerImpl() == null) { throw new NullArgumentException("MessageHandlerImpl"); } __messageProcessor = new DefaultMessageProcessor(config.getMessageHandlerImpl()); } __CFG_CONFIG = config; __IS_INITED = true; } }
/** * @param accountId 微信公众帐号ID * @param articles 图文消息对象集合 * @return 上传图文消息素材 * @throws Exception */ public static WxMediaUploadResult wxMediaUploadNews(String accountId, List<WxMassArticle> articles) throws Exception { __doCheckModuleInited(); if (articles == null || articles.isEmpty()) { throw new NullArgumentException("articles"); } StringBuilder _paramSB = new StringBuilder("{ \"articles\": ["); boolean _flag = false; for (WxMassArticle article : articles) { if (_flag) { _paramSB.append(","); } _paramSB.append(article.toJSON()); _flag = true; } _paramSB.append("]}"); JSONObject _json = __doCheckJsonResult(HttpClientHelper.create().doPost(WX_API.MEDIA_UPLOAD_NEWS + wxGetAccessToken(accountId), _paramSB.toString())); return new WxMediaUploadResult(WxMediaType.NEWS, _json.getString("media_id"), _json.getString("thumb_media_id"), _json.getLong("created_at")); }
/** * @param accountId 微信公众帐号ID * @param needUserInfo 是否弹出授权页面 * @param state 自定义参数(a-zA-Z0-9) * @param redirectURI 自定义重定向地址 * @return 返回微信用户授权URL地址 * @throws Exception */ public static String wxOAuthGetCodeURL(String accountId, boolean needUserInfo, String state, String redirectURI) throws Exception { __doCheckModuleInited(); String _appId = __dataProvider.getAppId(accountId); if (StringUtils.isBlank(_appId)) { throw new NullArgumentException("appId"); } if (StringUtils.isBlank(redirectURI)) { throw new NullArgumentException("redirectURI"); } Map<String, Object> _params = new HashMap<String, Object>(); _params.put("appid", _appId); _params.put("response_type", "code"); _params.put("redirect_uri", URLEncoder.encode(redirectURI, HttpClientHelper.DEFAULT_CHARSET)); _params.put("scope", needUserInfo ? "snsapi_userinfo" : "snsapi_base"); _params.put("state", StringUtils.defaultIfEmpty(state, "") + "#wechat_redirect"); return WX_API.OAUTH_GET_CODE.concat(__doParamSignatureSort(_params, false)); }
/** * { "access_token":"ACCESS_TOKEN", "expires_in":7200, "refresh_token":"REFRESH_TOKEN", "openid":"OPENID", "scope":"SCOPE" } * * @param accountId 微信公众帐号ID * @param code * @return 通过Code换取网页授权的AccessToken * @throws Exception */ public static WxOAuthToken wxOAuthGetToken(String accountId, String code) throws Exception { __doCheckModuleInited(); String _appId = __dataProvider.getAppId(accountId); if (StringUtils.isBlank(_appId)) { throw new NullArgumentException("appId"); } String _appSecret = __dataProvider.getAppSecret(accountId); if (StringUtils.isBlank(_appSecret)) { throw new NullArgumentException("appSecret"); } if (StringUtils.isBlank(code)) { throw new NullArgumentException("code"); } Map<String, String> _params = new HashMap<String, String>(); _params.put("appid", _appId); _params.put("secret", _appSecret); _params.put("code", code); _params.put("grant_type", "authorization_code"); JSONObject _json = __doCheckJsonResult(HttpClientHelper.create().doGet(WX_API.OAUTH_ACCESS_TOKEN, _params)); return new WxOAuthToken(_json.getString("access_token"), _json.getIntValue("expires_in"), _json.getString("refresh_token"), _json.getString("openid"), _json.getString("scope")); }
/** * @param accountId 微信公众帐号ID * @param refreshToken 哪个想刷就刷哪个~ * @return 刷新AccessToken * @throws Exception */ public static WxOAuthToken wxOAuthRefreshToken(String accountId, String refreshToken) throws Exception { __doCheckModuleInited(); String _appId = __dataProvider.getAppId(accountId); if (StringUtils.isBlank(_appId)) { throw new NullArgumentException("appId"); } if (StringUtils.isBlank(refreshToken)) { throw new NullArgumentException("refreshToken"); } Map<String, String> _params = new HashMap<String, String>(); _params.put("appid", _appId); _params.put("grant_type", "refresh_token"); _params.put("refresh_token", refreshToken); JSONObject _json = __doCheckJsonResult(HttpClientHelper.create().doGet(WX_API.OAUTH_REFRESH_TOKEN, _params)); return new WxOAuthToken(_json.getString("access_token"), _json.getIntValue("expires_in"), _json.getString("refresh_token"), _json.getString("openid"), _json.getString("scope")); }
/** * @param openid * @param lang 语言(可选) * @return 拉取用户信息 * @throws Exception */ public static WxOAuthUser wxOAuthUserGetInfo(String oauthAccessToken, String openid, WxLangType lang) throws Exception { __doCheckModuleInited(); if (StringUtils.isBlank(oauthAccessToken)) { throw new NullArgumentException("oauthAccessToken"); } if (StringUtils.isBlank(openid)) { throw new NullArgumentException("openid"); } Map<String, String> _params = new HashMap<String, String>(); _params.put("openid", openid); if (lang != null) { _params.put("lang", lang.toString()); } JSONObject _json = __doCheckJsonResult(HttpClientHelper.create().doGet(WX_API.OAUTH_USER_INFO.concat(oauthAccessToken), _params)); return new WxOAuthUser(_json.getString("openid"), _json.getString("unionid"), _json.getString("nickname"), _json.getInteger("sex"), _json.getString("city"), _json.getString("province"), _json.getString("country"), _json.getString("headimgurl"), JSON.parseArray(_json.getJSONArray("privilege").toJSONString(), String.class)); }
/** * 检验授权凭证(access_token)是否有效 * * @param oauthAccessToken 网页授权接口调用凭证 * @param openid 用户的唯一标识 * @return true / false * @throws Exception */ public static boolean wxOAuthAuthAccessToken(String oauthAccessToken, String openid) throws Exception { __doCheckModuleInited(); if (StringUtils.isBlank(oauthAccessToken)) { throw new NullArgumentException("oauthAccessToken"); } if (StringUtils.isBlank(openid)) { throw new NullArgumentException("openid"); } Map<String, String> _params = new HashMap<String, String>(); _params.put("openid", openid); try { __doCheckJsonResult(HttpClientHelper.create().doGet(WX_API.OAUTH_AUTH_ACCESS_TOKEN.concat(oauthAccessToken), _params)); } catch (Exception e) { return false; } return true; }
/** * 上传永久图文素材 * * @param accountId * @param articles * @return * @throws Exception */ public static String wxMaterialAddNews(String accountId, List<WxMassArticle> articles) throws Exception { __doCheckModuleInited(); if (articles == null || articles.isEmpty()) { throw new NullArgumentException("articles"); } StringBuilder _paramSB = new StringBuilder("{ \"articles\": ["); boolean _flag = false; for (WxMassArticle article : articles) { if (_flag) { _paramSB.append(","); } _paramSB.append(article.toJSON()); _flag = true; } _paramSB.append("]}"); JSONObject _json = __doCheckJsonResult(HttpClientHelper.create().doPost(WX_API.MATERIAL_ADD_NEWS + wxGetAccessToken(accountId), _paramSB.toString())); return _json.getString("media_id"); }
public static boolean tryParse(String s, InOutParam<Integer> out) { if (out == null) { throw new NullArgumentException("out"); } if (s == null || s.isEmpty()) { return false; } try { out.setValue(Integer.parseInt(s)); return true; } catch (NumberFormatException ex) { return false; } }
/** * Puts an object identified by a key * * @param key * @param obj */ @Override public void put(K key, T obj) { try { Object hashKey = getHashKey(key, obj); Object rangeKey = getRangeKey(key, obj); if (hashKey != null) { DynamoDBMapper mapper = new DynamoDBMapper( dynamoDBStoreHandler.getDynamoDbClient()); if (rangeKey != null) { mapper.load(persistentClass, hashKey, rangeKey); } else { mapper.load(persistentClass, hashKey); } mapper.save(obj); } else throw new GoraException("No HashKey found in Key nor in Object."); } catch (NullPointerException npe) { LOG.error("Error while putting an item. " + npe.toString()); throw new NullArgumentException(npe.getMessage()); } catch (Exception e) { LOG.error("Error while putting an item. " + obj.toString()); throw new RuntimeException(e); } }
/** * Sets the wrapped distributed process class. * * @param job * the reference to the Hadoop job. * @param cls * the distributed process class to wrap. * @throws NullPointerException * if any of specified arguments equals {@code null}. */ public static final void setWrappedProcessClass(final Job job, final Class<? extends DistributedProcess<?, ?, ?, ?, ?, ?>> cls) { if (job == null) { throw new NullArgumentException( "The reference to the Hadoop job not defined."); } if (cls == null) { throw new NullArgumentException( "The distributed process class not defined."); } job.getConfiguration().setClass(MAPREDUCE_JOB_REDUCE_WRAPPED_CLASS, cls, DistributedProcess.class); }