Hi Everybody,
I have to post an XML file from an Java Application to an intranet site.
The posting program is knows as transmit
and the receving program is receptor.
Can anyone please help me with this ? I need urgently. The XML file is not
getting posted at all.
TRANMIT - to push the XML data
public class transmit extends Object {
/**
* Constructor
*/
public void tranmit()
{
} //end of the contructor
/**
* Constructor
*/
public void pushAlert(String p_strFileName)
{
String strInput = "";
String strLine = "";
try
{
BufferedReader bufin = new BufferedReader(new
FileReader(p_strFileName));
while((strLine = bufin.readLine()) != null)
strInput = strInput + strLine;
System.out.println("The line should be " + strInput);
bufin.close();
//open the URL
URL urlcm = new
URL("http://development/servercon/servlet/receptor.jsp");
HttpURLConnection httpurlcm =
(HttpURLConnection)(urlcm.openConnection());
httpurlcm.setRequestMethod("POST");
httpurlcm.setRequestProperty("Content-Type", "text/xml;
charset=\"utf-8\"");
httpurlcm.setDoOutput(true);
OutputStreamWriter out = new
OutputStreamWriter(httpurlcm.getOutputStream(),"UTF8");
out.write(strInput);
out.close();
}
catch (Exception e)
{
System.out.println("exception Caught " + e);
}
} //end of the pushAlert
}
The Receptor.java is on the application server is :-
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class receptor extends HttpServlet {
/**
* Initialize global variables
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**
* Process the HTTP Get request
*/
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
String strInput = "";
String strLine = "";
//read from the request file.
BufferedReader bufreq = (BufferedReader) request.getReader();
while((strLine = bufreq.readLine()) != null)
strInput = strInput + strLine;
//System.out.println("The line should be " + strInput);
bufreq.close();
response.setContentType("text/html; charset=WINDOWS-1252");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>receptor</title>");
out.println("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;
charset=WINDOWS-1252\">");
out.println("</head>");
out.println("<body>Hello From receptor doGet()");
out.println(strInput);
out.println("</body></html>");
out.close();
}
/**
* Process the HTTP Post request
*/
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doGet(request,response);
/* response.setContentType("text/html; charset=WINDOWS-1252");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>receptor</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();*/
}
/**
* Get Servlet information
* @return java.lang.String
*/
public String getServletInfo() {
return "com.cm.servlets.receptor Information";
}
}
If anybody could help with that.
Urgently required.
Nazneen Nahid
* Phone 518-612-6826 DialComm *8-222-6826
* E-Mail mailto:[EMAIL PROTECTED]
Visit TCS at: http://www.tcs.com
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm