kermitus
03-14-2006, 05:07 PM
I am trying to send an XML stream via POST, as of right now when I run this code I just get an error from the remote server saying that I sent the XML Stream via get. Anyone have an idea what I need to edit so the XML stream is sent via POST to the URL in the code I have listed here? The URL is after the response.sendRedirect tag. I am thinking I need to change the response.sendRedirect tag or add something to it. Earlier I was given a tip to try calling the doPost method of the servlet where I am trying to send the XML stream I.E.
Protected void doPost(HttpServletRequest request, HttpServletResponse response){
servletInstance.doPost(request,response);
}
However I am not exactly sure how to implement this code. Not sure I understand. If this is ideally what I need to do, can someone explain this please, I would certainly appreciate it. I am a student, so I don't understand everything yet, but I learn very quickly.
Thanks,
Corey C
The following code is copied and pasted directly from my NetBeans console.
/*
* JavaTest.java
*
* Created on March 11, 2006, 5:07 PM
*/
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author Corey
* @version
*/
public class JavaTest extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();
String test = "";
out.println("<?xml version=\"1.0\"?>");
out.println("<head>");
out.println("<title>Servlet JavaTest</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet JavaTest at " + request.getContextPath () + "</h1>");
test="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n "+
"- <Request version=\"2.0\" id=\"1234567899:1\" xmlns=\"http://names4ever.com/schema/PirinDN/2.0\ (http://names4ever.com/schema/PirinDN/2.0/)" xmlns:a=\"http://rodopi.com/schema/crm/rAL/1.0\ (http://rodopi.com/schema/crm/rAL/1.0/)" xmlns:b=\"http://rodopi.com/schema/pd/rBL/1.0\ (http://rodopi.com/schema/pd/rBL/1.0/)" xmlns:cc=\"http://rodopi.com/schema/crm/rCC/1.0\ (http://rodopi.com/schema/crm/rCC/1.0/)" xmlns:ci=\"http://rodopi.com/schema/crm/rCIL/1.0\ (http://rodopi.com/schema/crm/rCIL/1.0/)" xmlns:i=\"http://rodopi.com/schema/fr/rIL/1.0\ (http://rodopi.com/schema/fr/rIL/1.0/)" xmlns:n=\"http://rodopi.com/schema/crm/rNL/1.0\ (http://rodopi.com/schema/crm/rNL/1.0/)" xmlns:xsi=\"<A href="http://www.w3.org/2001/XMLSchema-instance/">/n" target=_blank>http://www.w3.org/2001/XMLSchema-instance\">\n"+
"- <Header>\n"+
"- <Security>\n"+
"- <UsernameToken>\n"+
" <Username Type=\"customerId\">1234567899</Username>\n "+
"<Password Type=\"text\">secret</Password>\n "+
" </UsernameToken>\n"+
" </Security>\n"+
" </Header>\n"+
"- <Body>\n"+
"- <CheckDomain>\n"+
" <domain name="+request.getParameter("textfield") + "."+ request.getParameter("select")+" />\n" +
" <suggestions>true</suggestions> \n"+
" </CheckDomain>\n"+
"</Body>\n"+
"</Request>\")\n";
out.println(request.getParameter("textfield") +"."+ request.getParameter("select"));
response.sendRedirect("<A title='http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test' href="http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test">http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test);
out.println("</body>");
out.println("</html>");
out.close();
}
------------------------------HTTP SERVLET METHODS-------------------
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
Protected void doPost(HttpServletRequest request, HttpServletResponse response){
servletInstance.doPost(request,response);
}
However I am not exactly sure how to implement this code. Not sure I understand. If this is ideally what I need to do, can someone explain this please, I would certainly appreciate it. I am a student, so I don't understand everything yet, but I learn very quickly.
Thanks,
Corey C
The following code is copied and pasted directly from my NetBeans console.
/*
* JavaTest.java
*
* Created on March 11, 2006, 5:07 PM
*/
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author Corey
* @version
*/
public class JavaTest extends HttpServlet {
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();
String test = "";
out.println("<?xml version=\"1.0\"?>");
out.println("<head>");
out.println("<title>Servlet JavaTest</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet JavaTest at " + request.getContextPath () + "</h1>");
test="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n "+
"- <Request version=\"2.0\" id=\"1234567899:1\" xmlns=\"http://names4ever.com/schema/PirinDN/2.0\ (http://names4ever.com/schema/PirinDN/2.0/)" xmlns:a=\"http://rodopi.com/schema/crm/rAL/1.0\ (http://rodopi.com/schema/crm/rAL/1.0/)" xmlns:b=\"http://rodopi.com/schema/pd/rBL/1.0\ (http://rodopi.com/schema/pd/rBL/1.0/)" xmlns:cc=\"http://rodopi.com/schema/crm/rCC/1.0\ (http://rodopi.com/schema/crm/rCC/1.0/)" xmlns:ci=\"http://rodopi.com/schema/crm/rCIL/1.0\ (http://rodopi.com/schema/crm/rCIL/1.0/)" xmlns:i=\"http://rodopi.com/schema/fr/rIL/1.0\ (http://rodopi.com/schema/fr/rIL/1.0/)" xmlns:n=\"http://rodopi.com/schema/crm/rNL/1.0\ (http://rodopi.com/schema/crm/rNL/1.0/)" xmlns:xsi=\"<A href="http://www.w3.org/2001/XMLSchema-instance/">/n" target=_blank>http://www.w3.org/2001/XMLSchema-instance\">\n"+
"- <Header>\n"+
"- <Security>\n"+
"- <UsernameToken>\n"+
" <Username Type=\"customerId\">1234567899</Username>\n "+
"<Password Type=\"text\">secret</Password>\n "+
" </UsernameToken>\n"+
" </Security>\n"+
" </Header>\n"+
"- <Body>\n"+
"- <CheckDomain>\n"+
" <domain name="+request.getParameter("textfield") + "."+ request.getParameter("select")+" />\n" +
" <suggestions>true</suggestions> \n"+
" </CheckDomain>\n"+
"</Body>\n"+
"</Request>\")\n";
out.println(request.getParameter("textfield") +"."+ request.getParameter("select"));
response.sendRedirect("<A title='http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test' href="http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test">http://pirin.names4ever.com/TestXAPI/Pirin2Test.exe?"+test);
out.println("</body>");
out.println("</html>");
out.close();
}
------------------------------HTTP SERVLET METHODS-------------------
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
