URLConnection的FileNotFoundException异常非标准HTTP端口源 [英] URLConnection FileNotFoundException for non-standard HTTP port sources

查看:158
本文介绍了URLConnection的FileNotFoundException异常非标准HTTP端口源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Apache Ant的 获取任务获得由另一个团队在我们公司生成的WSDL列表。他们有他们的托管在WebLogic 9.x的服务器上 HTTP://....com:7925 /服务/ 。我能够通过浏览器去的页面,但获取任务让我尝试到页面复制到本地文件解析的时候出现FileNotFoundException。我仍然能够得到(使用ant任务)的URL没有非标准端口80用于HTTP。

我经历了蚁源$ C ​​$ C观看,缩小误差下降到URLConnection的。它好像在URLConnection的不承认该数据是HTTP流量,因为它不是标准的端口上,即使协议指定为HTTP。我闻使用Wireshark的,并在页面加载正确跨线交通,但仍得到FileNotFoundException异常。

下面是一个例子,你会看到错误(用URL变更为保护无辜者)。该错误是扔在 connection.getInputStream();

 进口的java.io.File;
进口的java.io.InputStream;
进口的java.net.URL;
进口java.net.URLConnection中;    公共类TestGet {
    私有静态URL来源;
    公共静态无效的主要(字串[] args){
        的doGet();
    }
    公共静态无效的doGet(){
            尝试{
            来源=新的URL(HTTP,test.com,7925,
                    /services/index.html);
            URLConnection的连接= source.openConnection();
            connection.connect();
            InputStream为= connection.getInputStream();
        }赶上(例外五){
            通信System.err.println(e.toString());
        }
    }}


解决方案

检查响应code正在由服务器返回

I was trying to use the Apache Ant Get task to get a list of WSDLs generated by another team in our company. They have them hosted on a weblogic 9.x server on http://....com:7925/services/. I am able to get to the page through a browser, but the get task gives me a FileNotFoundException when trying to copy the page to a local file to parse. I was still able to get (using the ant task) a URL without the non-standard port 80 for HTTP.

I looked through the Ant source code, and narrowed the error down to the URLConnection. It seems as though the URLConnection doesn't recognize the data is HTTP traffic, since it isn't on the standard port, even though the protocol is specified as HTTP. I sniffed the traffic using WireShark and the page loads correctly across the wire, but still gets the FileNotFoundException.

Here's an example where you will see the error (with the URL changed to protect the innocent). The error is thrown on connection.getInputStream();

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

    public class TestGet {
    private static URL source; 
    public static void main(String[] args) {
        doGet();
    }
    public static void doGet() {
            try {
            source = new URL("http", "test.com", 7925,
                    "/services/index.html");
            URLConnection connection = source.openConnection();
            connection.connect();
            InputStream is = connection.getInputStream();
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

}

解决方案

check the response code being returned by the server

这篇关于URLConnection的FileNotFoundException异常非标准HTTP端口源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆