在Java 8升级之后,http在http调用中不能为null

时间:2018-05-18 17:17:04

标签: http url connection illegalargumentexception

在WebSphere 8.5上将Java版本从6升级到8之后,我得到以下异常。以下是我的代码

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Date;
import java.util.logging.Level;
    try {

                cicsRecord = setLength(callData).trim();
                Date callTime = new Date();
                if (_logger.isLoggable(Level.INFO)) {
                    _logger.log(Level.INFO, callTime.getTime() + "  http://"
                            + cicsIp + ":" + cicsPort + callData);
                }

                URL url = new URL("http", cicsIp, cicsPort, callData);


                URLConnection connection =  url.openConnection();
                InputStream istream = connection.getInputStream();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(istream));

                data = bufferedReader.readLine();
                if (_logger.isLoggable(Level.INFO)) {
                    _logger.log(Level.INFO, "Return from Cics Data =" + data);
                }
                // this next line removes the headder info that mainframe requires
                // to be returned.
                responseData = new StringBuffer(data.substring(56));
                while ((data = bufferedReader.readLine()) != null) {
                    responseData.append(data);
                }
            } catch (Exception e) {
                throw new CicsException(e);
            }
            return responseData.toString();
        }

      private String setLength(String arg){
          StringBuilder dataBuilder = new StringBuilder();
          Integer length = new Integer(arg.length() - 100);
          String stringLength = new String(length.toString());
          int i = stringLength.length();
          int j = 68;
        _logger.log(Level.INFO, "arg Data =" + arg);
          dataBuilder.append(arg);
          dataBuilder.setCharAt(57,'L');
          dataBuilder.setCharAt(58,'E');
          dataBuilder.setCharAt(59,'N');
          dataBuilder.setCharAt(60,'G');
          dataBuilder.setCharAt(61,'T');
          dataBuilder.setCharAt(62,'H');
          dataBuilder.setCharAt(63,'=');
          dataBuilder.setCharAt(64,'0');
          dataBuilder.setCharAt(65,'0');
          dataBuilder.setCharAt(66,'0');
          dataBuilder.setCharAt(67,'0');
          dataBuilder.setCharAt(68,'0');
          //charLength = stringLength.charAt(5);
            while(i > 0) {
                dataBuilder.setCharAt(j, stringLength.charAt(i - 1));
                j--;
                i--;
            }
          return dataBuilder.toString();
      }
    the following is the exception trace
    Caused by: java.lang.IllegalArgumentException: URI can't be null.
          at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:159)
          at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1145)
          at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1045)
          at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:978)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1561)
          at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1489)
          at java.net.URLConnection.getContent(URLConnection.java:762)
          at java.net.URL.getContent(URL.java:1071)
          at com..compcom.eis.HttpCall.callCICS(HttpCall.java:108)

` 如果我将web sphere jdk版本切换到java 6,上面的代码工作正常,不确定是否用java 8正确解释了URL字符串。 我需要一些帮助来找到这背后的原因,如果我不能用java 8进行http调用,我是否有任何其他选项可以进行http调用 以下是我的进口

0 个答案:

没有答案