Article From:https://segmentfault.com/q/1010000011711399
Question:
  1. List item


Is the configuration of the server Tomcat wrong?
This is the code to generate two-dimensional code.
public String qrPay(Yyopregist_PC yy) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //Overdue timeString time_expire= sdf.format (System.currentTimeMillis () +24*60*60*1000);StringBuIlder sb = new StringBuilder ();Sb.append ("{" out_trade_no\ ":" "+ yy.getOutTradeNo () +" "" ");Sb.append ("total_amount\" ":" "+yy.getMoney () +" "," "discountable_amount\": "0.00\", "");Sb.apPend ("subject\": "," "+yy.getPayName () +" "," "body\": "", ").Sb.append ("" goods_detail\ ": [[]" good ""S_id\ ":", "+yy.getOutTradeNo () +", "," goods_name\ ":", "+yy.getPayName () +", "," goods_category\ ":", ",".Price\ ":", "+yy.getMoney (+)", "," quantity\ ":" 1\ "}, {" goods_id\ ":", "" +yy.getOutTradeNo () + ",", "," goods_n "Ame\ ":", "+yy.getPayName () +", "," goods_category\ ":", "," price\ ":", "+yy.getMoney () +", ",", "quantity\":"1\"], ");Sb.append ("operator_id\"): ",", "," store_id\ ":", "," terminal_id\ ":", "".Sb.appEnd ("time_expire\": "," "+time_expire+" "}");Logger.info ("Alipay generates two dimensional code parameters" +sb.toString ());

// AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();

    AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClientRSA2();
    // Using SDK to build group request modelAlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest ();RequEst.setBizContent (sb.toString ()); //plus.reallycare.cn/sdey_pcRequest.setNotifyUrl (url+ "/backend/api/v1/taizhouPcBookingOrder/alipayNotify "";

// request.putOtherTextParam(“ws_service_url”, “http://unitradeprod.t15032aqcn.alipay.net:8080”);

    AlipayTradePrecreateResponse response = null;
    try {
        // Use SDK to invoke the transaction order interface.Logger.info ("Alipay generates two dimensional code containing the callback parameter" +request);Response = alipayClient.execUte (request);Logger.info ("Alipay generates two dimensional code of body:" +response.getBody ());Logger.info ("Alipay generation"The two-dimensional code was successful: "+response.isSuccess () +";Logger.info ("Alipay generates two-dimensional code, the return information is:" +response.getMsg ());/ / here is just a simple print, please developers according to the actual situation of self processing.If (null = response & & response.isSuccess ()) {If (response.getCode ().Equals ("10000")) {Logger.info ("merchant Order No.:" +response.getO)UtTradeNo ());Logger. info ("two-dimensional code value:"+ response. getQrCode ()); / / The merchant generates two-dimensional code from this two-dimensional code value, and then displays it to the user, which is supported by the userFu Bao mobile wallet sweep code to complete paymentReturn response.getQrCode ();/ / the generation of two-dimensional code. There are many open source methods on the Internet. You can see: HTTp://blog.csdn.net/feiyu84/article/details/9089497} else {/ / print error codeLogger.info ("error code:" +response.getSubCode ());Logger.info ("Erroneous Description:" +response.getSubMsg ();}}} catch (AlipayApiException E) {E.printStackTrace ();Logger.info ("Error Description:" +e.getErrMsg ());Logger.info ("Alipay generates two dimensional code interface into exception."- - "+e.getMessage () +" = = = = exception case = = = = = "+e.getCause ());}Return null;}

Answer 0:

Your last one is socketTimeoutException, which gives priority to network issues such as intranet and intranet, firewall, and whether requests for special ports are blocked.

Answer 1:

Try to increase timeout time.

Answer 2:
 connection timeout = 5000(Create connection timeout timeRead timeout = 3000 (return read timeout)

Attach a tool category to you:

 private static String post(HttpPost post, Integer connTimeout, Integer readTimeout) throws Exception {
        Object client = null;
        String result = "";

        try {
            Builder customReqConf = RequestConfig.custom();
            if(connTimeout != null) {
                customReqConf.setConnectTimeout(connTimeout.intValue());
            }

            if(readTimeout != null) {
                customReqConf.setSocketTimeout(readTimeout.intValue());
            }

            post.setConfig(customReqConf.build());
            HttpResponse res;
            if(post.getURI().toString().startsWith("https")) {
                client = createSSLInsecureClient();
                res = ((HttpClient)client).execute(post);
            } else {
                client = client;
                res = ((HttpClient)client).execute(post);
            }

            result = IOUtils.toString(res.getEntity().getContent(), Consts.UTF_8.toString());
        } finally {
            post.releaseConnection();
            if(post.getURI().toString().startsWith("https") && client != null && client instanceof CloseableHttpClient) {
                ((CloseableHttpClient)client).close();
            }

        }

        return result;
    }

——————supplement

You can try setting the request timeout by setting the server. XML file in the conf folder under tomcat.

<Connector port="8080" protocol="HTTP/1.1" 
              connectionTimeout="20000" 
              redirectPort="8443" acceptCount="500" maxThreads="400" />

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *