使用java下载WSDL文件

时间:2014-01-28 08:55:15

标签: java wsdl

我正在尝试编写一个接受URL的java程序,并从该URL Location下载WSDL文件。将该WSDL文件保存在我的本地系统中,扩展名为.xml 我在互联网上找到了很多程序,但它们没有用。它们显示错误消息Access denied contact Your Service Provider.
我需要在不使用任何IDE(Netbeans,Eclipse)的情况下下载文件。

任何人都可以帮助我吗?提前谢谢。

我的JAVA代码

import java.awt.FlowLayout;//Defines the layout
import java.io.*;//For input-output operations
import java.net.HttpURLConnection;//For making a connection
import java.net.URL;//Helps in making a URL object
import javax.swing.JFrame;//Helps in making Swing Frame
import javax.swing.JProgressBar;//Helps in implementing Progress Bar
public class Downloader extends JFrame  
{
public static final void main(String[] args) throws Exception
{
    String site="http://saudishipping.net/service.asmx?wsdl";
    String filename="saudi.xml";
    JFrame frm=new JFrame();
    JProgressBar current = new JProgressBar(0, 100);
    //We are setting the size of progress bar
    current.setSize(50,50);
    //Initially the progress bar will be zero%.
    current.setValue(0);
    current.setStringPainted(true);
    //Adding the progress bar to the frame
    frm.add(current);
    frm.setVisible(true);//Making the frame visible
    frm.setLayout(new FlowLayout());
    frm.setSize(400, 200);
    //EXIT_ON_CLOSE make sure that the application gets exited when frame close
    frm.setDefaultCloseOperation(EXIT_ON_CLOSE);
    try 
    {
        URL url=new URL(site);
        HttpURLConnection connection =(HttpURLConnection)  url.openConnection();
        int filesize = connection.getContentLength();
        float totalDataRead=0;
        java.io.BufferedInputStream in = new java.io.BufferedInputStream(connection.getInputStream());
        java.io.FileOutputStream fos = new java.io.FileOutputStream(filename);
        java.io.BufferedOutputStream bout = new  BufferedOutputStream(fos,1024);
        byte[] data = new byte[1024];
        int i=0;
        while((i=in.read(data,0,1024))>=0)
        {
            totalDataRead=totalDataRead+i;
            bout.write(data,0,i); 
            float Percent=(totalDataRead*100)/filesize;
            current.setValue((int)Percent);
        }
        bout.close();
        in.close();
    }
    catch(Exception e)
    { 
  javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)null,e.getMessage(),   "Error",javax.swing.JOptionPane.DEFAULT_OPTION);
    }
  }
  }

1 个答案:

答案 0 :(得分:1)

当您通过浏览器时,网址http://saudishipping.net/service.asmx?wsdl是否显示在浏览器中?据我所知,它没有。所以我的猜测是地址可能不正确或者网络服务在给定网址上不可用。