Can I create XML file outside of my local network?

Hi, all

As the requirements, my server need pass a xml file to the customer server. It means my server will write a xml file to the customer's machine. My server have parsed a customer xml file by given url like "http://..../thexml.xml". Now the servere will pass the result in a xml type. If the customer gives a url in http or ftp. Can I do that?

Thanks in advance.

[394 byte] By [Oytan022] at [2007-9-26 7:46:19]
# 1

Hai,

One of the approach that you can follow is that, you can create a client side program on your end. Write a servlet that listens on your client machine. Make a URLConnection from your machine to the servlet and pass the xml file.

Client code

--

URL url = new URL("http://XXXXXXXX");

System.out.println("Opening Connection");

HttpURLConnection uc = (HttpURLConnection)url.openConnection();

System.out.println("Connection Opened");

if (!uc.getDoOutput())

{

uc.setDoOutput( true );

}

if (!uc.getDoInput())

{

uc.setDoInput( true );

}

uc.setRequestMethod( "POST" );

uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

uc.setRequestProperty( "Cache-Control", "no-cache" );

create an output stream and write data to it

create an input stream to receive data from servlet.

Servlet

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{

InputStreamReader istream = new InputStreamReader(request.getInputStream());

int c;

String readStr = "";

while ((c = (int)istream.read()) != -1)

{

System.out.print((char)c);

readStr += (char)c;

}

istream.close();

com.ls.staff.XMLConverter converter = new com.ls.staff.XMLConverter();

try

{

converter.parse(readStr);

}

catch(Exception e)

{

e.printStackTrace();

}

response.setContentType("text/html; charset=WINDOWS-1252");

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<head>");

out.println("<title>ConnectionServlet</title>");

out.println("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=WINDOWS-1252\">");

out.println("</head>");

out.println("<body>");

out.println("</body></html>");

out.close();

}

Hope this code help you.

sesetty at 2007-7-1 17:54:56 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...