jiangjixiangjava 2017-08-07 03:34 采纳率: 100%
浏览 1692
已采纳

HttpClient请求问题

这是报错日志
Caused by: java.io.FileNotFoundException: D:\hdm\lh\hbiparent\core\target\core\META-INF\context.xml (系统找不到指定的文件。)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at org.jetbrains.idea.tomcat.TomcatUtil.loadXMLFile(TomcatUtil.java:205)
... 28 moreeManager.jar
2017-08-07 11:07:16,381 [2438700] INFO - ij.compiler.impl.CompileDriver - COMPILATION STARTED (BUILD PROCESS)
2017-08-07 11:07:16,389 [2438708] INFO - j.compiler.server.BuildManager - Using preloaded build process to compile D:\hdm\lh\hbiparent
2017-08-07 11:07:16,764 [2439083] INFO - .server.BuildMessageDispatcher - 远程主机强迫关闭了一个现有的连接。
java.io.IOException: 远程主机强迫关闭了一个现有的连接。

这是代码
public Map getSessionId(String userid )
{
String token = null;
String sessionId = null;
http = new DefaultHttpClient();
try {

        String url = LOGINURL + "&username=" + userid;

        HttpPost post = new HttpPost(url);

        // post.setHeader("HYPLOGIN", userid);
        HttpResponse response = http.execute(post);
        BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer result = new StringBuffer();
        String line;
        while ((line = br.readLine()) != null) {
            result.append(line);
        }
        String string = result.toString();
        // System.out.println(string);
        string = string.substring(0, 2500);
        // System.out.println(string);

        String regex = "sToken.*=.*\"(.+?)\";.*sCSRFToken";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(string);
        while (matcher.find()) {
            token = matcher.group(1);
        }
        post.abort();

        // String mtoken = token.replace("\\n", "\\\n") + "=";
        // System.out.println(mtoken);

        HttpPost posthttp = new HttpPost(HTTPURL);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("Application", "FYCWYS"));
        nvps.add(new BasicNameValuePair("isContained", "true"));
        nvps.add(new BasicNameValuePair("isWorkspace", "true"));
        nvps.add(new BasicNameValuePair("LOCALE_LANGUAGE", "zh_CN"));
        nvps.add(new BasicNameValuePair("moduleid", "HyperionPlanning.planning.7"));
        nvps.add(new BasicNameValuePair("themeSelection", "BpmTadpole"));
        nvps.add(new BasicNameValuePair("upk_available", "false"));
        String mtoken = token.replace("\\n", "\\\n") + "=";
        nvps.add(new BasicNameValuePair("sso_token", mtoken));
        posthttp.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse responseSession = http.execute(posthttp);

        posthttp.abort();
        Header[] headers = responseSession.getHeaders("Set-Cookie");
        for (Header header : headers) {
            if (header.toString().contains("SESSIONID")) {
                String str = header.toString();
                // String reg = "Cookie:(.+?);.*path";
                String reg = "JSESSIONID=(.+?);.*path";
                Pattern pattern = Pattern.compile(reg);
                Matcher m = pattern.matcher(str);
                while (m.find()) {
                    sessionId = m.group(1).trim();
                }
            }
        }
        System.out.println(sessionId);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedOperationException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(sessionId);
    Map<String, String> map = new HashMap<>();
     map.put("sessionId",sessionId);


    return map;
  • 写回答

5条回答 默认 最新

  • 王搏 2017-08-07 10:10
    关注

    可能原因是 你在项目设置里导包 Tomcat启动失败 是因为你没在项目目录里把包放进去

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 博通raid 的写入速度很高也很低