com.alipay.api.internal.util.WebUtils Java Examples
The following examples show how to use
com.alipay.api.internal.util.WebUtils.
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: AbstractAlipayClient.java From alipay-sdk-java-all with Apache License 2.0 | 6 votes |
/** * 获取POST请求的base url * * @param requestHolder * @return * @throws AlipayApiException */ private String getRequestUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuilder urlSb = new StringBuilder(serverUrl); try { String sysMustQuery = WebUtils.buildQuery(loadTest ? LoadTestUtil.getParamsWithLoadTestFlag(requestHolder.getProtocalMustParams()) : requestHolder.getProtocalMustParams(), charset); String sysOptQuery = WebUtils.buildQuery(requestHolder.getProtocalOptParams(), charset); urlSb.append("?"); urlSb.append(sysMustQuery); if (sysOptQuery != null && sysOptQuery.length() > 0) { urlSb.append("&"); urlSb.append(sysOptQuery); } } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #2
Source File: DefaultAlipayClient.java From pay with Apache License 2.0 | 6 votes |
/** * GET模式下获取跳转链接 * * @param requestHolder * @return * @throws AlipayApiException */ private String getRedirectUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(serverUrl); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(sortedMap, charset); String sign = requestHolder.getProtocalMustParams().get(AlipayConstants.SIGN); urlSb.append("?"); urlSb.append(sortedQuery); if (sign != null & sign.length() > 0) { Map<String, String> signMap = new HashMap<String, String>(); signMap.put(AlipayConstants.SIGN, sign); String signQuery = WebUtils.buildQuery(signMap, charset); urlSb.append("&"); urlSb.append(signQuery); } } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #3
Source File: DefaultAlipayClient.java From pay with Apache License 2.0 | 6 votes |
/** * 获取POST请求的base url * * @param requestHolder * @return * @throws AlipayApiException */ private String getRequestUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(serverUrl); try { String sysMustQuery = WebUtils.buildQuery(requestHolder.getProtocalMustParams(), charset); String sysOptQuery = WebUtils.buildQuery(requestHolder.getProtocalOptParams(), charset); urlSb.append("?"); urlSb.append(sysMustQuery); if (sysOptQuery != null & sysOptQuery.length() > 0) { urlSb.append("&"); urlSb.append(sysOptQuery); } } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #4
Source File: DefaultAlipayClient.java From alipay-sdk with Apache License 2.0 | 6 votes |
/** * 获取POST请求的base url * * @param requestHolder * @return * @throws AlipayApiException */ private String getRequestUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(serverUrl); try { String sysMustQuery = WebUtils.buildQuery(requestHolder.getProtocalMustParams(), charset); String sysOptQuery = WebUtils.buildQuery(requestHolder.getProtocalOptParams(), charset); urlSb.append("?"); urlSb.append(sysMustQuery); if (sysOptQuery != null & sysOptQuery.length() > 0) { urlSb.append("&"); urlSb.append(sysOptQuery); } } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #5
Source File: ExecuteTest.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
@Test public void should_return_success_response_when_enable_keep_alive() throws AlipayApiException, InterruptedException { WebUtils.setKeepAliveTimeout(60); sendOneNormalRequest(); Thread.sleep(5000); sendOneNormalRequest(); }
Example #6
Source File: DefaultAlipayClient.java From pay with Apache License 2.0 | 5 votes |
/** * * * @param request * @param accessToken * @param signType * @return * @throws AlipayApiException */ private <T extends AlipayResponse> Map<String, Object> doPost(AlipayRequest<T> request, String accessToken, String appAuthToken) throws AlipayApiException { Map<String, Object> result = new HashMap<String, Object>(); RequestParametersHolder requestHolder = getRequestHolderWithSign(request, accessToken, appAuthToken); String url = getRequestUrl(requestHolder); // 打印完整请求报文 if (AlipayLogger.isBizDebugEnabled()) { AlipayLogger.logBizDebug(getRedirectUrl(requestHolder)); } String rsp = null; try { if (request instanceof AlipayUploadRequest) { AlipayUploadRequest<T> uRequest = (AlipayUploadRequest<T>) request; Map<String, FileItem> fileParams = AlipayUtils.cleanupMap(uRequest.getFileParams()); rsp = WebUtils.doPost(url, requestHolder.getApplicationParams(), fileParams, charset, connectTimeout, readTimeout); } else { rsp = WebUtils.doPost(url, requestHolder.getApplicationParams(), charset, connectTimeout, readTimeout); } } catch (IOException e) { throw new AlipayApiException(e); } result.put("rsp", rsp); result.put("textParams", requestHolder.getApplicationParams()); result.put("protocalMustParams", requestHolder.getProtocalMustParams()); result.put("protocalOptParams", requestHolder.getProtocalOptParams()); result.put("url", url); return result; }
Example #7
Source File: DefaultAlipayClient.java From pay with Apache License 2.0 | 5 votes |
/** * 拼装sdk调用时所传参数 * * @param requestHolder * @return * @throws AlipayApiException */ private String getSdkParams(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(sortedMap, charset); urlSb.append(sortedQuery); } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #8
Source File: DefaultAlipayClient.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * * * @param request * @param accessToken * @param appAuthToken * @return * @throws AlipayApiException */ private <T extends AlipayResponse> Map<String, Object> doPost(AlipayRequest<T> request, String accessToken, String appAuthToken) throws AlipayApiException { Map<String, Object> result = new HashMap<String, Object>(); RequestParametersHolder requestHolder = getRequestHolderWithSign(request, accessToken, appAuthToken); String url = getRequestUrl(requestHolder); // 打印完整请求报文 if (AlipayLogger.isBizDebugEnabled()) { AlipayLogger.logBizDebug(getRedirectUrl(requestHolder)); } String rsp = null; try { if (request instanceof AlipayUploadRequest) { AlipayUploadRequest<T> uRequest = (AlipayUploadRequest<T>) request; Map<String, FileItem> fileParams = AlipayUtils.cleanupMap(uRequest.getFileParams()); rsp = WebUtils.doPost(url, requestHolder.getApplicationParams(), fileParams, charset, connectTimeout, readTimeout, proxyHost, proxyPort); } else { rsp = WebUtils.doPost(url, requestHolder.getApplicationParams(), charset, connectTimeout, readTimeout, proxyHost, proxyPort); } } catch (IOException e) { throw new AlipayApiException(e); } result.put("rsp", rsp); result.put("textParams", requestHolder.getApplicationParams()); result.put("protocalMustParams", requestHolder.getProtocalMustParams()); result.put("protocalOptParams", requestHolder.getProtocalOptParams()); result.put("url", url); return result; }
Example #9
Source File: DefaultAlipayClient.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * 拼装sdk调用时所传参数 * * @param requestHolder * @return * @throws AlipayApiException */ private String getSdkParams(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(sortedMap, charset); urlSb.append(sortedQuery); } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #10
Source File: DefaultAlipayClient.java From alipay-sdk with Apache License 2.0 | 5 votes |
/** * GET模式下获取跳转链接 * * @param requestHolder * @return * @throws AlipayApiException */ private String getRedirectUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuffer urlSb = new StringBuffer(serverUrl); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(sortedMap, charset); urlSb.append("?"); urlSb.append(sortedQuery); } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #11
Source File: AbstractAlipayClient.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
/** * 拼装sdk调用时所传参数 * * @param requestHolder * @return * @throws AlipayApiException */ private String getSdkParams(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuilder urlSb = new StringBuilder(); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(loadTest ? LoadTestUtil.getParamsWithLoadTestFlag(sortedMap) : sortedMap, charset); urlSb.append(sortedQuery); } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #12
Source File: AbstractAlipayClient.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
/** * GET模式下获取跳转链接 * * @param requestHolder * @return * @throws AlipayApiException */ private String getRedirectUrl(RequestParametersHolder requestHolder) throws AlipayApiException { StringBuilder urlSb = new StringBuilder(serverUrl); try { Map<String, String> sortedMap = AlipaySignature.getSortedMap(requestHolder); String sortedQuery = WebUtils.buildQuery(loadTest ? LoadTestUtil.getParamsWithLoadTestFlag(sortedMap) : sortedMap, charset); urlSb.append("?"); urlSb.append(sortedQuery); } catch (IOException e) { throw new AlipayApiException(e); } return urlSb.toString(); }
Example #13
Source File: AbstractAlipayClient.java From alipay-sdk-java-all with Apache License 2.0 | 5 votes |
/** * @param request * @return * @throws AlipayApiException */ private Map<String, Object> doPost(BatchAlipayRequest request) throws AlipayApiException { Map<String, Object> result = new HashMap<String, Object>(); RequestParametersHolder requestHolder = getRequestHolderWithSign(request); String url = getRequestUrl(requestHolder); // 打印完整请求报文 if (AlipayLogger.isBizDebugEnabled()) { AlipayLogger.logBizDebug(getRedirectUrl(requestHolder)); } result.put("prepareTime", System.currentTimeMillis()); String rsp = null; try { rsp = WebUtils.doPost(url, requestHolder.getApplicationParams(), charset, connectTimeout, readTimeout, proxyHost, proxyPort); } catch (IOException e) { throw new AlipayApiException(e); } result.put("requestTime", System.currentTimeMillis()); result.put("rsp", rsp); result.put("textParams", requestHolder.getApplicationParams()); result.put("protocalMustParams", requestHolder.getProtocalMustParams()); result.put("protocalOptParams", requestHolder.getProtocalOptParams()); result.put("url", url); return result; }
Example #14
Source File: AlipayMsgClient.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
private void doConnect() throws Exception { if (isConnected()) { return; } synchronized (this) { if (isConnected()) { return; } RegisterResponse regResp = register(); Map<String, String> httpHeaders = new HashMap<String, String>(1); if (regResp.getZone() != null && regResp.getZone().length() > 0) { httpHeaders.put("cookie", "zone=" + regResp.getZone() + ";"); } if (loadTest) { httpHeaders.put("LoadTest", "true"); } httpHeaders.put("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); Map<String, String> params = new HashMap<String, String>(5); params.put("app_id", appId); params.put("charset", charset); params.put("link_token", regResp.getLinkToken()); params.put("timestamp", String.valueOf(System.currentTimeMillis())); params.put("sign_type", signType); params.put("sdk_version", AlipayConstants.SDK_VERSION); String signContent = AlipaySignature.getSignCheckContentV2(params); String sign = AlipaySignature.rsaSign(signContent, appPrivateKey, charset, signType); params.put("sign", sign); String query = WebUtils.buildQuery(params, charset); String urlStr = "ws" + (isSSL ? "s" : "") + "://" + serverHost + "/websocket?" + query; webSocketConnector = new MsgConnector(new URI(urlStr), httpHeaders, this, charset); if (!webSocketConnector.connectBlocking(10L, TimeUnit.SECONDS)) { throw new RuntimeException("connect timeout(10s)!"); } if (AlipayLogger.isBizDebugEnabled()) { AlipayLogger.logBizDebug("connected"); } } }
Example #15
Source File: ExecuteTest.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
@After public void tearDown() { WebUtils.setNeedCheckServerTrusted(true); WebUtils.setKeepAliveTimeout(0); }
Example #16
Source File: AlipayMsgClient.java From alipay-sdk-java-all with Apache License 2.0 | 4 votes |
private RegisterResponse register() throws Exception { Map<String, String> params = new HashMap<String, String>(4); params.put("timestamp", String.valueOf(System.currentTimeMillis())); params.put("sign_type", signType); params.put("app_id", appId); params.put("charset", charset); params.put("sdk_version", AlipayConstants.SDK_VERSION); params.put("nonce", UUID.randomUUID().toString().replace("-", "")); String signContent = AlipaySignature.getSignCheckContentV2(params); String sign = AlipaySignature.rsaSign(signContent, appPrivateKey, charset, signType); params.put("sign", sign); String query = WebUtils.buildQuery(params, charset); String urlStr = "http" + (isSSL ? "s" : "") + "://" + serverHost + "/websocket/register.do?" + query; URL url = new URL(urlStr); HttpURLConnection conn = null; InputStream stream = null; String rsp = null; try { conn = WebUtils.getConnection(url, "GET", "application/x-www-form-urlencoded;charset=" + charset); if (loadTest) { conn.setRequestProperty("LoadTest", "true"); } InputStream es = conn.getErrorStream(); stream = es == null ? conn.getInputStream() : es; BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset)); StringWriter writer = new StringWriter(); char[] chars = new char[256]; int count = 0; while ((count = reader.read(chars)) > 0) { writer.write(chars, 0, count); } rsp = writer.toString(); } finally { if (stream != null) { stream.close(); } if (conn != null) { conn.disconnect(); } } RegisterResponse res = new RegisterResponse(); res.setLinkToken(parseRegResp(rsp)); res.setZone(parseRegRespHeader(conn.getHeaderFields())); return res; }
Example #17
Source File: ExecuteTest.java From alipay-sdk-java-all with Apache License 2.0 | 3 votes |
/** * 手动测试用例 * <p> * 1. 删除JRE的cacerts后,设置要检查服务端证书,调用openapi失败。 * <p> * 2. 删除JRE的cacerts后,设置不检查服务端证书,调用openapi成功。 * <p> * 3. 恢复JRE的cacerts后,设置要检查服务端证书,调用openapi成功。 */ @Ignore public void should_return_success_when_ca_cert_not_exist_but_set_skip_ssl_server_cert_verify() throws AlipayApiException { alipayClient = new DefaultAlipayClient(TestAccount.Sandbox.GATEWAY, TestAccount.Sandbox.APP_ID, TestAccount.Sandbox.APP_PRIVATE_KEY, "json", "utf-8", TestAccount.Sandbox.ALIPAY_PUBLICKEY, "RSA2"); WebUtils.setNeedCheckServerTrusted(true); sendOneNormalRequest(); }