简体   繁体   中英

Download WSDL file using java

I am trying to write a java program that accepts the URL and download the WSDL File from that URL Location. Save that WSDL file in my local system with .xml extension.
I've found many programs in the Internet but they are not working. They display the error message Access denied contact Your Service Provider.
I need to download the file without using any IDEs(Netbeans, Eclipse).

Can anyone help me? Thanks in advance.

MY JAVA CODE

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);
    }
  }
  }

Is the url http://saudishipping.net/service.asmx?wsdl displaying anything in the browser when you past it? As far as I can see it doesn't. So my guess is the address might be incorrect or the webservice is not available on the given url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM